summaryrefslogtreecommitdiff
path: root/src/mixer.cpp
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2010-01-16 22:15:02 +0000
committerpeter1138 <peter1138@openttd.org>2010-01-16 22:15:02 +0000
commitdf06c14f610dfce9f3acd8638fc40df16b0d148e (patch)
tree9d8937b6267318e9ae842c9b4a2cfeaa6d7d11e6 /src/mixer.cpp
parent15adbad2f410dc6ccaba708619fbfdcf6dfccfc8 (diff)
downloadopenttd-df06c14f610dfce9f3acd8638fc40df16b0d148e.tar.xz
(svn r18835) -Fix: Large sounds could still cause an overflow with high sample rates, causing them to be cut off.
Diffstat (limited to 'src/mixer.cpp')
-rw-r--r--src/mixer.cpp10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/mixer.cpp b/src/mixer.cpp
index 6fcdcb11f..1b054f4e3 100644
--- a/src/mixer.cpp
+++ b/src/mixer.cpp
@@ -33,6 +33,7 @@ struct MixerChannel {
static MixerChannel _channels[8];
static uint32 _play_rate = 11025;
+static uint32 _max_size = UINT_MAX;
/**
* The theoretical maximum volume for a single sound sample. Multiple sound
@@ -172,15 +173,15 @@ void MxSetChannelRawSrc(MixerChannel *mc, int8 *mem, size_t size, uint rate, boo
mc->frac_speed = (rate << 16) / _play_rate;
+ if (is16bit) size /= 2;
+
/* adjust the magnitude to prevent overflow */
- while (size & ~0xFFFF) {
+ while (size >= _max_size) {
size >>= 1;
rate = (rate >> 1) + 1;
}
- int div = is16bit ? 2 : 1;
-
- mc->samples_left = (uint)size * _play_rate / rate / div;
+ mc->samples_left = (uint)size * _play_rate / rate;
mc->is16bit = is16bit;
}
@@ -200,5 +201,6 @@ void MxActivateChannel(MixerChannel *mc)
bool MxInitialize(uint rate)
{
_play_rate = rate;
+ _max_size = UINT_MAX / _play_rate;
return true;
}