void sfx::play_ambient_variant_sound( const std::string &id, const std::string &variant, int volume, int channel, int duration, float pitch ) { if( !check_sound( volume ) ) { return; } const sound_effect *eff = find_random_effect( id, variant ); if( eff == nullptr ) { return; } const sound_effect &selected_sound_effect = *eff; Mix_Chunk *effect_to_play = get_sfx_resource( selected_sound_effect.resource_id ); Mix_Chunk *shifted_effect = do_pitch_shift( effect_to_play, pitch ); Mix_VolumeChunk( shifted_effect, selected_sound_effect.volume * get_option<int>( "AMBIENT_SOUND_VOLUME" ) * volume / ( 100 * 100 ) ); if( duration ) { if( Mix_FadeInChannel( channel, shifted_effect, -1, duration ) == -1 ) { dbg( D_ERROR ) << "Failed to play sound effect: " << Mix_GetError(); } } else { if( Mix_PlayChannel( channel, shifted_effect, -1 ) == -1 ) { dbg( D_ERROR ) << "Failed to play sound effect: " << Mix_GetError(); } } Mix_RegisterEffect( channel, empty_effect, cleanup_when_channel_finished, shifted_effect ); }
void update_music_volume() { sounds::sound_enabled = ::get_option<bool>( "SOUND_ENABLED" ); if( !check_sound() ) { return; } Mix_VolumeMusic( get_option<int>( "MUSIC_VOLUME" ) ); }
void play_music_file( const std::string &filename, int volume ) { if( !check_sound( volume ) ) { return; } const std::string path = ( current_soundpack_path + "/" + filename ); current_music = Mix_LoadMUS( path.c_str() ); if( current_music == nullptr ) { dbg( D_ERROR ) << "Failed to load audio file " << path << ": " << Mix_GetError(); return; } Mix_VolumeMusic( volume * get_option<int>( "MUSIC_VOLUME" ) / 100 ); if( Mix_PlayMusic( current_music, 0 ) != 0 ) { dbg( D_ERROR ) << "Starting playlist " << path << " failed: " << Mix_GetError(); return; } Mix_HookMusicFinished( musicFinished ); }
void sfx::play_variant_sound( const std::string &id, const std::string &variant, int volume ) { if( !check_sound( volume ) ) { return; } const sound_effect *eff = find_random_effect( id, variant ); if( eff == nullptr ) { eff = find_random_effect( id, "default" ); if( eff == nullptr ) { return; } } const sound_effect &selected_sound_effect = *eff; Mix_Chunk *effect_to_play = get_sfx_resource( selected_sound_effect.resource_id ); Mix_VolumeChunk( effect_to_play, selected_sound_effect.volume * get_option<int>( "SOUND_EFFECT_VOLUME" ) * volume / ( 100 * 100 ) ); Mix_PlayChannel( -1, effect_to_play, 0 ); }
void sfx::play_ambient_variant_sound( const std::string &id, const std::string &variant, int volume, int channel, int duration ) { if( !check_sound( volume ) ) { return; } const sound_effect *eff = find_random_effect( id, variant ); if( eff == nullptr ) { return; } const sound_effect &selected_sound_effect = *eff; Mix_Chunk *effect_to_play = get_sfx_resource( selected_sound_effect.resource_id );; Mix_VolumeChunk( effect_to_play, selected_sound_effect.volume * get_option<int>( "SOUND_EFFECT_VOLUME" ) * volume / ( 100 * 100 ) ); if( Mix_FadeInChannel( channel, effect_to_play, -1, duration ) == -1 ) { dbg( D_ERROR ) << "Failed to play sound effect: " << Mix_GetError(); } }
void sfx::play_variant_sound_pitch( const std::string &id, const std::string &variant, int volume, int angle, float pitch ) { if( !check_sound( volume ) ) { return; } const sound_effect *eff = find_random_effect( id, variant ); if( eff == nullptr ) { return; } const sound_effect &selected_sound_effect = *eff; Mix_Chunk *effect_to_play = get_sfx_resource( selected_sound_effect.resource_id ); Mix_Chunk *shifted_effect = do_pitch_shift( effect_to_play, pitch ); Mix_VolumeChunk( shifted_effect, selected_sound_effect.volume * get_option<int>( "SOUND_EFFECT_VOLUME" ) * volume / ( 100 * 100 ) ); int channel = Mix_PlayChannel( -1, shifted_effect, 0 ); Mix_RegisterEffect( channel, empty_effect, cleanup_when_channel_finished, shifted_effect ); Mix_SetPosition( channel, angle, 1 ); }