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