diff options
| author | Max Horn | 2003-12-22 08:22:04 +0000 |
|---|---|---|
| committer | Max Horn | 2003-12-22 08:22:04 +0000 |
| commit | 1e5496b2c8fc998e9210d90e05ff006e0409918a (patch) | |
| tree | 30bc67d198403af556e378733d95d38d9261d802 /scumm/sound.cpp | |
| parent | 44f1ed75fd76fd9842acd5784a31672a37536996 (diff) | |
| download | scummvm-rg350-1e5496b2c8fc998e9210d90e05ff006e0409918a.tar.gz scummvm-rg350-1e5496b2c8fc998e9210d90e05ff006e0409918a.tar.bz2 scummvm-rg350-1e5496b2c8fc998e9210d90e05ff006e0409918a.zip | |
Moved bundle music code from class Sound to IMuseDigital (seems more natural; and allows for various cleanup)
svn-id: r11846
Diffstat (limited to 'scumm/sound.cpp')
| -rw-r--r-- | scumm/sound.cpp | 350 |
1 files changed, 0 insertions, 350 deletions
diff --git a/scumm/sound.cpp b/scumm/sound.cpp index 06be1f4673..ce475a4ad7 100644 --- a/scumm/sound.cpp +++ b/scumm/sound.cpp @@ -22,7 +22,6 @@ #include "stdafx.h" #include "scumm/actor.h" -#include "scumm/bundle.h" #include "scumm/imuse.h" #include "scumm/imuse_digi.h" #include "scumm/scumm.h" @@ -57,21 +56,14 @@ Sound::Sound(ScummEngine *parent) { memset(this,0,sizeof(Sound)); // palmos _scumm = parent; - _nameBundleMusic = ""; - _musicBundleBufFinal = NULL; - _musicBundleBufOutput = NULL; - _musicDisk = 0; _talkChannelHandle = 0; _currentCDSound = 0; _sfxFile = 0; - - _bundle = new Bundle(); } Sound::~Sound() { delete _sfxFile; - delete _bundle; } void Sound::addSoundToQueue(int sound) { @@ -821,8 +813,6 @@ void Sound::pauseSounds(bool pause) { _scumm->_mixer->pauseAll(pause); - _scumm->_sound->pauseBundleMusic(pause); - if (_scumm->_imuseDigital) { _scumm->_imuseDigital->pause(pause); } @@ -978,346 +968,6 @@ bool Sound::isSfxFinished() const { return !_scumm->_mixer->hasActiveSFXChannel(); } -uint32 Sound::decode12BitsSample(byte *src, byte **dst, uint32 size, bool stereo) { - uint32 s_size = (size / 3) * 4; - uint32 loop_size = s_size / 4; - if (stereo) { - s_size *= 2; - } - byte *ptr = *dst = (byte *)malloc(s_size); - - uint32 tmp; - while (loop_size--) { - byte v1 = *src++; - byte v2 = *src++; - byte v3 = *src++; - tmp = ((((v2 & 0x0f) << 8) | v1) << 4) - 0x8000; - *ptr++ = (byte)((tmp >> 8) & 0xff); - *ptr++ = (byte)(tmp & 0xff); - if (stereo) { - *ptr++ = (byte)((tmp >> 8) & 0xff); - *ptr++ = (byte)(tmp & 0xff); - } - tmp = ((((v2 & 0xf0) << 4) | v3) << 4) - 0x8000; - *ptr++ = (byte)((tmp >> 8) & 0xff); - *ptr++ = (byte)(tmp & 0xff); - if (stereo) { - *ptr++ = (byte)((tmp >> 8) & 0xff); - *ptr++ = (byte)(tmp & 0xff); - } - } - return s_size; -} - -static void music_handler(void *refCon) { - Sound *sound = (Sound *)refCon; - sound->bundleMusicHandler(g_scumm); -} - -void Sound::playBundleMusic(const char *song) { - if (_scumm->_silentDigitalImuse) { - return; - } - - if (_nameBundleMusic[0] == 0) { - if (_scumm->_gameId == GID_CMI) { - _outputMixerSize = (22050 * 2 * 2); - - char bunfile[20]; - if (_scumm->_features & GF_DEMO) { - if (_bundle->openMusicFile("music.bun", _scumm->getGameDataPath()) == false) { - _outputMixerSize = 0; - return; - } - } else { - - sprintf(bunfile, "musdisk%d.bun", _scumm->VAR(_scumm->VAR_CURRENTDISK)); - if (_musicDisk != _scumm->VAR(_scumm->VAR_CURRENTDISK)) - _bundle->closeMusicFile(); - - if (_bundle->openMusicFile(bunfile, _scumm->getGameDataPath()) == false) { - if (_bundle->openMusicFile("music.bun", _scumm->getGameDataPath()) == false) { - _outputMixerSize = 0; - return; - } - } - - _musicDisk = (byte)_scumm->VAR(_scumm->VAR_CURRENTDISK); - } - } else { - _outputMixerSize = ((22050 * 2 * 2) / 4) * 3; - - if (_bundle->openMusicFile("digmusic.bun", _scumm->getGameDataPath()) == false) - return; - } - _musicBundleBufFinal = (byte *)malloc(_outputMixerSize); - _musicBundleBufOutput = (byte *)malloc(((_outputMixerSize / 0x2000) + 1) * _outputMixerSize); - _currentSampleBundleMusic = 0; - _offsetSampleBundleMusic = 0; - _offsetBufBundleMusic = 0; - _bundleMusicPosition = 0; - _bundleSongPosInMs = 0; - _pauseBundleMusic = false; - _musicBundleToBeChanged = false; - _bundleMusicTrack = 0; - _numberSamplesBundleMusic = _bundle->getNumberOfMusicSamplesByName(song); - _nameBundleMusic = song; - _scumm->_timer->installTimerProc(&music_handler, 1000000, this); - } else if (strcmp(_nameBundleMusic, song) != 0) { - _newNameBundleMusic = song; - _musicBundleToBeChanged = true; - } -} - -void Sound::pauseBundleMusic(bool state) { - _pauseBundleMusic = state; -} - -void Sound::stopBundleMusic() { - // First stop the music timer - _scumm->_timer->removeTimerProc(&music_handler); - _nameBundleMusic = ""; - _scumm->_mixer->stopHandle(_bundleMusicTrack); - if (_musicBundleBufFinal) { - free(_musicBundleBufFinal); - _musicBundleBufFinal = NULL; - } - if (_musicBundleBufOutput) { - free(_musicBundleBufOutput); - _musicBundleBufOutput = NULL; - } -} - -void Sound::bundleMusicHandler(ScummEngine *scumm) { - byte *ptr; - int32 l, num = _numberSamplesBundleMusic, length, k; - int32 rate = 22050; - int32 tag, size = -1, header_size = 0; - - if (_pauseBundleMusic) - return; - - if (_musicBundleToBeChanged) { - _nameBundleMusic = _newNameBundleMusic; - _numberSamplesBundleMusic = _bundle->getNumberOfMusicSamplesByName(_nameBundleMusic); - _currentSampleBundleMusic = 0; - _offsetSampleBundleMusic = 0; - _offsetBufBundleMusic = 0; - _musicBundleToBeChanged = false; - _bundleMusicPosition = 0; - _bundleSongPosInMs = 0; - } - - ptr = _musicBundleBufOutput; - - for (k = 0, l = _currentSampleBundleMusic; l < num; k++) { - length = _bundle->decompressMusicSampleByName(_nameBundleMusic, l, (_musicBundleBufOutput + ((k * 0x2000) + _offsetBufBundleMusic))); - _offsetSampleBundleMusic += length; - - if (l == 0) { - tag = READ_BE_UINT32(ptr); ptr += 4; - if (tag != MKID_BE('iMUS')) { - error("Decompressing bundle song failed (unknown tag '%s')", tag2str(tag)); - } - - ptr += 12; - while (tag != MKID_BE('DATA')) { - tag = READ_BE_UINT32(ptr); ptr += 4; - switch(tag) { - case MKID_BE('FRMT'): - ptr += 12; - _bundleMusicSampleBits = READ_BE_UINT32(ptr); ptr += 4; - rate = READ_BE_UINT32(ptr); ptr += 4; - _bundleSampleChannels = READ_BE_UINT32(ptr); ptr += 4; - break; - case MKID_BE('TEXT'): - case MKID_BE('REGN'): - case MKID_BE('STOP'): - case MKID_BE('JUMP'): - case MKID_BE('SYNC'): - size = READ_BE_UINT32(ptr); ptr += size + 4; - break; - case MKID_BE('DATA'): - size = READ_BE_UINT32(ptr); ptr += 4; - break; - - default: - error("Unknown sound header %c%c%c%c", - (byte)(tag >> 24), - (byte)(tag >> 16), - (byte)(tag >> 8), - (byte)tag); - } - } - if (size < 0) { - error("Decompressing sound failed (missing size field)"); - } - header_size = (ptr - _musicBundleBufOutput); - } - - l++; - _currentSampleBundleMusic = l; - - if (_offsetSampleBundleMusic >= _outputMixerSize + header_size) { - memcpy(_musicBundleBufFinal, (_musicBundleBufOutput + header_size), _outputMixerSize); - _offsetBufBundleMusic = _offsetSampleBundleMusic - _outputMixerSize - header_size; - memcpy(_musicBundleBufOutput, (_musicBundleBufOutput + (_outputMixerSize + header_size)), _offsetBufBundleMusic); - _offsetSampleBundleMusic = _offsetBufBundleMusic; - break; - } - } - - if (_currentSampleBundleMusic == num) { - _currentSampleBundleMusic = 0; - _offsetSampleBundleMusic = 0; - _offsetBufBundleMusic = 0; - _bundleMusicPosition = 0; - _bundleSongPosInMs = 0; - } - - ptr = _musicBundleBufFinal; - - byte *buffer = NULL; - uint32 final_size; - if (_bundleMusicSampleBits == 12) { - final_size = decode12BitsSample(ptr, &buffer, _outputMixerSize, false); - } else if (_bundleMusicSampleBits == 16) { - buffer = (byte *)malloc(_outputMixerSize); - final_size = _outputMixerSize; - memcpy(buffer, ptr, _outputMixerSize); - } else { - warning("Sound::bundleMusicHandler TODO: more newStream options..."); - return; - } - - _bundleSongPosInMs = (_bundleMusicPosition * 5) / (_outputMixerSize / 200); - _bundleMusicPosition += final_size; - if (_bundleMusicTrack == 0) - _scumm->_mixer->newStream(&_bundleMusicTrack, rate, SoundMixer::FLAG_16BITS | SoundMixer::FLAG_STEREO, 300000); - _scumm->_mixer->appendStream(_bundleMusicTrack, buffer, final_size); - free(buffer); -} - -void Sound::playBundleSound(char *sound, PlayingSoundHandle *handle) { - byte *ptr = 0, *orig_ptr = 0; - byte *final; - bool result; - - if (_scumm->_noDigitalSamples) - return; - - if (_scumm->_gameId == GID_CMI) { - if (_scumm->_features & GF_DEMO) { - result = _bundle->openVoiceFile("voice.bun", _scumm->getGameDataPath()); - } else { - char voxfile[20]; - sprintf(voxfile, "voxdisk%d.bun", _scumm->VAR(_scumm->VAR_CURRENTDISK)); - if (_voiceDisk != _scumm->VAR(_scumm->VAR_CURRENTDISK)) - _bundle->closeVoiceFile(); - - result = _bundle->openVoiceFile(voxfile, _scumm->getGameDataPath()); - - if (result == false) - result = _bundle->openVoiceFile("voice.bun", _scumm->getGameDataPath()); - _voiceDisk = (byte)_scumm->VAR(_scumm->VAR_CURRENTDISK); - } - } else if (_scumm->_gameId == GID_DIG) - result = _bundle->openVoiceFile("digvoice.bun", _scumm->getGameDataPath()); - else - error("Don't know which bundle file to load"); - - if (!result) - return; - - int32 rate = 22050, pan = 0, channels, output_size = 0; - int32 tag, size = -1, bits = 0; - - if (_scumm->_gameId == GID_CMI) { - char name[20]; - strcpy(name, sound); - if (!(_scumm->_features & GF_DEMO)) // CMI demo does not have .IMX for voice but does for music... - strcat(name, ".IMX"); - output_size = _bundle->decompressVoiceSampleByName(name, &ptr); - } else { - output_size = _bundle->decompressVoiceSampleByName(sound, &ptr); - } - - orig_ptr = ptr; - if (output_size == 0 || orig_ptr == 0) { - goto bail; - } - - tag = READ_BE_UINT32(ptr); ptr += 4; - if (tag != MKID_BE('iMUS')) { - warning("Decompression of bundle sound failed"); - goto bail; - } - - ptr += 12; - while (tag != MKID_BE('DATA')) { - tag = READ_BE_UINT32(ptr); ptr += 4; - switch(tag) { - case MKID_BE('FRMT'): - ptr += 12; - bits = READ_BE_UINT32(ptr); ptr += 4; - rate = READ_BE_UINT32(ptr); ptr += 4; - channels = READ_BE_UINT32(ptr); ptr += 4; - break; - case MKID_BE('TEXT'): - case MKID_BE('REGN'): - case MKID_BE('STOP'): - case MKID_BE('JUMP'): - case MKID_BE('SYNC'): - size = READ_BE_UINT32(ptr); ptr += size + 4; - break; - case MKID_BE('DATA'): - size = READ_BE_UINT32(ptr); ptr += 4; - break; - default: - error("Unknown sound header %c%c%c%c", - (byte)(tag >> 24), - (byte)(tag >> 16), - (byte)(tag >> 8), - (byte)tag); - } - } - - if (size < 0) { - warning("Decompression sound failed (no size field)"); - goto bail; - } - - final = (byte *)malloc(size); - memcpy(final, ptr, size); - - if (_scumm->_actorToPrintStrFor != 0xFF && _scumm->_actorToPrintStrFor != 0) { - Actor *a = _scumm->derefActor(_scumm->_actorToPrintStrFor, "playBundleSound"); - rate = (rate * a->talkFrequency) / 256; - - // Adjust to fit the mixer's notion of panning. - if (pan != 64) - pan = 2 * a->talkPan - 127; - } - - // Stop any sound currently playing on the given handle - if (handle) - _scumm->_mixer->stopHandle(*handle); - - if (bits == 8) { - _scumm->_mixer->playRaw(handle, final, size, rate, SoundMixer::FLAG_UNSIGNED | SoundMixer::FLAG_AUTOFREE, -1, 255, pan); - } else if (bits == 16) { - // FIXME: For some weird reasons, sometimes we get an odd size, even though - // the data is supposed to be in 16 bit format... that makes no sense... - size &= ~1; - _scumm->_mixer->playRaw(handle, final, size, rate, SoundMixer::FLAG_16BITS | SoundMixer::FLAG_AUTOFREE, -1, 255, pan); - } else { - warning("Sound::playBundleSound() to do more options to playRaw..."); - } - -bail: - free(orig_ptr); -} - void Sound::playSfxSound(void *sound, uint32 size, uint rate, bool isUnsigned, PlayingSoundHandle *handle) { byte flags = SoundMixer::FLAG_AUTOFREE; if (isUnsigned) |
