2009-03-10 00:55:29 -07:00
|
|
|
/**
|
|
|
|
* OpenAL cross platform audio library
|
|
|
|
* Copyright (C) 1999-2007 by authors.
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
* Or go to http://www.gnu.org/copyleft/lgpl.html
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "alMain.h"
|
|
|
|
#include "AL/al.h"
|
|
|
|
#include "AL/alc.h"
|
|
|
|
|
|
|
|
#include <portaudio.h>
|
|
|
|
|
2011-06-12 04:37:32 -07:00
|
|
|
|
|
|
|
static const ALCchar pa_device[] = "PortAudio Default";
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_DYNLOAD
|
2012-03-01 03:37:06 -08:00
|
|
|
static void *pa_handle;
|
2009-03-10 00:55:29 -07:00
|
|
|
#define MAKE_FUNC(x) static typeof(x) * p##x
|
|
|
|
MAKE_FUNC(Pa_Initialize);
|
2009-09-15 22:45:27 -07:00
|
|
|
MAKE_FUNC(Pa_Terminate);
|
2009-03-10 00:55:29 -07:00
|
|
|
MAKE_FUNC(Pa_GetErrorText);
|
|
|
|
MAKE_FUNC(Pa_StartStream);
|
|
|
|
MAKE_FUNC(Pa_StopStream);
|
|
|
|
MAKE_FUNC(Pa_OpenStream);
|
|
|
|
MAKE_FUNC(Pa_CloseStream);
|
|
|
|
MAKE_FUNC(Pa_GetDefaultOutputDevice);
|
2009-09-15 23:14:14 -07:00
|
|
|
MAKE_FUNC(Pa_GetStreamInfo);
|
2009-03-10 00:55:29 -07:00
|
|
|
#undef MAKE_FUNC
|
|
|
|
|
2011-06-12 04:37:32 -07:00
|
|
|
#define Pa_Initialize pPa_Initialize
|
|
|
|
#define Pa_Terminate pPa_Terminate
|
|
|
|
#define Pa_GetErrorText pPa_GetErrorText
|
|
|
|
#define Pa_StartStream pPa_StartStream
|
|
|
|
#define Pa_StopStream pPa_StopStream
|
|
|
|
#define Pa_OpenStream pPa_OpenStream
|
|
|
|
#define Pa_CloseStream pPa_CloseStream
|
|
|
|
#define Pa_GetDefaultOutputDevice pPa_GetDefaultOutputDevice
|
|
|
|
#define Pa_GetStreamInfo pPa_GetStreamInfo
|
2011-06-26 15:40:15 -07:00
|
|
|
#endif
|
2009-09-27 00:21:40 -07:00
|
|
|
|
2011-08-18 23:56:11 -07:00
|
|
|
static ALCboolean pa_load(void)
|
2009-09-27 00:21:40 -07:00
|
|
|
{
|
2012-03-01 03:37:06 -08:00
|
|
|
PaError err;
|
2010-03-21 20:57:15 -07:00
|
|
|
|
2011-06-26 15:40:15 -07:00
|
|
|
#ifdef HAVE_DYNLOAD
|
2012-03-01 03:37:06 -08:00
|
|
|
if(!pa_handle)
|
|
|
|
{
|
2010-03-21 20:57:15 -07:00
|
|
|
#ifdef _WIN32
|
2011-06-12 04:37:32 -07:00
|
|
|
# define PALIB "portaudio.dll"
|
|
|
|
#elif defined(__APPLE__) && defined(__MACH__)
|
2009-09-27 00:21:40 -07:00
|
|
|
# define PALIB "libportaudio.2.dylib"
|
2011-06-22 16:43:37 -07:00
|
|
|
#elif defined(__OpenBSD__)
|
|
|
|
# define PALIB "libportaudio.so"
|
2009-09-27 00:21:40 -07:00
|
|
|
#else
|
|
|
|
# define PALIB "libportaudio.so.2"
|
|
|
|
#endif
|
|
|
|
|
2011-06-12 04:37:32 -07:00
|
|
|
pa_handle = LoadLib(PALIB);
|
2010-03-23 17:45:37 -07:00
|
|
|
if(!pa_handle)
|
2011-08-18 23:56:11 -07:00
|
|
|
return ALC_FALSE;
|
2010-03-23 17:45:37 -07:00
|
|
|
|
2011-06-12 04:37:32 -07:00
|
|
|
#define LOAD_FUNC(f) do { \
|
|
|
|
p##f = GetSymbol(pa_handle, #f); \
|
|
|
|
if(p##f == NULL) \
|
|
|
|
{ \
|
|
|
|
CloseLib(pa_handle); \
|
|
|
|
pa_handle = NULL; \
|
2011-08-18 23:56:11 -07:00
|
|
|
return ALC_FALSE; \
|
2011-06-12 04:37:32 -07:00
|
|
|
} \
|
|
|
|
} while(0)
|
|
|
|
LOAD_FUNC(Pa_Initialize);
|
|
|
|
LOAD_FUNC(Pa_Terminate);
|
|
|
|
LOAD_FUNC(Pa_GetErrorText);
|
|
|
|
LOAD_FUNC(Pa_StartStream);
|
|
|
|
LOAD_FUNC(Pa_StopStream);
|
|
|
|
LOAD_FUNC(Pa_OpenStream);
|
|
|
|
LOAD_FUNC(Pa_CloseStream);
|
|
|
|
LOAD_FUNC(Pa_GetDefaultOutputDevice);
|
|
|
|
LOAD_FUNC(Pa_GetStreamInfo);
|
2009-09-27 00:21:40 -07:00
|
|
|
#undef LOAD_FUNC
|
|
|
|
|
2011-06-12 04:37:32 -07:00
|
|
|
if((err=Pa_Initialize()) != paNoError)
|
2009-09-27 00:21:40 -07:00
|
|
|
{
|
2011-07-13 01:43:00 -07:00
|
|
|
ERR("Pa_Initialize() returned an error: %s\n", Pa_GetErrorText(err));
|
2011-06-12 04:37:32 -07:00
|
|
|
CloseLib(pa_handle);
|
2009-09-27 00:21:40 -07:00
|
|
|
pa_handle = NULL;
|
2011-08-18 23:56:11 -07:00
|
|
|
return ALC_FALSE;
|
2009-09-27 00:21:40 -07:00
|
|
|
}
|
|
|
|
}
|
2012-03-01 03:37:06 -08:00
|
|
|
#else
|
|
|
|
if((err=Pa_Initialize()) != paNoError)
|
|
|
|
{
|
|
|
|
ERR("Pa_Initialize() returned an error: %s\n", Pa_GetErrorText(err));
|
|
|
|
return ALC_FALSE;
|
|
|
|
}
|
|
|
|
#endif
|
2011-08-18 23:56:11 -07:00
|
|
|
return ALC_TRUE;
|
2009-09-27 00:21:40 -07:00
|
|
|
}
|
|
|
|
|
2009-03-10 00:55:29 -07:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
PaStream *stream;
|
2012-03-13 21:52:47 -07:00
|
|
|
PaStreamParameters params;
|
2010-02-24 18:51:57 -08:00
|
|
|
ALuint update_size;
|
2010-03-18 01:58:25 -07:00
|
|
|
|
|
|
|
RingBuffer *ring;
|
2009-03-10 00:55:29 -07:00
|
|
|
} pa_data;
|
|
|
|
|
|
|
|
|
|
|
|
static int pa_callback(const void *inputBuffer, void *outputBuffer,
|
|
|
|
unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo *timeInfo,
|
|
|
|
const PaStreamCallbackFlags statusFlags, void *userData)
|
|
|
|
{
|
|
|
|
ALCdevice *device = (ALCdevice*)userData;
|
|
|
|
|
|
|
|
(void)inputBuffer;
|
|
|
|
(void)timeInfo;
|
|
|
|
(void)statusFlags;
|
|
|
|
|
2009-09-15 19:30:27 -07:00
|
|
|
aluMixData(device, outputBuffer, framesPerBuffer);
|
2009-03-10 00:55:29 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-03-18 01:58:25 -07:00
|
|
|
static int pa_capture_cb(const void *inputBuffer, void *outputBuffer,
|
|
|
|
unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo *timeInfo,
|
|
|
|
const PaStreamCallbackFlags statusFlags, void *userData)
|
|
|
|
{
|
|
|
|
ALCdevice *device = (ALCdevice*)userData;
|
|
|
|
pa_data *data = (pa_data*)device->ExtraData;
|
|
|
|
|
|
|
|
(void)outputBuffer;
|
|
|
|
(void)timeInfo;
|
|
|
|
(void)statusFlags;
|
|
|
|
|
|
|
|
WriteRingBuffer(data->ring, inputBuffer, framesPerBuffer);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-03-10 00:55:29 -07:00
|
|
|
|
2011-08-24 14:24:48 -07:00
|
|
|
static ALCenum pa_open_playback(ALCdevice *device, const ALCchar *deviceName)
|
2009-03-10 00:55:29 -07:00
|
|
|
{
|
|
|
|
pa_data *data;
|
|
|
|
PaError err;
|
|
|
|
|
2009-08-27 18:55:18 -07:00
|
|
|
if(!deviceName)
|
|
|
|
deviceName = pa_device;
|
|
|
|
else if(strcmp(deviceName, pa_device) != 0)
|
2011-08-24 14:24:48 -07:00
|
|
|
return ALC_INVALID_VALUE;
|
2009-03-10 00:55:29 -07:00
|
|
|
|
|
|
|
data = (pa_data*)calloc(1, sizeof(pa_data));
|
2010-02-24 18:51:57 -08:00
|
|
|
data->update_size = device->UpdateSize;
|
|
|
|
|
2012-03-13 21:52:47 -07:00
|
|
|
data->params.device = -1;
|
|
|
|
if(!ConfigValueInt("port", "device", &data->params.device) ||
|
|
|
|
data->params.device < 0)
|
|
|
|
data->params.device = Pa_GetDefaultOutputDevice();
|
|
|
|
data->params.suggestedLatency = (device->UpdateSize*device->NumUpdates) /
|
|
|
|
(float)device->Frequency;
|
|
|
|
data->params.hostApiSpecificStreamInfo = NULL;
|
2009-03-10 00:55:29 -07:00
|
|
|
|
2012-03-13 21:52:47 -07:00
|
|
|
data->params.channelCount = ((device->FmtChans == DevFmtMono) ? 1 : 2);
|
2012-01-17 15:26:22 -08:00
|
|
|
|
2010-12-04 19:50:00 -08:00
|
|
|
switch(device->FmtType)
|
2009-03-10 00:55:29 -07:00
|
|
|
{
|
2010-12-04 19:50:00 -08:00
|
|
|
case DevFmtByte:
|
2012-03-13 21:52:47 -07:00
|
|
|
data->params.sampleFormat = paInt8;
|
2010-12-04 19:50:00 -08:00
|
|
|
break;
|
|
|
|
case DevFmtUByte:
|
2012-03-13 21:52:47 -07:00
|
|
|
data->params.sampleFormat = paUInt8;
|
2009-03-10 00:55:29 -07:00
|
|
|
break;
|
2010-12-04 19:50:00 -08:00
|
|
|
case DevFmtUShort:
|
|
|
|
/* fall-through */
|
|
|
|
case DevFmtShort:
|
2012-03-13 21:52:47 -07:00
|
|
|
data->params.sampleFormat = paInt16;
|
2009-03-10 00:55:29 -07:00
|
|
|
break;
|
2012-02-14 11:44:57 -08:00
|
|
|
case DevFmtUInt:
|
|
|
|
/* fall-through */
|
|
|
|
case DevFmtInt:
|
2012-03-13 21:52:47 -07:00
|
|
|
data->params.sampleFormat = paInt32;
|
2012-02-14 11:44:57 -08:00
|
|
|
break;
|
2010-12-04 19:50:00 -08:00
|
|
|
case DevFmtFloat:
|
2012-03-13 21:52:47 -07:00
|
|
|
data->params.sampleFormat = paFloat32;
|
2009-08-15 13:20:35 -07:00
|
|
|
break;
|
2009-03-10 00:55:29 -07:00
|
|
|
}
|
2009-12-02 04:03:51 -08:00
|
|
|
|
2012-03-13 22:18:51 -07:00
|
|
|
retry_open:
|
2012-03-13 21:52:47 -07:00
|
|
|
err = Pa_OpenStream(&data->stream, NULL, &data->params, device->Frequency,
|
2011-06-12 04:37:32 -07:00
|
|
|
device->UpdateSize, paNoFlag, pa_callback, device);
|
2009-03-10 00:55:29 -07:00
|
|
|
if(err != paNoError)
|
|
|
|
{
|
2012-03-13 22:18:51 -07:00
|
|
|
if(data->params.sampleFormat == paFloat32)
|
2012-01-17 15:26:22 -08:00
|
|
|
{
|
2012-03-13 22:18:51 -07:00
|
|
|
data->params.sampleFormat = paInt16;
|
2012-01-17 15:26:22 -08:00
|
|
|
goto retry_open;
|
|
|
|
}
|
2011-07-13 01:43:00 -07:00
|
|
|
ERR("Pa_OpenStream() returned an error: %s\n", Pa_GetErrorText(err));
|
2009-03-10 00:55:29 -07:00
|
|
|
free(data);
|
2011-08-24 14:24:48 -07:00
|
|
|
return ALC_INVALID_VALUE;
|
2009-03-10 00:55:29 -07:00
|
|
|
}
|
|
|
|
|
2012-03-13 22:18:51 -07:00
|
|
|
device->ExtraData = data;
|
2012-04-19 22:50:11 -07:00
|
|
|
device->DeviceName = strdup(deviceName);
|
2012-03-02 02:14:04 -08:00
|
|
|
|
2011-08-24 14:24:48 -07:00
|
|
|
return ALC_NO_ERROR;
|
2009-03-10 00:55:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void pa_close_playback(ALCdevice *device)
|
|
|
|
{
|
|
|
|
pa_data *data = (pa_data*)device->ExtraData;
|
|
|
|
PaError err;
|
|
|
|
|
2011-06-12 04:37:32 -07:00
|
|
|
err = Pa_CloseStream(data->stream);
|
2009-03-10 00:55:29 -07:00
|
|
|
if(err != paNoError)
|
2011-07-13 01:43:00 -07:00
|
|
|
ERR("Error closing stream: %s\n", Pa_GetErrorText(err));
|
2009-03-10 00:55:29 -07:00
|
|
|
|
|
|
|
free(data);
|
|
|
|
device->ExtraData = NULL;
|
|
|
|
}
|
|
|
|
|
2009-09-16 00:24:44 -07:00
|
|
|
static ALCboolean pa_reset_playback(ALCdevice *device)
|
2009-08-13 12:28:46 -07:00
|
|
|
{
|
2009-09-16 00:08:11 -07:00
|
|
|
pa_data *data = (pa_data*)device->ExtraData;
|
|
|
|
const PaStreamInfo *streamInfo;
|
|
|
|
|
2011-06-12 04:37:32 -07:00
|
|
|
streamInfo = Pa_GetStreamInfo(data->stream);
|
2012-01-17 16:38:58 -08:00
|
|
|
device->Frequency = streamInfo->sampleRate;
|
2010-02-24 18:51:57 -08:00
|
|
|
device->UpdateSize = data->update_size;
|
2009-09-16 00:08:11 -07:00
|
|
|
|
2012-03-13 22:18:51 -07:00
|
|
|
if(data->params.sampleFormat == paInt8)
|
|
|
|
device->FmtType = DevFmtByte;
|
|
|
|
else if(data->params.sampleFormat == paUInt8)
|
|
|
|
device->FmtType = DevFmtUByte;
|
|
|
|
else if(data->params.sampleFormat == paInt16)
|
|
|
|
device->FmtType = DevFmtShort;
|
|
|
|
else if(data->params.sampleFormat == paInt32)
|
|
|
|
device->FmtType = DevFmtInt;
|
|
|
|
else if(data->params.sampleFormat == paFloat32)
|
|
|
|
device->FmtType = DevFmtFloat;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ERR("Unexpected sample format: 0x%lx\n", data->params.sampleFormat);
|
|
|
|
return ALC_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(data->params.channelCount == 2)
|
|
|
|
device->FmtChans = DevFmtStereo;
|
|
|
|
else if(data->params.channelCount == 1)
|
|
|
|
device->FmtChans = DevFmtMono;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ERR("Unexpected channel count: %u\n", data->params.channelCount);
|
|
|
|
return ALC_FALSE;
|
|
|
|
}
|
|
|
|
SetDefaultChannelOrder(device);
|
|
|
|
|
2012-03-05 07:11:09 -08:00
|
|
|
return ALC_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ALCboolean pa_start_playback(ALCdevice *device)
|
|
|
|
{
|
|
|
|
pa_data *data = (pa_data*)device->ExtraData;
|
|
|
|
PaError err;
|
|
|
|
|
2011-06-12 04:37:32 -07:00
|
|
|
err = Pa_StartStream(data->stream);
|
2009-12-26 08:14:28 -08:00
|
|
|
if(err != paNoError)
|
|
|
|
{
|
2011-07-13 01:43:00 -07:00
|
|
|
ERR("Pa_StartStream() returned an error: %s\n", Pa_GetErrorText(err));
|
2009-12-26 08:14:28 -08:00
|
|
|
return ALC_FALSE;
|
|
|
|
}
|
|
|
|
|
2009-08-13 12:28:46 -07:00
|
|
|
return ALC_TRUE;
|
|
|
|
}
|
|
|
|
|
2009-09-16 00:24:44 -07:00
|
|
|
static void pa_stop_playback(ALCdevice *device)
|
2009-08-13 12:28:46 -07:00
|
|
|
{
|
2009-12-26 08:14:28 -08:00
|
|
|
pa_data *data = (pa_data*)device->ExtraData;
|
|
|
|
PaError err;
|
|
|
|
|
2011-06-12 04:37:32 -07:00
|
|
|
err = Pa_StopStream(data->stream);
|
2009-12-26 08:14:28 -08:00
|
|
|
if(err != paNoError)
|
2011-07-13 01:43:00 -07:00
|
|
|
ERR("Error stopping stream: %s\n", Pa_GetErrorText(err));
|
2009-08-13 12:28:46 -07:00
|
|
|
}
|
|
|
|
|
2009-03-10 00:55:29 -07:00
|
|
|
|
2011-08-24 14:44:15 -07:00
|
|
|
static ALCenum pa_open_capture(ALCdevice *device, const ALCchar *deviceName)
|
2009-03-10 00:55:29 -07:00
|
|
|
{
|
2010-03-18 01:58:25 -07:00
|
|
|
ALuint frame_size;
|
|
|
|
pa_data *data;
|
|
|
|
PaError err;
|
|
|
|
|
|
|
|
if(!deviceName)
|
2010-05-31 19:00:33 -07:00
|
|
|
deviceName = pa_device;
|
|
|
|
else if(strcmp(deviceName, pa_device) != 0)
|
2011-08-24 14:44:15 -07:00
|
|
|
return ALC_INVALID_VALUE;
|
2010-03-18 01:58:25 -07:00
|
|
|
|
|
|
|
data = (pa_data*)calloc(1, sizeof(pa_data));
|
|
|
|
if(data == NULL)
|
2011-08-24 14:44:15 -07:00
|
|
|
return ALC_OUT_OF_MEMORY;
|
2010-03-18 01:58:25 -07:00
|
|
|
|
2010-12-04 19:50:00 -08:00
|
|
|
frame_size = FrameSizeFromDevFmt(device->FmtChans, device->FmtType);
|
2010-03-18 01:58:25 -07:00
|
|
|
data->ring = CreateRingBuffer(frame_size, device->UpdateSize*device->NumUpdates);
|
|
|
|
if(data->ring == NULL)
|
|
|
|
goto error;
|
|
|
|
|
2012-03-13 21:52:47 -07:00
|
|
|
data->params.device = -1;
|
|
|
|
if(!ConfigValueInt("port", "capture", &data->params.device) ||
|
|
|
|
data->params.device < 0)
|
|
|
|
data->params.device = Pa_GetDefaultOutputDevice();
|
|
|
|
data->params.suggestedLatency = 0.0f;
|
|
|
|
data->params.hostApiSpecificStreamInfo = NULL;
|
2010-03-18 01:58:25 -07:00
|
|
|
|
2010-12-04 19:50:00 -08:00
|
|
|
switch(device->FmtType)
|
2010-03-18 01:58:25 -07:00
|
|
|
{
|
2010-12-04 19:50:00 -08:00
|
|
|
case DevFmtByte:
|
2012-03-13 21:52:47 -07:00
|
|
|
data->params.sampleFormat = paInt8;
|
2010-12-04 19:50:00 -08:00
|
|
|
break;
|
|
|
|
case DevFmtUByte:
|
2012-03-13 21:52:47 -07:00
|
|
|
data->params.sampleFormat = paUInt8;
|
2010-03-18 01:58:25 -07:00
|
|
|
break;
|
2010-12-04 19:50:00 -08:00
|
|
|
case DevFmtShort:
|
2012-03-13 21:52:47 -07:00
|
|
|
data->params.sampleFormat = paInt16;
|
2010-03-18 01:58:25 -07:00
|
|
|
break;
|
2012-02-14 11:44:57 -08:00
|
|
|
case DevFmtInt:
|
2012-03-13 21:52:47 -07:00
|
|
|
data->params.sampleFormat = paInt32;
|
2012-02-14 11:44:57 -08:00
|
|
|
break;
|
2010-12-04 19:50:00 -08:00
|
|
|
case DevFmtFloat:
|
2012-03-13 21:52:47 -07:00
|
|
|
data->params.sampleFormat = paFloat32;
|
2010-03-18 01:58:25 -07:00
|
|
|
break;
|
2012-02-14 11:44:57 -08:00
|
|
|
case DevFmtUInt:
|
2010-12-04 19:50:00 -08:00
|
|
|
case DevFmtUShort:
|
2012-02-14 11:44:57 -08:00
|
|
|
ERR("%s samples not supported\n", DevFmtTypeString(device->FmtType));
|
2010-03-18 01:58:25 -07:00
|
|
|
goto error;
|
|
|
|
}
|
2012-03-13 21:52:47 -07:00
|
|
|
data->params.channelCount = ChannelsFromDevFmt(device->FmtChans);
|
2010-03-18 01:58:25 -07:00
|
|
|
|
2012-03-13 21:52:47 -07:00
|
|
|
err = Pa_OpenStream(&data->stream, &data->params, NULL, device->Frequency,
|
2011-06-12 04:37:32 -07:00
|
|
|
paFramesPerBufferUnspecified, paNoFlag, pa_capture_cb, device);
|
2010-03-18 01:58:25 -07:00
|
|
|
if(err != paNoError)
|
|
|
|
{
|
2011-07-13 01:43:00 -07:00
|
|
|
ERR("Pa_OpenStream() returned an error: %s\n", Pa_GetErrorText(err));
|
2010-03-18 01:58:25 -07:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2012-04-19 22:50:11 -07:00
|
|
|
device->DeviceName = strdup(deviceName);
|
2010-03-18 01:58:25 -07:00
|
|
|
|
|
|
|
device->ExtraData = data;
|
2011-08-24 14:44:15 -07:00
|
|
|
return ALC_NO_ERROR;
|
2010-03-18 01:58:25 -07:00
|
|
|
|
|
|
|
error:
|
|
|
|
DestroyRingBuffer(data->ring);
|
|
|
|
free(data);
|
2011-08-24 14:44:15 -07:00
|
|
|
return ALC_INVALID_VALUE;
|
2009-03-10 00:55:29 -07:00
|
|
|
}
|
|
|
|
|
2010-03-18 01:58:25 -07:00
|
|
|
static void pa_close_capture(ALCdevice *device)
|
|
|
|
{
|
|
|
|
pa_data *data = (pa_data*)device->ExtraData;
|
|
|
|
PaError err;
|
|
|
|
|
2011-06-12 04:37:32 -07:00
|
|
|
err = Pa_CloseStream(data->stream);
|
2010-03-18 01:58:25 -07:00
|
|
|
if(err != paNoError)
|
2011-07-13 01:43:00 -07:00
|
|
|
ERR("Error closing stream: %s\n", Pa_GetErrorText(err));
|
2010-03-18 01:58:25 -07:00
|
|
|
|
|
|
|
free(data);
|
|
|
|
device->ExtraData = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pa_start_capture(ALCdevice *device)
|
|
|
|
{
|
|
|
|
pa_data *data = device->ExtraData;
|
|
|
|
PaError err;
|
|
|
|
|
2011-06-12 04:37:32 -07:00
|
|
|
err = Pa_StartStream(data->stream);
|
2010-03-18 01:58:25 -07:00
|
|
|
if(err != paNoError)
|
2011-07-13 01:43:00 -07:00
|
|
|
ERR("Error starting stream: %s\n", Pa_GetErrorText(err));
|
2010-03-18 01:58:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void pa_stop_capture(ALCdevice *device)
|
|
|
|
{
|
|
|
|
pa_data *data = (pa_data*)device->ExtraData;
|
|
|
|
PaError err;
|
|
|
|
|
2011-06-12 04:37:32 -07:00
|
|
|
err = Pa_StopStream(data->stream);
|
2010-03-18 01:58:25 -07:00
|
|
|
if(err != paNoError)
|
2011-07-13 01:43:00 -07:00
|
|
|
ERR("Error stopping stream: %s\n", Pa_GetErrorText(err));
|
2010-03-18 01:58:25 -07:00
|
|
|
}
|
|
|
|
|
2011-09-18 20:27:34 -07:00
|
|
|
static ALCenum pa_capture_samples(ALCdevice *device, ALCvoid *buffer, ALCuint samples)
|
2010-03-18 01:58:25 -07:00
|
|
|
{
|
|
|
|
pa_data *data = device->ExtraData;
|
2011-09-18 20:27:34 -07:00
|
|
|
ReadRingBuffer(data->ring, buffer, samples);
|
|
|
|
return ALC_NO_ERROR;
|
2010-03-18 01:58:25 -07:00
|
|
|
}
|
|
|
|
|
2011-09-18 20:27:34 -07:00
|
|
|
static ALCuint pa_available_samples(ALCdevice *device)
|
2010-03-18 01:58:25 -07:00
|
|
|
{
|
|
|
|
pa_data *data = device->ExtraData;
|
2011-09-18 20:27:34 -07:00
|
|
|
return RingBufferSize(data->ring);
|
2010-03-18 01:58:25 -07:00
|
|
|
}
|
2009-03-10 00:55:29 -07:00
|
|
|
|
|
|
|
|
|
|
|
static const BackendFuncs pa_funcs = {
|
|
|
|
pa_open_playback,
|
|
|
|
pa_close_playback,
|
2009-09-16 00:24:44 -07:00
|
|
|
pa_reset_playback,
|
2012-03-05 07:11:09 -08:00
|
|
|
pa_start_playback,
|
2009-09-16 00:24:44 -07:00
|
|
|
pa_stop_playback,
|
2009-03-10 00:55:29 -07:00
|
|
|
pa_open_capture,
|
2010-03-18 01:58:25 -07:00
|
|
|
pa_close_capture,
|
|
|
|
pa_start_capture,
|
|
|
|
pa_stop_capture,
|
|
|
|
pa_capture_samples,
|
2010-11-21 06:32:59 -08:00
|
|
|
pa_available_samples
|
2009-03-10 00:55:29 -07:00
|
|
|
};
|
|
|
|
|
2011-08-17 06:05:26 -07:00
|
|
|
ALCboolean alc_pa_init(BackendFuncs *func_list)
|
2009-03-10 00:55:29 -07:00
|
|
|
{
|
2011-08-18 23:56:11 -07:00
|
|
|
if(!pa_load())
|
|
|
|
return ALC_FALSE;
|
2009-09-27 00:21:40 -07:00
|
|
|
*func_list = pa_funcs;
|
2011-08-17 06:05:26 -07:00
|
|
|
return ALC_TRUE;
|
2009-03-10 00:55:29 -07:00
|
|
|
}
|
2009-08-26 23:45:00 -07:00
|
|
|
|
|
|
|
void alc_pa_deinit(void)
|
|
|
|
{
|
2012-03-01 03:37:06 -08:00
|
|
|
#ifdef HAVE_DYNLOAD
|
2010-05-28 02:22:17 -07:00
|
|
|
if(pa_handle)
|
|
|
|
{
|
2011-06-12 04:37:32 -07:00
|
|
|
Pa_Terminate();
|
|
|
|
CloseLib(pa_handle);
|
2010-05-28 02:22:17 -07:00
|
|
|
pa_handle = NULL;
|
|
|
|
}
|
2012-03-01 03:37:06 -08:00
|
|
|
#else
|
|
|
|
Pa_Terminate();
|
|
|
|
#endif
|
2009-08-26 23:45:00 -07:00
|
|
|
}
|
2009-08-27 06:09:33 -07:00
|
|
|
|
2011-06-14 04:02:58 -07:00
|
|
|
void alc_pa_probe(enum DevProbe type)
|
2009-08-27 06:09:33 -07:00
|
|
|
{
|
2011-06-14 04:02:58 -07:00
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case ALL_DEVICE_PROBE:
|
2012-05-09 16:28:16 -07:00
|
|
|
AppendAllDevicesList(pa_device);
|
2011-06-14 04:02:58 -07:00
|
|
|
break;
|
|
|
|
case CAPTURE_DEVICE_PROBE:
|
|
|
|
AppendCaptureDeviceList(pa_device);
|
|
|
|
break;
|
|
|
|
}
|
2009-08-27 06:09:33 -07:00
|
|
|
}
|