// returns -1 on failure, channel number on success int PlaySoundEx(int val1, int channel) { if (debug_flags & DBG_NOSFX) return -1; ScriptAudioClip *aclip = GetAudioClipForOldStyleNumber(game, false, val1); if (aclip && !is_audiotype_allowed_to_play((AudioFileType)aclip->fileType)) return -1; // if sound is off, ignore it if ((channel < SCHAN_NORMAL) || (channel >= MAX_SOUND_CHANNELS)) quit("!PlaySoundEx: invalid channel specified, must be 3-7"); // if an ambient sound is playing on this channel, abort it StopAmbientSound(channel); if (val1 < 0) { stop_and_destroy_channel (channel); return -1; } // if skipping a cutscene, don't try and play the sound if (play.fast_forward) return -1; // that sound is already in memory, play it if (!psp_audio_multithreaded) { if ((last_sound_played[channel] == val1) && (channels[channel] != NULL)) { debug_script_log("Playing sound %d on channel %d; cached", val1, channel); channels[channel]->restart(); channels[channel]->set_volume (play.sound_volume); return channel; } } // free the old sound stop_and_destroy_channel (channel); debug_script_log("Playing sound %d on channel %d", val1, channel); last_sound_played[channel] = val1; SOUNDCLIP *soundfx = aclip ? load_sound_and_play(aclip, false) : NULL; if (soundfx == NULL) { debug_script_warn("Sound sample load failure: cannot load sound %d", val1); debug_script_log("FAILED to load sound %d", val1); return -1; } channels[channel] = soundfx; channels[channel]->priority = 10; channels[channel]->set_volume (play.sound_volume); return channel; }
void IAGSEngine::PlaySoundChannel (int32 channel, int32 soundType, int32 volume, int32 loop, const char *filename) { stop_and_destroy_channel (channel); SOUNDCLIP *newcha = NULL; if (((soundType == PSND_MP3STREAM) || (soundType == PSND_OGGSTREAM)) && (loop != 0)) quit("IAGSEngine::PlaySoundChannel: streamed samples cannot loop"); if (soundType == PSND_WAVE) newcha = my_load_wave (filename, volume, loop); else if (soundType == PSND_MP3STREAM) newcha = my_load_mp3 (filename, volume); else if (soundType == PSND_OGGSTREAM) newcha = my_load_ogg (filename, volume); else if (soundType == PSND_MP3STATIC) newcha = my_load_static_mp3 (filename, volume, (loop != 0)); else if (soundType == PSND_OGGSTATIC) newcha = my_load_static_ogg (filename, volume, (loop != 0)); else if (soundType == PSND_MIDI) { if (midi_pos >= 0) quit("!IAGSEngine::PlaySoundChannel: MIDI already in use"); newcha = my_load_midi (filename, loop); newcha->set_volume (volume); } else if (soundType == PSND_MOD) { newcha = my_load_mod (filename, loop); newcha->set_volume (volume); } else quit("!IAGSEngine::PlaySoundChannel: unknown sound type"); channels[channel] = newcha; }
void StopAmbientSound (int channel) { if ((channel < 0) || (channel >= MAX_SOUND_CHANNELS)) quit("!StopAmbientSound: invalid channel"); if (ambient[channel].channel == 0) return; stop_and_destroy_channel(channel); ambient[channel].channel = 0; }
void stopmusic() { if (crossFading > 0) { // stop in the middle of a new track fading in // Abort the new track, and let the old one finish fading out stop_and_destroy_channel (crossFading); crossFading = -1; } else if (crossFading < 0) { // the music is already fading out if (game.options[OPT_CROSSFADEMUSIC] <= 0) { // If they have since disabled crossfading, stop the fadeout stop_and_destroy_channel(SCHAN_MUSIC); crossFading = 0; crossFadeStep = 0; update_music_volume(); } } else if ((game.options[OPT_CROSSFADEMUSIC] > 0) && (channels[SCHAN_MUSIC] != NULL) && (channels[SCHAN_MUSIC]->done == 0) && (current_music_type != 0) && (current_music_type != MUS_MIDI) && (current_music_type != MUS_MOD)) { crossFading = -1; crossFadeStep = 0; crossFadeVolumePerStep = game.options[OPT_CROSSFADEMUSIC]; crossFadeVolumeAtStart = calculate_max_volume(); } else stop_and_destroy_channel (SCHAN_MUSIC); play.cur_music_number = -1; current_music_type = 0; }
void PlaySilentMIDI (int mnum) { if (current_music_type == MUS_MIDI) quit("!PlaySilentMIDI: proper midi music is in progress"); set_volume (-1, 0); play.silent_midi = mnum; play.silent_midi_channel = SCHAN_SPEECH; stop_and_destroy_channel(play.silent_midi_channel); channels[play.silent_midi_channel] = load_sound_clip_from_old_style_number(true, mnum, false); if (channels[play.silent_midi_channel] == NULL) { quitprintf("!PlaySilentMIDI: failed to load aMusic%d", mnum); } channels[play.silent_midi_channel]->play(); channels[play.silent_midi_channel]->set_volume_percent(0); }
void stop_speech() { if (channels[SCHAN_SPEECH] != NULL) { play.music_master_volume = play.music_vol_was; // update the music in a bit (fixes two speeches follow each other // and music going up-then-down) update_music_at = 20; mvolcounter = 1; stop_and_destroy_channel (SCHAN_SPEECH); curLipLine = -1; if (play.no_textbg_when_voice == 2) { // set back to Sierra w/bgrnd play.no_textbg_when_voice = 1; game.options[OPT_SPEECHTYPE] = 2; } } }
void PlayAmbientSound (int channel, int sndnum, int vol, int x, int y) { // the channel parameter is to allow multiple ambient sounds in future if ((channel < 1) || (channel == SCHAN_SPEECH) || (channel >= MAX_SOUND_CHANNELS)) quit("!PlayAmbientSound: invalid channel number"); if ((vol < 1) || (vol > 255)) quit("!PlayAmbientSound: volume must be 1 to 255"); ScriptAudioClip *aclip = GetAudioClipForOldStyleNumber(game, false, sndnum); if (aclip && !is_audiotype_allowed_to_play((AudioFileType)aclip->fileType)) return; // only play the sound if it's not already playing if ((ambient[channel].channel < 1) || (channels[ambient[channel].channel] == NULL) || (channels[ambient[channel].channel]->done == 1) || (ambient[channel].num != sndnum)) { StopAmbientSound(channel); // in case a normal non-ambient sound was playing, stop it too stop_and_destroy_channel(channel); SOUNDCLIP *asound = aclip ? load_sound_and_play(aclip, true) : NULL; if (asound == NULL) { debug_script_warn ("Cannot load ambient sound %d", sndnum); debug_script_log("FAILED to load ambient sound %d", sndnum); return; } debug_script_log("Playing ambient sound %d on channel %d", sndnum, channel); ambient[channel].channel = channel; channels[channel] = asound; channels[channel]->priority = 15; // ambient sound higher priority than normal sfx } // calculate the maximum distance away the player can be, using X // only (since X centred is still more-or-less total Y) ambient[channel].maxdist = ((x > thisroom.width / 2) ? x : (thisroom.width - x)) - AMBIENCE_FULL_DIST; ambient[channel].num = sndnum; ambient[channel].x = x; ambient[channel].y = y; ambient[channel].vol = vol; update_ambient_sound_vol(); }
int play_speech(int charid,int sndid) { stop_and_destroy_channel (SCHAN_SPEECH); // don't play speech if we're skipping a cutscene if (play.fast_forward) return 0; if ((play.want_speech < 1) || (speech_file.IsEmpty())) return 0; SOUNDCLIP *speechmp3; String script_name; if (charid >= 0) { // append the first 4 characters of the script name to the filename if (game.chars[charid].scrname[0] == 'c') script_name.SetString(&game.chars[charid].scrname[1], 4); else script_name.SetString(game.chars[charid].scrname, 4); } else script_name = "NARR"; // append the speech number and create voice file name String voice_file = String::FromFormat("%s%d", script_name.GetCStr(), sndid); int ii; // Compare the base file name to the .pam file name curLipLine = -1; // See if we have voice lip sync for this line curLipLinePhoneme = -1; for (ii = 0; ii < numLipLines; ii++) { if (stricmp(splipsync[ii].filename, voice_file) == 0) { curLipLine = ii; break; } } // if the lip-sync is being used for voice sync, disable // the text-related lipsync if (numLipLines > 0) game.options[OPT_LIPSYNCTEXT] = 0; voice_file.Append(".wav"); AssetPath asset_name(speech_file, voice_file); speechmp3 = my_load_wave(asset_name, play.speech_volume, 0); if (speechmp3 == NULL) { voice_file.ReplaceMid(voice_file.GetLength() - 3, 3, "ogg"); speechmp3 = my_load_ogg(asset_name, play.speech_volume); } if (speechmp3 == NULL) { voice_file.ReplaceMid(voice_file.GetLength() - 3, 3, "mp3"); speechmp3 = my_load_mp3(asset_name, play.speech_volume); } if (speechmp3 != NULL) { if (speechmp3->play() == 0) speechmp3 = NULL; } if (speechmp3 == NULL) { voice_file.ClipRight(4); // cut the extension for debug output debug_script_warn("Speech load failure: '%s'", voice_file.GetCStr()); curLipLine = -1; return 0; } channels[SCHAN_SPEECH] = speechmp3; play.music_vol_was = play.music_master_volume; // Negative value means set exactly; positive means drop that amount if (play.speech_music_drop < 0) play.music_master_volume = -play.speech_music_drop; else play.music_master_volume -= play.speech_music_drop; apply_volume_drop_modifier(true); update_music_volume(); update_music_at = 0; mvolcounter = 0; update_ambient_sound_vol(); // change Sierra w/bgrnd to Sierra without background when voice // is available (for Tierra) if ((game.options[OPT_SPEECHTYPE] == 2) && (play.no_textbg_when_voice > 0)) { game.options[OPT_SPEECHTYPE] = 1; play.no_textbg_when_voice = 2; } return 1; }