aboutsummaryrefslogtreecommitdiff
path: root/engines/cryo/sound.cpp
diff options
context:
space:
mode:
authorStrangerke2016-11-29 22:42:59 -0800
committerEugene Sandulenko2017-01-25 22:42:09 +0100
commitf3bb961fec26c0cebf670383d2eaa0534f66c54a (patch)
tree0562bc9259f9a17c351462d0476c1f7064a8107d /engines/cryo/sound.cpp
parent878a3c85157a6d92a594cd7cc51bef9f61604a1b (diff)
downloadscummvm-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/sound.cpp')
-rw-r--r--engines/cryo/sound.cpp99
1 files changed, 99 insertions, 0 deletions
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++;
+}
+
+
}