diff options
author | Strangerke | 2016-11-29 22:42:59 -0800 |
---|---|---|
committer | Eugene Sandulenko | 2017-01-25 22:42:09 +0100 |
commit | f3bb961fec26c0cebf670383d2eaa0534f66c54a (patch) | |
tree | 0562bc9259f9a17c351462d0476c1f7064a8107d /engines/cryo | |
parent | 878a3c85157a6d92a594cd7cc51bef9f61604a1b (diff) | |
download | scummvm-rg350-f3bb961fec26c0cebf670383d2eaa0534f66c54a.tar.gz scummvm-rg350-f3bb961fec26c0cebf670383d2eaa0534f66c54a.tar.bz2 scummvm-rg350-f3bb961fec26c0cebf670383d2eaa0534f66c54a.zip |
CRYO: Turn soundgroup_t into a class
Diffstat (limited to 'engines/cryo')
-rw-r--r-- | engines/cryo/clsoundgroup.cpp | 120 | ||||
-rw-r--r-- | engines/cryo/cryolib.h | 19 | ||||
-rw-r--r-- | engines/cryo/module.mk | 1 | ||||
-rw-r--r-- | engines/cryo/sound.cpp | 99 | ||||
-rw-r--r-- | engines/cryo/sound.h | 27 | ||||
-rw-r--r-- | engines/cryo/video.cpp | 28 | ||||
-rw-r--r-- | engines/cryo/video.h | 4 |
7 files changed, 142 insertions, 156 deletions
diff --git a/engines/cryo/clsoundgroup.cpp b/engines/cryo/clsoundgroup.cpp deleted file mode 100644 index 9eb2ca691a..0000000000 --- a/engines/cryo/clsoundgroup.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#include "cryo/cryolib.h" - -namespace Cryo { - -soundgroup_t *CLSoundGroup_New(int16 numSounds, int16 length, int16 sampleSize, float rate, int16 mode) { - soundgroup_t *sg = (soundgroup_t *)malloc(sizeof(*sg)); - if (numSounds < kCryoMaxClSounds) - sg->_numSounds = numSounds; - else - error("CLSoundGroup_New - numSounds >= kCryoMaxClSounds"); - - for (int i = 0; i < sg->_numSounds; i++) { - sound_t *sound = CLSoundRaw_New(length, rate, sampleSize, mode); - sg->_sounds[i] = sound; - sound->_maxLength = length; - } - sg->_soundIndex = 0; - sg->_playIndex = 0; - sg->_forceWait = true; - - return sg; -} - -void CLSoundGroup_Free(soundgroup_t *sg) { - for (int16 i = 0; i < sg->_numSounds; i++) - CLSoundRaw_Free(sg->_sounds[i]); - free(sg); -} - -void CLSoundGroup_Reverse16All(soundgroup_t *sg) { - for (int16 i = 0; i < sg->_numSounds; i++) - sg->_sounds[i]->_reversed = true; -} - -void *CLSoundGroup_GetNextBuffer(soundgroup_t *sg) { - sound_t *sound = sg->_sounds[sg->_soundIndex]; - if (sg->_forceWait) - while (sound->_locked) ; - return sound->sndHandle + sound->_headerLen; -} - -bool CLSoundGroup_AssignDatas(soundgroup_t *sg, void *buffer, int length, bool isSigned) { - sound_t *sound = sg->_sounds[sg->_soundIndex]; - if (sg->_forceWait) - while (sound->_locked) ; - else if (sound->_locked) - return false; - sound->_buffer = (char *)buffer; - CLSound_SetLength(sound, length); - sound->_length = length; -// if(sound->reversed && sound->sampleSize == 16) -// ReverseBlock16(buffer, length); -// if(isSigned) -// CLSound_Signed2NonSigned(buffer, length); - if (sg->_soundIndex == sg->_numSounds - 1) - sg->_soundIndex = 0; - else - sg->_soundIndex++; - - return true; -} - -bool CLSoundGroup_SetDatas(soundgroup_t *sg, void *data, int length, bool isSigned) { - sound_t *sound = sg->_sounds[sg->_soundIndex]; - if (length >= sound->_maxLength) - error("CLSoundGroup_SetDatas - Unexpected length"); - - if (sg->_forceWait) - while (sound->_locked) ; - else if (sound->_locked) - return false; - - void *buffer = sound->sndHandle + sound->_headerLen; - sound->_buffer = (char *)buffer; - memcpy(buffer, data, length); - CLSound_SetLength(sound, length); - sound->_length = length; -// if(sound->reversed && sound->sampleSize == 16) -// ReverseBlock16(buffer, length); -// if(isSigned) -// CLSound_Signed2NonSigned(buffer, length); - if (sg->_soundIndex == sg->_numSounds - 1) - sg->_soundIndex = 0; - else - sg->_soundIndex++; - - return true; -} - -void CLSoundGroup_PlayNextSample(soundgroup_t *sg, soundchannel_t *ch) { - CLSoundChannel_Play(ch, sg->_sounds[sg->_playIndex]); - if (sg->_playIndex == sg->_numSounds - 1) - sg->_playIndex = 0; - else - sg->_playIndex++; -} - -} // End of namespace Cryo diff --git a/engines/cryo/cryolib.h b/engines/cryo/cryolib.h index 5470d2871d..aa23e3d3f3 100644 --- a/engines/cryo/cryolib.h +++ b/engines/cryo/cryolib.h @@ -146,17 +146,6 @@ struct sound_t { }; typedef struct sound_t sound_t; -#define kCryoMaxClSounds 64 - -struct soundgroup_t { - sound_t *_sounds[kCryoMaxClSounds]; - int16 _numSounds; - int16 _soundIndex; - int16 _playIndex; - bool _forceWait; -}; -typedef struct soundgroup_t soundgroup_t; - #define kCryoMaxChSounds 10 struct soundchannel_t { @@ -173,14 +162,6 @@ struct soundchannel_t { }; typedef struct soundchannel_t soundchannel_t; -soundgroup_t *CLSoundGroup_New(int16 numSounds, int16 length, int16 sampleSize, float rate, int16 mode); -void CLSoundGroup_Free(soundgroup_t *sg); -void CLSoundGroup_Reverse16All(soundgroup_t *sg); -void *CLSoundGroup_GetNextBuffer(soundgroup_t *sg); -bool CLSoundGroup_AssignDatas(soundgroup_t *sg, void *buffer, int length, bool isSigned); -bool CLSoundGroup_SetDatas(soundgroup_t *sg, void *data, int length, bool isSigned); -void CLSoundGroup_PlayNextSample(soundgroup_t *sg, soundchannel_t *ch); - sound_t *CLSoundRaw_New(int16 length, float rate, int16 sampleSize, int16 mode); void CLSoundRaw_Free(sound_t *sound); void CLSoundRaw_AssignBuffer(sound_t *sound, void *buffer, int bufferOffs, int length); diff --git a/engines/cryo/module.mk b/engines/cryo/module.mk index 825432f285..be76752ea1 100644 --- a/engines/cryo/module.mk +++ b/engines/cryo/module.mk @@ -1,7 +1,6 @@ MODULE := engines/cryo MODULE_OBJS = \ - clsoundgroup.o \ clsoundraw.o \ cryolib.o \ sound.o \ diff --git a/engines/cryo/sound.cpp b/engines/cryo/sound.cpp index c6ed250451..9e3a6ae695 100644 --- a/engines/cryo/sound.cpp +++ b/engines/cryo/sound.cpp @@ -68,4 +68,103 @@ void CSoundChannel::applyVolumeChange() { _mixer->setChannelBalance(_soundHandle, balance);
}
+/****************************************************************/
+
+SoundGroup::SoundGroup(CryoEngine *vm, int16 numSounds, int16 length, int16 sampleSize, float rate, int16 mode) : _vm(vm) {
+ if (numSounds < kCryoMaxClSounds)
+ _numSounds = numSounds;
+ else
+ error("CLSoundGroup_New - numSounds >= kCryoMaxClSounds");
+
+ for (int i = 0; i < _numSounds; i++) {
+ _sounds[i] = CLSoundRaw_New(length, rate, sampleSize, mode);
+ _sounds[i]->_maxLength = length;
+ }
+ _soundIndex = 0;
+ _playIndex = 0;
+ _forceWait = true;
+}
+
+// Original name: CLSoundGroup_Free
+SoundGroup::~SoundGroup() {
+ for (int16 i = 0; i < _numSounds; i++)
+ CLSoundRaw_Free(_sounds[i]);
+}
+
+// Original name: CLSoundGroup_Reverse16All
+void SoundGroup::reverse16All() {
+ for (int16 i = 0; i < _numSounds; i++)
+ _sounds[i]->_reversed = true;
+}
+
+// Original name: CLSoundGroup_GetNextBuffer
+void *SoundGroup::getNextBuffer() {
+ sound_t *sound = _sounds[_soundIndex];
+ if (_forceWait)
+ while (sound->_locked) ;
+ return sound->sndHandle + sound->_headerLen;
+}
+
+// Original name: CLSoundGroup_AssignDatas
+bool SoundGroup::assignDatas(void *buffer, int length, bool isSigned) {
+ sound_t *sound = _sounds[_soundIndex];
+ if (_forceWait)
+ while (sound->_locked)
+ ;
+ else if (sound->_locked)
+ return false;
+
+ sound->_buffer = (char *)buffer;
+ CLSound_SetLength(sound, length);
+ sound->_length = length;
+ // if(sound->reversed && sound->sampleSize == 16)
+ // ReverseBlock16(buffer, length);
+ // if(isSigned)
+ // CLSound_Signed2NonSigned(buffer, length);
+ if (_soundIndex == _numSounds - 1)
+ _soundIndex = 0;
+ else
+ _soundIndex++;
+
+ return true;
+}
+
+// Original name: CLSoundGroup_SetDatas
+bool SoundGroup::setDatas(void *data, int length, bool isSigned) {
+ sound_t *sound = _sounds[_soundIndex];
+ if (length >= sound->_maxLength)
+ error("CLSoundGroup_SetDatas - Unexpected length");
+
+ if (_forceWait)
+ while (sound->_locked) ;
+ else if (sound->_locked)
+ return false;
+
+ void *buffer = sound->sndHandle + sound->_headerLen;
+ sound->_buffer = (char *)buffer;
+ memcpy(buffer, data, length);
+ CLSound_SetLength(sound, length);
+ sound->_length = length;
+ // if(sound->reversed && sound->sampleSize == 16)
+ // ReverseBlock16(buffer, length);
+ // if(isSigned)
+ // CLSound_Signed2NonSigned(buffer, length);
+ if (_soundIndex == _numSounds - 1)
+ _soundIndex = 0;
+ else
+ _soundIndex++;
+
+ return true;
+}
+
+// Original name: CLSoundGroup_PlayNextSample
+void SoundGroup::playNextSample(soundchannel_t *ch) {
+ CLSoundChannel_Play(ch, _sounds[_playIndex]);
+ if (_playIndex == _numSounds - 1)
+ _playIndex = 0;
+ else
+ _playIndex++;
+}
+
+
}
diff --git a/engines/cryo/sound.h b/engines/cryo/sound.h index 74300adcb8..13e12590b0 100644 --- a/engines/cryo/sound.h +++ b/engines/cryo/sound.h @@ -4,8 +4,12 @@ #include "audio/mixer.h"
#include "audio/decoders/raw.h"
+#include "cryo/cryolib.h"
+
namespace Cryo {
+class CryoEngine;
+
class CSoundChannel {
private:
Audio::Mixer *_mixer;
@@ -38,4 +42,27 @@ private: void applyVolumeChange();
};
+#define kCryoMaxClSounds 64
+
+class SoundGroup {
+private:
+ CryoEngine *_vm;
+
+public:
+ SoundGroup(CryoEngine *vm, int16 numSounds, int16 length, int16 sampleSize, float rate, int16 mode);
+ ~SoundGroup();
+
+ void reverse16All();
+ void *getNextBuffer();
+ bool assignDatas(void *buffer, int length, bool isSigned);
+ bool setDatas(void *data, int length, bool isSigned);
+ void playNextSample(soundchannel_t *ch);
+
+ sound_t *_sounds[kCryoMaxClSounds];
+ int16 _numSounds;
+ int16 _soundIndex;
+ int16 _playIndex;
+ bool _forceWait;
+};
+
}
diff --git a/engines/cryo/video.cpp b/engines/cryo/video.cpp index fc9ed4afcc..83df7daf23 100644 --- a/engines/cryo/video.cpp +++ b/engines/cryo/video.cpp @@ -128,15 +128,15 @@ 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); - _soundGroup = CLSoundGroup_New(numSounds, length, sampleSize, rate, mode); + _soundGroup = new SoundGroup(_vm, numSounds, length, sampleSize, rate, mode); if (sampleSize == 16) - CLSoundGroup_Reverse16All(_soundGroup); + _soundGroup->reverse16All(); } // Original name: CLHNM_SetupSoundADPCM void HnmPlayer::setupSoundADPCM(int16 numSounds, int16 length, int16 sampleSize, float rate, int16 mode) { _soundChannelAdpcm = CLSoundChannel_New(mode); - _soundGroupAdpcm = CLSoundGroup_New(numSounds, length, sampleSize, rate, mode); + _soundGroupAdpcm = new SoundGroup(_vm, numSounds, length, sampleSize, rate, mode); } // Original name: CLHNM_CloseSound @@ -147,7 +147,7 @@ void HnmPlayer::closeSound() { _soundChannel = nullptr; } if (_soundGroup) { - CLSoundGroup_Free(_soundGroup); + delete(_soundGroup); _soundGroup = nullptr; } if (_soundChannelAdpcm) { @@ -156,8 +156,8 @@ void HnmPlayer::closeSound() { _soundChannel = nullptr; } if (_soundGroupAdpcm) { - CLSoundGroup_Free(_soundGroupAdpcm); - _soundGroup = nullptr; + delete(_soundGroupAdpcm); + _soundGroupAdpcm = nullptr; } } @@ -509,12 +509,12 @@ bool HnmPlayer::nextElement(hnm_t *hnm) { if (_useAdpcm) { if (!_soundStarted) { for (int16 i = 0; i < _pendingSounds; i++) - CLSoundGroup_PlayNextSample(_soundGroupAdpcm, _soundChannel); + _soundGroupAdpcm->playNextSample(_soundChannel); _soundStarted = true; } } else if (!_soundStarted) { for (int16 i = 0; i < _pendingSounds; i++) - CLSoundGroup_PlayNextSample(_soundGroup, _soundChannel); + _soundGroup->playNextSample(_soundChannel); _soundStarted = true; } @@ -539,25 +539,25 @@ bool HnmPlayer::nextElement(hnm_t *hnm) { if (!h6) { int sound_size = sz - 8; if (!_useAdpcm) { - CLSoundGroup_SetDatas(_soundGroup, hnm->_dataPtr, sound_size - 2, false); + _soundGroup->setDatas(hnm->_dataPtr, sound_size - 2, false); if (_soundStarted) - CLSoundGroup_PlayNextSample(_soundGroup, _soundChannel); + _soundGroup->playNextSample(_soundChannel); else _pendingSounds++; } else { - int16 *sound_buffer = (int16 *)CLSoundGroup_GetNextBuffer(_soundGroupAdpcm); + int16 *sound_buffer = (int16 *)_soundGroupAdpcm->getNextBuffer(); if (!_pendingSounds) { const int kDecompTableSize = 256 * sizeof(int16); loadDecompTable((int16 *)hnm->_dataPtr); decompADPCM(hnm->_dataPtr + kDecompTableSize, sound_buffer, sound_size - kDecompTableSize); - CLSoundGroup_AssignDatas(_soundGroupAdpcm, sound_buffer, (sound_size - kDecompTableSize) * 2, false); + _soundGroupAdpcm->assignDatas(sound_buffer, (sound_size - kDecompTableSize) * 2, false); } else { decompADPCM(hnm->_dataPtr, sound_buffer, sound_size); - CLSoundGroup_AssignDatas(_soundGroupAdpcm, sound_buffer, sound_size * 2, false); + _soundGroupAdpcm->assignDatas(sound_buffer, sound_size * 2, false); } _pendingSounds++; if (_soundStarted) - CLSoundGroup_PlayNextSample(_soundGroupAdpcm, _soundChannel); + _soundGroupAdpcm->playNextSample(_soundChannel); } } else error("nextElement - unexpected flag"); diff --git a/engines/cryo/video.h b/engines/cryo/video.h index ea41905479..a3a2f6dab6 100644 --- a/engines/cryo/video.h +++ b/engines/cryo/video.h @@ -71,9 +71,9 @@ private: void (*_customChunkHandler)(byte *buffer, int size, int16 id, char h6, char h7); soundchannel_t *_soundChannel; - soundgroup_t *_soundGroup; + SoundGroup *_soundGroup; soundchannel_t *_soundChannelAdpcm; - soundgroup_t *_soundGroupAdpcm; + SoundGroup *_soundGroupAdpcm; public: uint16 _curVideoNum; |