AGS: Removed "volume" param out of load clip factory functions

From upstream 903c4d7d69bf0400447b099cbd0b2818f3c1f7c7
This commit is contained in:
Paul Gilbert 2022-03-18 22:33:29 -07:00
parent 35efd2e8fd
commit a4bf82bd35
7 changed files with 79 additions and 83 deletions

View File

@ -375,40 +375,31 @@ void PlayMP3File(const char *filename) {
bool doLoop = (_GP(play).music_repeat > 0);
SOUNDCLIP *clip = nullptr;
int sound_type = 0;
if (!clip) {
clip = my_load_static_ogg(asset_name, 150, doLoop);
if (clip) {
if (clip->play()) {
AudioChans::SetChannel(useChan, clip);
_G(current_music_type) = MUS_OGG;
_GP(play).cur_music_number = 1000;
// save the filename (if it's not what we were supplied with)
if (filename != &_GP(play).playmp3file_name[0])
strcpy(_GP(play).playmp3file_name, filename);
} else {
clip->destroy();
delete clip;
clip = nullptr;
}
}
clip = my_load_ogg(asset_name, doLoop);
sound_type = MUS_OGG;
}
if (!clip) {
clip = my_load_static_mp3(asset_name, 150, doLoop);
if (clip) {
if (clip->play()) {
AudioChans::SetChannel(useChan, clip);
_G(current_music_type) = MUS_MP3;
_GP(play).cur_music_number = 1000;
// save the filename (if it's not what we were supplied with)
if (filename != &_GP(play).playmp3file_name[0])
strcpy(_GP(play).playmp3file_name, filename);
} else {
clip->destroy();
delete clip;
clip = nullptr;
}
clip = my_load_mp3(asset_name, doLoop);
sound_type = MUS_MP3;
}
if (clip) {
clip->set_volume(150);
if (clip->play()) {
AudioChans::SetChannel(useChan, clip);
_G(current_music_type) = sound_type;
_GP(play).cur_music_number = 1000;
// save the filename (if it's not what we were supplied with)
if (filename != &_GP(play).playmp3file_name[0])
snprintf(_GP(play).playmp3file_name, sizeof(_GP(play).playmp3file_name), filename);
} else {
clip->destroy();
delete clip;
clip = nullptr;
}
}
@ -517,16 +508,26 @@ static bool play_voice_clip_on_channel(const String &voice_name) {
String asset_name = voice_name;
asset_name.Append(".wav");
SOUNDCLIP *speechmp3 = my_load_wave(get_voice_over_assetpath(asset_name), _GP(play).speech_volume, 0);
SOUNDCLIP *speechmp3 = my_load_wave(get_voice_over_assetpath(asset_name), false);
if (speechmp3 == nullptr) {
asset_name.ReplaceMid(asset_name.GetLength() - 3, 3, "ogg");
speechmp3 = my_load_ogg(get_voice_over_assetpath(asset_name), _GP(play).speech_volume);
speechmp3 = my_load_ogg(get_voice_over_assetpath(asset_name), false);
}
if (speechmp3 == nullptr) {
asset_name.ReplaceMid(asset_name.GetLength() - 3, 3, "mp3");
speechmp3 = my_load_mp3(get_voice_over_assetpath(asset_name), _GP(play).speech_volume);
speechmp3 = my_load_mp3(get_voice_over_assetpath(asset_name), false);
}
if (speechmp3 != nullptr) {
speechmp3->set_volume(_GP(play).speech_volume);
if (!speechmp3->play()) {
// not assigned to a channel, so clean up manually.
speechmp3->destroy();
delete speechmp3;
speechmp3 = nullptr;
}
}
if (speechmp3 == nullptr) {
@ -534,13 +535,6 @@ static bool play_voice_clip_on_channel(const String &voice_name) {
return false;
}
if (!speechmp3->play()) {
// Could not play, so clean up manually.
speechmp3->destroy();
delete speechmp3;
speechmp3 = nullptr;
}
AudioChans::SetChannel(SCHAN_SPEECH, speechmp3);
return true;
}

View File

@ -202,14 +202,14 @@ SOUNDCLIP *load_sound_clip(ScriptAudioClip *audioClip, bool repeat) {
AssetPath asset_name = get_audio_clip_assetpath(audioClip->bundlingType, audioClip->fileName);
switch (audioClip->fileType) {
case eAudioFileOGG:
soundClip = my_load_static_ogg(asset_name, audioClip->defaultVolume, repeat);
soundClip = my_load_static_ogg(asset_name, repeat);
break;
case eAudioFileMP3:
soundClip = my_load_static_mp3(asset_name, audioClip->defaultVolume, repeat);
soundClip = my_load_static_mp3(asset_name, repeat);
break;
case eAudioFileWAV:
case eAudioFileVOC:
soundClip = my_load_wave(asset_name, audioClip->defaultVolume, repeat);
soundClip = my_load_wave(asset_name, repeat);
break;
case eAudioFileMIDI:
soundClip = my_load_midi(asset_name, repeat);

View File

@ -39,22 +39,22 @@
namespace AGS3 {
SOUNDCLIP *my_load_wave(const AssetPath &asset_name, int voll, bool loop) {
SOUNDCLIP *my_load_wave(const AssetPath &asset_name, bool loop) {
Common::SeekableReadStream *data = _GP(AssetMgr)->OpenAssetStream(asset_name.Name, asset_name.Filter);
if (data) {
Audio::AudioStream *audioStream = Audio::makeWAVStream(data, DisposeAfterUse::YES);
return new SoundClipWave<MUS_WAVE>(audioStream, voll, loop);
return new SoundClipWave<MUS_WAVE>(audioStream, loop);
} else {
return nullptr;
}
}
SOUNDCLIP *my_load_static_mp3(const AssetPath &asset_name, int voll, bool loop) {
SOUNDCLIP *my_load_static_mp3(const AssetPath &asset_name, bool loop) {
#ifdef USE_MAD
Common::SeekableReadStream *data = _GP(AssetMgr)->OpenAssetStream(asset_name.Name, asset_name.Filter);
if (data) {
Audio::AudioStream *audioStream = Audio::makeMP3Stream(data, DisposeAfterUse::YES);
return new SoundClipWave<MUS_MP3>(audioStream, voll, false);
return new SoundClipWave<MUS_MP3>(audioStream, false);
} else {
return nullptr;
}
@ -63,16 +63,16 @@ SOUNDCLIP *my_load_static_mp3(const AssetPath &asset_name, int voll, bool loop)
#endif
}
SOUNDCLIP *my_load_mp3(const AssetPath &asset_name, int voll) {
return my_load_static_mp3(asset_name, voll, false);
SOUNDCLIP *my_load_mp3(const AssetPath &asset_name, bool loop) {
return my_load_static_mp3(asset_name, loop);
}
SOUNDCLIP *my_load_static_ogg(const AssetPath &asset_name, int voll, bool loop) {
SOUNDCLIP *my_load_static_ogg(const AssetPath &asset_name, bool loop) {
#ifdef USE_VORBIS
Common::SeekableReadStream *data = _GP(AssetMgr)->OpenAssetStream(asset_name.Name, asset_name.Filter);
if (data) {
Audio::AudioStream *audioStream = Audio::makeVorbisStream(data, DisposeAfterUse::YES);
return new SoundClipWave<MUS_OGG>(audioStream, voll, loop);
return new SoundClipWave<MUS_OGG>(audioStream, loop);
} else {
return nullptr;
}
@ -81,8 +81,8 @@ SOUNDCLIP *my_load_static_ogg(const AssetPath &asset_name, int voll, bool loop)
#endif
}
SOUNDCLIP *my_load_ogg(const AssetPath &asset_name, int voll) {
return my_load_static_ogg(asset_name, voll, false);
SOUNDCLIP *my_load_ogg(const AssetPath &asset_name, bool loop) {
return my_load_static_ogg(asset_name, loop);
}
SOUNDCLIP *my_load_midi(const AssetPath &asset_name, bool loop) {
@ -125,7 +125,7 @@ SOUNDCLIP *my_load_mod(const AssetPath &asset_name, bool loop) {
return nullptr;
}
return new SoundClipWave<MUS_MOD>(audioStream, 255, loop);
return new SoundClipWave<MUS_MOD>(audioStream, loop);
} else {
return nullptr;
}

View File

@ -33,11 +33,11 @@
namespace AGS3 {
SOUNDCLIP *my_load_wave(const AssetPath &asset_name, int voll, bool loop);
SOUNDCLIP *my_load_mp3(const AssetPath &asset_name, int voll);
SOUNDCLIP *my_load_static_mp3(const AssetPath &asset_name, int voll, bool loop);
SOUNDCLIP *my_load_static_ogg(const AssetPath &asset_name, int voll, bool loop);
SOUNDCLIP *my_load_ogg(const AssetPath &asset_name, int voll);
SOUNDCLIP *my_load_wave(const AssetPath &asset_name, bool loop);
SOUNDCLIP *my_load_mp3(const AssetPath &asset_name, bool loop);
SOUNDCLIP *my_load_static_mp3(const AssetPath &asset_name, bool loop);
SOUNDCLIP *my_load_static_ogg(const AssetPath &asset_name, bool loop);
SOUNDCLIP *my_load_ogg(const AssetPath &asset_name, bool doLoop);
SOUNDCLIP *my_load_midi(const AssetPath &asset_name, bool loop);
SOUNDCLIP *my_load_mod(const AssetPath &asset_name, bool loop);

View File

@ -32,11 +32,11 @@ SOUNDCLIP::SOUNDCLIP() : _panning(12. / 8), _panningAsPercentage(0),
/*------------------------------------------------------------------*/
SoundClipWaveBase::SoundClipWaveBase(Audio::AudioStream *stream, int volume, bool repeat) :
SoundClipWaveBase::SoundClipWaveBase(Audio::AudioStream *stream, bool repeat) :
SOUNDCLIP(), _state(SoundClipInitial), _stream(stream) {
_mixer = ::AGS::g_vm->_mixer;
_repeat = repeat;
_vol = volume;
_vol = 255;
if (repeat) {
Audio::SeekableAudioStream *str = dynamic_cast<Audio::SeekableAudioStream *>(stream);

View File

@ -172,7 +172,7 @@ public:
SoundClipState _state;
bool _waitingToPlay = false;
SoundClipWaveBase(Audio::AudioStream *stream, int volume, bool repeat = false);
SoundClipWaveBase(Audio::AudioStream *stream, bool repeat = false);
~SoundClipWaveBase() override {
destroy();
}
@ -199,8 +199,8 @@ public:
template<int SOUND_TYPE>
struct SoundClipWave : public SoundClipWaveBase {
SoundClipWave(Audio::AudioStream *stream, int volume, bool repeat = false) :
SoundClipWaveBase(stream, volume, repeat) {}
SoundClipWave(Audio::AudioStream *stream, bool repeat = false) :
SoundClipWaveBase(stream, repeat) {}
int get_sound_type() const {
return SOUND_TYPE;
}

View File

@ -508,27 +508,29 @@ void IAGSEngine::PlaySoundChannel(int32 channel, int32 soundType, int32 volume,
// TODO: find out how engine was supposed to decide on where to load the sound from
AssetPath asset_name(filename, "audio");
if (soundType == PSND_WAVE)
newcha = my_load_wave(asset_name, volume, (loop != 0));
else if (soundType == PSND_MP3STREAM)
newcha = my_load_mp3(asset_name, volume);
else if (soundType == PSND_OGGSTREAM)
newcha = my_load_ogg(asset_name, volume);
else if (soundType == PSND_MP3STATIC)
newcha = my_load_static_mp3(asset_name, volume, (loop != 0));
else if (soundType == PSND_OGGSTATIC)
newcha = my_load_static_ogg(asset_name, volume, (loop != 0));
else if (soundType == PSND_MIDI) {
if (_GP(play).silent_midi != 0 || _G(current_music_type) == MUS_MIDI)
quit("!IAGSEngine::PlaySoundChannel: MIDI already in use");
newcha = my_load_midi(asset_name, (loop != 0));
newcha->set_volume(volume);
} else if (soundType == PSND_MOD) {
newcha = my_load_mod(asset_name, (loop != 0));
newcha->set_volume(volume);
} else
quit("!IAGSEngine::PlaySoundChannel: unknown sound type");
switch (soundType) {
case PSND_WAVE:
newcha = my_load_wave(asset_name, (loop != 0)); break;
case PSND_MP3STREAM:
case PSND_MP3STATIC:
newcha = my_load_mp3(asset_name, (loop != 0)); break;
case PSND_OGGSTREAM:
case PSND_OGGSTATIC:
newcha = my_load_ogg(asset_name, (loop != 0)); break;
case PSND_MIDI:
if (_GP(play).silent_midi != 0 || _G(current_music_type) == MUS_MIDI) {
debug_script_warn("IAGSEngine::PlaySoundChannel: MIDI already in use");
return;
}
newcha = my_load_midi(asset_name, (loop != 0)); break;
case PSND_MOD:
newcha = my_load_mod(asset_name, (loop != 0)); break;
default:
debug_script_warn("IAGSEngine::PlaySoundChannel: unknown sound type %d", soundType);
return;
}
newcha->set_volume(volume);
AudioChans::SetChannel(channel, newcha);
}
// Engine interface 12 and above are below