Finish support of compressed dubbing

Now even the length of a compressed stream is measured precisely and
the dubbing sounds exactly like the original.

svn-id: r50618
This commit is contained in:
Robert Špalek 2010-07-03 05:05:28 +00:00
parent 8d26e7c2d2
commit 0fd3558986
4 changed files with 20 additions and 17 deletions

View File

@ -166,10 +166,10 @@ void Animation::drawFrame(Surface *surface) {
const SoundSample *sample = _samples[_currentFrame];
if (_hasChangedFrame && sample) {
uint duration = _vm->_sound->playSound(sample, Audio::Mixer::kMaxChannelVolume, false);
debugC(3, kDraciSoundDebugLevel,
"Playing sample on animation %d, frame %d: %d+%d at %dHz",
_id, _currentFrame, sample->_offset, sample->_length, sample->_frequency);
_vm->_sound->playSound(sample, Audio::Mixer::kMaxChannelVolume, false);
"Playing sample on animation %d, frame %d: %d+%d at %dHz: %dms",
_id, _currentFrame, sample->_offset, sample->_length, sample->_frequency, duration);
}
_hasChangedFrame = false;
}

View File

@ -729,10 +729,10 @@ void Script::talk(const Common::Array<int> &params) {
// Speak the dubbing if possible
uint dubbingDuration = 0;
if (sample) {
dubbingDuration = (uint) (1000.0 * sample->_length / sample->_frequency + 500.0);
dubbingDuration = _vm->_sound->playVoice(sample);
debugC(3, kDraciSoundDebugLevel, "Playing sentence %d: %d+%d with duration %dms",
sentenceID, sample->_offset, sample->_length, dubbingDuration);
_vm->_sound->playVoice(sample);
dubbingDuration += 500;
}
// Record time

View File

@ -285,11 +285,11 @@ SndHandle *Sound::getHandle() {
return NULL; // for compilers that don't support NORETURN
}
void Sound::playSoundBuffer(Audio::SoundHandle *handle, const SoundSample &buffer, int volume,
uint Sound::playSoundBuffer(Audio::SoundHandle *handle, const SoundSample &buffer, int volume,
sndHandleType handleType, bool loop) {
if (!buffer._stream && !buffer._data) {
warning("Empty stream");
return;
return 0;
}
// Create a new SeekableReadStream which will be automatically disposed
// after the sample stops playing. Do not dispose the original
@ -335,22 +335,24 @@ void Sound::playSoundBuffer(Audio::SoundHandle *handle, const SoundSample &buffe
default:
error("Unsupported compression format %d", static_cast<int> (buffer._format));
delete stream;
return;
return 0;
}
const uint length = reader->getLength().msecs();
const Audio::Mixer::SoundType soundType = (handleType == kVoiceHandle) ?
Audio::Mixer::kSpeechSoundType : Audio::Mixer::kSFXSoundType;
Audio::AudioStream *audio_stream = Audio::makeLoopingAudioStream(reader, loop ? 0 : 1);
_mixer->playStream(soundType, handle, audio_stream, -1, volume);
return length;
}
void Sound::playSound(const SoundSample *buffer, int volume, bool loop) {
uint Sound::playSound(const SoundSample *buffer, int volume, bool loop) {
if (!buffer || _muteSound)
return;
return 0;
SndHandle *handle = getHandle();
handle->type = kEffectHandle;
playSoundBuffer(&handle->handle, *buffer, 2 * volume, handle->type, loop);
return playSoundBuffer(&handle->handle, *buffer, 2 * volume, handle->type, loop);
}
void Sound::pauseSound() {
@ -374,13 +376,13 @@ void Sound::stopSound() {
}
}
void Sound::playVoice(const SoundSample *buffer) {
uint Sound::playVoice(const SoundSample *buffer) {
if (!buffer || _muteVoice)
return;
return 0;
SndHandle *handle = getHandle();
handle->type = kVoiceHandle;
playSoundBuffer(&handle->handle, *buffer, Audio::Mixer::kMaxChannelVolume, handle->type, false);
return playSoundBuffer(&handle->handle, *buffer, Audio::Mixer::kMaxChannelVolume, handle->type, false);
}
void Sound::pauseVoice() {

View File

@ -189,13 +189,13 @@ public:
Sound(Audio::Mixer *mixer);
~Sound() {}
void playSound(const SoundSample *buffer, int volume, bool loop);
uint playSound(const SoundSample *buffer, int volume, bool loop);
void pauseSound();
void resumeSound();
void stopSound();
bool isMutedSound() const { return _muteSound; }
void playVoice(const SoundSample *buffer);
uint playVoice(const SoundSample *buffer);
void pauseVoice();
void resumeVoice();
void stopVoice();
@ -209,7 +209,8 @@ public:
int talkSpeed() const { return _talkSpeed; }
private:
void playSoundBuffer(Audio::SoundHandle *handle, const SoundSample &buffer, int volume,
// Returns the length of the sound sample in miliseconds.
uint playSoundBuffer(Audio::SoundHandle *handle, const SoundSample &buffer, int volume,
sndHandleType handleType, bool loop);
SndHandle *getHandle();