diff options
author | Max Horn | 2003-06-15 00:54:14 +0000 |
---|---|---|
committer | Max Horn | 2003-06-15 00:54:14 +0000 |
commit | f1fc68773d32783eea28d9ae711a26dd461cea1a (patch) | |
tree | 839ac04e53b6fd1a03285d858c22b291542a906b /scumm | |
parent | 6ece4cfbdaca67440b24bb387e66402d5d638ae1 (diff) | |
download | scummvm-rg350-f1fc68773d32783eea28d9ae711a26dd461cea1a.tar.gz scummvm-rg350-f1fc68773d32783eea28d9ae711a26dd461cea1a.tar.bz2 scummvm-rg350-f1fc68773d32783eea28d9ae711a26dd461cea1a.zip |
made stuff in class Sound protected where possible; moved readCreativeVocFile to imuse_digi.cpp and turned it into a static function; put the DigitalTrackInfo stuff into sound.cpp (keeping it private); removed #includes from sound.h (this cuts down interdependencies a little)
svn-id: r8493
Diffstat (limited to 'scumm')
-rw-r--r-- | scumm/imuse_digi.cpp | 55 | ||||
-rw-r--r-- | scumm/saveload.cpp | 1 | ||||
-rw-r--r-- | scumm/script_v6.cpp | 7 | ||||
-rw-r--r-- | scumm/script_v8.cpp | 3 | ||||
-rw-r--r-- | scumm/scummvm.cpp | 2 | ||||
-rw-r--r-- | scumm/smush/smush_player.cpp | 2 | ||||
-rw-r--r-- | scumm/sound.cpp | 112 | ||||
-rw-r--r-- | scumm/sound.h | 78 |
8 files changed, 134 insertions, 126 deletions
diff --git a/scumm/imuse_digi.cpp b/scumm/imuse_digi.cpp index 94ad5e58de..e09abb6acd 100644 --- a/scumm/imuse_digi.cpp +++ b/scumm/imuse_digi.cpp @@ -23,6 +23,7 @@ #include "scumm/scumm.h" #include "scumm/imuse_digi.h" #include "scumm/sound.h" +#include "sound/mixer.h" //////////////////////////////////////// // @@ -31,6 +32,57 @@ // //////////////////////////////////////// +static byte *readCreativeVocFile(byte *ptr, uint32 &size, uint32 &rate, uint32 &loops) { + assert(strncmp((char *)ptr, "Creative Voice File\x1A", 20) == 0); + int32 offset = READ_LE_UINT16(ptr + 20); + int16 version = READ_LE_UINT16(ptr + 22); + int16 code = READ_LE_UINT16(ptr + 24); + assert(version == 0x010A || version == 0x0114); + assert(code == ~version + 0x1234); + bool quit = 0; + byte *ret_sound = 0; size = 0, loops = 0; + while (!quit) { + int len = READ_LE_UINT32(ptr + offset); + offset += 4; + code = len & 0xFF; + len >>= 8; + switch(code) { + case 0: quit = 1; break; + case 1: { + int time_constant = ptr[offset++]; + int packing = ptr[offset++]; + len -= 2; + rate = 1000000L / (256L - time_constant); + debug(9, "VOC Data Bloc : %d, %d, %d", rate, packing, len); + if (packing == 0) { + if (size) { + ret_sound = (byte *)realloc(ret_sound, size + len); + } else { + ret_sound = (byte *)malloc(len); + } + memcpy(ret_sound + size, ptr + offset, len); + size += len; + } else { + warning("VOC file packing %d unsupported", packing); + } + } break; + case 6: // begin of loop + loops = len + 1; + break; + case 7: // end of loop + break; + default: + warning("Invalid code in VOC file : %d", code); + quit = 1; + break; + } + // FIXME some FT samples (ex. 362) has bad length, 2 bytes too short + offset += len; + } + debug(9, "VOC Data Size : %d", size); + return ret_sound; +} + static void imus_digital_handler(void *engine) { // Avoid race condition if (engine && ((Scumm *)engine)->_imuseDigital) @@ -808,7 +860,7 @@ void IMuseDigital::startSound(int sound) { _channel[l]._channels = 2; _channel[l]._mixerSize = (22050 / 5) * 2; _channel[l]._mixerFlags = SoundMixer::FLAG_AUTOFREE | SoundMixer::FLAG_STEREO | SoundMixer::FLAG_REVERSE_STEREO | SoundMixer::FLAG_UNSIGNED; - byte * t_ptr= _scumm->_sound->readCreativeVocFile(ptr, size, _channel[l]._freq, _channel[l]._numLoops); + byte * t_ptr= readCreativeVocFile(ptr, size, _channel[l]._freq, _channel[l]._numLoops); if (_channel[l]._freq == 22222) { _channel[l]._freq = 22050; @@ -1189,7 +1241,6 @@ int IMuseDigital::getSoundStatus(int sound) { } - #ifdef __PALM_OS__ #include "scumm_globals.h" // init globals void IMuseDigital_initGlobals() { diff --git a/scumm/saveload.cpp b/scumm/saveload.cpp index 92d56a1ce5..b3f76ea485 100644 --- a/scumm/saveload.cpp +++ b/scumm/saveload.cpp @@ -31,6 +31,7 @@ #include "sound.h" #include "verbs.h" #include "common/config-file.h" +#include "sound/mixer.h" struct SaveGameHeader { uint32 type; diff --git a/scumm/script_v6.cpp b/scumm/script_v6.cpp index 0de160b0bd..e2a65615c0 100644 --- a/scumm/script_v6.cpp +++ b/scumm/script_v6.cpp @@ -22,17 +22,18 @@ #include "stdafx.h" -#include "scumm.h" +#include <time.h> + #include "actor.h" #include "charset.h" #include "imuse.h" #include "intern.h" +#include "scumm.h" #include "sound.h" #include "verbs.h" -#include <time.h> #include "smush/smush_player.h" - #include "sound/mididrv.h" +#include "sound/mixer.h" #include "dialogs.h" // FIXME: This is just for the FT-INSANE warning. // Remove when INSANE is implemented diff --git a/scumm/script_v8.cpp b/scumm/script_v8.cpp index 7d762f67a8..764820faee 100644 --- a/scumm/script_v8.cpp +++ b/scumm/script_v8.cpp @@ -26,9 +26,10 @@ #include "intern.h" #include "sound.h" #include "verbs.h" - #include "smush/smush_player.h" +#include "sound/mixer.h" + #include <time.h> diff --git a/scumm/scummvm.cpp b/scumm/scummvm.cpp index 7bcf14734f..11336126e4 100644 --- a/scumm/scummvm.cpp +++ b/scumm/scummvm.cpp @@ -903,8 +903,6 @@ void Scumm::scummInit() { // FIXME: disabled, why we need this, it's looks completly dummy and slow down startup // getGraphicsPerformance(); - _sound->_current_cache = 0; - _lastSaveTime = _system->get_msecs(); } diff --git a/scumm/smush/smush_player.cpp b/scumm/smush/smush_player.cpp index 69dbfa5167..f20d007221 100644 --- a/scumm/smush/smush_player.cpp +++ b/scumm/smush/smush_player.cpp @@ -881,7 +881,7 @@ void SmushPlayer::play(const char *filename, const char *directory) { File f; f.open(filename, directory); if (!f.isOpen()) { - warning("SmushPlayer::setupAnim() File not found %s", filename); + warning("SmushPlayer::play() File not found %s", filename); return; } diff --git a/scumm/sound.cpp b/scumm/sound.cpp index c2ce8eb996..78bd0b1b39 100644 --- a/scumm/sound.cpp +++ b/scumm/sound.cpp @@ -24,6 +24,7 @@ #include "scumm.h" #include "sound.h" #include "sound/mididrv.h" +#include "sound/mixer.h" #include "imuse.h" #include "imuse_digi.h" #include "player_v2.h" @@ -34,6 +35,53 @@ #include "sound/midiparser.h" + +enum { + SOUND_HEADER_SIZE = 26, + SOUND_HEADER_BIG_SIZE = 26 + 8 +}; + + +class DigitalTrackInfo { +public: + virtual bool error() = 0; + virtual int play(SoundMixer *mixer, int start, int delay) = 0; + virtual ~DigitalTrackInfo() { } +}; + +#ifdef USE_MAD +class MP3TrackInfo : public DigitalTrackInfo { +private: + struct mad_header _mad_header; + long _size; + File *_file; + bool _error_flag; + +public: + MP3TrackInfo(File *file); + ~MP3TrackInfo(); + bool error() { return _error_flag; } + int play(SoundMixer *mixer, int start, int delay); +}; +#endif + +#ifdef USE_VORBIS +class VorbisTrackInfo : public DigitalTrackInfo { +private: + File *_file; + OggVorbis_File _ov_file; + bool _error_flag; + +public: + VorbisTrackInfo(File *file); + ~VorbisTrackInfo(); + bool error() { return _error_flag; } + int play(SoundMixer *mixer, int start, int delay); +}; +#endif + + + Sound::Sound(Scumm *parent) { memset(this,0,sizeof(Sound)); // palmos @@ -43,6 +91,7 @@ Sound::Sound(Scumm *parent) { _musicBundleBufOutput = NULL; _musicDisk = 0; _talkChannel = -1; + _current_cache = 0; } Sound::~Sound() { @@ -119,57 +168,6 @@ void Sound::processSoundQues() { _soundQuePos = 0; } -byte *Sound::readCreativeVocFile(byte *ptr, uint32 &size, uint32 &rate, uint32 &loops) { - assert(strncmp((char *)ptr, "Creative Voice File\x1A", 20) == 0); - int32 offset = READ_LE_UINT16(ptr + 20); - int16 version = READ_LE_UINT16(ptr + 22); - int16 code = READ_LE_UINT16(ptr + 24); - assert(version == 0x010A || version == 0x0114); - assert(code == ~version + 0x1234); - bool quit = 0; - byte *ret_sound = 0; size = 0, loops = 0; - while (!quit) { - int len = READ_LE_UINT32(ptr + offset); - offset += 4; - code = len & 0xFF; - len >>= 8; - switch(code) { - case 0: quit = 1; break; - case 1: { - int time_constant = ptr[offset++]; - int packing = ptr[offset++]; - len -= 2; - rate = 1000000L / (256L - time_constant); - debug(9, "VOC Data Bloc : %d, %d, %d", rate, packing, len); - if (packing == 0) { - if (size) { - ret_sound = (byte *)realloc(ret_sound, size + len); - } else { - ret_sound = (byte *)malloc(len); - } - memcpy(ret_sound + size, ptr + offset, len); - size += len; - } else { - warning("VOC file packing %d unsupported", packing); - } - } break; - case 6: // begin of loop - loops = len + 1; - break; - case 7: // end of loop - break; - default: - warning("Invalid code in VOC file : %d", code); - quit = 1; - break; - } - // FIXME some FT samples (ex. 362) has bad length, 2 bytes too short - offset += len; - } - debug(9, "VOC Data Size : %d", size); - return ret_sound; -} - void Sound::playSound(int soundID) { byte *ptr; char *sound; @@ -1582,7 +1580,7 @@ int Sound::updateMP3CD() { } #ifdef USE_MAD -Sound::MP3TrackInfo::MP3TrackInfo(File *file) { +MP3TrackInfo::MP3TrackInfo(File *file) { struct mad_stream stream; struct mad_frame frame; unsigned char buffer[8192]; @@ -1653,7 +1651,7 @@ error: delete file; } -int Sound::MP3TrackInfo::play(SoundMixer *mixer, int start, int delay) { +int MP3TrackInfo::play(SoundMixer *mixer, int start, int delay) { unsigned int offset; mad_timer_t duration; @@ -1674,7 +1672,7 @@ int Sound::MP3TrackInfo::play(SoundMixer *mixer, int start, int delay) { return mixer->playMP3CDTrack(NULL, _file, duration); } -Sound::MP3TrackInfo::~MP3TrackInfo() { +MP3TrackInfo::~MP3TrackInfo() { if (! _error_flag) _file->close(); } @@ -1744,7 +1742,7 @@ static ov_callbacks File_wrap = { read_wrap, seek_wrap, close_wrap, tell_wrap }; -Sound::VorbisTrackInfo::VorbisTrackInfo(File *file) { +VorbisTrackInfo::VorbisTrackInfo(File *file) { file_info *f = new file_info; f->file = file; @@ -1772,7 +1770,7 @@ Sound::VorbisTrackInfo::VorbisTrackInfo(File *file) { #define VORBIS_TREMOR #endif -int Sound::VorbisTrackInfo::play(SoundMixer *mixer, int start, int delay) { +int VorbisTrackInfo::play(SoundMixer *mixer, int start, int delay) { #ifdef VORBIS_TREMOR ov_time_seek(&_ov_file, (ogg_int64_t)(start / 75.0 * 1000)); #else @@ -1783,7 +1781,7 @@ int Sound::VorbisTrackInfo::play(SoundMixer *mixer, int start, int delay) { true); } -Sound::VorbisTrackInfo::~VorbisTrackInfo() { +VorbisTrackInfo::~VorbisTrackInfo() { if (! _error_flag) { ov_clear(&_ov_file); delete _file; diff --git a/scumm/sound.h b/scumm/sound.h index 468422e554..32fa39c183 100644 --- a/scumm/sound.h +++ b/scumm/sound.h @@ -22,21 +22,14 @@ #define SOUND_H #include "scummsys.h" -#include "sound/mixer.h" -#include "common/timer.h" -class Scumm; +class DigitalTrackInfo; class File; +class Scumm; +struct MP3OffsetTable; class Sound { - -private: - -enum { - SOUND_HEADER_SIZE = 26, - SOUND_HEADER_BIG_SIZE = 26 + 8 -}; - +protected: int16 _soundQuePos, _soundQue[0x100]; int16 _soundQue2Pos, _soundQue2[10]; bool _soundsPaused2; @@ -85,50 +78,11 @@ enum { int _dig_cd_num_loops; bool _dig_cd_playing; - class DigitalTrackInfo { - public: - virtual bool error() = 0; - virtual int play(SoundMixer *mixer, int start, int delay) = 0; - virtual ~DigitalTrackInfo() { } - }; - DigitalTrackInfo *_track_info[CACHE_TRACKS]; -#ifdef USE_MAD - class MP3TrackInfo : public DigitalTrackInfo { - private: - struct mad_header _mad_header; - long _size; - File *_file; - bool _error_flag; - - public: - MP3TrackInfo(File *file); - ~MP3TrackInfo(); - bool error() { return _error_flag; } - int play(SoundMixer *mixer, int start, int delay); - }; -#endif - -#ifdef USE_VORBIS - class VorbisTrackInfo : public DigitalTrackInfo { - private: - File *_file; - OggVorbis_File _ov_file; - bool _error_flag; - - public: - VorbisTrackInfo(File *file); - ~VorbisTrackInfo(); - bool error() { return _error_flag; } - int play(SoundMixer *mixer, int start, int delay); - }; -#endif - Scumm *_scumm; public: - int _current_cache; int32 _bundleMusicPosition; @@ -137,6 +91,7 @@ public: int16 _sound_volume_master, _sound_volume_music, _sound_volume_sfx; byte _sfxMode; +public: Sound(Scumm *parent); ~Sound(); void addSoundToQueue(int sound); @@ -152,25 +107,18 @@ public: bool isSoundInQueue(int sound); void stopSound(int a); void stopAllSounds(); - void clearSoundQue(); void soundKludge(int *list, int num); void talkSound(uint32 a, uint32 b, int mode, int frame); void setupSound(); void pauseSounds(bool pause); - int startSfxSound(File *file, int file_size); - File *openSfxFile(); - void stopSfxSound(); - bool isSfxFinished(); - uint32 decode12BitsSample(byte *src, byte **dst, uint32 size, bool stereo); + void playBundleMusic(const char *song); void pauseBundleMusic(bool state); void bundleMusicHandler(Scumm *scumm); void stopBundleMusic(); int playBundleSound(char *sound); - byte *readCreativeVocFile(byte *ptr, uint32 &size, uint32 &rate, uint32 &loops); - int playSfxSound(void *sound, uint32 size, uint rate, bool isUnsigned); - int playSfxSound_MP3(void *sound, uint32 size); - int playSfxSound_Vorbis(void *sound, uint32 size); + + uint32 decode12BitsSample(byte *src, byte **dst, uint32 size, bool stereo); void startCDTimer(); void stopCDTimer(); @@ -181,6 +129,16 @@ public: void updateCD(); protected: + void clearSoundQue(); + + File *openSfxFile(); + int startSfxSound(File *file, int file_size); + void stopSfxSound(); + bool isSfxFinished(); + int playSfxSound(void *sound, uint32 size, uint rate, bool isUnsigned); + int playSfxSound_MP3(void *sound, uint32 size); + int playSfxSound_Vorbis(void *sound, uint32 size); + int getCachedTrack(int track); int playMP3CDTrack(int track, int num_loops, int start, int delay); int stopMP3CD(); |