diff options
-rw-r--r-- | engines/agi/sound.cpp | 4 | ||||
-rw-r--r-- | engines/agi/sound.h | 6 | ||||
-rw-r--r-- | engines/cine/sound_driver.cpp | 4 | ||||
-rw-r--r-- | engines/cine/sound_driver.h | 6 | ||||
-rw-r--r-- | engines/engine.cpp | 2 | ||||
-rw-r--r-- | engines/kyra/sound.h | 2 | ||||
-rw-r--r-- | engines/kyra/sound_adlib.cpp | 5 | ||||
-rw-r--r-- | engines/scumm/player_mod.cpp | 5 | ||||
-rw-r--r-- | engines/scumm/player_mod.h | 2 | ||||
-rw-r--r-- | engines/scumm/player_nes.cpp | 4 | ||||
-rw-r--r-- | engines/scumm/player_nes.h | 6 | ||||
-rw-r--r-- | engines/scumm/player_v2.cpp | 5 | ||||
-rw-r--r-- | engines/scumm/player_v2.h | 6 | ||||
-rw-r--r-- | engines/sky/music/adlibmusic.cpp | 4 | ||||
-rw-r--r-- | engines/sky/music/adlibmusic.h | 6 | ||||
-rw-r--r-- | engines/sword1/music.cpp | 4 | ||||
-rw-r--r-- | engines/sword1/music.h | 6 | ||||
-rw-r--r-- | engines/sword2/sound.cpp | 4 | ||||
-rw-r--r-- | engines/sword2/sound.h | 1 | ||||
-rw-r--r-- | sound/mixer.cpp | 41 | ||||
-rw-r--r-- | sound/mixer.h | 21 | ||||
-rw-r--r-- | sound/softsynth/adlib.cpp | 5 | ||||
-rw-r--r-- | sound/softsynth/emumidi.h | 1 | ||||
-rw-r--r-- | sound/softsynth/ym2612.cpp | 5 |
24 files changed, 52 insertions, 103 deletions
diff --git a/engines/agi/sound.cpp b/engines/agi/sound.cpp index f4a2ee790e..2863f7b16b 100644 --- a/engines/agi/sound.cpp +++ b/engines/agi/sound.cpp @@ -324,14 +324,14 @@ int SoundMgr::initSound() { /*loadInstruments("demo.sys"); */ #endif - _mixer->setupPremix(this); + _mixer->playInputStream(Audio::Mixer::kPlainSoundType, &_soundHandle, this, -1, Audio::Mixer::kMaxChannelVolume, 0, false, true); return r; } void SoundMgr::deinitSound() { debugC(3, kDebugLevelSound, "()"); - _mixer->setupPremix(NULL); + _mixer->stopHandle(_soundHandle); free(sndBuffer); } diff --git a/engines/agi/sound.h b/engines/agi/sound.h index 415b891762..8a4f6a5deb 100644 --- a/engines/agi/sound.h +++ b/engines/agi/sound.h @@ -26,10 +26,7 @@ #define AGI_SOUND_H #include "sound/audiostream.h" - -namespace Audio { -class Mixer; -} // End of namespace Audio +#include "sound/mixer.h" namespace Agi { @@ -128,6 +125,7 @@ public: private: Audio::Mixer *_mixer; + Audio::SoundHandle _soundHandle; uint32 _sampleRate; void premixerCall(int16 *buf, uint len); diff --git a/engines/cine/sound_driver.cpp b/engines/cine/sound_driver.cpp index 84b0a1416e..0bc7c8c33f 100644 --- a/engines/cine/sound_driver.cpp +++ b/engines/cine/sound_driver.cpp @@ -60,11 +60,11 @@ AdlibSoundDriver::AdlibSoundDriver(Audio::Mixer *mixer) memset(_channelsVolumeTable, 0, sizeof(_channelsVolumeTable)); memset(_instrumentsTable, 0, sizeof(_instrumentsTable)); initCard(); - _mixer->setupPremix(this); + _mixer->playInputStream(Audio::Mixer::kPlainSoundType, &_soundHandle, this, -1, Audio::Mixer::kMaxChannelVolume, 0, false, true); } AdlibSoundDriver::~AdlibSoundDriver() { - _mixer->setupPremix(NULL); + _mixer->stopHandle(_soundHandle); } void AdlibSoundDriver::setupChannel(int channel, const byte *data, int instrument, int volume) { diff --git a/engines/cine/sound_driver.h b/engines/cine/sound_driver.h index 2cb2b5c97f..c6fc571f89 100644 --- a/engines/cine/sound_driver.h +++ b/engines/cine/sound_driver.h @@ -27,10 +27,7 @@ #include "sound/audiostream.h" #include "sound/fmopl.h" - -namespace Audio { - class Mixer; -} +#include "sound/mixer.h" namespace Cine { @@ -105,6 +102,7 @@ protected: FM_OPL *_opl; int _sampleRate; Audio::Mixer *_mixer; + Audio::SoundHandle _soundHandle; byte _vibrato; int _channelsVolumeTable[4]; diff --git a/engines/engine.cpp b/engines/engine.cpp index b6837d5ee2..5ba7acbffe 100644 --- a/engines/engine.cpp +++ b/engines/engine.cpp @@ -50,7 +50,7 @@ Engine::Engine(OSystem *syst) } Engine::~Engine() { - _mixer->stopAll(true); + _mixer->stopAll(); g_engine = NULL; } diff --git a/engines/kyra/sound.h b/engines/kyra/sound.h index 5a602cb980..e286187fc7 100644 --- a/engines/kyra/sound.h +++ b/engines/kyra/sound.h @@ -57,8 +57,6 @@ namespace Audio { class AudioStream; -class Mixer; -class SoundHandle; } // end of namespace Audio namespace Kyra { diff --git a/engines/kyra/sound_adlib.cpp b/engines/kyra/sound_adlib.cpp index 307bf49efc..3cb309278e 100644 --- a/engines/kyra/sound_adlib.cpp +++ b/engines/kyra/sound_adlib.cpp @@ -406,6 +406,7 @@ private: Common::Mutex _mutex; Audio::Mixer *_mixer; + Audio::SoundHandle _soundHandle; bool _v2; @@ -445,7 +446,7 @@ AdlibDriver::AdlibDriver(Audio::Mixer *mixer, bool v2) { _tablePtr1 = _tablePtr2 = 0; - _mixer->setupPremix(this); + _mixer->playInputStream(Audio::Mixer::kPlainSoundType, &_soundHandle, this, -1, Audio::Mixer::kMaxChannelVolume, 0, false, true); _samplesPerCallback = getRate() / CALLBACKS_PER_SECOND; _samplesPerCallbackRemainder = getRate() % CALLBACKS_PER_SECOND; @@ -456,7 +457,7 @@ AdlibDriver::AdlibDriver(Audio::Mixer *mixer, bool v2) { } AdlibDriver::~AdlibDriver() { - _mixer->setupPremix(0); + _mixer->stopHandle(_soundHandle); OPLDestroy(_adlib); _adlib = 0; } diff --git a/engines/scumm/player_mod.cpp b/engines/scumm/player_mod.cpp index 8ce3c80132..38a5c8554e 100644 --- a/engines/scumm/player_mod.cpp +++ b/engines/scumm/player_mod.cpp @@ -46,12 +46,11 @@ Player_MOD::Player_MOD(Audio::Mixer *mixer) { _playproc = NULL; _playparam = NULL; - _mixer->setupPremix(this); + _mixer->playInputStream(Audio::Mixer::kPlainSoundType, &_soundHandle, this, -1, Audio::Mixer::kMaxChannelVolume, 0, false, true); } Player_MOD::~Player_MOD() { - // Detach the premix callback handler - _mixer->setupPremix(0); + _mixer->stopHandle(_soundHandle); for (int i = 0; i < MOD_MAXCHANS; i++) { if (!_channels[i].id) continue; diff --git a/engines/scumm/player_mod.h b/engines/scumm/player_mod.h index 6146c1c4a2..6e381191d1 100644 --- a/engines/scumm/player_mod.h +++ b/engines/scumm/player_mod.h @@ -26,6 +26,7 @@ #include "scumm/scumm.h" #include "sound/audiostream.h" +#include "sound/mixer.h" namespace Audio { class RateConverter; @@ -77,6 +78,7 @@ private: }; Audio::Mixer *_mixer; + Audio::SoundHandle _soundHandle; uint32 _mixamt; uint32 _mixpos; diff --git a/engines/scumm/player_nes.cpp b/engines/scumm/player_nes.cpp index eaa59fb4f8..4836ad5629 100644 --- a/engines/scumm/player_nes.cpp +++ b/engines/scumm/player_nes.cpp @@ -620,11 +620,11 @@ Player_NES::Player_NES(ScummEngine *scumm, Audio::Mixer *mixer) { APU_writeControl(0); - _mixer->setupPremix(this); + _mixer->playInputStream(Audio::Mixer::kPlainSoundType, &_soundHandle, this, -1, Audio::Mixer::kMaxChannelVolume, 0, false, true); } Player_NES::~Player_NES() { - _mixer->setupPremix(0); + _mixer->stopHandle(_soundHandle); delete _apu; } diff --git a/engines/scumm/player_nes.h b/engines/scumm/player_nes.h index 6140460838..eaececee2d 100644 --- a/engines/scumm/player_nes.h +++ b/engines/scumm/player_nes.h @@ -27,10 +27,7 @@ #include "common/scummsys.h" #include "scumm/music.h" #include "sound/audiostream.h" - -namespace Audio { - class Mixer; -} +#include "sound/mixer.h" namespace Scumm { @@ -80,6 +77,7 @@ private: ScummEngine *_vm; Audio::Mixer *_mixer; + Audio::SoundHandle _soundHandle; APUe::APU *_apu; int _sample_rate; int _samples_per_frame; diff --git a/engines/scumm/player_v2.cpp b/engines/scumm/player_v2.cpp index 1eb7b958dd..9f764a5d0b 100644 --- a/engines/scumm/player_v2.cpp +++ b/engines/scumm/player_v2.cpp @@ -375,13 +375,12 @@ Player_V2::Player_V2(ScummEngine *scumm, Audio::Mixer *mixer, bool pcjr) { set_pcjr(pcjr); setMusicVolume(255); - _mixer->setupPremix(this); + _mixer->playInputStream(Audio::Mixer::kPlainSoundType, &_soundHandle, this, -1, Audio::Mixer::kMaxChannelVolume, 0, false, true); } Player_V2::~Player_V2() { mutex_up(); - // Detach the premix callback handler - _mixer->setupPremix(0); + _mixer->stopHandle(_soundHandle); mutex_down(); } diff --git a/engines/scumm/player_v2.h b/engines/scumm/player_v2.h index cfcd986958..704c3d9795 100644 --- a/engines/scumm/player_v2.h +++ b/engines/scumm/player_v2.h @@ -28,10 +28,7 @@ #include "common/mutex.h" #include "scumm/music.h" #include "sound/audiostream.h" - -namespace Audio { - class Mixer; -} +#include "sound/mixer.h" namespace Scumm { @@ -96,6 +93,7 @@ public: protected: bool _isV3Game; Audio::Mixer *_mixer; + Audio::SoundHandle _soundHandle; ScummEngine *_vm; bool _pcjr; diff --git a/engines/sky/music/adlibmusic.cpp b/engines/sky/music/adlibmusic.cpp index 7df70e4a0f..36c962af5a 100644 --- a/engines/sky/music/adlibmusic.cpp +++ b/engines/sky/music/adlibmusic.cpp @@ -39,12 +39,12 @@ AdlibMusic::AdlibMusic(Audio::Mixer *pMixer, Disk *pDisk) _opl = makeAdlibOPL(_sampleRate); - _mixer->setupPremix(this); + _mixer->playInputStream(Audio::Mixer::kPlainSoundType, &_soundHandle, this, -1, Audio::Mixer::kMaxChannelVolume, 0, false, true); } AdlibMusic::~AdlibMusic(void) { - _mixer->setupPremix(0); + _mixer->stopHandle(_soundHandle); } void AdlibMusic::premixerCall(int16 *data, uint len) { diff --git a/engines/sky/music/adlibmusic.h b/engines/sky/music/adlibmusic.h index 016d43287e..b50157c3b5 100644 --- a/engines/sky/music/adlibmusic.h +++ b/engines/sky/music/adlibmusic.h @@ -26,10 +26,7 @@ #include "sky/music/musicbase.h" #include "sound/audiostream.h" #include "sound/fmopl.h" - -namespace Audio { - class Mixer; -} +#include "sound/mixer.h" namespace Sky { @@ -50,6 +47,7 @@ public: private: FM_OPL *_opl; Audio::Mixer *_mixer; + Audio::SoundHandle _soundHandle; uint8 *_initSequence; uint32 _sampleRate, _nextMusicPoll; virtual void setupPointers(void); diff --git a/engines/sword1/music.cpp b/engines/sword1/music.cpp index fe3b90c052..41d47dc5d9 100644 --- a/engines/sword1/music.cpp +++ b/engines/sword1/music.cpp @@ -255,11 +255,11 @@ Music::Music(Audio::Mixer *pMixer) { _converter[0] = NULL; _converter[1] = NULL; _volumeL = _volumeR = 192; - _mixer->setupPremix(this); + _mixer->playInputStream(Audio::Mixer::kPlainSoundType, &_soundHandle, this, -1, Audio::Mixer::kMaxChannelVolume, 0, false, true); } Music::~Music() { - _mixer->setupPremix(0); + _mixer->stopHandle(_soundHandle); delete _converter[0]; delete _converter[1]; } diff --git a/engines/sword1/music.h b/engines/sword1/music.h index 606c3d3004..75bb2521c1 100644 --- a/engines/sword1/music.h +++ b/engines/sword1/music.h @@ -27,12 +27,9 @@ #include "common/mutex.h" #include "common/file.h" #include "sound/audiostream.h" +#include "sound/mixer.h" #include "sound/rate.h" -namespace Audio { - class Mixer; -} - namespace Sword1 { #define TOTAL_TUNES 270 @@ -108,6 +105,7 @@ private: MusicHandle _handles[2]; Audio::RateConverter *_converter[2]; Audio::Mixer *_mixer; + Audio::SoundHandle _soundHandle; uint32 _sampleRate; Common::Mutex _mutex; diff --git a/engines/sword2/sound.cpp b/engines/sword2/sound.cpp index b1de94f3ad..1a7cc1cee6 100644 --- a/engines/sword2/sound.cpp +++ b/engines/sword2/sound.cpp @@ -83,11 +83,11 @@ Sound::Sound(Sword2Engine *vm) { _mixBuffer = NULL; _mixBufferLen = 0; - _vm->_mixer->setupPremix(this, Audio::Mixer::kMusicSoundType); + _vm->_mixer->playInputStream(Audio::Mixer::kMusicSoundType, &_mixerSoundHandle, this, -1, Audio::Mixer::kMaxChannelVolume, 0, false, true); } Sound::~Sound() { - _vm->_mixer->setupPremix(0); + _vm->_mixer->stopHandle(_mixerSoundHandle); clearFxQueue(true); stopMusic(true); diff --git a/engines/sword2/sound.h b/engines/sword2/sound.h index 8c24494148..932e557eaa 100644 --- a/engines/sword2/sound.h +++ b/engines/sword2/sound.h @@ -176,6 +176,7 @@ private: Common::Mutex _mutex; + Audio::SoundHandle _mixerSoundHandle; Audio::SoundHandle _leadInHandle; Audio::SoundHandle _leadOutHandle; diff --git a/sound/mixer.cpp b/sound/mixer.cpp index 1712209237..26fd195b07 100644 --- a/sound/mixer.cpp +++ b/sound/mixer.cpp @@ -108,7 +108,6 @@ Mixer::Mixer() { _handleSeed = 0; - _premixChannel = 0; int i = 0; for (i = 0; i < ARRAYSIZE(_volumeForSoundType); i++) @@ -121,29 +120,14 @@ Mixer::Mixer() { } Mixer::~Mixer() { - stopAll(true); - - delete _premixChannel; - _premixChannel = 0; + for (int i = 0; i != NUM_CHANNELS; i++) + delete _channels[i]; } uint Mixer::getOutputRate() const { return (uint)_syst->getOutputSampleRate(); } -void Mixer::setupPremix(AudioStream *stream, SoundType type) { - Common::StackLock lock(_mutex); - - delete _premixChannel; - _premixChannel = 0; - - if (stream == 0) - return; - - // Create the channel - _premixChannel = new Channel(this, type, stream, false); -} - void Mixer::insertChannel(SoundHandle *handle, Channel *chan) { int index = -1; @@ -246,10 +230,7 @@ void Mixer::mix(int16 *buf, uint len) { // zero the buf memset(buf, 0, 2 * len * sizeof(int16)); - if (_premixChannel && !_premixChannel->isPaused()) - _premixChannel->mix(buf, len); - - // now mix all channels + // mix all channels for (int i = 0; i != NUM_CHANNELS; i++) if (_channels[i]) { if (_channels[i]->isFinished()) { @@ -268,18 +249,14 @@ void Mixer::mixCallback(void *s, byte *samples, int len) { ((Mixer *)s)->mix((int16 *)samples, len >> 2); } -void Mixer::stopAll(bool force) { +void Mixer::stopAll() { Common::StackLock lock(_mutex); for (int i = 0; i != NUM_CHANNELS; i++) { - if (_channels[i] != 0) { - if (force || !_channels[i]->isPermanent()) { - delete _channels[i]; - _channels[i] = 0; - } + if (_channels[i] != 0 && !_channels[i]->isPermanent()) { + delete _channels[i]; + _channels[i] = 0; } } - - // Note: the _premixChannel is *not* affected by stopAll! } void Mixer::stopID(int id) { @@ -341,10 +318,6 @@ void Mixer::pauseAll(bool paused) { _channels[i]->pause(paused); } } - - // Unlike stopAll, we also pause the premix channel, if present. - if (_premixChannel) - _premixChannel->pause(paused); } void Mixer::pauseID(int id, bool paused) { diff --git a/sound/mixer.h b/sound/mixer.h index f2bec71057..9b10bbf996 100644 --- a/sound/mixer.h +++ b/sound/mixer.h @@ -102,8 +102,6 @@ private: OSystem *_syst; Common::Mutex _mutex; - Channel *_premixChannel; - int _volumeForSoundType[4]; uint32 _handleSeed; @@ -120,8 +118,8 @@ public: /** * Is the mixer ready and setup? This may not be the case on systems which * don't support digital sound output. In that case, the mixer proc may - * never be called. That in turn can cause breakage in games which use the - * premix callback for syncing. In particular, the Adlib MIDI emulation... + * never be called. That in turn can cause breakage in games which try to + * sync with an audio stream. In particular, the Adlib MIDI emulation... * * @return whether the mixer is ready and setup */ @@ -130,15 +128,6 @@ public: /** - * Set the premix stream. This is mainly used for the adlib music, but - * is not limited to it. The premix stream is invoked by the mixer whenever - * it needs to generate any data, before any other mixing takes place. - */ - void setupPremix(AudioStream *stream, SoundType type = kPlainSoundType); - - - - /** * Start playing the given raw sound data. * Internally, this simply creates an audio input stream wrapping the data * (using the makeLinearInputStream factory function), which is then @@ -182,7 +171,7 @@ public: /** * Stop all currently playing sounds. */ - void stopAll(bool force = false); + void stopAll(); /** * Stop playing the sound with given ID. @@ -201,8 +190,8 @@ public: /** - * Pause/unpause all sounds, including all regular channels and the - * premix channel. + * Pause/unpause all sounds, including all regular and permanent + * channels * * @param paused true to pause everything, false to unpause */ diff --git a/sound/softsynth/adlib.cpp b/sound/softsynth/adlib.cpp index 96b1add13f..15a99069be 100644 --- a/sound/softsynth/adlib.cpp +++ b/sound/softsynth/adlib.cpp @@ -847,7 +847,7 @@ int MidiDriver_ADLIB::open() { adlib_write(0xBD, 0x00); create_lookup_table(); - _mixer->setupPremix(this); + _mixer->playInputStream(Audio::Mixer::kPlainSoundType, &_mixerSoundHandle, this, -1, Audio::Mixer::kMaxChannelVolume, 0, false, true); return 0; } @@ -857,8 +857,7 @@ void MidiDriver_ADLIB::close() { return; _isOpen = false; - // Detach the premix callback handler - _mixer->setupPremix(0); + _mixer->stopHandle(_mixerSoundHandle); uint i; for (i = 0; i < ARRAYSIZE(_voices); ++i) { diff --git a/sound/softsynth/emumidi.h b/sound/softsynth/emumidi.h index 557e9b04cc..43161e51e4 100644 --- a/sound/softsynth/emumidi.h +++ b/sound/softsynth/emumidi.h @@ -30,6 +30,7 @@ class MidiDriver_Emulated : public Audio::AudioStream, public MidiDriver { protected: bool _isOpen; Audio::Mixer *_mixer; + Audio::SoundHandle _mixerSoundHandle; private: Common::TimerManager::TimerProc _timerProc; diff --git a/sound/softsynth/ym2612.cpp b/sound/softsynth/ym2612.cpp index 40962c04c5..823e371a88 100644 --- a/sound/softsynth/ym2612.cpp +++ b/sound/softsynth/ym2612.cpp @@ -741,7 +741,7 @@ int MidiDriver_YM2612::open() { MidiDriver_Emulated::open(); - _mixer->setupPremix(this); + _mixer->playInputStream(Audio::Mixer::kPlainSoundType, &_mixerSoundHandle, this, -1, Audio::Mixer::kMaxChannelVolume, 0, false, true); return 0; } @@ -750,8 +750,7 @@ void MidiDriver_YM2612::close() { return; _isOpen = false; - // Detach the premix callback handler - _mixer->setupPremix(0); + _mixer->stopHandle(_mixerSoundHandle); } void MidiDriver_YM2612::send(uint32 b) { |