CRYO: rename SoundChannel, get rid of soundraw

This commit is contained in:
Strangerke 2017-01-03 16:24:12 -08:00 committed by Eugene Sandulenko
parent c667702f2c
commit b669a704e2
10 changed files with 106 additions and 121 deletions

View File

@ -1,63 +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 {
sound_t *CLSoundRaw_New(int16 length, float rate, int16 sampleSize, int16 mode) {
sound_t *sound = (sound_t *)malloc(sizeof(*sound));
if (sound) {
sound->_maxLength = length;
sound->_rate = rate;
sound->_sampleSize = sampleSize;
sound->_buffer = nullptr;
// sound->sndHandle = CLMemory_AllocHandle(arg1 + 100);
// if(!sound->sndHandle)
// error("CLSoundRaw_New - Not enough memory");
// else
CLSound_PrepareSample(sound, mode);
} else
error("CLSoundRaw_New - Not enough memory");
return sound;
}
void CLSoundRaw_Free(sound_t *sound) {
while (sound->_locked)
;
// CLMemory_FreeHandle(sound->sndHandle);
free(sound);
}
void CLSoundRaw_AssignBuffer(sound_t *sound, void *buffer, int bufferOffs, int length) {
CLSound_SetLength(sound, length);
sound->_length = length;
char *buf = bufferOffs + (char *)buffer;
// if(CLSound_GetWantsDesigned())
// CLSound_Signed2NonSigned(buf, length);
sound->_buffer = buf;
// if(sound->reversed && sound->sampleSize == 16)
// ReverseBlock16(buf, length);
}
} // End of namespace Cryo

View File

@ -341,24 +341,65 @@ void CLFile_Write(Common::File &handle, void *buffer, int32 *size) {
///// CLSound ///// CLSound
// base sound // base sound
void CLSound_PrepareSample(sound_t *sound, int16 mode) {
sound->_mode = mode; sound_t::sound_t(int16 length, float rate, int16 sampleSize, int16 mode) {
sound->_locked = 0; _sndHandle = nullptr;
sound->_loopTimes = 0; _headerLen = 0;
sound->_reversed = false; _headerOffset = 0;
sound->_unused32 = 0;
sound->_volume = 255; _length = 0;
_mode = 0;
_locked = 0;
_loopStart = 0;
_loopTimes = 0;
_reversed = false;
_volume = 0;
_maxLength = length;
_rate = rate;
_sampleSize = sampleSize;
_buffer = nullptr;
// sndHandle = CLMemory_AllocHandle(arg1 + 100);
// if(!sndHandle)
// error("CLSoundRaw_New - Not enough memory");
// else
prepareSample(mode);
} }
void CLSound_SetWantsDesigned(int16 designed) { sound_t::~sound_t() {
while (_locked)
;
} }
void CLSound_SetLength(sound_t *sound, int length) { void CLSoundRaw_AssignBuffer(sound_t *sound, void *buffer, int bufferOffs, int length) {
sound->setLength(length);
sound->_length = length;
char *buf = bufferOffs + (char *)buffer;
// if(CLSound_GetWantsDesigned())
// CLSound_Signed2NonSigned(buf, length);
sound->_buffer = buf;
// if(sound->reversed && sound->sampleSize == 16)
// ReverseBlock16(buf, length);
}
void sound_t::prepareSample(int16 mode) {
_mode = mode;
_locked = 0;
_loopTimes = 0;
_reversed = false;
_unused32 = 0;
_volume = 255;
}
void sound_t::setWantsDesigned(int16 designed) {
}
void sound_t::setLength(int length) {
} }
///// CLSoundChannel ///// CLSoundChannel
/// sound output device that plays queue of sounds /// sound output device that plays queue of sounds
soundchannel_t::soundchannel_t(int arg1) { SoundChannel::SoundChannel(int arg1) {
_volumeLeft = _volumeRight = 255; _volumeLeft = _volumeRight = 255;
_numSounds = 0; _numSounds = 0;
@ -366,21 +407,21 @@ soundchannel_t::soundchannel_t(int arg1) {
_sounds[i] = nullptr; _sounds[i] = nullptr;
} }
soundchannel_t::~soundchannel_t() { SoundChannel::~SoundChannel() {
} }
void soundchannel_t::stop() { void SoundChannel::stop() {
// _vm->_mixer->stopHandle(this); // _vm->_mixer->stopHandle(this);
} }
void soundchannel_t::play(sound_t *sound) { void SoundChannel::play(sound_t *sound) {
} }
int16 soundchannel_t::getVolume() { int16 SoundChannel::getVolume() {
return (_volumeLeft + _volumeRight) / 2; return (_volumeLeft + _volumeRight) / 2;
} }
void soundchannel_t::setVolume(int16 volume) { void SoundChannel::setVolume(int16 volume) {
if (volume < 0 || volume > 255) if (volume < 0 || volume > 255)
return; return;
@ -388,14 +429,14 @@ void soundchannel_t::setVolume(int16 volume) {
_volumeRight = volume; _volumeRight = volume;
} }
void soundchannel_t::setVolumeRight(int16 volume) { void SoundChannel::setVolumeRight(int16 volume) {
if (volume < 0 || volume > 255) if (volume < 0 || volume > 255)
return; return;
_volumeRight = volume; _volumeRight = volume;
} }
void soundchannel_t::setVolumeLeft(int16 volume) { void SoundChannel::setVolumeLeft(int16 volume) {
if (volume < 0 || volume > 255) if (volume < 0 || volume > 255)
return; return;

View File

@ -136,30 +136,46 @@ struct hnm_t {
}; };
typedef struct hnm_t hnm_t; typedef struct hnm_t hnm_t;
struct sound_t { class sound_t {
char *_sndHandle; private:
int16 _headerLen;
int32 _headerOffset; int32 _headerOffset;
int16 _unused0A; int16 _unused0A;
char *_buffer;
int _unused16; int _unused16;
int16 _maxLength;
float _rate;
int16 _sampleSize;
int _length;
int16 _mode; int16 _mode;
volatile int16 _locked;
int32 _loopStart; int32 _loopStart;
int16 _loopTimes; int16 _loopTimes;
bool _reversed;
int16 _unused32; int16 _unused32;
int16 _volume; int16 _volume;
public:
sound_t(int16 length, float rate, int16 sampleSize, int16 mode);
~sound_t();
void assignBuffer(void *buffer, int bufferOffs, int length);
void prepareSample(int16 mode);
void setWantsDesigned(int16 designed);
void setLength(int length);
char *_sndHandle;
char *_buffer;
float _rate;
int16 _maxLength;
int16 _headerLen;
int16 _sampleSize;
int _length;
bool _reversed;
volatile int16 _locked;
}; };
#define kCryoMaxChSounds 10 #define kCryoMaxChSounds 10
class soundchannel_t { class SoundChannel {
private: private:
int16 _volumeLeft; int16 _volumeLeft;
int16 _volumeRight; int16 _volumeRight;
@ -168,8 +184,8 @@ private:
sound_t *_sounds[kCryoMaxChSounds]; sound_t *_sounds[kCryoMaxChSounds];
public: public:
soundchannel_t(int arg1); SoundChannel(int arg1);
~soundchannel_t(); ~SoundChannel();
void stop(); void stop();
void play(sound_t *sound); void play(sound_t *sound);
@ -179,10 +195,6 @@ public:
void setVolumeLeft(int16 volume); void setVolumeLeft(int16 volume);
}; };
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);
void SysBeep(int x); void SysBeep(int x);
int32 TickCount(); int32 TickCount();
void FlushEvents(int16 arg1, int16 arg2); void FlushEvents(int16 arg1, int16 arg2);
@ -210,10 +222,6 @@ void CLPalette_BeSystem();
void CLFile_Write(Common::File &handle, void *buffer, int32 *size); void CLFile_Write(Common::File &handle, void *buffer, int32 *size);
void CLSound_PrepareSample(sound_t *sound, int16 mode);
void CLSound_SetWantsDesigned(int16 designed);
void CLSound_SetLength(sound_t *sound, int length);
void CRYOLib_ManagersInit(); void CRYOLib_ManagersInit();
void CRYOLib_ManagersDone(); void CRYOLib_ManagersDone();

View File

@ -5734,9 +5734,9 @@ void EdenGame::run() {
_vm->_video->setupSound(5, 0x2000, 8, 11025 * 65536.0 , 0); _vm->_video->setupSound(5, 0x2000, 8, 11025 * 65536.0 , 0);
_vm->_video->setForceZero2Black(true); _vm->_video->setForceZero2Black(true);
_vm->_video->setupTimer(12.5); _vm->_video->setupTimer(12.5);
_voiceSound = CLSoundRaw_New(0, 11025 * 65536.0, 8, 0); _voiceSound = new sound_t(0, 11025 * 65536.0, 8, 0);
_hnmSoundChannel = _vm->_video->getSoundChannel(); _hnmSoundChannel = _vm->_video->getSoundChannel();
CLSound_SetWantsDesigned(1); // CHECKME: Used? _voiceSound->setWantsDesigned(1); // CHECKME: Used?
_musicChannel = new CSoundChannel(_vm->_mixer, 11025, false); _musicChannel = new CSoundChannel(_vm->_mixer, 11025, false);
_voiceChannel = new CSoundChannel(_vm->_mixer, 11025, false); _voiceChannel = new CSoundChannel(_vm->_mixer, 11025, false);

View File

@ -641,7 +641,7 @@ private:
CSoundChannel *_musicChannel; CSoundChannel *_musicChannel;
CSoundChannel *_voiceChannel; CSoundChannel *_voiceChannel;
soundchannel_t *_hnmSoundChannel; SoundChannel *_hnmSoundChannel;
sound_t *_voiceSound; sound_t *_voiceSound;
View *_view2; View *_view2;

View File

@ -1,12 +1,11 @@
MODULE := engines/cryo MODULE := engines/cryo
MODULE_OBJS = \ MODULE_OBJS = \
clsoundraw.o \
cryolib.o \
sound.o \
eden.o \
cryo.o \ cryo.o \
cryolib.o \
detection.o \ detection.o \
eden.o \
sound.o \
staticdata.o \ staticdata.o \
video.o video.o

View File

@ -74,10 +74,10 @@ SoundGroup::SoundGroup(CryoEngine *vm, int16 numSounds, int16 length, int16 samp
if (numSounds < kCryoMaxClSounds) if (numSounds < kCryoMaxClSounds)
_numSounds = numSounds; _numSounds = numSounds;
else else
error("CLSoundGroup_New - numSounds >= kCryoMaxClSounds"); error("SoundGroup - numSounds >= kCryoMaxClSounds");
for (int i = 0; i < _numSounds; i++) { for (int i = 0; i < _numSounds; i++) {
_sounds[i] = CLSoundRaw_New(length, rate, sampleSize, mode); _sounds[i] = new sound_t(length, rate, sampleSize, mode);
_sounds[i]->_maxLength = length; _sounds[i]->_maxLength = length;
} }
_soundIndex = 0; _soundIndex = 0;
@ -88,7 +88,7 @@ SoundGroup::SoundGroup(CryoEngine *vm, int16 numSounds, int16 length, int16 samp
// Original name: CLSoundGroup_Free // Original name: CLSoundGroup_Free
SoundGroup::~SoundGroup() { SoundGroup::~SoundGroup() {
for (int16 i = 0; i < _numSounds; i++) for (int16 i = 0; i < _numSounds; i++)
CLSoundRaw_Free(_sounds[i]); delete(_sounds[i]);
} }
// Original name: CLSoundGroup_Reverse16All // Original name: CLSoundGroup_Reverse16All
@ -115,7 +115,7 @@ bool SoundGroup::assignDatas(void *buffer, int length, bool isSigned) {
return false; return false;
sound->_buffer = (char *)buffer; sound->_buffer = (char *)buffer;
CLSound_SetLength(sound, length); sound->setLength(length);
sound->_length = length; sound->_length = length;
// if(sound->reversed && sound->sampleSize == 16) // if(sound->reversed && sound->sampleSize == 16)
// ReverseBlock16(buffer, length); // ReverseBlock16(buffer, length);
@ -143,7 +143,7 @@ bool SoundGroup::setDatas(void *data, int length, bool isSigned) {
void *buffer = sound->_sndHandle + sound->_headerLen; void *buffer = sound->_sndHandle + sound->_headerLen;
sound->_buffer = (char *)buffer; sound->_buffer = (char *)buffer;
memcpy(buffer, data, length); memcpy(buffer, data, length);
CLSound_SetLength(sound, length); sound->setLength(length);
sound->_length = length; sound->_length = length;
// if(sound->reversed && sound->sampleSize == 16) // if(sound->reversed && sound->sampleSize == 16)
// ReverseBlock16(buffer, length); // ReverseBlock16(buffer, length);
@ -158,7 +158,7 @@ bool SoundGroup::setDatas(void *data, int length, bool isSigned) {
} }
// Original name: CLSoundGroup_PlayNextSample // Original name: CLSoundGroup_PlayNextSample
void SoundGroup::playNextSample(soundchannel_t *ch) { void SoundGroup::playNextSample(SoundChannel *ch) {
ch->play(_sounds[_playIndex]); ch->play(_sounds[_playIndex]);
if (_playIndex == _numSounds - 1) if (_playIndex == _numSounds - 1)
_playIndex = 0; _playIndex = 0;

View File

@ -56,7 +56,7 @@ public:
void *getNextBuffer(); void *getNextBuffer();
bool assignDatas(void *buffer, int length, bool isSigned); bool assignDatas(void *buffer, int length, bool isSigned);
bool setDatas(void *data, int length, bool isSigned); bool setDatas(void *data, int length, bool isSigned);
void playNextSample(soundchannel_t *ch); void playNextSample(SoundChannel *ch);
sound_t *_sounds[kCryoMaxClSounds]; sound_t *_sounds[kCryoMaxClSounds];
int16 _numSounds; int16 _numSounds;

View File

@ -127,7 +127,7 @@ void HnmPlayer::wantsSound(bool sound) {
// Original name: CLHNM_SetupSound // Original name: CLHNM_SetupSound
void HnmPlayer::setupSound(int16 numSounds, int16 length, int16 sampleSize, float rate, int16 mode) { void HnmPlayer::setupSound(int16 numSounds, int16 length, int16 sampleSize, float rate, int16 mode) {
_soundChannel = new soundchannel_t(mode); _soundChannel = new SoundChannel(mode);
_soundGroup = new SoundGroup(_vm, numSounds, length, sampleSize, rate, mode); _soundGroup = new SoundGroup(_vm, numSounds, length, sampleSize, rate, mode);
if (sampleSize == 16) if (sampleSize == 16)
_soundGroup->reverse16All(); _soundGroup->reverse16All();
@ -135,7 +135,7 @@ void HnmPlayer::setupSound(int16 numSounds, int16 length, int16 sampleSize, floa
// Original name: CLHNM_SetupSoundADPCM // Original name: CLHNM_SetupSoundADPCM
void HnmPlayer::setupSoundADPCM(int16 numSounds, int16 length, int16 sampleSize, float rate, int16 mode) { void HnmPlayer::setupSoundADPCM(int16 numSounds, int16 length, int16 sampleSize, float rate, int16 mode) {
_soundChannelAdpcm = new soundchannel_t(mode); _soundChannelAdpcm = new SoundChannel(mode);
_soundGroupAdpcm = new SoundGroup(_vm, numSounds, length, sampleSize, rate, mode); _soundGroupAdpcm = new SoundGroup(_vm, numSounds, length, sampleSize, rate, mode);
} }
@ -581,7 +581,7 @@ bool HnmPlayer::nextElement(hnm_t *hnm) {
} }
// Original name: CLHNM_GetSoundChannel // Original name: CLHNM_GetSoundChannel
soundchannel_t *HnmPlayer::getSoundChannel() { SoundChannel *HnmPlayer::getSoundChannel() {
return _soundChannel; return _soundChannel;
} }

View File

@ -70,9 +70,9 @@ private:
void (*_customChunkHandler)(byte *buffer, int size, int16 id, char h6, char h7); void (*_customChunkHandler)(byte *buffer, int size, int16 id, char h6, char h7);
soundchannel_t *_soundChannel; SoundChannel *_soundChannel;
SoundGroup *_soundGroup; SoundGroup *_soundGroup;
soundchannel_t *_soundChannelAdpcm; SoundChannel *_soundChannelAdpcm;
SoundGroup *_soundGroupAdpcm; SoundGroup *_soundGroupAdpcm;
public: public:
@ -99,7 +99,7 @@ public:
hnm_t *resetInternals(); hnm_t *resetInternals();
void setFile(hnm_t *hnm, Common::File *file); void setFile(hnm_t *hnm, Common::File *file);
soundchannel_t *getSoundChannel(); SoundChannel *getSoundChannel();
}; };
} // End of namespace Cryo } // End of namespace Cryo