src/audio/ums/SDL_umsaudio.c
author Sam Lantinga <slouken@libsdl.org>
Sun, 24 Sep 2006 00:55:19 +0000
changeset 2041 4a32d186f35b
parent 1982 3b4ce57c6215
child 2049 5f6550e5184f
child 3798 c8b3d3d13ed1
permissions -rw-r--r--
Fixed bug #316
Looks like this is a long standing typo... is this code even used anymore?
slouken@0
     1
/*
slouken@1312
     2
    SDL - Simple DirectMedia Layer
slouken@1312
     3
    Copyright (C) 1997-2006 Sam Lantinga
slouken@0
     4
slouken@0
     5
    This library is free software; you can redistribute it and/or
slouken@1312
     6
    modify it under the terms of the GNU Lesser General Public
slouken@0
     7
    License as published by the Free Software Foundation; either
slouken@1312
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@0
     9
slouken@0
    10
    This library is distributed in the hope that it will be useful,
slouken@0
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@0
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1312
    13
    Lesser General Public License for more details.
slouken@0
    14
slouken@1312
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1312
    16
    License along with this library; if not, write to the Free Software
slouken@1312
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@0
    18
slouken@0
    19
    Carsten Griwodz
slouken@0
    20
    griff@kom.tu-darmstadt.de
slouken@0
    21
slouken@0
    22
    based on linux/SDL_dspaudio.c by Sam Lantinga
slouken@0
    23
*/
slouken@1402
    24
#include "SDL_config.h"
slouken@0
    25
slouken@0
    26
/* Allow access to a raw mixing buffer */
slouken@0
    27
slouken@0
    28
#include <errno.h>
slouken@0
    29
#include <unistd.h>
slouken@0
    30
#include <fcntl.h>
slouken@0
    31
#include <sys/types.h>
slouken@0
    32
#include <sys/time.h>
slouken@0
    33
#include <sys/ioctl.h>
slouken@0
    34
#include <sys/stat.h>
slouken@0
    35
#include <sys/mman.h>
slouken@0
    36
slouken@0
    37
#include "SDL_audio.h"
slouken@1361
    38
#include "../SDL_audio_c.h"
slouken@1361
    39
#include "../SDL_audiodev_c.h"
slouken@0
    40
#include "SDL_umsaudio.h"
slouken@0
    41
slouken@0
    42
/* The tag name used by UMS audio */
slouken@0
    43
#define UMS_DRIVER_NAME         "ums"
slouken@0
    44
slouken@0
    45
#define DEBUG_AUDIO 1
slouken@0
    46
slouken@0
    47
/* Audio driver functions */
slouken@1895
    48
static int UMS_OpenAudio(_THIS, SDL_AudioSpec * spec);
slouken@0
    49
static void UMS_PlayAudio(_THIS);
slouken@0
    50
static Uint8 *UMS_GetAudioBuf(_THIS);
slouken@0
    51
static void UMS_CloseAudio(_THIS);
slouken@0
    52
slouken@1895
    53
static UMSAudioDevice_ReturnCode UADOpen(_THIS, string device, string mode,
slouken@1895
    54
                                         long flags);
slouken@0
    55
static UMSAudioDevice_ReturnCode UADClose(_THIS);
slouken@1895
    56
static UMSAudioDevice_ReturnCode UADGetBitsPerSample(_THIS, long *bits);
slouken@0
    57
static UMSAudioDevice_ReturnCode UADSetBitsPerSample(_THIS, long bits);
slouken@1895
    58
static UMSAudioDevice_ReturnCode UADSetSampleRate(_THIS, long rate,
slouken@1895
    59
                                                  long *set_rate);
slouken@0
    60
static UMSAudioDevice_ReturnCode UADSetByteOrder(_THIS, string byte_order);
slouken@0
    61
static UMSAudioDevice_ReturnCode UADSetAudioFormatType(_THIS, string fmt);
slouken@0
    62
static UMSAudioDevice_ReturnCode UADSetNumberFormat(_THIS, string fmt);
slouken@0
    63
static UMSAudioDevice_ReturnCode UADInitialize(_THIS);
slouken@0
    64
static UMSAudioDevice_ReturnCode UADStart(_THIS);
slouken@0
    65
static UMSAudioDevice_ReturnCode UADStop(_THIS);
slouken@1895
    66
static UMSAudioDevice_ReturnCode UADSetTimeFormat(_THIS,
slouken@1895
    67
                                                  UMSAudioTypes_TimeFormat
slouken@1895
    68
                                                  fmt);
slouken@1895
    69
static UMSAudioDevice_ReturnCode UADWriteBuffSize(_THIS, long *buff_size);
slouken@1895
    70
static UMSAudioDevice_ReturnCode UADWriteBuffRemain(_THIS, long *buff_size);
slouken@1895
    71
static UMSAudioDevice_ReturnCode UADWriteBuffUsed(_THIS, long *buff_size);
slouken@1895
    72
static UMSAudioDevice_ReturnCode UADSetDMABufferSize(_THIS, long bytes,
slouken@1895
    73
                                                     long *bytes_ret);
slouken@1895
    74
static UMSAudioDevice_ReturnCode UADSetVolume(_THIS, long volume);
slouken@1895
    75
static UMSAudioDevice_ReturnCode UADSetBalance(_THIS, long balance);
slouken@1895
    76
static UMSAudioDevice_ReturnCode UADSetChannels(_THIS, long channels);
slouken@1895
    77
static UMSAudioDevice_ReturnCode UADPlayRemainingData(_THIS, boolean block);
slouken@1895
    78
static UMSAudioDevice_ReturnCode UADEnableOutput(_THIS, string output,
slouken@1895
    79
                                                 long *left_gain,
slouken@1895
    80
                                                 long *right_gain);
slouken@1895
    81
static UMSAudioDevice_ReturnCode UADWrite(_THIS, UMSAudioTypes_Buffer * buff,
slouken@1895
    82
                                          long samples,
slouken@1895
    83
                                          long *samples_written);
slouken@0
    84
slouken@0
    85
/* Audio driver bootstrap functions */
slouken@1895
    86
static int
slouken@1895
    87
Audio_Available(void)
slouken@0
    88
{
slouken@0
    89
    return 1;
slouken@0
    90
}
slouken@0
    91
slouken@1895
    92
static void
slouken@1895
    93
Audio_DeleteDevice(_THIS)
slouken@0
    94
{
slouken@1895
    95
    if (this->hidden->playbuf._buffer)
slouken@1895
    96
        SDL_free(this->hidden->playbuf._buffer);
slouken@1895
    97
    if (this->hidden->fillbuf._buffer)
slouken@1895
    98
        SDL_free(this->hidden->fillbuf._buffer);
slouken@1895
    99
    _somFree(this->hidden->umsdev);
slouken@1336
   100
    SDL_free(this->hidden);
slouken@1336
   101
    SDL_free(this);
slouken@0
   102
}
slouken@0
   103
slouken@1895
   104
static SDL_AudioDevice *
slouken@1895
   105
Audio_CreateDevice(int devindex)
slouken@0
   106
{
slouken@0
   107
    SDL_AudioDevice *this;
slouken@0
   108
slouken@0
   109
    /*
slouken@0
   110
     * Allocate and initialize management storage and private management
slouken@0
   111
     * storage for this SDL-using library.
slouken@0
   112
     */
slouken@1895
   113
    this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice));
slouken@1895
   114
    if (this) {
slouken@1336
   115
        SDL_memset(this, 0, (sizeof *this));
slouken@1895
   116
        this->hidden = (struct SDL_PrivateAudioData *)
slouken@1895
   117
            SDL_malloc((sizeof *this->hidden));
slouken@0
   118
    }
slouken@1895
   119
    if ((this == NULL) || (this->hidden == NULL)) {
slouken@0
   120
        SDL_OutOfMemory();
slouken@1895
   121
        if (this) {
slouken@1336
   122
            SDL_free(this);
slouken@0
   123
        }
slouken@1895
   124
        return (0);
slouken@0
   125
    }
slouken@1336
   126
    SDL_memset(this->hidden, 0, (sizeof *this->hidden));
slouken@0
   127
#ifdef DEBUG_AUDIO
slouken@0
   128
    fprintf(stderr, "Creating UMS Audio device\n");
slouken@0
   129
#endif
slouken@0
   130
slouken@0
   131
    /*
slouken@0
   132
     * Calls for UMS env initialization and audio object construction.
slouken@0
   133
     */
slouken@1895
   134
    this->hidden->ev = somGetGlobalEnvironment();
slouken@0
   135
    this->hidden->umsdev = UMSAudioDeviceNew();
slouken@0
   136
slouken@0
   137
    /*
slouken@0
   138
     * Set the function pointers.
slouken@0
   139
     */
slouken@1895
   140
    this->OpenAudio = UMS_OpenAudio;
slouken@1895
   141
    this->WaitAudio = NULL;     /* we do blocking output */
slouken@1895
   142
    this->PlayAudio = UMS_PlayAudio;
slouken@0
   143
    this->GetAudioBuf = UMS_GetAudioBuf;
slouken@1895
   144
    this->CloseAudio = UMS_CloseAudio;
slouken@1895
   145
    this->free = Audio_DeleteDevice;
slouken@0
   146
slouken@0
   147
#ifdef DEBUG_AUDIO
slouken@0
   148
    fprintf(stderr, "done\n");
slouken@0
   149
#endif
slouken@0
   150
    return this;
slouken@0
   151
}
slouken@0
   152
slouken@0
   153
AudioBootStrap UMS_bootstrap = {
slouken@2041
   154
    UMS_DRIVER_NAME, "AIX UMS audio",
slouken@1895
   155
    Audio_Available, Audio_CreateDevice
slouken@0
   156
};
slouken@0
   157
slouken@1895
   158
static Uint8 *
slouken@1895
   159
UMS_GetAudioBuf(_THIS)
slouken@0
   160
{
slouken@0
   161
#ifdef DEBUG_AUDIO
slouken@0
   162
    fprintf(stderr, "enter UMS_GetAudioBuf\n");
slouken@0
   163
#endif
slouken@0
   164
    return this->hidden->fillbuf._buffer;
slouken@0
   165
/*
slouken@0
   166
    long                      bufSize;
slouken@0
   167
    UMSAudioDevice_ReturnCode rc;
slouken@0
   168
slouken@0
   169
    rc = UADSetTimeFormat(this, UMSAudioTypes_Bytes );
slouken@0
   170
    rc = UADWriteBuffSize(this,  bufSize );
slouken@0
   171
*/
slouken@0
   172
}
slouken@0
   173
slouken@1895
   174
static void
slouken@1895
   175
UMS_CloseAudio(_THIS)
slouken@0
   176
{
slouken@0
   177
    UMSAudioDevice_ReturnCode rc;
slouken@0
   178
slouken@0
   179
#ifdef DEBUG_AUDIO
slouken@0
   180
    fprintf(stderr, "enter UMS_CloseAudio\n");
slouken@0
   181
#endif
slouken@0
   182
    rc = UADPlayRemainingData(this, TRUE);
slouken@0
   183
    rc = UADStop(this);
slouken@0
   184
    rc = UADClose(this);
slouken@0
   185
}
slouken@0
   186
slouken@1895
   187
static void
slouken@1895
   188
UMS_PlayAudio(_THIS)
slouken@0
   189
{
slouken@0
   190
    UMSAudioDevice_ReturnCode rc;
slouken@1895
   191
    long samplesToWrite;
slouken@1895
   192
    long samplesWritten;
slouken@1895
   193
    UMSAudioTypes_Buffer swpbuf;
slouken@0
   194
slouken@0
   195
#ifdef DEBUG_AUDIO
slouken@0
   196
    fprintf(stderr, "enter UMS_PlayAudio\n");
slouken@0
   197
#endif
slouken@1895
   198
    samplesToWrite =
slouken@1895
   199
        this->hidden->playbuf._length / this->hidden->bytesPerSample;
slouken@1895
   200
    do {
slouken@1895
   201
        rc = UADWrite(this, &this->hidden->playbuf,
slouken@1895
   202
                      samplesToWrite, &samplesWritten);
slouken@1895
   203
        samplesToWrite -= samplesWritten;
slouken@0
   204
slouken@1895
   205
        /* rc values: UMSAudioDevice_Success
slouken@1895
   206
         *            UMSAudioDevice_Failure
slouken@1895
   207
         *            UMSAudioDevice_Preempted
slouken@1895
   208
         *            UMSAudioDevice_Interrupted
slouken@1895
   209
         *            UMSAudioDevice_DeviceError
slouken@1895
   210
         */
slouken@1895
   211
        if (rc == UMSAudioDevice_DeviceError) {
slouken@0
   212
#ifdef DEBUG_AUDIO
slouken@1895
   213
            fprintf(stderr, "Returning from PlayAudio with devices error\n");
slouken@0
   214
#endif
slouken@1895
   215
            return;
slouken@1895
   216
        }
slouken@0
   217
    }
slouken@1895
   218
    while (samplesToWrite > 0);
slouken@0
   219
slouken@0
   220
    SDL_LockAudio();
slouken@1895
   221
    SDL_memcpy(&swpbuf, &this->hidden->playbuf, sizeof(UMSAudioTypes_Buffer));
slouken@1895
   222
    SDL_memcpy(&this->hidden->playbuf, &this->hidden->fillbuf,
slouken@1895
   223
               sizeof(UMSAudioTypes_Buffer));
slouken@1895
   224
    SDL_memcpy(&this->hidden->fillbuf, &swpbuf, sizeof(UMSAudioTypes_Buffer));
slouken@0
   225
    SDL_UnlockAudio();
slouken@0
   226
slouken@0
   227
#ifdef DEBUG_AUDIO
slouken@0
   228
    fprintf(stderr, "Wrote audio data and swapped buffer\n");
slouken@0
   229
#endif
slouken@0
   230
}
slouken@0
   231
slouken@0
   232
#if 0
slouken@1895
   233
//      /* Set the DSP frequency */
slouken@1895
   234
//      value = spec->freq;
slouken@1895
   235
//      if ( ioctl(this->hidden->audio_fd, SOUND_PCM_WRITE_RATE, &value) < 0 ) {
slouken@1895
   236
//              SDL_SetError("Couldn't set audio frequency");
slouken@1895
   237
//              return(-1);
slouken@1895
   238
//      }
slouken@1895
   239
//      spec->freq = value;
slouken@0
   240
#endif
slouken@0
   241
slouken@1895
   242
static int
slouken@1895
   243
UMS_OpenAudio(_THIS, SDL_AudioSpec * spec)
slouken@0
   244
{
slouken@1895
   245
    char *audiodev = "/dev/paud0";
slouken@1895
   246
    long lgain;
slouken@1895
   247
    long rgain;
slouken@1895
   248
    long outRate;
slouken@1895
   249
    long outBufSize;
slouken@1895
   250
    long bitsPerSample;
slouken@1895
   251
    long samplesPerSec;
slouken@1895
   252
    long success;
icculus@1982
   253
    SDL_AudioFormat test_format;
slouken@1895
   254
    int frag_spec;
slouken@0
   255
    UMSAudioDevice_ReturnCode rc;
slouken@0
   256
slouken@0
   257
#ifdef DEBUG_AUDIO
slouken@0
   258
    fprintf(stderr, "enter UMS_OpenAudio\n");
slouken@0
   259
#endif
slouken@1895
   260
    rc = UADOpen(this, audiodev, "PLAY", UMSAudioDevice_BlockingIO);
slouken@1895
   261
    if (rc != UMSAudioDevice_Success) {
slouken@1895
   262
        SDL_SetError("Couldn't open %s: %s", audiodev, strerror(errno));
slouken@1895
   263
        return -1;
slouken@0
   264
    }
slouken@1895
   265
slouken@1895
   266
    rc = UADSetAudioFormatType(this, "PCM");
slouken@0
   267
slouken@0
   268
    success = 0;
slouken@0
   269
    test_format = SDL_FirstAudioFormat(spec->format);
slouken@1895
   270
    do {
slouken@0
   271
#ifdef DEBUG_AUDIO
slouken@0
   272
        fprintf(stderr, "Trying format 0x%4.4x\n", test_format);
slouken@0
   273
#endif
slouken@1895
   274
        switch (test_format) {
slouken@0
   275
        case AUDIO_U8:
slouken@0
   276
/* from the mac code: better ? */
slouken@0
   277
/* sample_bits = spec->size / spec->samples / spec->channels * 8; */
slouken@1895
   278
            success = 1;
slouken@0
   279
            bitsPerSample = 8;
slouken@1895
   280
            rc = UADSetSampleRate(this, spec->freq << 16, &outRate);
slouken@1895
   281
            rc = UADSetByteOrder(this, "MSB");  /* irrelevant */
slouken@0
   282
            rc = UADSetNumberFormat(this, "UNSIGNED");
slouken@0
   283
            break;
slouken@0
   284
        case AUDIO_S8:
slouken@1895
   285
            success = 1;
slouken@0
   286
            bitsPerSample = 8;
slouken@1895
   287
            rc = UADSetSampleRate(this, spec->freq << 16, &outRate);
slouken@1895
   288
            rc = UADSetByteOrder(this, "MSB");  /* irrelevant */
slouken@0
   289
            rc = UADSetNumberFormat(this, "SIGNED");
slouken@0
   290
            break;
slouken@0
   291
        case AUDIO_S16LSB:
slouken@1895
   292
            success = 1;
slouken@0
   293
            bitsPerSample = 16;
slouken@1895
   294
            rc = UADSetSampleRate(this, spec->freq << 16, &outRate);
slouken@0
   295
            rc = UADSetByteOrder(this, "LSB");
slouken@0
   296
            rc = UADSetNumberFormat(this, "SIGNED");
slouken@0
   297
            break;
slouken@0
   298
        case AUDIO_S16MSB:
slouken@1895
   299
            success = 1;
slouken@0
   300
            bitsPerSample = 16;
slouken@1895
   301
            rc = UADSetSampleRate(this, spec->freq << 16, &outRate);
slouken@0
   302
            rc = UADSetByteOrder(this, "MSB");
slouken@0
   303
            rc = UADSetNumberFormat(this, "SIGNED");
slouken@0
   304
            break;
slouken@0
   305
        case AUDIO_U16LSB:
slouken@1895
   306
            success = 1;
slouken@0
   307
            bitsPerSample = 16;
slouken@1895
   308
            rc = UADSetSampleRate(this, spec->freq << 16, &outRate);
slouken@0
   309
            rc = UADSetByteOrder(this, "LSB");
slouken@0
   310
            rc = UADSetNumberFormat(this, "UNSIGNED");
slouken@0
   311
            break;
slouken@0
   312
        case AUDIO_U16MSB:
slouken@1895
   313
            success = 1;
slouken@0
   314
            bitsPerSample = 16;
slouken@1895
   315
            rc = UADSetSampleRate(this, spec->freq << 16, &outRate);
slouken@0
   316
            rc = UADSetByteOrder(this, "MSB");
slouken@0
   317
            rc = UADSetNumberFormat(this, "UNSIGNED");
slouken@0
   318
            break;
slouken@0
   319
        default:
slouken@0
   320
            break;
slouken@0
   321
        }
slouken@1895
   322
        if (!success) {
slouken@0
   323
            test_format = SDL_NextAudioFormat();
slouken@0
   324
        }
slouken@0
   325
    }
slouken@1895
   326
    while (!success && test_format);
slouken@0
   327
slouken@1895
   328
    if (success == 0) {
slouken@0
   329
        SDL_SetError("Couldn't find any hardware audio formats");
slouken@0
   330
        return -1;
slouken@0
   331
    }
slouken@0
   332
slouken@0
   333
    spec->format = test_format;
slouken@0
   334
slouken@1895
   335
    for (frag_spec = 0; (0x01 << frag_spec) < spec->size; ++frag_spec);
slouken@1895
   336
    if ((0x01 << frag_spec) != spec->size) {
slouken@0
   337
        SDL_SetError("Fragment size must be a power of two");
slouken@0
   338
        return -1;
slouken@0
   339
    }
slouken@1895
   340
    if (frag_spec > 2048)
slouken@1895
   341
        frag_spec = 2048;
slouken@0
   342
slouken@1895
   343
    this->hidden->bytesPerSample = (bitsPerSample / 8) * spec->channels;
slouken@1895
   344
    samplesPerSec = this->hidden->bytesPerSample * outRate;
slouken@0
   345
slouken@1895
   346
    this->hidden->playbuf._length = 0;
slouken@0
   347
    this->hidden->playbuf._maximum = spec->size;
slouken@1895
   348
    this->hidden->playbuf._buffer = (unsigned char *) SDL_malloc(spec->size);
slouken@1895
   349
    this->hidden->fillbuf._length = 0;
slouken@0
   350
    this->hidden->fillbuf._maximum = spec->size;
slouken@1895
   351
    this->hidden->fillbuf._buffer = (unsigned char *) SDL_malloc(spec->size);
slouken@0
   352
slouken@1895
   353
    rc = UADSetBitsPerSample(this, bitsPerSample);
slouken@1895
   354
    rc = UADSetDMABufferSize(this, frag_spec, &outBufSize);
slouken@1895
   355
    rc = UADSetChannels(this, spec->channels);  /* functions reduces to mono or stereo */
slouken@0
   356
slouken@1895
   357
    lgain = 100;                /*maximum left input gain */
slouken@1895
   358
    rgain = 100;                /*maimum right input gain */
slouken@1895
   359
    rc = UADEnableOutput(this, "LINE_OUT", &lgain, &rgain);
slouken@0
   360
    rc = UADInitialize(this);
slouken@0
   361
    rc = UADStart(this);
slouken@0
   362
    rc = UADSetVolume(this, 100);
slouken@0
   363
    rc = UADSetBalance(this, 0);
slouken@0
   364
slouken@0
   365
    /* We're ready to rock and roll. :-) */
slouken@0
   366
    return 0;
slouken@0
   367
}
slouken@1895
   368

slouken@0
   369
slouken@1895
   370
static UMSAudioDevice_ReturnCode
slouken@1895
   371
UADGetBitsPerSample(_THIS, long *bits)
slouken@0
   372
{
slouken@1895
   373
    return UMSAudioDevice_get_bits_per_sample(this->hidden->umsdev,
slouken@1895
   374
                                              this->hidden->ev, bits);
slouken@0
   375
}
slouken@0
   376
slouken@1895
   377
static UMSAudioDevice_ReturnCode
slouken@1895
   378
UADSetBitsPerSample(_THIS, long bits)
slouken@0
   379
{
slouken@1895
   380
    return UMSAudioDevice_set_bits_per_sample(this->hidden->umsdev,
slouken@1895
   381
                                              this->hidden->ev, bits);
slouken@0
   382
}
slouken@0
   383
slouken@1895
   384
static UMSAudioDevice_ReturnCode
slouken@1895
   385
UADSetSampleRate(_THIS, long rate, long *set_rate)
slouken@0
   386
{
slouken@0
   387
    /* from the mac code: sample rate = spec->freq << 16; */
slouken@1895
   388
    return UMSAudioDevice_set_sample_rate(this->hidden->umsdev,
slouken@1895
   389
                                          this->hidden->ev, rate, set_rate);
slouken@0
   390
}
slouken@0
   391
slouken@1895
   392
static UMSAudioDevice_ReturnCode
slouken@1895
   393
UADSetByteOrder(_THIS, string byte_order)
slouken@0
   394
{
slouken@1895
   395
    return UMSAudioDevice_set_byte_order(this->hidden->umsdev,
slouken@1895
   396
                                         this->hidden->ev, byte_order);
slouken@0
   397
}
slouken@0
   398
slouken@1895
   399
static UMSAudioDevice_ReturnCode
slouken@1895
   400
UADSetAudioFormatType(_THIS, string fmt)
slouken@0
   401
{
slouken@0
   402
    /* possible PCM, A_LAW or MU_LAW */
slouken@1895
   403
    return UMSAudioDevice_set_audio_format_type(this->hidden->umsdev,
slouken@1895
   404
                                                this->hidden->ev, fmt);
slouken@0
   405
}
slouken@0
   406
slouken@1895
   407
static UMSAudioDevice_ReturnCode
slouken@1895
   408
UADSetNumberFormat(_THIS, string fmt)
slouken@0
   409
{
slouken@0
   410
    /* possible SIGNED, UNSIGNED, or TWOS_COMPLEMENT */
slouken@1895
   411
    return UMSAudioDevice_set_number_format(this->hidden->umsdev,
slouken@1895
   412
                                            this->hidden->ev, fmt);
slouken@0
   413
}
slouken@0
   414
slouken@1895
   415
static UMSAudioDevice_ReturnCode
slouken@1895
   416
UADInitialize(_THIS)
slouken@0
   417
{
slouken@1895
   418
    return UMSAudioDevice_initialize(this->hidden->umsdev, this->hidden->ev);
slouken@0
   419
}
slouken@0
   420
slouken@1895
   421
static UMSAudioDevice_ReturnCode
slouken@1895
   422
UADStart(_THIS)
slouken@0
   423
{
slouken@1895
   424
    return UMSAudioDevice_start(this->hidden->umsdev, this->hidden->ev);
slouken@0
   425
}
slouken@0
   426
slouken@1895
   427
static UMSAudioDevice_ReturnCode
slouken@1895
   428
UADSetTimeFormat(_THIS, UMSAudioTypes_TimeFormat fmt)
slouken@0
   429
{
slouken@0
   430
    /*
slouken@0
   431
     * Switches the time format to the new format, immediately.
slouken@0
   432
     * possible UMSAudioTypes_Msecs, UMSAudioTypes_Bytes or UMSAudioTypes_Samples
slouken@0
   433
     */
slouken@1895
   434
    return UMSAudioDevice_set_time_format(this->hidden->umsdev,
slouken@1895
   435
                                          this->hidden->ev, fmt);
slouken@0
   436
}
slouken@0
   437
slouken@1895
   438
static UMSAudioDevice_ReturnCode
slouken@1895
   439
UADWriteBuffSize(_THIS, long *buff_size)
slouken@0
   440
{
slouken@0
   441
    /*
slouken@0
   442
     * returns write buffer size in the current time format
slouken@0
   443
     */
slouken@1895
   444
    return UMSAudioDevice_write_buff_size(this->hidden->umsdev,
slouken@1895
   445
                                          this->hidden->ev, buff_size);
slouken@0
   446
}
slouken@0
   447
slouken@1895
   448
static UMSAudioDevice_ReturnCode
slouken@1895
   449
UADWriteBuffRemain(_THIS, long *buff_size)
slouken@0
   450
{
slouken@0
   451
    /*
slouken@0
   452
     * returns amount of available space in the write buffer
slouken@0
   453
     * in the current time format
slouken@0
   454
     */
slouken@1895
   455
    return UMSAudioDevice_write_buff_remain(this->hidden->umsdev,
slouken@1895
   456
                                            this->hidden->ev, buff_size);
slouken@0
   457
}
slouken@0
   458
slouken@1895
   459
static UMSAudioDevice_ReturnCode
slouken@1895
   460
UADWriteBuffUsed(_THIS, long *buff_size)
slouken@0
   461
{
slouken@0
   462
    /*
slouken@0
   463
     * returns amount of filled space in the write buffer
slouken@0
   464
     * in the current time format
slouken@0
   465
     */
slouken@1895
   466
    return UMSAudioDevice_write_buff_used(this->hidden->umsdev,
slouken@1895
   467
                                          this->hidden->ev, buff_size);
slouken@0
   468
}
slouken@0
   469
slouken@1895
   470
static UMSAudioDevice_ReturnCode
slouken@1895
   471
UADSetDMABufferSize(_THIS, long bytes, long *bytes_ret)
slouken@0
   472
{
slouken@0
   473
    /*
slouken@0
   474
     * Request a new DMA buffer size, maximum requested size 2048.
slouken@0
   475
     * Takes effect with next initialize() call.
slouken@0
   476
     * Devices may or may not support DMA.
slouken@0
   477
     */
slouken@1895
   478
    return UMSAudioDevice_set_DMA_buffer_size(this->hidden->umsdev,
slouken@1895
   479
                                              this->hidden->ev,
slouken@1895
   480
                                              bytes, bytes_ret);
slouken@0
   481
}
slouken@0
   482
slouken@1895
   483
static UMSAudioDevice_ReturnCode
slouken@1895
   484
UADSetVolume(_THIS, long volume)
slouken@0
   485
{
slouken@0
   486
    /*
slouken@0
   487
     * Set the volume.
slouken@0
   488
     * Takes effect immediately.
slouken@0
   489
     */
slouken@1895
   490
    return UMSAudioDevice_set_volume(this->hidden->umsdev,
slouken@1895
   491
                                     this->hidden->ev, volume);
slouken@0
   492
}
slouken@0
   493
slouken@1895
   494
static UMSAudioDevice_ReturnCode
slouken@1895
   495
UADSetBalance(_THIS, long balance)
slouken@0
   496
{
slouken@0
   497
    /*
slouken@0
   498
     * Set the balance.
slouken@0
   499
     * Takes effect immediately.
slouken@0
   500
     */
slouken@1895
   501
    return UMSAudioDevice_set_balance(this->hidden->umsdev,
slouken@1895
   502
                                      this->hidden->ev, balance);
slouken@0
   503
}
slouken@0
   504
slouken@1895
   505
static UMSAudioDevice_ReturnCode
slouken@1895
   506
UADSetChannels(_THIS, long channels)
slouken@0
   507
{
slouken@0
   508
    /*
slouken@0
   509
     * Set mono or stereo.
slouken@0
   510
     * Takes effect with next initialize() call.
slouken@0
   511
     */
slouken@1895
   512
    if (channels != 1)
slouken@1895
   513
        channels = 2;
slouken@1895
   514
    return UMSAudioDevice_set_number_of_channels(this->hidden->umsdev,
slouken@1895
   515
                                                 this->hidden->ev, channels);
slouken@0
   516
}
slouken@0
   517
slouken@1895
   518
static UMSAudioDevice_ReturnCode
slouken@1895
   519
UADOpen(_THIS, string device, string mode, long flags)
slouken@0
   520
{
slouken@1895
   521
    return UMSAudioDevice_open(this->hidden->umsdev,
slouken@1895
   522
                               this->hidden->ev, device, mode, flags);
slouken@0
   523
}
slouken@0
   524
slouken@1895
   525
static UMSAudioDevice_ReturnCode
slouken@1895
   526
UADWrite(_THIS, UMSAudioTypes_Buffer * buff,
slouken@1895
   527
         long samples, long *samples_written)
slouken@0
   528
{
slouken@1895
   529
    return UMSAudioDevice_write(this->hidden->umsdev,
slouken@1895
   530
                                this->hidden->ev,
slouken@1895
   531
                                buff, samples, samples_written);
slouken@0
   532
}
slouken@0
   533
slouken@1895
   534
static UMSAudioDevice_ReturnCode
slouken@1895
   535
UADPlayRemainingData(_THIS, boolean block)
slouken@0
   536
{
slouken@1895
   537
    return UMSAudioDevice_play_remaining_data(this->hidden->umsdev,
slouken@1895
   538
                                              this->hidden->ev, block);
slouken@0
   539
}
slouken@0
   540
slouken@1895
   541
static UMSAudioDevice_ReturnCode
slouken@1895
   542
UADStop(_THIS)
slouken@0
   543
{
slouken@1895
   544
    return UMSAudioDevice_stop(this->hidden->umsdev, this->hidden->ev);
slouken@0
   545
}
slouken@0
   546
slouken@1895
   547
static UMSAudioDevice_ReturnCode
slouken@1895
   548
UADClose(_THIS)
slouken@0
   549
{
slouken@1895
   550
    return UMSAudioDevice_close(this->hidden->umsdev, this->hidden->ev);
slouken@0
   551
}
slouken@0
   552
slouken@1895
   553
static UMSAudioDevice_ReturnCode
slouken@1895
   554
UADEnableOutput(_THIS, string output, long *left_gain, long *right_gain)
slouken@0
   555
{
slouken@1895
   556
    return UMSAudioDevice_enable_output(this->hidden->umsdev,
slouken@1895
   557
                                        this->hidden->ev,
slouken@1895
   558
                                        output, left_gain, right_gain);
slouken@0
   559
}
slouken@0
   560
slouken@1895
   561
/* vi: set ts=4 sw=4 expandtab: */