[Scummvm-devel] Questions about sound streaming
N. E. C.
beholdnec at gmail.com
Thu Nov 6 23:35:47 CET 2014
Hi,
I am implementing a new engine (still in the experimental stage at
this point), and I'm having trouble with sound.
The engine contains a movie player. After decoding and displaying the
final video frame, I want the player to enter an Ending state where it
waits for the audio to finish, and then enter the Stopped state when
the audio is done. However, I there are some things I'm not sure
about.
Here is an overview of my code.
When the movie starts, I make a QueuingAudioStream and tell the mixer
to play it. There are no queued audio buffers yet.
_audioStream = Audio::makeQueuingAudioStream(22050, false);
_mixer->playStream(Audio::Mixer::kPlainSoundType, &_audioHandle, _audioStream);
QUESTION 1: Would it be better to queue sound BEFORE calling playStream?
QUESTION 2: The sound is premixed, so it is impossible to control the
music, speech and SFX volumes separately. Is it appropriate to use
kPlainSoundType in this situation?
QUESTION 3: The volume controls in the global menu seem to have no
effect. Am I doing something wrong?
When a sound packet is found, I copy the data into a buffer allocated
with malloc, and tell the audio stream to queue it.
// _buf was allocated with malloc and loaded with 8-bit unsigned PCM
_audioStream->queueBuffer(_buf, _totalSize, DisposeAfterUse::YES,
Audio::FLAG_UNSIGNED);
_buf = nullptr; // Audio buffer will be freed by the audio system.
After the final sound packet is queued, I tell the stream to finish.
_audioStream->finish();
_audioStream = nullptr; // Discard.
QUESTION 4: Will the mixer free the audio stream?
When the player is in the Ending state, it checks whether the audio
handle is active to know when to enter the Stopped state.
if (!_mixer->isSoundHandleActive(_audioHandle)) {
_audioHandle = Audio::SoundHandle(); // Discard
_state = kStopped;
}
QUESTION 5: Is this the correct way to tell whether a sound stream has
finished playing?
Thanks for the help!
P.S. I was about to ask why my player was hanging in the Ending state,
but I think found the problem while typing this email. Fun, huh?
More information about the Scummvm-devel
mailing list