summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2011-05-03 02:29:26 -0700
committerChris Robinson <[email protected]>2011-05-03 02:29:26 -0700
commitba236ad1084ffc99890f0301f444ddc7d63a64e1 (patch)
tree57c2cb594091d19ff86485d2a9039e69ad595778
parent9a28402b90c596ccdc7d1a4ee93f5711637bb484 (diff)
Add a frequency-request device flag
-rw-r--r--Alc/ALc.c17
-rw-r--r--Alc/alsa.c8
-rw-r--r--Alc/coreaudio.c16
-rw-r--r--Alc/oss.c8
-rw-r--r--Alc/portaudio.c8
-rw-r--r--Alc/pulseaudio.c6
-rw-r--r--Alc/solaris.c8
-rw-r--r--Alc/winmm.c8
-rw-r--r--OpenAL32/Include/alMain.h2
9 files changed, 66 insertions, 15 deletions
diff --git a/Alc/ALc.c b/Alc/ALc.c
index 45374467..9bc2f41a 100644
--- a/Alc/ALc.c
+++ b/Alc/ALc.c
@@ -1032,12 +1032,10 @@ static ALCboolean UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
enum DevFmtChannels schans;
enum DevFmtType stype;
ALboolean running;
- ALuint oldRate;
ALuint attrIdx;
ALuint i;
running = ((device->NumContexts > 0) ? AL_TRUE : AL_FALSE);
- oldRate = device->Frequency;
// Check for attributes
if(attrList && attrList[0])
@@ -1059,6 +1057,14 @@ static ALCboolean UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
numStereo = device->NumStereoSources;
numSends = device->NumAuxSends;
+ if(!ConfigValueExists(NULL, "frequency"))
+ device->Flags &= ~DEVICE_FREQUENCY_REQUEST;
+ else
+ {
+ freq = GetConfigValueInt(NULL, "frequency", SWMIXER_OUTPUT_RATE);
+ if(freq < 8000) freq = 8000;
+ }
+
attrIdx = 0;
while(attrList[attrIdx])
{
@@ -1100,8 +1106,8 @@ static ALCboolean UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
else if(!ConfigValueExists(NULL, "frequency"))
{
freq = attrList[attrIdx + 1];
- if(freq < 8000)
- freq = 8000;
+ if(freq < 8000) freq = 8000;
+ device->Flags |= DEVICE_FREQUENCY_REQUEST;
}
}
@@ -1361,6 +1367,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice(const ALCchar *deviceName,
device->szDeviceName = NULL;
+ device->Flags |= DEVICE_FREQUENCY_REQUEST;
device->Frequency = frequency;
if(DecomposeDevFormat(format, &device->FmtChans, &device->FmtType) == AL_FALSE)
{
@@ -2296,6 +2303,8 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName)
InitUIntMap(&device->DatabufferMap);
//Set output format
+ if(ConfigValueExists(NULL, "frequency"))
+ device->Flags |= DEVICE_FREQUENCY_REQUEST;
device->Frequency = GetConfigValueInt(NULL, "frequency", SWMIXER_OUTPUT_RATE);
if(device->Frequency < 8000)
device->Frequency = 8000;
diff --git a/Alc/alsa.c b/Alc/alsa.c
index a7e87587..500ab13b 100644
--- a/Alc/alsa.c
+++ b/Alc/alsa.c
@@ -664,7 +664,13 @@ static ALCboolean alsa_reset_playback(ALCdevice *device)
psnd_pcm_sw_params_free(sp);
- device->Frequency = rate;
+ if(device->Frequency != rate)
+ {
+ if((device->Flags&DEVICE_FREQUENCY_REQUEST))
+ AL_PRINT("Failed to set requested frequency %dhz, got %dhz instead\n", device->Frequency, rate);
+ device->Flags &= ~DEVICE_FREQUENCY_REQUEST;
+ device->Frequency = rate;
+ }
SetDefaultChannelOrder(device);
diff --git a/Alc/coreaudio.c b/Alc/coreaudio.c
index c0ef09c1..2ca9802b 100644
--- a/Alc/coreaudio.c
+++ b/Alc/coreaudio.c
@@ -155,11 +155,17 @@ static ALCboolean ca_reset_playback(ALCdevice *device)
return ALC_FALSE;
}
- /* set AL device's sample rate */
- device->UpdateSize = (ALuint)((ALuint64)device->UpdateSize *
- streamFormat.mSampleRate /
- device->Frequency);
- device->Frequency = streamFormat.mSampleRate;
+ if(device->Frequency != streamFormat.mSampleRate)
+ {
+ if((device->Flags&DEVICE_FREQUENCY_REQUEST))
+ AL_PRINT("CoreAudio does not support changing sample rates (wanted %dhz, got %dhz)\n", device->Frequency, streamFormat.mSampleRate);
+ device->Flags &= ~DEVICE_FREQUENCY_REQUEST;
+
+ device->UpdateSize = (ALuint)((ALuint64)device->UpdateSize *
+ streamFormat.mSampleRate /
+ device->Frequency);
+ device->Frequency = streamFormat.mSampleRate;
+ }
/* FIXME: How to tell what channels are what in the output device, and how
* to specify what we're giving? eg, 6.0 vs 5.1 */
diff --git a/Alc/oss.c b/Alc/oss.c
index ea18689d..0f91bc04 100644
--- a/Alc/oss.c
+++ b/Alc/oss.c
@@ -262,7 +262,13 @@ static ALCboolean oss_reset_playback(ALCdevice *device)
return ALC_FALSE;
}
- device->Frequency = ossSpeed;
+ if(device->Frequency != (ALuint)ossSpeed)
+ {
+ if((device->Flags&DEVICE_FREQUENCY_REQUEST))
+ AL_PRINT("Failed to set requested frequency %dhz, got %dhz instead\n", device->Frequency, ossSpeed);
+ device->Flags &= ~DEVICE_FREQUENCY_REQUEST;
+ device->Frequency = ossSpeed;
+ }
device->UpdateSize = info.fragsize / frameSize;
device->NumUpdates = info.fragments + 1;
diff --git a/Alc/portaudio.c b/Alc/portaudio.c
index 77c7236f..b144973a 100644
--- a/Alc/portaudio.c
+++ b/Alc/portaudio.c
@@ -249,7 +249,13 @@ static ALCboolean pa_reset_playback(ALCdevice *device)
PaError err;
streamInfo = pPa_GetStreamInfo(data->stream);
- device->Frequency = streamInfo->sampleRate;
+ 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;
+ }
device->UpdateSize = data->update_size;
err = pPa_StartStream(data->stream);
diff --git a/Alc/pulseaudio.c b/Alc/pulseaudio.c
index f3754fed..0520e627 100644
--- a/Alc/pulseaudio.c
+++ b/Alc/pulseaudio.c
@@ -877,7 +877,7 @@ static ALCboolean pulse_reset_playback(ALCdevice *device) //{{{
ppa_threaded_mainloop_wait(data->loop);
ppa_operation_unref(o);
}
- if(!ConfigValueExists(NULL, "frequency"))
+ if(!(device->Flags&DEVICE_FREQUENCY_REQUEST))
flags |= PA_STREAM_FIX_RATE;
data->frame_size = FrameSizeFromDevFmt(device->FmtChans, device->FmtType);
@@ -941,6 +941,10 @@ static ALCboolean pulse_reset_playback(ALCdevice *device) //{{{
{
pa_operation *o;
+ if((device->Flags&DEVICE_FREQUENCY_REQUEST))
+ AL_PRINT("Failed to set frequency %dhz, got %dhz instead\n", device->Frequency, data->spec.rate);
+ device->Flags &= ~DEVICE_FREQUENCY_REQUEST;
+
/* Server updated our playback rate, so modify the buffer attribs
* accordingly. */
data->attr.minreq = (ALuint64)(data->attr.minreq/data->frame_size) *
diff --git a/Alc/solaris.c b/Alc/solaris.c
index 18c73343..1b94be1d 100644
--- a/Alc/solaris.c
+++ b/Alc/solaris.c
@@ -192,7 +192,13 @@ static ALCboolean solaris_reset_playback(ALCdevice *device)
return ALC_FALSE;
}
- device->Frequency = info.play.sample_rate;
+ if(device->Frequency != info.play.sample_rate)
+ {
+ if((device->Flags&DEVICE_FREQUENCY_REQUEST))
+ AL_PRINT("Failed to set requested frequency %dhz, got %dhz instead\n", device->Frequency, info.play.sample_rate);
+ device->Flags &= ~DEVICE_FREQUENCY_REQUEST;
+ device->Frequency = info.play.sample_rate;
+ }
device->UpdateSize = (info.play.buffer_size/device->NumUpdates) + 1;
data->data_size = device->UpdateSize * frameSize;
diff --git a/Alc/winmm.c b/Alc/winmm.c
index 10d0c28f..348e764f 100644
--- a/Alc/winmm.c
+++ b/Alc/winmm.c
@@ -428,7 +428,13 @@ static ALCboolean WinMMResetPlayback(ALCdevice *device)
device->UpdateSize = (ALuint)((ALuint64)device->UpdateSize *
pData->Frequency / device->Frequency);
- device->Frequency = pData->Frequency;
+ if(device->Frequency != streamInfo->sampleRate)
+ {
+ if((device->Flags&DEVICE_FREQUENCY_REQUEST))
+ AL_PRINT("WinMM does not support changing sample rates (wanted %dhz, got %dhz)\n", device->Frequency, pData->Frequency);
+ device->Flags &= ~DEVICE_FREQUENCY_REQUEST;
+ device->Frequency = pData->Frequency;
+ }
pData->lWaveBuffersCommitted = 0;
diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h
index aa1b50a1..d8825305 100644
--- a/OpenAL32/Include/alMain.h
+++ b/OpenAL32/Include/alMain.h
@@ -525,6 +525,8 @@ struct ALCdevice_struct
#define DEVICE_DUPLICATE_STEREO (1<<0)
// Use HRTF filters for mixing sounds
#define DEVICE_USE_HRTF (1<<1)
+// Frequency was requested by the app or config file
+#define DEVICE_FREQUENCY_REQUEST (1<<2)
struct ALCcontext_struct