HDB: Do not allocate sound handles dynamically

This commit is contained in:
Eugene Sandulenko 2019-08-21 21:06:55 +02:00
parent c3032f7742
commit 73b6724b92
2 changed files with 29 additions and 35 deletions

View File

@ -1469,13 +1469,13 @@ void Sound::setMusicVolume(int volume) {
if (_song1.fadingIn)
_song1.fadeInVol = volume;
if (!_song1.fadingOut)
g_hdb->_mixer->setChannelVolume(*_song1.handle, volume);
g_hdb->_mixer->setChannelVolume(_song1.handle, volume);
}
if (_song2.playing) {
if (_song2.fadingIn)
_song1.fadeInVol = volume;
if (!_song2.fadingOut)
g_hdb->_mixer->setChannelVolume(*_song2.handle, volume);
g_hdb->_mixer->setChannelVolume(_song2.handle, volume);
}
}
@ -1629,7 +1629,7 @@ void Sound::playVoice(int index, int actor) {
// is voice channel already active? if so, shut 'er down (automagically called StopVoice via callback)
if (_voices[actor].active)
g_hdb->_mixer->stopHandle(*_voices[actor].handle);
g_hdb->_mixer->stopHandle(_voices[actor].handle);
// make sure we aren't playing a line more than once this time (only on CHANNEL 0)
if (!actor && _voicePlayed[index - FIRST_VOICE])
@ -1652,11 +1652,11 @@ void Sound::playVoice(int index, int actor) {
return;
}
g_hdb->_mixer->setChannelVolume(*_voices[actor].handle, _sfxVolume);
g_hdb->_mixer->setChannelVolume(_voices[actor].handle, _sfxVolume);
g_hdb->_mixer->playStream(
Audio::Mixer::kSpeechSoundType,
_voices[actor].handle,
&_voices[actor].handle,
audioStream,
-1,
Audio::Mixer::kMaxChannelVolume,
@ -1674,11 +1674,11 @@ void Sound::playVoice(int index, int actor) {
return;
}
g_hdb->_mixer->setChannelVolume(*_voices[actor].handle, _sfxVolume);
g_hdb->_mixer->setChannelVolume(_voices[actor].handle, _sfxVolume);
g_hdb->_mixer->playStream(
Audio::Mixer::kSpeechSoundType,
_voices[actor].handle,
&_voices[actor].handle,
audioStream,
-1,
Audio::Mixer::kMaxChannelVolume,
@ -1744,11 +1744,11 @@ void Sound::stopChannel(int channel) {
void Sound::stopMusic() {
if (_song1.playing) {
_song1.playing = false;
g_hdb->_mixer->stopHandle(*_song1.handle);
g_hdb->_mixer->stopHandle(_song1.handle);
}
if (_song2.playing) {
_song2.playing = false;
g_hdb->_mixer->stopHandle(*_song2.handle);
g_hdb->_mixer->stopHandle(_song2.handle);
}
}
@ -1797,19 +1797,19 @@ void Sound::beginMusic(SoundType song, bool fadeIn, int ramp) {
Audio::SeekableAudioStream *audioStream = Audio::makeMP3Stream(stream, DisposeAfterUse::YES);
Audio::AudioStream *loopingStream = new Audio::LoopingAudioStream(audioStream, 0, DisposeAfterUse::YES);
g_hdb->_mixer->setChannelVolume(*_song1.handle, _musicVolume);
g_hdb->_mixer->setChannelVolume(_song1.handle, _musicVolume);
// do we need to fade-in this song?
if (fadeIn) {
_song1.fadeInRamp = ramp;
_song1.fadingIn = true;
_song1.fadeInVol = 0;
g_hdb->_mixer->setChannelVolume(*_song1.handle, 0);
g_hdb->_mixer->setChannelVolume(_song1.handle, 0);
}
g_hdb->_mixer->playStream(
Audio::Mixer::kMusicSoundType,
_song1.handle,
&_song1.handle,
loopingStream,
-1,
Audio::Mixer::kMaxChannelVolume,
@ -1825,19 +1825,19 @@ void Sound::beginMusic(SoundType song, bool fadeIn, int ramp) {
Audio::SeekableAudioStream *audioStream = Audio::makeVorbisStream(stream, DisposeAfterUse::YES);
Audio::AudioStream *loopingStream = new Audio::LoopingAudioStream(audioStream, 0, DisposeAfterUse::YES);
g_hdb->_mixer->setChannelVolume(*_song1.handle, _musicVolume);
g_hdb->_mixer->setChannelVolume(_song1.handle, _musicVolume);
// do we need to fade-in this song?
if (fadeIn) {
_song1.fadeInRamp = ramp;
_song1.fadingIn = true;
_song1.fadeInVol = 0;
g_hdb->_mixer->setChannelVolume(*_song1.handle, 0);
g_hdb->_mixer->setChannelVolume(_song1.handle, 0);
}
g_hdb->_mixer->playStream(
Audio::Mixer::kMusicSoundType,
_song1.handle,
&_song1.handle,
loopingStream,
-1,
Audio::Mixer::kMaxChannelVolume,
@ -1869,19 +1869,19 @@ void Sound::beginMusic(SoundType song, bool fadeIn, int ramp) {
Audio::SeekableAudioStream *audioStream = Audio::makeMP3Stream(stream, DisposeAfterUse::YES);
Audio::AudioStream *loopingStream = new Audio::LoopingAudioStream(audioStream, 0, DisposeAfterUse::YES);
g_hdb->_mixer->setChannelVolume(*_song2.handle, _musicVolume);
g_hdb->_mixer->setChannelVolume(_song2.handle, _musicVolume);
// do we need to fade-in this song?
if (fadeIn) {
_song2.fadeInRamp = ramp;
_song2.fadingIn = true;
_song2.fadeInVol = 0;
g_hdb->_mixer->setChannelVolume(*_song2.handle, 0);
g_hdb->_mixer->setChannelVolume(_song2.handle, 0);
}
g_hdb->_mixer->playStream(
Audio::Mixer::kMusicSoundType,
_song2.handle,
&_song2.handle,
loopingStream,
-1,
Audio::Mixer::kMaxChannelVolume,
@ -1897,19 +1897,19 @@ void Sound::beginMusic(SoundType song, bool fadeIn, int ramp) {
Audio::SeekableAudioStream *audioStream = Audio::makeVorbisStream(stream, DisposeAfterUse::YES);
Audio::AudioStream *loopingStream = new Audio::LoopingAudioStream(audioStream, 0, DisposeAfterUse::YES);
g_hdb->_mixer->setChannelVolume(*_song2.handle, _musicVolume);
g_hdb->_mixer->setChannelVolume(_song2.handle, _musicVolume);
// do we need to fade-in this song?
if (fadeIn) {
_song2.fadeInRamp = ramp;
_song2.fadingIn = true;
_song2.fadeInVol = 0;
g_hdb->_mixer->setChannelVolume(*_song2.handle, 0);
g_hdb->_mixer->setChannelVolume(_song2.handle, 0);
}
g_hdb->_mixer->playStream(
Audio::Mixer::kMusicSoundType,
_song2.handle,
&_song2.handle,
loopingStream,
-1,
Audio::Mixer::kMaxChannelVolume,
@ -1930,7 +1930,7 @@ void Sound::updateMusic() {
if (_song1.fadingOut) {
_song1.fadeOutVol = 0;
_song1.playing = false;
g_hdb->_mixer->stopHandle(*_song1.handle);
g_hdb->_mixer->stopHandle(_song1.handle);
} else if (_song1.fadingIn) {
_song1.fadeInVol = _musicVolume;
_song1.fadingIn = false;
@ -1941,7 +1941,7 @@ void Sound::updateMusic() {
if (_song2.fadingOut) {
_song2.fadeOutVol = 0;
_song2.playing = false;
g_hdb->_mixer->stopHandle(*_song2.handle);
g_hdb->_mixer->stopHandle(_song2.handle);
} else if (_song2.fadingIn) {
_song2.fadeInVol = _musicVolume;
_song2.fadingIn = false;

View File

@ -1427,12 +1427,9 @@ struct SoundLookUp {
struct Voice {
bool active;
Audio::SoundHandle *handle;
Audio::SoundHandle handle;
Voice() : active(false), handle(new Audio::SoundHandle) {}
~Voice() {
delete handle;
}
Voice() : active(false) {}
};
enum SndMem {
@ -1462,7 +1459,7 @@ struct SoundCache {
struct Song {
bool playing;
SoundType song;
Audio::SoundHandle *handle;
Audio::SoundHandle handle;
bool fadingOut;
int fadeOutVol;
@ -1472,12 +1469,9 @@ struct Song {
int fadeInVol;
int fadeInRamp;
Song() : playing(false), song(SONG_NONE), handle(new Audio::SoundHandle()),
Song() : playing(false), song(SONG_NONE),
fadingOut(false), fadeOutVol(0), fadeOutRamp(0),
fadingIn(false), fadeInVol(0), fadeInRamp(0) {}
~Song() {
delete handle;
}
};
class Sound {
@ -1515,11 +1509,11 @@ public:
void playVoice(int index, int actor);
void stopVoices() {
if (_voices[0].active) {
g_hdb->_mixer->stopHandle(*_voices[0].handle);
g_hdb->_mixer->stopHandle(_voices[0].handle);
_voices[0].active = false;
}
if (_voices[1].active) {
g_hdb->_mixer->stopHandle(*_voices[1].handle);
g_hdb->_mixer->stopHandle(_voices[1].handle);
_voices[1].active = false;
}
}