2009-03-10 07:55:29 +00: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 11:37:32 +00:00
|
|
|
|
|
|
|
static const ALCchar pa_device[] = "PortAudio Default";
|
|
|
|
|
|
|
|
|
2009-03-10 07:55:29 +00:00
|
|
|
static void *pa_handle;
|
2011-06-12 11:37:32 +00:00
|
|
|
#ifdef HAVE_DYNLOAD
|
2009-03-10 07:55:29 +00:00
|
|
|
#define MAKE_FUNC(x) static typeof(x) * p##x
|
|
|
|
MAKE_FUNC(Pa_Initialize);
|
2009-09-16 05:45:27 +00:00
|
|
|
MAKE_FUNC(Pa_Terminate);
|
2009-03-10 07:55:29 +00: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-16 06:14:14 +00:00
|
|
|
MAKE_FUNC(Pa_GetStreamInfo);
|
2009-03-10 07:55:29 +00:00
|
|
|
#undef MAKE_FUNC
|
|
|
|
|
2011-06-12 11:37:32 +00: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
|
2009-09-27 07:21:40 +00:00
|
|
|
|
2009-12-26 16:49:11 +00:00
|
|
|
void *pa_load(void)
|
2009-09-27 07:21:40 +00:00
|
|
|
{
|
2010-05-28 09:22:17 +00:00
|
|
|
if(!pa_handle)
|
2009-09-27 07:21:40 +00:00
|
|
|
{
|
2010-03-22 03:57:15 +00:00
|
|
|
PaError err;
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
2011-06-12 11:37:32 +00:00
|
|
|
# define PALIB "portaudio.dll"
|
|
|
|
#elif defined(__APPLE__) && defined(__MACH__)
|
2009-09-27 07:21:40 +00:00
|
|
|
# define PALIB "libportaudio.2.dylib"
|
2011-06-22 23:43:37 +00:00
|
|
|
#elif defined(__OpenBSD__)
|
|
|
|
# define PALIB "libportaudio.so"
|
2009-09-27 07:21:40 +00:00
|
|
|
#else
|
|
|
|
# define PALIB "libportaudio.so.2"
|
|
|
|
#endif
|
|
|
|
|
2011-06-12 11:37:32 +00:00
|
|
|
pa_handle = LoadLib(PALIB);
|
2010-03-24 00:45:37 +00:00
|
|
|
if(!pa_handle)
|
|
|
|
return NULL;
|
|
|
|
|
2011-06-12 11:37:32 +00:00
|
|
|
#define LOAD_FUNC(f) do { \
|
|
|
|
p##f = GetSymbol(pa_handle, #f); \
|
|
|
|
if(p##f == NULL) \
|
|
|
|
{ \
|
|
|
|
CloseLib(pa_handle); \
|
|
|
|
pa_handle = NULL; \
|
|
|
|
return NULL; \
|
|
|
|
} \
|
|
|
|
} 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 07:21:40 +00:00
|
|
|
#undef LOAD_FUNC
|
|
|
|
|
2011-06-12 11:37:32 +00:00
|
|
|
if((err=Pa_Initialize()) != paNoError)
|
2009-09-27 07:21:40 +00:00
|
|
|
{
|
2011-06-12 11:37:32 +00:00
|
|
|
AL_PRINT("Pa_Initialize() returned an error: %s\n", Pa_GetErrorText(err));
|
|
|
|
CloseLib(pa_handle);
|
2009-09-27 07:21:40 +00:00
|
|
|
pa_handle = NULL;
|
2009-12-26 16:49:11 +00:00
|
|
|
return NULL;
|
2009-09-27 07:21:40 +00:00
|
|
|
}
|
|
|
|
}
|
2009-12-26 16:49:11 +00:00
|
|
|
return pa_handle;
|
2009-09-27 07:21:40 +00:00
|
|
|
}
|
2011-06-12 11:37:32 +00:00
|
|
|
#else
|
|
|
|
void *pa_load(void)
|
|
|
|
{
|
|
|
|
if(!pa_handle)
|
|
|
|
{
|
|
|
|
pa_handle = (void*)0xDEADBEEF;
|
|
|
|
if((err=Pa_Initialize()) != paNoError)
|
|
|
|
{
|
|
|
|
AL_PRINT("Pa_Initialize() returned an error: %s\n", Pa_GetErrorText(err));
|
|
|
|
pa_handle = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return pa_handle;
|
|
|
|
}
|
|
|
|
#endif
|
2009-09-27 07:21:40 +00:00
|
|
|
|
2009-03-10 07:55:29 +00:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
PaStream *stream;
|
2010-02-25 02:51:57 +00:00
|
|
|
ALuint update_size;
|
2010-03-18 08:58:25 +00:00
|
|
|
|
|
|
|
RingBuffer *ring;
|
2009-03-10 07:55:29 +00: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-16 02:30:27 +00:00
|
|
|
aluMixData(device, outputBuffer, framesPerBuffer);
|
2009-03-10 07:55:29 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-03-18 08:58:25 +00: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 07:55:29 +00:00
|
|
|
|
|
|
|
static ALCboolean pa_open_playback(ALCdevice *device, const ALCchar *deviceName)
|
|
|
|
{
|
2009-09-16 06:14:14 +00:00
|
|
|
const PaStreamInfo *streamInfo;
|
2009-03-10 07:55:29 +00:00
|
|
|
PaStreamParameters outParams;
|
|
|
|
pa_data *data;
|
|
|
|
PaError err;
|
|
|
|
|
2009-08-28 01:55:18 +00:00
|
|
|
if(!deviceName)
|
|
|
|
deviceName = pa_device;
|
|
|
|
else if(strcmp(deviceName, pa_device) != 0)
|
|
|
|
return ALC_FALSE;
|
2009-03-10 07:55:29 +00:00
|
|
|
|
2009-12-26 16:49:11 +00:00
|
|
|
if(!pa_load())
|
2009-09-27 07:21:40 +00:00
|
|
|
return ALC_FALSE;
|
|
|
|
|
2009-03-10 07:55:29 +00:00
|
|
|
data = (pa_data*)calloc(1, sizeof(pa_data));
|
2010-02-25 02:51:57 +00:00
|
|
|
data->update_size = device->UpdateSize;
|
|
|
|
|
2009-03-10 07:55:29 +00:00
|
|
|
device->ExtraData = data;
|
|
|
|
|
|
|
|
outParams.device = GetConfigValueInt("port", "device", -1);
|
|
|
|
if(outParams.device < 0)
|
2011-06-12 11:37:32 +00:00
|
|
|
outParams.device = Pa_GetDefaultOutputDevice();
|
2009-09-17 05:58:54 +00:00
|
|
|
outParams.suggestedLatency = (device->UpdateSize*device->NumUpdates) /
|
2009-03-10 07:55:29 +00:00
|
|
|
(float)device->Frequency;
|
|
|
|
outParams.hostApiSpecificStreamInfo = NULL;
|
|
|
|
|
2010-12-05 03:50:00 +00:00
|
|
|
switch(device->FmtType)
|
2009-03-10 07:55:29 +00:00
|
|
|
{
|
2010-12-05 03:50:00 +00:00
|
|
|
case DevFmtByte:
|
|
|
|
outParams.sampleFormat = paInt8;
|
|
|
|
break;
|
|
|
|
case DevFmtUByte:
|
2009-03-10 07:55:29 +00:00
|
|
|
outParams.sampleFormat = paUInt8;
|
|
|
|
break;
|
2010-12-05 03:50:00 +00:00
|
|
|
case DevFmtUShort:
|
|
|
|
device->FmtType = DevFmtShort;
|
|
|
|
/* fall-through */
|
|
|
|
case DevFmtShort:
|
2009-03-10 07:55:29 +00:00
|
|
|
outParams.sampleFormat = paInt16;
|
|
|
|
break;
|
2010-12-05 03:50:00 +00:00
|
|
|
case DevFmtFloat:
|
2009-08-15 20:20:35 +00:00
|
|
|
outParams.sampleFormat = paFloat32;
|
|
|
|
break;
|
2009-03-10 07:55:29 +00:00
|
|
|
}
|
2010-12-05 03:50:00 +00:00
|
|
|
outParams.channelCount = ChannelsFromDevFmt(device->FmtChans);
|
2009-03-10 07:55:29 +00:00
|
|
|
|
2009-12-02 12:03:51 +00:00
|
|
|
SetDefaultChannelOrder(device);
|
|
|
|
|
2011-06-12 11:37:32 +00:00
|
|
|
err = Pa_OpenStream(&data->stream, NULL, &outParams, device->Frequency,
|
|
|
|
device->UpdateSize, paNoFlag, pa_callback, device);
|
2009-03-10 07:55:29 +00:00
|
|
|
if(err != paNoError)
|
|
|
|
{
|
2011-06-12 11:37:32 +00:00
|
|
|
AL_PRINT("Pa_OpenStream() returned an error: %s\n", Pa_GetErrorText(err));
|
2009-03-10 07:55:29 +00:00
|
|
|
device->ExtraData = NULL;
|
|
|
|
free(data);
|
|
|
|
return ALC_FALSE;
|
|
|
|
}
|
2011-06-12 11:37:32 +00:00
|
|
|
streamInfo = Pa_GetStreamInfo(data->stream);
|
2009-03-10 07:55:29 +00:00
|
|
|
|
2009-08-28 01:55:18 +00:00
|
|
|
device->szDeviceName = strdup(deviceName);
|
2009-09-16 06:14:14 +00:00
|
|
|
device->Frequency = streamInfo->sampleRate;
|
2009-12-26 16:14:28 +00:00
|
|
|
|
2009-03-10 07:55:29 +00:00
|
|
|
return ALC_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pa_close_playback(ALCdevice *device)
|
|
|
|
{
|
|
|
|
pa_data *data = (pa_data*)device->ExtraData;
|
|
|
|
PaError err;
|
|
|
|
|
2011-06-12 11:37:32 +00:00
|
|
|
err = Pa_CloseStream(data->stream);
|
2009-03-10 07:55:29 +00:00
|
|
|
if(err != paNoError)
|
2011-06-12 11:37:32 +00:00
|
|
|
AL_PRINT("Error closing stream: %s\n", Pa_GetErrorText(err));
|
2009-03-10 07:55:29 +00:00
|
|
|
|
|
|
|
free(data);
|
|
|
|
device->ExtraData = NULL;
|
|
|
|
}
|
|
|
|
|
2009-09-16 07:24:44 +00:00
|
|
|
static ALCboolean pa_reset_playback(ALCdevice *device)
|
2009-08-13 19:28:46 +00:00
|
|
|
{
|
2009-09-16 07:08:11 +00:00
|
|
|
pa_data *data = (pa_data*)device->ExtraData;
|
|
|
|
const PaStreamInfo *streamInfo;
|
2009-12-26 16:14:28 +00:00
|
|
|
PaError err;
|
2009-09-16 07:08:11 +00:00
|
|
|
|
2011-06-12 11:37:32 +00:00
|
|
|
streamInfo = Pa_GetStreamInfo(data->stream);
|
2011-05-03 09:29:26 +00:00
|
|
|
if(device->Frequency != streamInfo->sampleRate)
|
|
|
|
{
|
|
|
|
if((device->Flags&DEVICE_FREQUENCY_REQUEST))
|
|
|
|
AL_PRINT("PortAudio does not support changing sample rates (wanted %dhz, got %.1fhz)\n", device->Frequency, streamInfo->sampleRate);
|
|
|
|
device->Flags &= ~DEVICE_FREQUENCY_REQUEST;
|
|
|
|
device->Frequency = streamInfo->sampleRate;
|
|
|
|
}
|
2010-02-25 02:51:57 +00:00
|
|
|
device->UpdateSize = data->update_size;
|
2009-09-16 07:08:11 +00:00
|
|
|
|
2011-06-12 11:37:32 +00:00
|
|
|
err = Pa_StartStream(data->stream);
|
2009-12-26 16:14:28 +00:00
|
|
|
if(err != paNoError)
|
|
|
|
{
|
2011-06-12 11:37:32 +00:00
|
|
|
AL_PRINT("Pa_StartStream() returned an error: %s\n", Pa_GetErrorText(err));
|
2009-12-26 16:14:28 +00:00
|
|
|
return ALC_FALSE;
|
|
|
|
}
|
|
|
|
|
2009-08-13 19:28:46 +00:00
|
|
|
return ALC_TRUE;
|
|
|
|
}
|
|
|
|
|
2009-09-16 07:24:44 +00:00
|
|
|
static void pa_stop_playback(ALCdevice *device)
|
2009-08-13 19:28:46 +00:00
|
|
|
{
|
2009-12-26 16:14:28 +00:00
|
|
|
pa_data *data = (pa_data*)device->ExtraData;
|
|
|
|
PaError err;
|
|
|
|
|
2011-06-12 11:37:32 +00:00
|
|
|
err = Pa_StopStream(data->stream);
|
2009-12-26 16:14:28 +00:00
|
|
|
if(err != paNoError)
|
2011-06-12 11:37:32 +00:00
|
|
|
AL_PRINT("Error stopping stream: %s\n", Pa_GetErrorText(err));
|
2009-08-13 19:28:46 +00:00
|
|
|
}
|
|
|
|
|
2009-03-10 07:55:29 +00:00
|
|
|
|
2009-08-14 02:36:14 +00:00
|
|
|
static ALCboolean pa_open_capture(ALCdevice *device, const ALCchar *deviceName)
|
2009-03-10 07:55:29 +00:00
|
|
|
{
|
2010-03-18 08:58:25 +00:00
|
|
|
PaStreamParameters inParams;
|
|
|
|
ALuint frame_size;
|
|
|
|
pa_data *data;
|
|
|
|
PaError err;
|
|
|
|
|
|
|
|
if(!deviceName)
|
2010-06-01 02:00:33 +00:00
|
|
|
deviceName = pa_device;
|
|
|
|
else if(strcmp(deviceName, pa_device) != 0)
|
2010-03-18 08:58:25 +00:00
|
|
|
return ALC_FALSE;
|
|
|
|
|
|
|
|
if(!pa_load())
|
|
|
|
return ALC_FALSE;
|
|
|
|
|
|
|
|
data = (pa_data*)calloc(1, sizeof(pa_data));
|
|
|
|
if(data == NULL)
|
|
|
|
{
|
|
|
|
alcSetError(device, ALC_OUT_OF_MEMORY);
|
|
|
|
return ALC_FALSE;
|
|
|
|
}
|
|
|
|
|
2010-12-05 03:50:00 +00:00
|
|
|
frame_size = FrameSizeFromDevFmt(device->FmtChans, device->FmtType);
|
2010-03-18 08:58:25 +00:00
|
|
|
data->ring = CreateRingBuffer(frame_size, device->UpdateSize*device->NumUpdates);
|
|
|
|
if(data->ring == NULL)
|
|
|
|
{
|
|
|
|
alcSetError(device, ALC_OUT_OF_MEMORY);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
inParams.device = GetConfigValueInt("port", "capture", -1);
|
|
|
|
if(inParams.device < 0)
|
2011-06-12 11:37:32 +00:00
|
|
|
inParams.device = Pa_GetDefaultOutputDevice();
|
2010-03-18 08:58:25 +00:00
|
|
|
inParams.suggestedLatency = 0.0f;
|
|
|
|
inParams.hostApiSpecificStreamInfo = NULL;
|
|
|
|
|
2010-12-05 03:50:00 +00:00
|
|
|
switch(device->FmtType)
|
2010-03-18 08:58:25 +00:00
|
|
|
{
|
2010-12-05 03:50:00 +00:00
|
|
|
case DevFmtByte:
|
|
|
|
inParams.sampleFormat = paInt8;
|
|
|
|
break;
|
|
|
|
case DevFmtUByte:
|
2010-03-18 08:58:25 +00:00
|
|
|
inParams.sampleFormat = paUInt8;
|
|
|
|
break;
|
2010-12-05 03:50:00 +00:00
|
|
|
case DevFmtShort:
|
2010-03-18 08:58:25 +00:00
|
|
|
inParams.sampleFormat = paInt16;
|
|
|
|
break;
|
2010-12-05 03:50:00 +00:00
|
|
|
case DevFmtFloat:
|
2010-03-18 08:58:25 +00:00
|
|
|
inParams.sampleFormat = paFloat32;
|
|
|
|
break;
|
2010-12-05 03:50:00 +00:00
|
|
|
case DevFmtUShort:
|
|
|
|
AL_PRINT("Unsigned short not supported\n");
|
2010-03-18 08:58:25 +00:00
|
|
|
goto error;
|
|
|
|
}
|
2010-12-05 03:50:00 +00:00
|
|
|
inParams.channelCount = ChannelsFromDevFmt(device->FmtChans);
|
2010-03-18 08:58:25 +00:00
|
|
|
|
2011-06-12 11:37:32 +00:00
|
|
|
err = Pa_OpenStream(&data->stream, &inParams, NULL, device->Frequency,
|
|
|
|
paFramesPerBufferUnspecified, paNoFlag, pa_capture_cb, device);
|
2010-03-18 08:58:25 +00:00
|
|
|
if(err != paNoError)
|
|
|
|
{
|
2011-06-12 11:37:32 +00:00
|
|
|
AL_PRINT("Pa_OpenStream() returned an error: %s\n", Pa_GetErrorText(err));
|
2010-03-18 08:58:25 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
device->szDeviceName = strdup(deviceName);
|
|
|
|
|
|
|
|
device->ExtraData = data;
|
|
|
|
return ALC_TRUE;
|
|
|
|
|
|
|
|
error:
|
|
|
|
DestroyRingBuffer(data->ring);
|
|
|
|
free(data);
|
2009-03-10 07:55:29 +00:00
|
|
|
return ALC_FALSE;
|
|
|
|
}
|
|
|
|
|
2010-03-18 08:58:25 +00:00
|
|
|
static void pa_close_capture(ALCdevice *device)
|
|
|
|
{
|
|
|
|
pa_data *data = (pa_data*)device->ExtraData;
|
|
|
|
PaError err;
|
|
|
|
|
2011-06-12 11:37:32 +00:00
|
|
|
err = Pa_CloseStream(data->stream);
|
2010-03-18 08:58:25 +00:00
|
|
|
if(err != paNoError)
|
2011-06-12 11:37:32 +00:00
|
|
|
AL_PRINT("Error closing stream: %s\n", Pa_GetErrorText(err));
|
2010-03-18 08:58:25 +00:00
|
|
|
|
|
|
|
free(data);
|
|
|
|
device->ExtraData = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pa_start_capture(ALCdevice *device)
|
|
|
|
{
|
|
|
|
pa_data *data = device->ExtraData;
|
|
|
|
PaError err;
|
|
|
|
|
2011-06-12 11:37:32 +00:00
|
|
|
err = Pa_StartStream(data->stream);
|
2010-03-18 08:58:25 +00:00
|
|
|
if(err != paNoError)
|
2011-06-12 11:37:32 +00:00
|
|
|
AL_PRINT("Error starting stream: %s\n", Pa_GetErrorText(err));
|
2010-03-18 08:58:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void pa_stop_capture(ALCdevice *device)
|
|
|
|
{
|
|
|
|
pa_data *data = (pa_data*)device->ExtraData;
|
|
|
|
PaError err;
|
|
|
|
|
2011-06-12 11:37:32 +00:00
|
|
|
err = Pa_StopStream(data->stream);
|
2010-03-18 08:58:25 +00:00
|
|
|
if(err != paNoError)
|
2011-06-12 11:37:32 +00:00
|
|
|
AL_PRINT("Error stopping stream: %s\n", Pa_GetErrorText(err));
|
2010-03-18 08:58:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void pa_capture_samples(ALCdevice *device, ALCvoid *buffer, ALCuint samples)
|
|
|
|
{
|
|
|
|
pa_data *data = device->ExtraData;
|
|
|
|
if(samples <= (ALCuint)RingBufferSize(data->ring))
|
|
|
|
ReadRingBuffer(data->ring, buffer, samples);
|
|
|
|
else
|
|
|
|
alcSetError(device, ALC_INVALID_VALUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ALCuint pa_available_samples(ALCdevice *device)
|
|
|
|
{
|
|
|
|
pa_data *data = device->ExtraData;
|
|
|
|
return RingBufferSize(data->ring);
|
|
|
|
}
|
2009-03-10 07:55:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
static const BackendFuncs pa_funcs = {
|
|
|
|
pa_open_playback,
|
|
|
|
pa_close_playback,
|
2009-09-16 07:24:44 +00:00
|
|
|
pa_reset_playback,
|
|
|
|
pa_stop_playback,
|
2009-03-10 07:55:29 +00:00
|
|
|
pa_open_capture,
|
2010-03-18 08:58:25 +00:00
|
|
|
pa_close_capture,
|
|
|
|
pa_start_capture,
|
|
|
|
pa_stop_capture,
|
|
|
|
pa_capture_samples,
|
2010-11-21 14:32:59 +00:00
|
|
|
pa_available_samples
|
2009-03-10 07:55:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void alc_pa_init(BackendFuncs *func_list)
|
|
|
|
{
|
2009-09-27 07:21:40 +00:00
|
|
|
*func_list = pa_funcs;
|
2009-03-10 07:55:29 +00:00
|
|
|
}
|
2009-08-27 06:45:00 +00:00
|
|
|
|
|
|
|
void alc_pa_deinit(void)
|
|
|
|
{
|
2010-05-28 09:22:17 +00:00
|
|
|
if(pa_handle)
|
|
|
|
{
|
2011-06-12 11:37:32 +00:00
|
|
|
Pa_Terminate();
|
|
|
|
#ifdef HAVE_DYNLOAD
|
|
|
|
CloseLib(pa_handle);
|
2010-05-28 09:22:17 +00:00
|
|
|
#endif
|
|
|
|
pa_handle = NULL;
|
|
|
|
}
|
2009-08-27 06:45:00 +00:00
|
|
|
}
|
2009-08-27 13:09:33 +00:00
|
|
|
|
2011-06-14 11:02:58 +00:00
|
|
|
void alc_pa_probe(enum DevProbe type)
|
2009-08-27 13:09:33 +00:00
|
|
|
{
|
2009-12-26 16:49:11 +00:00
|
|
|
if(!pa_load()) return;
|
2009-08-27 13:09:33 +00:00
|
|
|
|
2011-06-14 11:02:58 +00:00
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case DEVICE_PROBE:
|
|
|
|
AppendDeviceList(pa_device);
|
|
|
|
break;
|
|
|
|
case ALL_DEVICE_PROBE:
|
|
|
|
AppendAllDeviceList(pa_device);
|
|
|
|
break;
|
|
|
|
case CAPTURE_DEVICE_PROBE:
|
|
|
|
AppendCaptureDeviceList(pa_device);
|
|
|
|
break;
|
|
|
|
}
|
2009-08-27 13:09:33 +00:00
|
|
|
}
|