aboutsummaryrefslogtreecommitdiff
path: root/scumm
diff options
context:
space:
mode:
authorMax Horn2003-06-21 23:29:34 +0000
committerMax Horn2003-06-21 23:29:34 +0000
commitbd4370c25166ad0e49c78d9e4407d39358e17b91 (patch)
treeae1acc56b83cdb642da285be7373ab116f3efd1f /scumm
parent7281ac690732a93e9407f56e61976ea4b7c54fad (diff)
downloadscummvm-rg350-bd4370c25166ad0e49c78d9e4407d39358e17b91.tar.gz
scummvm-rg350-bd4370c25166ad0e49c78d9e4407d39358e17b91.tar.bz2
scummvm-rg350-bd4370c25166ad0e49c78d9e4407d39358e17b91.zip
lots of mixer cleanup / refactoring / reengineering
svn-id: r8594
Diffstat (limited to 'scumm')
-rw-r--r--scumm/imuse_digi.cpp26
-rw-r--r--scumm/imuse_digi.h2
-rw-r--r--scumm/smush/smush_mixer.cpp29
-rw-r--r--scumm/smush/smush_player.cpp4
-rw-r--r--scumm/sound.cpp4
5 files changed, 37 insertions, 28 deletions
diff --git a/scumm/imuse_digi.cpp b/scumm/imuse_digi.cpp
index f2bab909da..f31db2272b 100644
--- a/scumm/imuse_digi.cpp
+++ b/scumm/imuse_digi.cpp
@@ -94,16 +94,16 @@ IMuseDigital::IMuseDigital(Scumm *scumm) {
memset(_channel, 0, sizeof(Channel) * MAX_DIGITAL_CHANNELS);
_scumm = scumm;
for (int32 l = 0; l < MAX_DIGITAL_CHANNELS; l++) {
- _channel[l]._initialized = false;
+ _channel[l]._mixerChannel = -1;
}
- _scumm->_mixer->beginSlots(MAX_DIGITAL_CHANNELS + 1);
_scumm->_timer->installProcedure(imus_digital_handler, 200000);
_pause = false;
}
IMuseDigital::~IMuseDigital() {
for (int32 l = 0; l < MAX_DIGITAL_CHANNELS; l++) {
- _scumm->_mixer->stop(l);
+ if (_channel[l]._mixerChannel != -1)
+ _scumm->_mixer->stop(_channel[l]._mixerChannel);
}
_scumm->_timer->releaseProcedure(imus_digital_handler);
}
@@ -708,17 +708,20 @@ static const imuse_ft_music_table _ftSeqMusicTable[] = {
void IMuseDigital::handler() {
uint32 l = 0, i = 0;
- if (_pause == true)
+ if (_pause)
return;
for (l = 0; l < MAX_DIGITAL_CHANNELS;l ++) {
if (_channel[l]._used) {
if (_channel[l]._toBeRemoved == true) {
- _scumm->_mixer->stop(l);
+ if (_channel[l]._mixerChannel != -1) {
+ _scumm->_mixer->stop(_channel[l]._mixerChannel);
+ _channel[l]._mixerChannel = -1;
+ }
if (_scumm->_mixer->_channels[l] == NULL) {
free(_channel[l]._data);
_channel[l]._used = false;
- _channel[l]._initialized = false;
+ _channel[l]._mixerChannel = -1;
}
continue;
}
@@ -764,7 +767,7 @@ void IMuseDigital::handler() {
uint32 new_size = _channel[l]._mixerSize;
uint32 mixer_size = new_size;
- if (_channel[l]._initialized == false) {
+ if (_channel[l]._mixerChannel == -1) {
mixer_size *= 2;
new_size *= 2;
}
@@ -820,12 +823,11 @@ void IMuseDigital::handler() {
}
if (_scumm->_silentDigitalImuse == false) {
- if (_channel[l]._initialized == false) {
- _scumm->_mixer->playStream(l, buf, mixer_size,
- _channel[l]._freq, _channel[l]._mixerFlags, 3, 100000);
- _channel[l]._initialized = true;
+ if (_channel[l]._mixerChannel == -1) {
+ _channel[l]._mixerChannel = _scumm->_mixer->playStream(buf, mixer_size,
+ _channel[l]._freq, _channel[l]._mixerFlags, 100000);
} else {
- _scumm->_mixer->append(l, buf, mixer_size);
+ _scumm->_mixer->append(_channel[l]._mixerChannel, buf, mixer_size);
}
}
free(buf);
diff --git a/scumm/imuse_digi.h b/scumm/imuse_digi.h
index a3239c5e4d..8b50ce218f 100644
--- a/scumm/imuse_digi.h
+++ b/scumm/imuse_digi.h
@@ -69,9 +69,9 @@ private:
int32 _idSound;
uint32 _mixerSize;
uint8 _mixerFlags;
+ int _mixerChannel;
bool _used;
bool _toBeRemoved;
- bool _initialized;
};
Channel _channel[MAX_DIGITAL_CHANNELS];
diff --git a/scumm/smush/smush_mixer.cpp b/scumm/smush/smush_mixer.cpp
index 96a0a00ef0..f75fd92881 100644
--- a/scumm/smush/smush_mixer.cpp
+++ b/scumm/smush/smush_mixer.cpp
@@ -30,9 +30,9 @@
SmushMixer::SmushMixer(SoundMixer *m) :
_mixer(m),
- _nextIndex(_mixer->_beginSlots),
+ _nextIndex(0),
_soundFrequency(22050) {
- for (int32 i = _mixer->_beginSlots; i < SoundMixer::NUM_CHANNELS; i++) {
+ for (int32 i = 0; i < SoundMixer::NUM_CHANNELS; i++) {
_channels[i].id = -1;
_channels[i].chan = NULL;
_channels[i].mixer_index = -1;
@@ -40,11 +40,15 @@ SmushMixer::SmushMixer(SoundMixer *m) :
}
SmushMixer::~SmushMixer() {
+ for (int32 i = 0; i < SoundMixer::NUM_CHANNELS; i++) {
+ if (_channels[i].mixer_index != -1)
+ _mixer->stop(_channels[i].mixer_index);
+ }
}
SmushChannel *SmushMixer::findChannel(int32 track) {
debug(9, "SmushMixer::findChannel(%d)", track);
- for (int32 i = _mixer->_beginSlots; i < SoundMixer::NUM_CHANNELS; i++) {
+ for (int32 i = 0; i < SoundMixer::NUM_CHANNELS; i++) {
if (_channels[i].id == track)
return _channels[i].chan;
}
@@ -57,12 +61,12 @@ bool SmushMixer::addChannel(SmushChannel *c) {
debug(9, "SmushMixer::addChannel(%d)", track);
- for (i = _mixer->_beginSlots; i < SoundMixer::NUM_CHANNELS; i++) {
+ for (i = 0; i < SoundMixer::NUM_CHANNELS; i++) {
if (_channels[i].id == track)
warning("SmushMixer::addChannel(%d) : channel already exists", track);
}
if (_nextIndex >= SoundMixer::NUM_CHANNELS)
- _nextIndex = _mixer->_beginSlots;
+ _nextIndex = 0;
for (i = _nextIndex; i < SoundMixer::NUM_CHANNELS; i++) {
if (_channels[i].chan == NULL || _channels[i].id == -1) {
@@ -74,7 +78,7 @@ bool SmushMixer::addChannel(SmushChannel *c) {
}
}
- for (i = _mixer->_beginSlots; i < _nextIndex; i++) {
+ for (i = 0; i < _nextIndex; i++) {
if (_channels[i].chan == NULL || _channels[i].id == -1) {
_channels[i].chan = c;
_channels[i].id = track;
@@ -86,7 +90,7 @@ bool SmushMixer::addChannel(SmushChannel *c) {
warning("_nextIndex == %d", _nextIndex);
- for (i = _mixer->_beginSlots; i < SoundMixer::NUM_CHANNELS; i++) {
+ for (i = 0; i < SoundMixer::NUM_CHANNELS; i++) {
warning("channel %d : %p(%d, %d) %d %d", i, (void *)_channels[i].chan,
_channels[i].chan ? _channels[i].chan->getTrackIdentifier() : -1,
_channels[i].chan ? _channels[i].chan->isTerminated() : 1,
@@ -99,9 +103,13 @@ bool SmushMixer::addChannel(SmushChannel *c) {
bool SmushMixer::handleFrame() {
debug(9, "SmushMixer::handleFrame()");
- for (int i = _mixer->_beginSlots; i < SoundMixer::NUM_CHANNELS; i++) {
+ for (int i = 0; i < SoundMixer::NUM_CHANNELS; i++) {
if (_channels[i].id != -1) {
if (_channels[i].chan->isTerminated()) {
+ if (_channels[i].mixer_index != -1) {
+ _mixer->stop(_channels[i].mixer_index);
+ _channels[i].mixer_index = -1;
+ }
delete _channels[i].chan;
_channels[i].id = -1;
_channels[i].chan = NULL;
@@ -131,7 +139,7 @@ bool SmushMixer::handleFrame() {
if (_silentMixer == false) {
if (_channels[i].mixer_index == -1) {
- _channels[i].mixer_index = _mixer->playStream(-1, data, size, rate, flags);
+ _channels[i].mixer_index = _mixer->playStream(data, size, rate, flags, 2000000);
} else {
_mixer->append(_channels[i].mixer_index, data, size);
}
@@ -145,7 +153,7 @@ bool SmushMixer::handleFrame() {
bool SmushMixer::stop() {
debug(9, "SmushMixer::stop()");
- for (int i = _mixer->_beginSlots; i < SoundMixer::NUM_CHANNELS; i++) {
+ for (int i = 0; i < SoundMixer::NUM_CHANNELS; i++) {
if (_channels[i].id != -1) {
delete _channels[i].chan;
_channels[i].id = -1;
@@ -154,4 +162,3 @@ bool SmushMixer::stop() {
}
return true;
}
-
diff --git a/scumm/smush/smush_player.cpp b/scumm/smush/smush_player.cpp
index 928dbc8f25..d27a92f1c6 100644
--- a/scumm/smush/smush_player.cpp
+++ b/scumm/smush/smush_player.cpp
@@ -451,8 +451,8 @@ void SmushPlayer::handleImuseAction(Chunk &b) {
} while (--count);
if (_IACTchannel == -1) {
- _IACTchannel = _scumm->_mixer->playStream(-1, output_data, 0x1000, 22050,
- SoundMixer::FLAG_STEREO | SoundMixer::FLAG_16BITS, -1, 200000);
+ _IACTchannel = _scumm->_mixer->playStream(output_data, 0x1000, 22050,
+ SoundMixer::FLAG_STEREO | SoundMixer::FLAG_16BITS, 200000);
} else {
_scumm->_mixer->append(_IACTchannel, output_data, 0x1000);
}
diff --git a/scumm/sound.cpp b/scumm/sound.cpp
index 61daedd78c..19f4c74c13 100644
--- a/scumm/sound.cpp
+++ b/scumm/sound.cpp
@@ -1176,8 +1176,8 @@ void Sound::bundleMusicHandler(Scumm *scumm) {
_bundleMusicPosition += final_size;
if (_bundleMusicTrack == -1) {
- _bundleMusicTrack = _scumm->_mixer->playStream(_scumm->_mixer->_beginSlots - 1, buffer, final_size, rate,
- SoundMixer::FLAG_16BITS | SoundMixer::FLAG_STEREO, -1, 300000);
+ _bundleMusicTrack = _scumm->_mixer->playStream(buffer, final_size, rate,
+ SoundMixer::FLAG_16BITS | SoundMixer::FLAG_STEREO, 300000);
} else {
_scumm->_mixer->append(_bundleMusicTrack, buffer, final_size);
}