reverted parts of commits #29447 and #29446 (caused regressions in ADL music playback) and properly (I hope) fixed the sound issues described in tracker item #1763053.

svn-id: r29766
This commit is contained in:
Gregory Montoir 2007-12-08 15:24:42 +00:00
parent 9f43e2cf8a
commit 6ef7e37488
3 changed files with 28 additions and 29 deletions

View File

@ -1434,8 +1434,6 @@ void o1_freePartRange() {
assert(startIdx + numIdx <= NUM_MAX_ANIMDATA);
g_sound->stopMusic();
debugC(5, kCineDebugScript, "Line: %d: freePartRange(%d,%d)", _currentLine, startIdx, numIdx);
freeAnimDataRange(startIdx, numIdx);
}

View File

@ -774,6 +774,10 @@ PaulaSound::PaulaSound(Audio::Mixer *mixer, CineEngine *vm)
}
PaulaSound::~PaulaSound() {
for (int i = 0; i < NUM_CHANNELS; ++i) {
stopSound(i);
}
stopMusic();
}
void PaulaSound::loadMusic(const char *name) {
@ -798,17 +802,12 @@ void PaulaSound::loadMusic(const char *name) {
void PaulaSound::playMusic() {
_mixer->stopHandle(_moduleHandle);
if (_moduleStream) {
_mixer->playInputStream(Audio::Mixer::kMusicSoundType, &_moduleHandle, _moduleStream, -1, 255, 0, false);
_mixer->playInputStream(Audio::Mixer::kMusicSoundType, &_moduleHandle, _moduleStream);
}
}
void PaulaSound::stopMusic() {
_mixer->stopHandle(_moduleHandle);
_mixer->pauseAll(true);
for(int i = 0;i < NUM_CHANNELS;i++)
_soundChannelsTable[i].data = 0;
}
void PaulaSound::fadeOutMusic() {
@ -817,19 +816,28 @@ void PaulaSound::fadeOutMusic() {
}
void PaulaSound::playSound(int channel, int frequency, const uint8 *data, int size, int volumeStep, int stepCount, int volume, int repeat) {
stopSound(channel);
SoundChannel *ch = &_soundChannelsTable[channel];
ch->frequency = frequency;
ch->data = data;
ch->size = size;
ch->volumeStep = volumeStep;
ch->stepCount = stepCount;
ch->step = stepCount;
ch->repeat = repeat != 0;
ch->volume = volume;
size = MIN<int>(size - SPL_HDR_SIZE, READ_BE_UINT16(data + 4));
if (size > 0) {
ch->data = (byte *)malloc(size);
if (ch->data) {
memcpy(ch->data, data + SPL_HDR_SIZE, size);
ch->frequency = frequency;
ch->size = size;
ch->volumeStep = volumeStep;
ch->stepCount = stepCount;
ch->step = stepCount;
ch->repeat = repeat != 0;
ch->volume = volume;
}
}
}
void PaulaSound::stopSound(int channel) {
_mixer->stopHandle(_channelsTable[channel]);
free(_soundChannelsTable[channel].data);
_soundChannelsTable[channel].data = 0;
}
void PaulaSound::update() {
@ -844,23 +852,16 @@ void PaulaSound::update() {
ch->step = ch->stepCount;
ch->volume = CLIP(ch->volume + ch->volumeStep, 0, 63);
playSoundChannel(i, ch->frequency, ch->data, ch->size, ch->volume);
if (!ch->repeat) {
ch->data = 0;
}
ch->data = 0;
}
}
}
void PaulaSound::playSoundChannel(int channel, int frequency, const uint8 *data, int size, int volume) {
stopSound(channel);
void PaulaSound::playSoundChannel(int channel, int frequency, uint8 *data, int size, int volume) {
assert(frequency > 0);
frequency = PAULA_FREQ / frequency;
size = MIN<int>(size - SPL_HDR_SIZE, READ_BE_UINT16(data + 4));
data += SPL_HDR_SIZE;
if (size > 0) {
_mixer->playRaw(Audio::Mixer::kSFXSoundType, &_channelsTable[channel], const_cast<byte *>(data), size, frequency, 0);
_mixer->setChannelVolume(_channelsTable[channel], volume * Audio::Mixer::kMaxChannelVolume / 63);
}
_mixer->playRaw(Audio::Mixer::kSFXSoundType, &_channelsTable[channel], data, size, frequency, 0);
_mixer->setChannelVolume(_channelsTable[channel], volume * Audio::Mixer::kMaxChannelVolume / 63);
}
} // End of namespace Cine

View File

@ -104,7 +104,7 @@ public:
struct SoundChannel {
int frequency;
const uint8 *data;
uint8 *data;
int size;
int volumeStep;
int stepCount;
@ -115,7 +115,7 @@ public:
protected:
void playSoundChannel(int channel, int frequency, const uint8 *data, int size, int volume);
void playSoundChannel(int channel, int frequency, uint8 *data, int size, int volume);
Audio::SoundHandle _channelsTable[NUM_CHANNELS];
SoundChannel _soundChannelsTable[NUM_CHANNELS];