Add a frequency-request device flag
This commit is contained in:
parent
9a28402b90
commit
ba236ad108
17
Alc/ALc.c
17
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;
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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 */
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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) *
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user