From c667702f2c6f9e4adc301eb0a11f4c3c327076ad Mon Sep 17 00:00:00 2001 From: Strangerke Date: Mon, 2 Jan 2017 14:49:49 -0800 Subject: CRYO: Change soundchannel_t into a class --- engines/cryo/cryolib.cpp | 44 ++++++++++++++++++++------------------------ engines/cryo/cryolib.h | 23 +++++++++++++---------- engines/cryo/eden.cpp | 8 ++++---- engines/cryo/sound.cpp | 2 +- engines/cryo/video.cpp | 14 +++++++------- 5 files changed, 45 insertions(+), 46 deletions(-) (limited to 'engines/cryo') diff --git a/engines/cryo/cryolib.cpp b/engines/cryo/cryolib.cpp index dbc279f969..3aa6e997d6 100644 --- a/engines/cryo/cryolib.cpp +++ b/engines/cryo/cryolib.cpp @@ -358,52 +358,48 @@ void CLSound_SetLength(sound_t *sound, int length) { ///// CLSoundChannel /// sound output device that plays queue of sounds -soundchannel_t *CLSoundChannel_New(int arg1) { - soundchannel_t *ch = (soundchannel_t *)malloc(sizeof(*ch)); - if (!ch) - return nullptr; - - ch->_volumeLeft = ch->_volumeRight = 255; - ch->_numSounds = 0; +soundchannel_t::soundchannel_t(int arg1) { + _volumeLeft = _volumeRight = 255; + _numSounds = 0; for (int16 i = 0; i < kCryoMaxChSounds; i++) - ch->_sounds[i] = nullptr; - - return ch; + _sounds[i] = nullptr; } -void CLSoundChannel_Free(soundchannel_t *ch) { - free(ch); +soundchannel_t::~soundchannel_t() { } -void CLSoundChannel_Stop(soundchannel_t *ch) { - // _vm->_mixer->stopHandle(ch->ch); +void soundchannel_t::stop() { + // _vm->_mixer->stopHandle(this); } -void CLSoundChannel_Play(soundchannel_t *ch, sound_t *sound) { +void soundchannel_t::play(sound_t *sound) { } -int16 CLSoundChannel_GetVolume(soundchannel_t *ch) { - return (ch->_volumeLeft + ch->_volumeRight) / 2; +int16 soundchannel_t::getVolume() { + return (_volumeLeft + _volumeRight) / 2; } -void CLSoundChannel_SetVolume(soundchannel_t *ch, int16 volume) { +void soundchannel_t::setVolume(int16 volume) { if (volume < 0 || volume > 255) return; - ch->_volumeLeft = volume; - ch->_volumeRight = volume; + + _volumeLeft = volume; + _volumeRight = volume; } -void CLSoundChannel_SetVolumeRight(soundchannel_t *ch, int16 volume) { +void soundchannel_t::setVolumeRight(int16 volume) { if (volume < 0 || volume > 255) return; - ch->_volumeRight = volume; + + _volumeRight = volume; } -void CLSoundChannel_SetVolumeLeft(soundchannel_t *ch, int16 volume) { +void soundchannel_t::setVolumeLeft(int16 volume) { if (volume < 0 || volume > 255) return; - ch->_volumeLeft = volume; + + _volumeLeft = volume; } ///// CLTimer diff --git a/engines/cryo/cryolib.h b/engines/cryo/cryolib.h index 051e06b703..b6d72e303e 100644 --- a/engines/cryo/cryolib.h +++ b/engines/cryo/cryolib.h @@ -159,12 +159,24 @@ struct sound_t { #define kCryoMaxChSounds 10 -struct soundchannel_t { +class soundchannel_t { +private: int16 _volumeLeft; int16 _volumeRight; int16 _numSounds; sound_t *_sounds[kCryoMaxChSounds]; + +public: + soundchannel_t(int arg1); + ~soundchannel_t(); + + void stop(); + void play(sound_t *sound); + int16 getVolume(); + void setVolume(int16 volume); + void setVolumeRight(int16 volume); + void setVolumeLeft(int16 volume); }; sound_t *CLSoundRaw_New(int16 length, float rate, int16 sampleSize, int16 mode); @@ -202,15 +214,6 @@ void CLSound_PrepareSample(sound_t *sound, int16 mode); void CLSound_SetWantsDesigned(int16 designed); void CLSound_SetLength(sound_t *sound, int length); -soundchannel_t *CLSoundChannel_New(int arg1); -void CLSoundChannel_Free(soundchannel_t *ch); -void CLSoundChannel_Stop(soundchannel_t *ch); -void CLSoundChannel_Play(soundchannel_t *ch, sound_t *sound); -int16 CLSoundChannel_GetVolume(soundchannel_t *ch); -void CLSoundChannel_SetVolume(soundchannel_t *ch, int16 volume); -void CLSoundChannel_SetVolumeRight(soundchannel_t *ch, int16 volume); -void CLSoundChannel_SetVolumeLeft(soundchannel_t *ch, int16 volume); - void CRYOLib_ManagersInit(); void CRYOLib_ManagersDone(); diff --git a/engines/cryo/eden.cpp b/engines/cryo/eden.cpp index a3187e598e..5900a7ba7a 100644 --- a/engines/cryo/eden.cpp +++ b/engines/cryo/eden.cpp @@ -5838,7 +5838,7 @@ void EdenGame::edmain() { void EdenGame::intro() { if (_vm->getPlatform() == Common::kPlatformMacintosh) { // Play intro videos in HQ - CLSoundChannel_Stop(_hnmSoundChannel); + _hnmSoundChannel->stop(); _vm->_video->closeSound(); _vm->_video->setupSound(5, 0x2000, 16, 22050 * 65536.0, 0); _hnmSoundChannel = _vm->_video->getSoundChannel(); @@ -5847,7 +5847,7 @@ void EdenGame::intro() { CLBlitter_FillScreenView(0); _specialTextMode = false; playHNM(2001); - CLSoundChannel_Stop(_hnmSoundChannel); + _hnmSoundChannel->stop(); _vm->_video->closeSound(); _vm->_video->setupSound(5, 0x2000, 8, 11025 * 65536.0, 0); _hnmSoundChannel = _vm->_video->getSoundChannel(); @@ -6354,8 +6354,8 @@ void EdenGame::showMovie(char arg1) { _vm->_video->readHeader(_hnmContext); if (_vm->_video->_curVideoNum == 92) { // _hnmContext->_header._unusedFlag2 = 0; CHECKME: Useless? - CLSoundChannel_SetVolumeLeft(_hnmSoundChannel, 0); - CLSoundChannel_SetVolumeRight(_hnmSoundChannel, 0); + _hnmSoundChannel->setVolumeLeft(0); + _hnmSoundChannel->setVolumeRight(0); } if (_vm->_video->getVersion(_hnmContext) != 4) diff --git a/engines/cryo/sound.cpp b/engines/cryo/sound.cpp index 2a262125fb..736ce049dd 100644 --- a/engines/cryo/sound.cpp +++ b/engines/cryo/sound.cpp @@ -159,7 +159,7 @@ bool SoundGroup::setDatas(void *data, int length, bool isSigned) { // Original name: CLSoundGroup_PlayNextSample void SoundGroup::playNextSample(soundchannel_t *ch) { - CLSoundChannel_Play(ch, _sounds[_playIndex]); + ch->play(_sounds[_playIndex]); if (_playIndex == _numSounds - 1) _playIndex = 0; else diff --git a/engines/cryo/video.cpp b/engines/cryo/video.cpp index 104620466b..d15985a51c 100644 --- a/engines/cryo/video.cpp +++ b/engines/cryo/video.cpp @@ -127,7 +127,7 @@ void HnmPlayer::wantsSound(bool sound) { // Original name: CLHNM_SetupSound void HnmPlayer::setupSound(int16 numSounds, int16 length, int16 sampleSize, float rate, int16 mode) { - _soundChannel = CLSoundChannel_New(mode); + _soundChannel = new soundchannel_t(mode); _soundGroup = new SoundGroup(_vm, numSounds, length, sampleSize, rate, mode); if (sampleSize == 16) _soundGroup->reverse16All(); @@ -135,15 +135,15 @@ void HnmPlayer::setupSound(int16 numSounds, int16 length, int16 sampleSize, floa // Original name: CLHNM_SetupSoundADPCM void HnmPlayer::setupSoundADPCM(int16 numSounds, int16 length, int16 sampleSize, float rate, int16 mode) { - _soundChannelAdpcm = CLSoundChannel_New(mode); + _soundChannelAdpcm = new soundchannel_t(mode); _soundGroupAdpcm = new SoundGroup(_vm, numSounds, length, sampleSize, rate, mode); } // Original name: CLHNM_CloseSound void HnmPlayer::closeSound() { if (_soundChannel) { - CLSoundChannel_Stop(_soundChannel); - CLSoundChannel_Free(_soundChannel); + _soundChannel->stop(); + delete(_soundChannel); _soundChannel = nullptr; } if (_soundGroup) { @@ -151,9 +151,9 @@ void HnmPlayer::closeSound() { _soundGroup = nullptr; } if (_soundChannelAdpcm) { - CLSoundChannel_Stop(_soundChannelAdpcm); - CLSoundChannel_Free(_soundChannelAdpcm); - _soundChannel = nullptr; + _soundChannelAdpcm->stop(); + delete(_soundChannelAdpcm); + _soundChannelAdpcm = nullptr; } if (_soundGroupAdpcm) { delete(_soundGroupAdpcm); -- cgit v1.2.3