mirror of
https://github.com/scummvm/scummvm.git
synced 2026-06-20 05:45:29 +00:00
Patch #1663933 (Kill premix channel) with a few tiny additional tweaks by me
svn-id: r25752
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
+2
-4
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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];
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@ Engine::Engine(OSystem *syst)
|
||||
}
|
||||
|
||||
Engine::~Engine() {
|
||||
_mixer->stopAll(true);
|
||||
_mixer->stopAll();
|
||||
|
||||
g_engine = NULL;
|
||||
}
|
||||
|
||||
@@ -57,8 +57,6 @@
|
||||
|
||||
namespace Audio {
|
||||
class AudioStream;
|
||||
class Mixer;
|
||||
class SoundHandle;
|
||||
} // end of namespace Audio
|
||||
|
||||
namespace Kyra {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -176,6 +176,7 @@ private:
|
||||
|
||||
Common::Mutex _mutex;
|
||||
|
||||
Audio::SoundHandle _mixerSoundHandle;
|
||||
Audio::SoundHandle _leadInHandle;
|
||||
Audio::SoundHandle _leadOutHandle;
|
||||
|
||||
|
||||
+7
-34
@@ -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) {
|
||||
|
||||
+5
-16
@@ -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
|
||||
*/
|
||||
@@ -129,15 +127,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
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user