aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2020-04-28 16:30:11 -0700
committerChris Robinson <[email protected]>2020-04-28 16:30:11 -0700
commit065775d814a972bfedf2cc8e5db35a56f1eecb93 (patch)
tree2b2ea2ca270356d36f076667f795ea94d0c6982d
parent45cb3e495675f30b28b7394cc8e38b99707e9dda (diff)
Limit the maximum settable sample rate
-rw-r--r--alc/alc.cpp20
-rw-r--r--alc/alcmain.h2
2 files changed, 14 insertions, 8 deletions
diff --git a/alc/alc.cpp b/alc/alc.cpp
index e177bc56..1d299b1b 100644
--- a/alc/alc.cpp
+++ b/alc/alc.cpp
@@ -1865,7 +1865,8 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const int *attrList)
WARN("Missing format for loopback device\n");
return ALC_INVALID_VALUE;
}
- if(!IsValidALCChannels(schans) || !IsValidALCType(stype) || freq < MIN_OUTPUT_RATE)
+ if(!IsValidALCChannels(schans) || !IsValidALCType(stype) || freq < MIN_OUTPUT_RATE
+ || freq > MAX_OUTPUT_RATE)
return ALC_INVALID_VALUE;
if(schans == ALC_BFORMAT3D_SOFT)
{
@@ -1906,7 +1907,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const int *attrList)
device->Flags.unset<FrequencyRequest>();
else
{
- freq = maxu(freq, MIN_OUTPUT_RATE);
+ freq = clampu(freq, MIN_OUTPUT_RATE, MAX_OUTPUT_RATE);
const double scale{static_cast<double>(freq) / device->Frequency};
device->UpdateSize = static_cast<ALuint>(device->UpdateSize*scale + 0.5);
@@ -3693,13 +3694,15 @@ START_API_FUNC
if(ALuint freq{ConfigValueUInt(deviceName, nullptr, "frequency").value_or(0)})
{
- if(freq < MIN_OUTPUT_RATE)
+ if(freq < MIN_OUTPUT_RATE || freq > MAX_OUTPUT_RATE)
{
- ERR("%uhz request clamped to %uhz minimum\n", freq, MIN_OUTPUT_RATE);
- freq = MIN_OUTPUT_RATE;
+ const ALuint newfreq{clampu(freq, MIN_OUTPUT_RATE, MAX_OUTPUT_RATE)};
+ ERR("%uhz request clamped to %uhz\n", freq, newfreq);
+ freq = newfreq;
}
- device->UpdateSize = (device->UpdateSize*freq + device->Frequency/2) / device->Frequency;
- device->BufferSize = (device->BufferSize*freq + device->Frequency/2) / device->Frequency;
+ const double scale{static_cast<double>(freq) / device->Frequency};
+ device->UpdateSize = static_cast<ALuint>(device->UpdateSize*scale + 0.5);
+ device->BufferSize = static_cast<ALuint>(device->BufferSize*scale + 0.5);
device->Frequency = freq;
device->Flags.set<FrequencyRequest>();
}
@@ -4081,7 +4084,8 @@ START_API_FUNC
alcSetError(dev.get(), ALC_INVALID_VALUE);
else
{
- if(IsValidALCType(type) && IsValidALCChannels(channels) && freq >= MIN_OUTPUT_RATE)
+ if(IsValidALCType(type) && IsValidALCChannels(channels) && freq >= MIN_OUTPUT_RATE
+ && freq <= MAX_OUTPUT_RATE)
return ALC_TRUE;
}
diff --git a/alc/alcmain.h b/alc/alcmain.h
index a53065b4..9c539c44 100644
--- a/alc/alcmain.h
+++ b/alc/alcmain.h
@@ -43,7 +43,9 @@ struct bs2b;
#define MIN_OUTPUT_RATE 8000
+#define MAX_OUTPUT_RATE 192000
#define DEFAULT_OUTPUT_RATE 44100
+
#define DEFAULT_UPDATE_SIZE 882 /* 20ms */
#define DEFAULT_NUM_UPDATES 3