From eeba630cbf48b093bd07d3e8413d6059fddb07df Mon Sep 17 00:00:00 2001 From: Kari Salminen Date: Wed, 13 Aug 2008 01:02:00 +0000 Subject: Changed Agi::SoundMgr's sound buffer to a member array of size BUFFER_SIZE. Also added initialization of _playing to false in SoundMgr's constructor. Hopefully helps with the occasional crashes in the sound code when starting the first sound in an AGI game. svn-id: r33815 --- engines/agi/sound.cpp | 19 +++++++------------ engines/agi/sound.h | 3 ++- 2 files changed, 9 insertions(+), 13 deletions(-) (limited to 'engines/agi') diff --git a/engines/agi/sound.cpp b/engines/agi/sound.cpp index 77f79272f8..69ccc2c218 100644 --- a/engines/agi/sound.cpp +++ b/engines/agi/sound.cpp @@ -435,13 +435,9 @@ void IIgsMidiChannel::stopSounds() { _gsChannels.clear(); } -static int16 *buffer; - int SoundMgr::initSound() { int r = -1; - buffer = _sndBuffer = (int16 *)calloc(2, BUFFER_SIZE); - _env = false; switch (_vm->_soundemu) { @@ -478,7 +474,6 @@ int SoundMgr::initSound() { void SoundMgr::deinitSound() { debugC(3, kDebugLevelSound, "()"); _mixer->stopHandle(_soundHandle); - free(_sndBuffer); } void SoundMgr::stopNote(int i) { @@ -1185,7 +1180,7 @@ bool SoundMgr::loadInstruments() { return _gsSound.loadWaveFile(waveFsnode->getPath(), *exeInfo) && _gsSound.loadInstrumentHeaders(exeFsnode->getPath(), *exeInfo); } -static void fillAudio(void *udata, int16 *stream, uint len) { +void SoundMgr::fillAudio(void *udata, int16 *stream, uint len) { SoundMgr *soundMgr = (SoundMgr *)udata; uint32 p = 0; static uint32 n = 0, s = 0; @@ -1193,32 +1188,32 @@ static void fillAudio(void *udata, int16 *stream, uint len) { len <<= 2; debugC(5, kDebugLevelSound, "(%p, %p, %d)", (void *)udata, (void *)stream, len); - memcpy(stream, (uint8 *)buffer + s, p = n); + memcpy(stream, ((uint8 *)&_sndBuffer[0]) + s, p = n); for (n = 0, len -= p; n < len; p += n, len -= n) { soundMgr->playSound(); n = soundMgr->mixSound() << 1; if (len < n) { - memcpy((uint8 *)stream + p, buffer, len); + memcpy((uint8 *)stream + p, _sndBuffer, len); s = len; n -= s; return; } else { - memcpy((uint8 *)stream + p, buffer, n); + memcpy((uint8 *)stream + p, _sndBuffer, n); } } soundMgr->playSound(); n = soundMgr->mixSound() << 1; - memcpy((uint8 *)stream + p, buffer, s = len); + memcpy((uint8 *)stream + p, _sndBuffer, s = len); n -= s; } -SoundMgr::SoundMgr(AgiBase *agi, Audio::Mixer *pMixer) { +SoundMgr::SoundMgr(AgiBase *agi, Audio::Mixer *pMixer) : _sndBuffer() { _vm = agi; _mixer = pMixer; _sampleRate = pMixer->getOutputRate(); _endflag = -1; + _playing = false; _playingSound = -1; - _sndBuffer = 0; _waveform = 0; } diff --git a/engines/agi/sound.h b/engines/agi/sound.h index f1c2782421..9b71ac388e 100644 --- a/engines/agi/sound.h +++ b/engines/agi/sound.h @@ -468,10 +468,11 @@ private: int _playingSound; uint8 _env; - int16 *_sndBuffer; + int16 _sndBuffer[BUFFER_SIZE]; const int16 *_waveform; void premixerCall(int16 *buf, uint len); + void fillAudio(void *udata, int16 *stream, uint len); public: void unloadSound(int); -- cgit v1.2.3 From be9192687b22e11bee2fe98f5e06a7a2dd623fd1 Mon Sep 17 00:00:00 2001 From: Kari Salminen Date: Wed, 13 Aug 2008 01:10:03 +0000 Subject: Shutting up Valgrind about using uninitialised values from array _chn in function stopNote. svn-id: r33816 --- engines/agi/sound.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/agi') diff --git a/engines/agi/sound.cpp b/engines/agi/sound.cpp index 69ccc2c218..ec56763a93 100644 --- a/engines/agi/sound.cpp +++ b/engines/agi/sound.cpp @@ -1207,7 +1207,7 @@ void SoundMgr::fillAudio(void *udata, int16 *stream, uint len) { n -= s; } -SoundMgr::SoundMgr(AgiBase *agi, Audio::Mixer *pMixer) : _sndBuffer() { +SoundMgr::SoundMgr(AgiBase *agi, Audio::Mixer *pMixer) : _sndBuffer(), _chn() { _vm = agi; _mixer = pMixer; _sampleRate = pMixer->getOutputRate(); -- cgit v1.2.3 From f69cc559b9d35526b25ac76bcc82046471b39d06 Mon Sep 17 00:00:00 2001 From: Kari Salminen Date: Wed, 13 Aug 2008 11:36:45 +0000 Subject: Reverted r33815 (But not r33816). svn-id: r33819 --- engines/agi/sound.cpp | 19 ++++++++++++------- engines/agi/sound.h | 3 +-- 2 files changed, 13 insertions(+), 9 deletions(-) (limited to 'engines/agi') diff --git a/engines/agi/sound.cpp b/engines/agi/sound.cpp index ec56763a93..cfa87d2c98 100644 --- a/engines/agi/sound.cpp +++ b/engines/agi/sound.cpp @@ -435,9 +435,13 @@ void IIgsMidiChannel::stopSounds() { _gsChannels.clear(); } +static int16 *buffer; + int SoundMgr::initSound() { int r = -1; + buffer = _sndBuffer = (int16 *)calloc(2, BUFFER_SIZE); + _env = false; switch (_vm->_soundemu) { @@ -474,6 +478,7 @@ int SoundMgr::initSound() { void SoundMgr::deinitSound() { debugC(3, kDebugLevelSound, "()"); _mixer->stopHandle(_soundHandle); + free(_sndBuffer); } void SoundMgr::stopNote(int i) { @@ -1180,7 +1185,7 @@ bool SoundMgr::loadInstruments() { return _gsSound.loadWaveFile(waveFsnode->getPath(), *exeInfo) && _gsSound.loadInstrumentHeaders(exeFsnode->getPath(), *exeInfo); } -void SoundMgr::fillAudio(void *udata, int16 *stream, uint len) { +static void fillAudio(void *udata, int16 *stream, uint len) { SoundMgr *soundMgr = (SoundMgr *)udata; uint32 p = 0; static uint32 n = 0, s = 0; @@ -1188,32 +1193,32 @@ void SoundMgr::fillAudio(void *udata, int16 *stream, uint len) { len <<= 2; debugC(5, kDebugLevelSound, "(%p, %p, %d)", (void *)udata, (void *)stream, len); - memcpy(stream, ((uint8 *)&_sndBuffer[0]) + s, p = n); + memcpy(stream, (uint8 *)buffer + s, p = n); for (n = 0, len -= p; n < len; p += n, len -= n) { soundMgr->playSound(); n = soundMgr->mixSound() << 1; if (len < n) { - memcpy((uint8 *)stream + p, _sndBuffer, len); + memcpy((uint8 *)stream + p, buffer, len); s = len; n -= s; return; } else { - memcpy((uint8 *)stream + p, _sndBuffer, n); + memcpy((uint8 *)stream + p, buffer, n); } } soundMgr->playSound(); n = soundMgr->mixSound() << 1; - memcpy((uint8 *)stream + p, _sndBuffer, s = len); + memcpy((uint8 *)stream + p, buffer, s = len); n -= s; } -SoundMgr::SoundMgr(AgiBase *agi, Audio::Mixer *pMixer) : _sndBuffer(), _chn() { +SoundMgr::SoundMgr(AgiBase *agi, Audio::Mixer *pMixer) : _chn() { _vm = agi; _mixer = pMixer; _sampleRate = pMixer->getOutputRate(); _endflag = -1; - _playing = false; _playingSound = -1; + _sndBuffer = 0; _waveform = 0; } diff --git a/engines/agi/sound.h b/engines/agi/sound.h index 9b71ac388e..f1c2782421 100644 --- a/engines/agi/sound.h +++ b/engines/agi/sound.h @@ -468,11 +468,10 @@ private: int _playingSound; uint8 _env; - int16 _sndBuffer[BUFFER_SIZE]; + int16 *_sndBuffer; const int16 *_waveform; void premixerCall(int16 *buf, uint len); - void fillAudio(void *udata, int16 *stream, uint len); public: void unloadSound(int); -- cgit v1.2.3 From 09762ac7a6c7e201b44466b8286aa1e53e7fadaa Mon Sep 17 00:00:00 2001 From: Kari Salminen Date: Wed, 13 Aug 2008 11:57:48 +0000 Subject: Fixed initialization of some SoundMgr-class's member variables. Moved _sndBuffer's allocation to SoundMgr's constructor and its deallocation to the destructor. Made fillAudio SoundMgr's method and removed a superfluous global static variable 'int16 *buffer'. Should help with the occasional crashes when starting the first sound in an AGI game. svn-id: r33822 --- engines/agi/sound.cpp | 21 ++++++++++----------- engines/agi/sound.h | 1 + 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'engines/agi') diff --git a/engines/agi/sound.cpp b/engines/agi/sound.cpp index cfa87d2c98..9fe8fbf41a 100644 --- a/engines/agi/sound.cpp +++ b/engines/agi/sound.cpp @@ -435,13 +435,10 @@ void IIgsMidiChannel::stopSounds() { _gsChannels.clear(); } -static int16 *buffer; - int SoundMgr::initSound() { int r = -1; - buffer = _sndBuffer = (int16 *)calloc(2, BUFFER_SIZE); - + memset(_sndBuffer, 0, BUFFER_SIZE << 1); _env = false; switch (_vm->_soundemu) { @@ -478,7 +475,6 @@ int SoundMgr::initSound() { void SoundMgr::deinitSound() { debugC(3, kDebugLevelSound, "()"); _mixer->stopHandle(_soundHandle); - free(_sndBuffer); } void SoundMgr::stopNote(int i) { @@ -1185,7 +1181,7 @@ bool SoundMgr::loadInstruments() { return _gsSound.loadWaveFile(waveFsnode->getPath(), *exeInfo) && _gsSound.loadInstrumentHeaders(exeFsnode->getPath(), *exeInfo); } -static void fillAudio(void *udata, int16 *stream, uint len) { +void SoundMgr::fillAudio(void *udata, int16 *stream, uint len) { SoundMgr *soundMgr = (SoundMgr *)udata; uint32 p = 0; static uint32 n = 0, s = 0; @@ -1193,22 +1189,22 @@ static void fillAudio(void *udata, int16 *stream, uint len) { len <<= 2; debugC(5, kDebugLevelSound, "(%p, %p, %d)", (void *)udata, (void *)stream, len); - memcpy(stream, (uint8 *)buffer + s, p = n); + memcpy(stream, (uint8 *)_sndBuffer + s, p = n); for (n = 0, len -= p; n < len; p += n, len -= n) { soundMgr->playSound(); n = soundMgr->mixSound() << 1; if (len < n) { - memcpy((uint8 *)stream + p, buffer, len); + memcpy((uint8 *)stream + p, _sndBuffer, len); s = len; n -= s; return; } else { - memcpy((uint8 *)stream + p, buffer, n); + memcpy((uint8 *)stream + p, _sndBuffer, n); } } soundMgr->playSound(); n = soundMgr->mixSound() << 1; - memcpy((uint8 *)stream + p, buffer, s = len); + memcpy((uint8 *)stream + p, _sndBuffer, s = len); n -= s; } @@ -1218,7 +1214,9 @@ SoundMgr::SoundMgr(AgiBase *agi, Audio::Mixer *pMixer) : _chn() { _sampleRate = pMixer->getOutputRate(); _endflag = -1; _playingSound = -1; - _sndBuffer = 0; + _env = false; + _playing = false; + _sndBuffer = (int16 *)calloc(2, BUFFER_SIZE); _waveform = 0; } @@ -1231,6 +1229,7 @@ void SoundMgr::setVolume(uint8 volume) { } SoundMgr::~SoundMgr() { + free(_sndBuffer); } } // End of namespace Agi diff --git a/engines/agi/sound.h b/engines/agi/sound.h index f1c2782421..a1f079891f 100644 --- a/engines/agi/sound.h +++ b/engines/agi/sound.h @@ -472,6 +472,7 @@ private: const int16 *_waveform; void premixerCall(int16 *buf, uint len); + void fillAudio(void *udata, int16 *stream, uint len); public: void unloadSound(int); -- cgit v1.2.3