aboutsummaryrefslogtreecommitdiff
path: root/engines/gob/sound
diff options
context:
space:
mode:
authorSven Hesse2008-12-14 04:13:48 +0000
committerSven Hesse2008-12-14 04:13:48 +0000
commit8770cef478eab747d6f08de4a4f2dc1344c31f4c (patch)
tree00294c0f4e6b24701e964b4321285143eba0cf36 /engines/gob/sound
parent68dcb1ffee87ce04dceb879f5eb3916fb99a1abe (diff)
downloadscummvm-rg350-8770cef478eab747d6f08de4a4f2dc1344c31f4c.tar.gz
scummvm-rg350-8770cef478eab747d6f08de4a4f2dc1344c31f4c.tar.bz2
scummvm-rg350-8770cef478eab747d6f08de4a4f2dc1344c31f4c.zip
16bit background "music" for Urban Runner
svn-id: r35353
Diffstat (limited to 'engines/gob/sound')
-rw-r--r--engines/gob/sound/sounddesc.cpp17
-rw-r--r--engines/gob/sound/sounddesc.h1
-rw-r--r--engines/gob/sound/soundmixer.cpp35
-rw-r--r--engines/gob/sound/soundmixer.h9
4 files changed, 50 insertions, 12 deletions
diff --git a/engines/gob/sound/sounddesc.cpp b/engines/gob/sound/sounddesc.cpp
index ee3125728b..c4c78eebbd 100644
--- a/engines/gob/sound/sounddesc.cpp
+++ b/engines/gob/sound/sounddesc.cpp
@@ -43,6 +43,7 @@ SoundDesc::SoundDesc() {
_frequency = 0;
_flag = 0;
_id = 0;
+ _mixerFlags = 0;
}
SoundDesc::~SoundDesc() {
@@ -86,9 +87,19 @@ void SoundDesc::free() {
}
void SoundDesc::convToSigned() {
- if (((_type == SOUND_SND) || (_type == SOUND_WAV)) && _data && _dataPtr)
+ if ((_type != SOUND_SND) && (_type != SOUND_WAV))
+ return;
+ if (!_data || !_dataPtr)
+ return;
+
+ if (_mixerFlags & Audio::Mixer::FLAG_16BITS) {
+ uint16 *data = (uint16 *) _dataPtr;
+ for (uint32 i = 0; i < _size; i++)
+ data[i] ^= 0x8000;
+ } else
for (uint32 i = 0; i < _size; i++)
_dataPtr[i] ^= 0x80;
+
}
int16 SoundDesc::calcFadeOutLength(int16 frequency) {
@@ -125,8 +136,8 @@ bool SoundDesc::loadWAV(byte *data, uint32 dSize) {
return false;
if (wavFlags & Audio::Mixer::FLAG_16BITS) {
- warning("TODO: SoundDesc::loadWAV() - 16bit");
- return false;
+ _mixerFlags |= Audio::Mixer::FLAG_16BITS;
+ wavSize >>= 1;
}
if (wavFlags & Audio::Mixer::FLAG_STEREO) {
diff --git a/engines/gob/sound/sounddesc.h b/engines/gob/sound/sounddesc.h
index fe1da14760..83efd61e6d 100644
--- a/engines/gob/sound/sounddesc.h
+++ b/engines/gob/sound/sounddesc.h
@@ -48,6 +48,7 @@ public:
int16 _frequency;
int16 _flag;
int16 _id;
+ byte _mixerFlags;
byte *getData() { return _dataPtr; }
diff --git a/engines/gob/sound/soundmixer.cpp b/engines/gob/sound/soundmixer.cpp
index 1a287d782f..483bf7608e 100644
--- a/engines/gob/sound/soundmixer.cpp
+++ b/engines/gob/sound/soundmixer.cpp
@@ -32,7 +32,8 @@ SoundMixer::SoundMixer(Audio::Mixer &mixer, Audio::Mixer::SoundType type) : _mix
_rate = _mixer->getOutputRate();
_end = true;
- _data = 0;
+ _data8 = 0;
+ _data16 = 0;
_length = 0;
_freq = 0;
_repCount = 0;
@@ -57,6 +58,13 @@ SoundMixer::~SoundMixer() {
_mixer->stopHandle(_handle);
}
+inline int16 SoundMixer::getData(int offset) {
+ if (!_16bit)
+ return (int16) _data8[offset];
+ else
+ return (int16) _data16[offset];
+}
+
bool SoundMixer::isPlaying() const {
return !_end;
}
@@ -69,7 +77,8 @@ void SoundMixer::stop(int16 fadeLength) {
Common::StackLock slock(_mutex);
if (fadeLength <= 0) {
- _data = 0;
+ _data8 = 0;
+ _data16 = 0;
_end = true;
_playingSound = 0;
return;
@@ -97,7 +106,16 @@ void SoundMixer::setSample(SoundDesc &sndDesc, int16 repCount, int16 frequency,
sndDesc._repCount = repCount - 1;
sndDesc._frequency = frequency;
- _data = (int8 *) sndDesc.getData();
+ _16bit = (sndDesc._mixerFlags & Audio::Mixer::FLAG_16BITS) != 0;
+
+ if (_16bit) {
+ _data16 = (int16 *) sndDesc.getData();
+ _shift = 0;
+ } else {
+ _data8 = (int8 *) sndDesc.getData();
+ _shift = 8;
+ }
+
_length = sndDesc.size();
_freq = frequency;
@@ -110,7 +128,7 @@ void SoundMixer::setSample(SoundDesc &sndDesc, int16 repCount, int16 frequency,
_offsetInc = (_freq << FRAC_BITS) / _rate;
_last = _cur;
- _cur = _data[0];
+ _cur = getData(0);
_curFadeSamples = 0;
if (fadeLength == 0) {
@@ -152,7 +170,7 @@ int SoundMixer::readBuffer(int16 *buffer, const int numSamples) {
Common::StackLock slock(_mutex);
for (int i = 0; i < numSamples; i++) {
- if (!_data)
+ if (!_data8 && !_data16)
return i;
if (_end || (_offset >= _length))
checkEndSample();
@@ -162,7 +180,7 @@ int SoundMixer::readBuffer(int16 *buffer, const int numSamples) {
// Linear interpolation. See sound/rate.cpp
int16 val = (_last + (((_cur - _last) * _offsetFrac +
- FRAC_HALF) >> FRAC_BITS)) << 8;
+ FRAC_HALF) >> FRAC_BITS)) << _shift;
*buffer++ = (val * _fadeVol) >> 16;
_offsetFrac += _offsetInc;
@@ -170,7 +188,7 @@ int SoundMixer::readBuffer(int16 *buffer, const int numSamples) {
// Was there an integral change?
if (fracToInt(_offsetFrac) > 0) {
_last = _cur;
- _cur = _data[_offset];
+ _cur = getData(_offset);
_offset += fracToInt(_offsetFrac);
_offsetFrac &= FRAC_LO_MASK;
}
@@ -192,7 +210,8 @@ int SoundMixer::readBuffer(int16 *buffer, const int numSamples) {
void SoundMixer::endFade() {
if (_fadeVolStep > 0) {
- _data = 0;
+ _data8 = 0;
+ _data16 = 0;
_end = true;
_playingSound = 0;
} else {
diff --git a/engines/gob/sound/soundmixer.h b/engines/gob/sound/soundmixer.h
index 3e8e6b5c1b..f32beb149f 100644
--- a/engines/gob/sound/soundmixer.h
+++ b/engines/gob/sound/soundmixer.h
@@ -61,8 +61,12 @@ protected:
Audio::SoundHandle _handle;
Common::Mutex _mutex;
+ bool _16bit;
+ int _shift;
+
bool _end;
- int8 *_data;
+ int8 *_data8;
+ int16 *_data16;
uint32 _length;
uint32 _rate;
int32 _freq;
@@ -88,6 +92,9 @@ protected:
int16 frequency, int16 fadeLength);
virtual void checkEndSample();
virtual void endFade();
+
+private:
+ inline int16 getData(int offset);
};
} // End of namespace Gob