aboutsummaryrefslogtreecommitdiff
path: root/engines/kyra/sound.cpp
diff options
context:
space:
mode:
authorFlorian Kagerer2009-05-23 23:33:31 +0000
committerFlorian Kagerer2009-05-23 23:33:31 +0000
commit5a4b3c54414d7415af6a0838ba558177586a4427 (patch)
tree325e9e8d48c0900eff926b7b844dc4914d0dd6de /engines/kyra/sound.cpp
parenta19c23ab7a3f0daaf3e047d96865d78c92f4841c (diff)
downloadscummvm-rg350-5a4b3c54414d7415af6a0838ba558177586a4427.tar.gz
scummvm-rg350-5a4b3c54414d7415af6a0838ba558177586a4427.tar.bz2
scummvm-rg350-5a4b3c54414d7415af6a0838ba558177586a4427.zip
KYRA/LOL: restructured voice playing code so that audio compression can be supported
svn-id: r40839
Diffstat (limited to 'engines/kyra/sound.cpp')
-rw-r--r--engines/kyra/sound.cpp85
1 files changed, 29 insertions, 56 deletions
diff --git a/engines/kyra/sound.cpp b/engines/kyra/sound.cpp
index 5b32b69e19..975cff740a 100644
--- a/engines/kyra/sound.cpp
+++ b/engines/kyra/sound.cpp
@@ -66,17 +66,24 @@ bool Sound::voiceFileIsPresent(const char *file) {
return false;
}
-int32 Sound::voicePlay(const char *file, uint8 volume, bool isSfx) {
- char filenamebuffer[25];
+int32 Sound::voicePlay(const char *file, uint8 volume, bool isSfx, bool appendSuffix) {
+ int32 ptime = 0;
+ Audio::AudioStream *audioStream = getVoiceStream(file, &ptime, appendSuffix);
- int h = 0;
- while (_mixer->isSoundHandleActive(_soundChannels[h].channelHandle) && h < kNumChannelHandles)
- h++;
- if (h >= kNumChannelHandles)
+ if (!audioStream) {
+ warning("Couldn't load sound file '%s'", file);
return 0;
+ }
- Audio::AudioStream *audioStream = 0;
+ playVoiceStream(audioStream, file, volume, isSfx) ;
+ return ptime;
+}
+
+Audio::AudioStream *Sound::getVoiceStream(const char *file, int32 *totalPlayingTime, bool appendSuffix) {
+ char filenamebuffer[25];
+
+ Audio::AudioStream *audioStream = 0;
for (int i = 0; _supportedCodecs[i].fileext; ++i) {
strcpy(filenamebuffer, file);
strcat(filenamebuffer, _supportedCodecs[i].fileext);
@@ -88,9 +95,12 @@ int32 Sound::voicePlay(const char *file, uint8 volume, bool isSfx) {
break;
}
+ int32 vocStreamPlayTime = 0;
+
if (!audioStream) {
strcpy(filenamebuffer, file);
- strcat(filenamebuffer, ".VOC");
+ if (appendSuffix)
+ strcat(filenamebuffer, ".VOC");
uint32 fileSize = 0;
byte *fileData = _vm->resource()->fileData(filenamebuffer, &fileSize);
@@ -100,62 +110,25 @@ int32 Sound::voicePlay(const char *file, uint8 volume, bool isSfx) {
Common::MemoryReadStream vocStream(fileData, fileSize);
audioStream = Audio::makeVOCStream(vocStream, Audio::Mixer::FLAG_UNSIGNED);
- delete[] fileData;
- fileSize = 0;
- }
-
- if (!audioStream) {
- warning("Couldn't load sound file '%s'", file);
- return 0;
+ if (audioStream)
+ vocStreamPlayTime = vocStream.size() * 1000 / audioStream->getRate();
+ } else {
+ vocStreamPlayTime = audioStream->getTotalPlayTime();
}
-
- _soundChannels[h].file = file;
- _mixer->playInputStream(isSfx ? Audio::Mixer::kSFXSoundType : Audio::Mixer::kSpeechSoundType, &_soundChannels[h].channelHandle, audioStream, -1, volume);
-
- return audioStream->getTotalPlayTime();
+
+ *totalPlayingTime = vocStreamPlayTime;
+ return audioStream;
}
-uint32 Sound::voicePlayFromList(Common::List<const char*> fileList) {
+void Sound::playVoiceStream(Audio::AudioStream *stream, const char *handleName, uint8 volume, bool isSfx) {
int h = 0;
while (_mixer->isSoundHandleActive(_soundChannels[h].channelHandle) && h < kNumChannelHandles)
h++;
if (h >= kNumChannelHandles)
- return 0;
-
- Audio::AppendableAudioStream *out = Audio::makeAppendableAudioStream(22050, Audio::Mixer::FLAG_AUTOFREE | Audio::Mixer::FLAG_UNSIGNED);
- uint32 totalPlayTime = 0;
-
- for (Common::List<const char*>::iterator i = fileList.begin(); i != fileList.end(); i++) {
- Common::SeekableReadStream *file = _vm->resource()->createReadStream(*i);
-
- if (!file) {
- warning("Couldn't load voice file: %s", *i);
- continue;
- }
-
- int size, rate;
- uint8 *data = Audio::loadVOCFromStream(*file, size, rate);
- delete file;
-
- // FIXME/HACK: While loadVOCStream uses malloc / realloc,
- // AppendableAudioStream uses delete[] to free the passed buffer.
- // As a consequence we just 'move' the data to a buffer allocated
- // via new[].
- uint8 *vocBuffer = new uint8[size];
- assert(vocBuffer);
- memcpy(vocBuffer, data, size);
- free(data);
-
- out->queueBuffer(vocBuffer, size);
- totalPlayTime += size;
- }
-
- totalPlayTime = (totalPlayTime * 1000) / 22050;
- out->finish();
+ return;
- _soundChannels[h].file = *fileList.begin();
- _mixer->playInputStream(Audio::Mixer::kSpeechSoundType, &_soundChannels[h].channelHandle, out);
- return totalPlayTime;
+ _soundChannels[h].file = handleName;
+ _mixer->playInputStream(isSfx ? Audio::Mixer::kSFXSoundType : Audio::Mixer::kSpeechSoundType, &_soundChannels[h].channelHandle, stream, -1, volume);
}
void Sound::voiceStop(const char *file) {