void SoundManager::launchBackGroundMusic(const std::string & filename){ //If a background music is running if(m_BackgroundMusic != NULL){ Mix_FadeOutChannel(0, 1000); } Mix_HaltChannel(0); destroySound(&m_BackgroundMusic); loadSound(&m_BackgroundMusic, filename); if(m_BackgroundMusic != NULL){ if(Mix_FadeInChannel(0, m_BackgroundMusic, -1, 1000) == -1){ std::cout << "SOUNDMANAGER : Impossible to play : " << filename << std::endl; } } }
int CHANNEL_play_sound(int channel, CSOUND *sound, int loops, int fadein) { _pipe_usage++; if (_pipe_usage == 1) { //fprintf(stderr, "watch pipe\n"); GB.Watch(_pipe[0], GB_WATCH_READ, (void *)free_finished_channel, 0); } if (fadein > 0) return Mix_FadeInChannel(channel, sound->chunk, loops, fadein); else return Mix_PlayChannel(channel, sound->chunk, loops); }
int SDLAudio::FadeInSFX( std::string SFXName, int time, int loops, int channel) { /** Play SFX */ SListIterator<SGZSound*> SFXListITR = SFXList.GetIterator(); for( SFXListITR.Start(); SFXListITR.Valid(); SFXListITR.Forth() ) if((SFXListITR.Item()->Name.compare(SFXName))==0) { return Mix_FadeInChannel(channel, SFXListITR.Item()->Data, loops, time); } SGZLogger.warn("AudioMAN: Can't find SFX \"%s\" to Fade In!\n", SFXName.c_str()); return -1; }
void play_thrust(void) { #ifndef NOSOUND #ifdef ARGS if (sound_arg) { #endif // Mix_PlayChannel(0, sound[SND_THRUST],-1); Mix_FadeInChannel(1, sound[SND_THRUST],-1,1000); #ifdef ARGS } #endif #endif }
CHANNEL sound_play(SOUND *s, int loop, int fadein) { CHANNEL c; if (fadein) { c = Mix_FadeInChannel(-1, s, loop ? -1 : 0, fadein * 1000); } else { c = Mix_PlayChannel(-1, s, loop ? -1 : 0); } if (c == -1) FATAL(Mix_GetError()); return c; }
void SdlAudio::ME_Play(std::string const& file, int volume, int /* pitch */, int fadein) { std::string const path = FileFinder::FindMusic(file); if (path.empty()) { Output::Warning("Music not found: %s", file.c_str()); return; } me.reset(Mix_LoadWAV(path.c_str()), &Mix_FreeChunk); if (!me) { Output::Warning("Couldn't load %s ME.\n%s\n", file.c_str(), Mix_GetError()); return; } me_channel = Mix_FadeInChannel(-1, me.get(), 0, fadein); Mix_Volume(me_channel, volume * MIX_MAX_VOLUME / 100); if (me_channel == -1) { Output::Warning("Couldn't play %s ME.\n%s\n", file.c_str(), Mix_GetError()); return; } me_stopped_bgm = (Mix_PlayingMusic() == 1); // Mix_ChannelFinished(me_finish); }
void SdlAudio::BGS_Play(std::string const& file, int volume, int /* pitch */, int fadein) { std::string const path = FileFinder::FindMusic(file); if (path.empty()) { Output::Warning("Music not found: %s", file.c_str()); return; } bgs.reset(Mix_LoadWAV(path.c_str()), &Mix_FreeChunk); if (!bgs) { Output::Warning("Couldn't load %s BGS.\n%s\n", file.c_str(), Mix_GetError()); return; } bgs_channel = Mix_FadeInChannel(-1, bgs.get(), -1, fadein); Mix_Volume(bgs_channel, volume * MIX_MAX_VOLUME / 100); if (bgs_channel == -1) { Output::Warning("Couldn't play %s BGS.\n%s\n", file.c_str(), Mix_GetError()); return; } bgs_playing = true; }
static VALUE Mixer_s_fadeInChannel(VALUE mod, VALUE channel, VALUE wave, VALUE loops, VALUE ms) { int playing_channel; playing_channel = Mix_FadeInChannel(NUM2INT(channel), Get_Mix_Chunk(wave), NUM2INT(loops), NUM2INT(ms)); if( playing_channel == -1 ) { rb_raise(eSDLError, "couldn't play wave: %s", Mix_GetError()); } /* to avoid gc problem */ rb_ary_store(playing_wave, playing_channel, wave); return INT2FIX(playing_channel); }
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(); } }
/*************************************************************//** * * @brief サウンドエフェクトのフェードインでの再生を行う * @param サウンドエフェクト * @param 割り当てるチャネル( -1の場合は自動割り当て ) * @param 再生回数( -1の場合はループ再生 ) * @param フェードインの時間 * @param 割り当てられたチャネルを取得するポインタ * @return 正常終了:true * @return 異常終了:false * ****************************************************************/ bool C_SoundManager::FadeInPlaySoundEffect(const C_SoundManager::SoundEffectPtr& prSoundEffect, int32_t allocateChannel, int32_t playCount, int32_t fadeInTime, int32_t* pGetAllocateChannel) { assert(prSoundEffect); // サウンドエフェクトをフェードインで再生し、割り当てられたチャネルを取得 int32_t allocatedChannel = Mix_FadeInChannel(allocateChannel, prSoundEffect.get(), playCount, fadeInTime); if (allocatedChannel == C_SoundManagerImpl::s_ALLOCATE_CHANNEL_ERROR_VALUE) { PrintLog("[ C_SoundManager::FadeInPlaySoundEffect ] : チャネルの割り当てに失敗しました。\n"); PrintLog(" エラー内容 : %s\n", Mix_GetError()); return false; } // ポインタが設定されている場合は割り当てられたチャネルを取得する if (pGetAllocateChannel != nullptr) *pGetAllocateChannel = allocatedChannel; return true; }
d_define_method(track, play_fade_in)(struct s_object *self, t_boolean restart, int delay) { d_using(track); t_boolean start_required = d_true; int channel; if ((track_attributes->channel != d_track_auto_channel) && ((Mix_Playing(track_attributes->channel)) || (Mix_Paused(track_attributes->channel)))) { if (restart) Mix_HaltChannel(track_attributes->channel); else { if (Mix_Paused(track_attributes->channel)) Mix_Resume(track_attributes->channel); start_required = d_false; } } if (start_required) { if (track_attributes->auto_channel) channel = d_track_auto_channel; else channel = track_attributes->next_channel; d_call(self, m_track_set_volume, track_attributes->volume); if ((track_attributes->channel = Mix_FadeInChannel(channel, track_attributes->chunk, track_attributes->loops, delay)) != -1) d_call(self, m_track_set_position, track_attributes->angle, track_attributes->distance); } return self; }
void play_sound_internal(const std::string& files, channel_group group, unsigned int repeats, unsigned int distance, int id, int loop_ticks, int fadein_ticks) { if(files.empty() || distance >= DISTANCE_SILENT || !mix_ok) { return; } audio_lock lock; // find a free channel in the desired group int channel = Mix_GroupAvailable(group); if(channel == -1) { LOG_AUDIO << "All channels dedicated to sound group(" << group << ") are busy, skipping.\n"; return; } Mix_Chunk *chunk; std::string file = pick_one(files); try { chunk = load_chunk(file, group); assert(chunk); } catch(const chunk_load_exception&) { return; } /* * This check prevents SDL_Mixer from blowing up on Windows when UI sound is played * in response to toggling the checkbox which disables sound. */ if(group != SOUND_UI) { Mix_SetDistance(channel, distance); } int res; if(loop_ticks > 0) { if(fadein_ticks > 0) { res = Mix_FadeInChannelTimed(channel, chunk, -1, fadein_ticks, loop_ticks); } else { res = Mix_PlayChannel(channel, chunk, -1); } if(res >= 0) { Mix_ExpireChannel(channel, loop_ticks); } } else { if(fadein_ticks > 0) { res = Mix_FadeInChannel(channel, chunk, repeats, fadein_ticks); } else { res = Mix_PlayChannel(channel, chunk, repeats); } } if(res < 0) { ERR_AUDIO << "error playing sound effect: " << Mix_GetError() << std::endl; //still keep it in the sound cache, in case we want to try again later return; } channel_ids[channel] = id; //reserve the channel's chunk from being freed, since it is playing channel_chunks[res] = chunk; }
int SDLPlayAudioFadeIn(Mix_Chunk* SDLAudioClip, unsigned int fadeTime, int loopCount) { Mix_FadeInChannel(-1, SDLAudioClip, loopCount, fadeTime); }
void enemy_logic(unsigned long dt) { int x, y; int move_down = 0; double rate; enemy_speed = getEnemySpeed(); if (enemy[0][0].x < 0 || enemy[0][0].x + (11*32*gScale) > SCREEN_WIDTH) { enemy_direction *= -1; move_down = 1; } for (y = 0; y < 5; y++) { for (x = 0; x < 11; x++) { enemy[x][y].x += enemy_speed * enemy_direction * dt; if (move_down) { // prevents enemies getting stuck on side then disappearing enemy[x][y].x += enemy_speed * enemy_direction * dt; enemy[x][y].y += 16 * gScale; } enemy[x][y].rect.x = (int)enemy[x][y].x; enemy[x][y].rect.y = (int)enemy[x][y].y; // spawn bullets with an equal fire rate throughout level // since enemies decrease, higher chance of a given alive enemy // shooting as enemies are shot down and levels passed rate = 100000.0 * ((float)enemy_total+1.0)/55.0 * (1.0/gDifficulty); if (enemy[x][y].alive && rand() % (int)rate < 2*dt) { bullet_fire(enemy[x][y].rect.x + enemy[x][y].rect.w/2 - gScale, enemy[x][y].rect.y + enemy[x][y].rect.h - 1, 0); } } } // Command ship spawn algorithm // Random chance to spawn after enemies move two rows down if (!command_spawned && (rand() % 40000 < 2*dt) && enemy[0][0].rect.y > 160) { command_spawned = 1; command.alive = 1; command_speed = (rand() % 3) + 1; command_points = command_speed * 100; Mix_FadeInChannel(-1, gCommandEntrance, -1, 2000); } // force command ship to spawn if it gets close to end of wave else if (!command_spawned && enemy_total < 8) { command_spawned = 1; command.alive = 1; command_speed = (rand() % 3) + 1; command_points = command_speed * 100; Mix_FadeInChannel(-1, gCommandEntrance, -1, 2000); } if (command.alive) { command.x -= .02f * gScale * command_speed * dt; command.rect.x = (int)command.x; if (command.rect.x + command.rect.w < 0) { command.alive = 0; Mix_HaltChannel(-1); Mix_PlayChannel(-1, gCommandExit, 0); } } // reset level if all enemies were killed if (enemy_total == 0) { SDL_Delay(2000); gDifficulty *= 2.0f; enemy_reset(); bullet_reset(); defense_reset(); } }