aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaweł Kołodziejski2002-10-15 21:55:04 +0000
committerPaweł Kołodziejski2002-10-15 21:55:04 +0000
commit09225027f1f8b87360952904b6f55f69976b040a (patch)
tree4cca795d9594cdfbb3b6d4ba53ed090e6e41fae3
parent15ac1c1ee9292073fb8dead67111e31c8f328690 (diff)
downloadscummvm-rg350-09225027f1f8b87360952904b6f55f69976b040a.tar.gz
scummvm-rg350-09225027f1f8b87360952904b6f55f69976b040a.tar.bz2
scummvm-rg350-09225027f1f8b87360952904b6f55f69976b040a.zip
changes to imuse
svn-id: r5157
-rw-r--r--scumm/imuse.cpp26
-rw-r--r--scumm/imuse.h2
-rw-r--r--scumm/smush/scumm_renderer.cpp18
-rw-r--r--scumm/sound.cpp6
-rw-r--r--sound/mixer.cpp37
-rw-r--r--sound/mixer.h8
6 files changed, 53 insertions, 44 deletions
diff --git a/scumm/imuse.cpp b/scumm/imuse.cpp
index 82f1232e9f..1da040876b 100644
--- a/scumm/imuse.cpp
+++ b/scumm/imuse.cpp
@@ -4997,11 +4997,18 @@ static void imus_digital_handler(void * engine) {
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]._mixerTrack = -1;
+ }
+ _scumm->_mixer->beginSlots(MAX_DIGITAL_CHANNELS + 1);
_scumm->_timer->installProcedure(imus_digital_handler, 200);
_pause = false;
}
IMuseDigital::~IMuseDigital() {
+ for (int32 l = 0; l < MAX_DIGITAL_CHANNELS; l++) {
+ _scumm->_mixer->stop(l);
+ }
_scumm->_timer->releaseProcedure(imus_digital_handler);
}
@@ -5406,7 +5413,6 @@ void IMuseDigital::handler() {
if (_channel[l]._toBeRemoved == true) {
_channel[l]._used = false;
free(_channel[l]._data);
- memset(&_channel[l], 0, sizeof(channel));
continue;
}
@@ -5507,16 +5513,11 @@ void IMuseDigital::handler() {
}
}
-
if (_channel[l]._mixerTrack == -1) {
- _channel[l]._mixerTrack = _scumm->_mixer->playStream(NULL, -1, buf, mixer_size,
- _channel[l]._freq, _channel[l]._mixerFlags);
- continue;
- } else if (_scumm->_mixer->_channels[_channel[l]._mixerTrack] == NULL) {
- _channel[l]._mixerTrack = _scumm->_mixer->playStream(NULL, -1, buf, mixer_size,
- _channel[l]._freq, _channel[l]._mixerFlags);
+ _channel[l]._mixerTrack = _scumm->_mixer->playStream(NULL, l, buf, mixer_size,
+ _channel[l]._freq, _channel[l]._mixerFlags, -1, 800000);
} else {
- _scumm->_mixer->append(_channel[l]._mixerTrack, buf, mixer_size,
+ _scumm->_mixer->append(l, buf, mixer_size,
_channel[l]._freq, _channel[l]._mixerFlags);
}
}
@@ -5550,7 +5551,6 @@ void IMuseDigital::startSound(int sound) {
if (READ_UINT32_UNALIGNED(ptr) == MKID('Crea')) {
_channel[l]._bits = 8;
_channel[l]._channels = 2;
- _channel[l]._mixerTrack = -1;
_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);
@@ -5624,6 +5624,11 @@ void IMuseDigital::startSound(int sound) {
if (tag == MKID_BE('DATA')) break;
}
+ if ((sound == 123) || (sound == 122)) {
+ _channel[l]._isJump = false;
+ _channel[l]._numJumps = 0;
+ }
+
uint32 header_size = ptr - s_ptr;
_channel[l]._offsetStop -= header_size;
if (_channel[l]._bits == 12) {
@@ -5646,7 +5651,6 @@ void IMuseDigital::startSound(int sound) {
}
}
}
- _channel[l]._mixerTrack = -1;
_channel[l]._mixerSize = (22050 / 5) * 2;
_channel[l]._mixerFlags = SoundMixer::FLAG_AUTOFREE | SoundMixer::FLAG_STEREO | SoundMixer::FLAG_REVERSE_STEREO;
if (_channel[l]._bits == 12) {
diff --git a/scumm/imuse.h b/scumm/imuse.h
index 2620276073..0740d5d075 100644
--- a/scumm/imuse.h
+++ b/scumm/imuse.h
@@ -61,7 +61,7 @@ private:
IMuseInternal *_imuse; // Pointer to the real imuse object
};
-#define MAX_DIGITAL_CHANNELS 16
+#define MAX_DIGITAL_CHANNELS 8
#define MAX_IMUSE_JUMPS 1
#define MAX_IMUSE_REGIONS 3
diff --git a/scumm/smush/scumm_renderer.cpp b/scumm/smush/scumm_renderer.cpp
index 94e0616ebd..89cc8dadb5 100644
--- a/scumm/smush/scumm_renderer.cpp
+++ b/scumm/smush/scumm_renderer.cpp
@@ -51,8 +51,8 @@ public:
bool update();
};
-ScummMixer::ScummMixer(SoundMixer * m) : _mixer(m), _nextIndex(0) {
- for(int32 i = 0; i < SoundMixer::NUM_CHANNELS; i++) {
+ScummMixer::ScummMixer(SoundMixer * m) : _mixer(m), _nextIndex(_mixer->_beginSlots) {
+ for(int32 i = _mixer->_beginSlots; i < SoundMixer::NUM_CHANNELS; i++) {
_channels[i].id = -1;
_channels[i].chan = 0;
_channels[i].first = true;
@@ -69,7 +69,7 @@ bool ScummMixer::init() {
_Channel * ScummMixer::findChannel(int32 track) {
debug(9, "scumm_mixer::findChannel(%d)", track);
- for(int32 i = 0; i < SoundMixer::NUM_CHANNELS; i++) {
+ for(int32 i = _mixer->_beginSlots; i < SoundMixer::NUM_CHANNELS; i++) {
if(_channels[i].id == track)
return _channels[i].chan;
}
@@ -82,11 +82,11 @@ bool ScummMixer::addChannel(_Channel * c) {
debug(9, "ScummMixer::addChannel(%d)", track);
- for(i = 0; i < SoundMixer::NUM_CHANNELS; i++) {
+ for(i = _mixer->_beginSlots; i < SoundMixer::NUM_CHANNELS; i++) {
if(_channels[i].id == track)
warning("mixer::addChannel(%d) : channel already exist !", track);
}
- if(_nextIndex >= SoundMixer::NUM_CHANNELS) _nextIndex = 0;
+ if(_nextIndex >= SoundMixer::NUM_CHANNELS) _nextIndex = _mixer->_beginSlots;
for(i = _nextIndex; i < SoundMixer::NUM_CHANNELS; i++) {
if(_channels[i].chan == 0 || _channels[i].id == -1) {
@@ -98,7 +98,7 @@ bool ScummMixer::addChannel(_Channel * c) {
}
}
- for(i = 0; i < _nextIndex; i++) {
+ for(i = _mixer->_beginSlots; i < _nextIndex; i++) {
if(_channels[i].chan == 0 || _channels[i].id == -1) {
_channels[i].chan = c;
_channels[i].id = track;
@@ -110,7 +110,7 @@ bool ScummMixer::addChannel(_Channel * c) {
fprintf(stderr, "_nextIndex == %d\n", _nextIndex);
- for(i = 0; i < SoundMixer::NUM_CHANNELS; i++) {
+ for(i = _mixer->_beginSlots; i < SoundMixer::NUM_CHANNELS; i++) {
fprintf(stderr, "channel %d : %p(%ld, %d) %d %d\n", i, _channels[i].chan,
_channels[i].chan ? _channels[i].chan->getTrackIdentifier() : -1,
_channels[i].chan ? _channels[i].chan->isTerminated() : 1,
@@ -123,7 +123,7 @@ bool ScummMixer::addChannel(_Channel * c) {
bool ScummMixer::handleFrame() {
debug(9, "ScummMixer::handleFrame()");
- for(int i = 0; i < SoundMixer::NUM_CHANNELS; i++) {
+ for(int i = _mixer->_beginSlots; i < SoundMixer::NUM_CHANNELS; i++) {
if(_channels[i].id != -1) {
debug(9, "updating channel %d (%p)", _channels[i].id, _channels[i].chan);
if(_channels[i].chan->isTerminated()) {
@@ -181,7 +181,7 @@ bool ScummMixer::handleFrame() {
bool ScummMixer::stop() {
debug(9, "ScummMixer::stop()");
- for(int i = 0; i < SoundMixer::NUM_CHANNELS; i++) {
+ for(int i = _mixer->_beginSlots; i < SoundMixer::NUM_CHANNELS; i++) {
if(_channels[i].id != -1) {
delete _channels[i].chan;
_channels[i].id = -1;
diff --git a/scumm/sound.cpp b/scumm/sound.cpp
index 00204c8b3a..2b790799d4 100644
--- a/scumm/sound.cpp
+++ b/scumm/sound.cpp
@@ -943,7 +943,7 @@ void Sound::bundleMusicHandler(Scumm * scumm) {
if (_musicBundleToBeRemoved == true) {
_scumm->_timer->releaseProcedure(&music_handler);
_nameBundleMusic = NULL;
- _scumm->_mixer->stopChannel(_bundleMusicTrack);
+ _scumm->_mixer->stop(_bundleMusicTrack);
_bundleMusicTrack = -1;
if (_musicBundleBufFinal) {
free(_musicBundleBufFinal);
@@ -1033,8 +1033,8 @@ void Sound::bundleMusicHandler(Scumm * scumm) {
uint32 final_size = decode12BitsSample(ptr, &buffer, size);
if (_bundleMusicTrack == -1) {
- _bundleMusicTrack = _scumm->_mixer->playStream(NULL, -1, buffer, final_size, rate,
- SoundMixer::FLAG_AUTOFREE | SoundMixer::FLAG_16BITS | SoundMixer::FLAG_STEREO, -1);
+ _bundleMusicTrack = _scumm->_mixer->playStream(NULL, _scumm->_mixer->_beginSlots - 1, buffer, final_size, rate,
+ SoundMixer::FLAG_AUTOFREE | SoundMixer::FLAG_16BITS | SoundMixer::FLAG_STEREO, -1, 800000);
} else {
_scumm->_mixer->append(_bundleMusicTrack, buffer, final_size, rate,
SoundMixer::FLAG_AUTOFREE | SoundMixer::FLAG_16BITS | SoundMixer::FLAG_STEREO);
diff --git a/sound/mixer.cpp b/sound/mixer.cpp
index e13f6c601b..7edca2a86c 100644
--- a/sound/mixer.cpp
+++ b/sound/mixer.cpp
@@ -27,6 +27,7 @@
SoundMixer::SoundMixer() {
_volumeTable = (int16 *)calloc(256 * sizeof(int16), 1);
+ _beginSlots = 0;
}
SoundMixer::~SoundMixer() {
@@ -67,7 +68,7 @@ int SoundMixer::append(int index, void * sound, uint32 size, uint rate, byte fla
int SoundMixer::insertAt(PlayingSoundHandle * handle, int index, Channel * chan) {
if(index == -1) {
- for (int i = 0; i != NUM_CHANNELS; i++)
+ for (int i = _beginSlots; i != NUM_CHANNELS; i++)
if (_channels[i] == NULL) { index = i; break; }
if(index == -1) {
warning("SoundMixer::out of mixer slots");
@@ -85,7 +86,7 @@ int SoundMixer::insertAt(PlayingSoundHandle * handle, int index, Channel * chan)
}
int SoundMixer::playRaw(PlayingSoundHandle * handle, void * sound, uint32 size, uint rate, byte flags) {
- for (int i = 0; i != NUM_CHANNELS; i++) {
+ for (int i = _beginSlots; i != NUM_CHANNELS; i++) {
if (_channels[i] == NULL) {
return insertAt(handle, i, new ChannelRaw(this, sound, size, rate, flags, -1));
}
@@ -96,7 +97,7 @@ int SoundMixer::playRaw(PlayingSoundHandle * handle, void * sound, uint32 size,
}
int SoundMixer::playRaw(PlayingSoundHandle * handle, void * sound, uint32 size, uint rate, byte flags, int id) {
- for (int i = 0; i != NUM_CHANNELS; i++) {
+ for (int i = _beginSlots; i != NUM_CHANNELS; i++) {
if (_channels[i] == NULL) {
return insertAt(handle, i, new ChannelRaw(this, sound, size, rate, flags, id));
}
@@ -107,24 +108,21 @@ int SoundMixer::playRaw(PlayingSoundHandle * handle, void * sound, uint32 size,
}
int SoundMixer::playStream(PlayingSoundHandle * handle, int idx, void * sound, uint32 size,
- uint rate, byte flags, int32 timeout) {
- return insertAt(handle, idx, new ChannelStream(this, sound, size, rate, flags, timeout));
+ uint rate, byte flags, int32 timeout, int32 buffer_size) {
+ return insertAt(handle, idx, new ChannelStream(this, sound, size, rate, flags, timeout, buffer_size));
}
-void SoundMixer::stopChannel(int index) {
- if ((index < 0) || (index >= NUM_CHANNELS)) {
- warning("soundMixer::stopChannel has invalid index %d", index);
+void SoundMixer::beginSlots(int index) {
+ if ((index < 0) && (index >= NUM_CHANNELS)) {
+ warning("soundMixer::beginSlots has invalid index %d", index);
return;
}
-
- if (_channels[index] != NULL) {
- _channels[index]->_toBeDestroyed = true;
- }
+ _beginSlots = index;
}
#ifdef COMPRESSED_SOUND_FILE
int SoundMixer::playMP3(PlayingSoundHandle * handle, void *sound, uint32 size, byte flags) {
- for (int i = 0; i != NUM_CHANNELS; i++) {
+ for (int i = _beginSlots; i != NUM_CHANNELS; i++) {
if (_channels[i] == NULL) {
return insertAt(handle, i, new ChannelMP3(this, sound, size, flags));
}
@@ -135,7 +133,7 @@ int SoundMixer::playMP3(PlayingSoundHandle * handle, void *sound, uint32 size, b
}
int SoundMixer::playMP3CDTrack(PlayingSoundHandle * handle, File * file, mad_timer_t duration) {
/* Stop the previously playing CD track (if any) */
- for (int i = 0; i != NUM_CHANNELS; i++) {
+ for (int i = _beginSlots; i != NUM_CHANNELS; i++) {
if (_channels[i] == NULL) {
return insertAt(handle, i, new ChannelMP3CDMusic(this, file, duration));
}
@@ -201,6 +199,11 @@ void SoundMixer::stop(PlayingSoundHandle psh) {
}
void SoundMixer::stop(int index) {
+ if ((index < 0) || (index >= NUM_CHANNELS)) {
+ warning("soundMixer::stop has invalid index %d", index);
+ return;
+ }
+
if (_channels[index])
_channels[index]->destroy();
}
@@ -210,7 +213,7 @@ void SoundMixer::pause(bool paused) {
}
bool SoundMixer::hasActiveChannel() {
- for (int i = 0; i != NUM_CHANNELS; i++)
+ for (int i = _beginSlots; i != NUM_CHANNELS; i++)
if (_channels[i])
return true;
return false;
@@ -624,10 +627,10 @@ void SoundMixer::ChannelRaw::realDestroy() {
}
SoundMixer::ChannelStream::ChannelStream(SoundMixer * mixer, void * sound, uint32 size, uint rate,
- byte flags, int32 timeout) {
+ byte flags, int32 timeout, int32 buffer_size) {
_mixer = mixer;
_flags = flags;
- _bufferSize = 2000000;
+ _bufferSize = buffer_size;
_ptr = (byte *)malloc(_bufferSize);
memcpy(_ptr, sound, size);
_endOfData = _ptr + size;
diff --git a/sound/mixer.h b/sound/mixer.h
index e5d7b4aeaa..491ee5fccb 100644
--- a/sound/mixer.h
+++ b/sound/mixer.h
@@ -85,7 +85,7 @@ private:
byte _flags;
public:
- ChannelStream(SoundMixer * mixer, void * sound, uint32 size, uint rate, byte flags, int32 timout);
+ ChannelStream(SoundMixer * mixer, void * sound, uint32 size, uint rate, byte flags, int32 timout, int32 buffer_size);
void append(void * sound, uint32 size);
void mix(int16 * data, uint len);
@@ -163,12 +163,15 @@ public:
Channel * _channels[NUM_CHANNELS];
PlayingSoundHandle * _handles[NUM_CHANNELS];
+ int _beginSlots;
+
SoundMixer();
~SoundMixer();
int insertAt(PlayingSoundHandle * handle, int index, Channel * chan);
void append(void * data, uint32 len);
void unInsert(Channel * chan);
+ void beginSlots(int index);
/* start playing a raw sound */
enum {
@@ -183,8 +186,7 @@ public:
int playRaw(PlayingSoundHandle * handle, void * sound, uint32 size, uint rate, byte flags);
int playRaw(PlayingSoundHandle * handle, void * sound, uint32 size, uint rate, byte flags, int id);
int playStream(PlayingSoundHandle * handle, int index, void * sound, uint32 size, uint rate,
- byte flags, int32 timeout = 3);
- void stopChannel(int index);
+ byte flags, int32 timeout = 3, int32 buffer_size = 2000000);
#ifdef COMPRESSED_SOUND_FILE
int playMP3(PlayingSoundHandle * handle, void * sound, uint32 size, byte flags);
int playMP3CDTrack(PlayingSoundHandle * handle, File * file, mad_timer_t duration);