~ubuntu-branches/ubuntu/quantal/openal-soft/quantal

« back to all changes in this revision

Viewing changes to Alc/portaudio.c

  • Committer: Bazaar Package Importer
  • Author(s): Andres Mejia
  • Date: 2011-04-22 18:30:58 UTC
  • mfrom: (7.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110422183058-pgxqd8022xk3vwao
Tags: 1:1.13-2
Don't build with ALSA compatibility on non-Linux architectures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
#undef MAKE_FUNC
47
47
 
48
48
 
49
 
static const ALCchar pa_device[] = "PortAudio Software";
50
 
static const ALCchar pa_capture[] = "PortAudio Capture";
51
 
static volatile ALuint load_count;
 
49
static const ALCchar pa_device[] = "PortAudio Default";
52
50
 
53
51
 
54
52
void *pa_load(void)
55
53
{
56
 
    if(load_count == 0)
 
54
    if(!pa_handle)
57
55
    {
58
56
        PaError err;
59
57
 
92
90
} while(0)
93
91
 
94
92
#else
95
 
        str = NULL;
96
93
        pa_handle = (void*)0xDEADBEEF;
97
94
#define LOAD_FUNC(f) p##f = f
98
95
#endif
124
121
            return NULL;
125
122
        }
126
123
    }
127
 
    ++load_count;
128
 
 
129
124
    return pa_handle;
130
125
}
131
126
 
132
 
void pa_unload(void)
133
 
{
134
 
    if(load_count == 0 || --load_count > 0)
135
 
        return;
136
 
 
137
 
    pPa_Terminate();
138
 
#ifdef _WIN32
139
 
    FreeLibrary(pa_handle);
140
 
#elif defined(HAVE_DLFCN_H)
141
 
    dlclose(pa_handle);
142
 
#endif
143
 
    pa_handle = NULL;
144
 
}
145
 
 
146
127
 
147
128
typedef struct {
148
129
    PaStream *stream;
209
190
                                 (float)device->Frequency;
210
191
    outParams.hostApiSpecificStreamInfo = NULL;
211
192
 
212
 
    switch(aluBytesFromFormat(device->Format))
 
193
    switch(device->FmtType)
213
194
    {
214
 
        case 1:
 
195
        case DevFmtByte:
 
196
            outParams.sampleFormat = paInt8;
 
197
            break;
 
198
        case DevFmtUByte:
215
199
            outParams.sampleFormat = paUInt8;
216
200
            break;
217
 
        case 2:
 
201
        case DevFmtUShort:
 
202
            device->FmtType = DevFmtShort;
 
203
            /* fall-through */
 
204
        case DevFmtShort:
218
205
            outParams.sampleFormat = paInt16;
219
206
            break;
220
 
        case 4:
 
207
        case DevFmtFloat:
221
208
            outParams.sampleFormat = paFloat32;
222
209
            break;
223
 
        default:
224
 
            AL_PRINT("Unknown format: 0x%x\n", device->Format);
225
 
            device->ExtraData = NULL;
226
 
            free(data);
227
 
            pa_unload();
228
 
            return ALC_FALSE;
229
210
    }
230
 
    outParams.channelCount = aluChannelsFromFormat(device->Format);
 
211
    outParams.channelCount = ChannelsFromDevFmt(device->FmtChans);
231
212
 
232
213
    SetDefaultChannelOrder(device);
233
214
 
238
219
        AL_PRINT("Pa_OpenStream() returned an error: %s\n", pPa_GetErrorText(err));
239
220
        device->ExtraData = NULL;
240
221
        free(data);
241
 
        pa_unload();
242
222
        return ALC_FALSE;
243
223
    }
244
224
    streamInfo = pPa_GetStreamInfo(data->stream);
260
240
 
261
241
    free(data);
262
242
    device->ExtraData = NULL;
263
 
 
264
 
    pa_unload();
265
243
}
266
244
 
267
245
static ALCboolean pa_reset_playback(ALCdevice *device)
303
281
    PaError err;
304
282
 
305
283
    if(!deviceName)
306
 
        deviceName = pa_capture;
307
 
    else if(strcmp(deviceName, pa_capture) != 0)
 
284
        deviceName = pa_device;
 
285
    else if(strcmp(deviceName, pa_device) != 0)
308
286
        return ALC_FALSE;
309
287
 
310
288
    if(!pa_load())
317
295
        return ALC_FALSE;
318
296
    }
319
297
 
320
 
    frame_size = aluChannelsFromFormat(device->Format) *
321
 
                 aluBytesFromFormat(device->Format);
 
298
    frame_size = FrameSizeFromDevFmt(device->FmtChans, device->FmtType);
322
299
    data->ring = CreateRingBuffer(frame_size, device->UpdateSize*device->NumUpdates);
323
300
    if(data->ring == NULL)
324
301
    {
332
309
    inParams.suggestedLatency = 0.0f;
333
310
    inParams.hostApiSpecificStreamInfo = NULL;
334
311
 
335
 
    switch(aluBytesFromFormat(device->Format))
 
312
    switch(device->FmtType)
336
313
    {
337
 
        case 1:
 
314
        case DevFmtByte:
 
315
            inParams.sampleFormat = paInt8;
 
316
            break;
 
317
        case DevFmtUByte:
338
318
            inParams.sampleFormat = paUInt8;
339
319
            break;
340
 
        case 2:
 
320
        case DevFmtShort:
341
321
            inParams.sampleFormat = paInt16;
342
322
            break;
343
 
        case 4:
 
323
        case DevFmtFloat:
344
324
            inParams.sampleFormat = paFloat32;
345
325
            break;
346
 
        default:
347
 
            AL_PRINT("Unknown format: 0x%x\n", device->Format);
 
326
        case DevFmtUShort:
 
327
            AL_PRINT("Unsigned short not supported\n");
348
328
            goto error;
349
329
    }
350
 
    inParams.channelCount = aluChannelsFromFormat(device->Format);
 
330
    inParams.channelCount = ChannelsFromDevFmt(device->FmtChans);
351
331
 
352
332
    err = pPa_OpenStream(&data->stream, &inParams, NULL, device->Frequency,
353
333
                         paFramesPerBufferUnspecified, paNoFlag, pa_capture_cb, device);
365
345
error:
366
346
    DestroyRingBuffer(data->ring);
367
347
    free(data);
368
 
    pa_unload();
369
348
    return ALC_FALSE;
370
349
}
371
350
 
380
359
 
381
360
    free(data);
382
361
    device->ExtraData = NULL;
383
 
 
384
 
    pa_unload();
385
362
}
386
363
 
387
364
static void pa_start_capture(ALCdevice *device)
440
417
 
441
418
void alc_pa_deinit(void)
442
419
{
 
420
    if(pa_handle)
 
421
    {
 
422
        pPa_Terminate();
 
423
#ifdef _WIN32
 
424
        FreeLibrary(pa_handle);
 
425
#elif defined(HAVE_DLFCN_H)
 
426
        dlclose(pa_handle);
 
427
#endif
 
428
        pa_handle = NULL;
 
429
    }
443
430
}
444
431
 
445
432
void alc_pa_probe(int type)
451
438
    else if(type == ALL_DEVICE_PROBE)
452
439
        AppendAllDeviceList(pa_device);
453
440
    else if(type == CAPTURE_DEVICE_PROBE)
454
 
        AppendCaptureDeviceList(pa_capture);
455
 
 
456
 
    pa_unload();
 
441
        AppendCaptureDeviceList(pa_device);
457
442
}