static void * t3f_fade_music_thread(void * arg) { ALLEGRO_TIMER * timer; ALLEGRO_EVENT_QUEUE * queue; bool done = false; ALLEGRO_EVENT event; float s = t3f_music_fade_speed / 50.0; timer = al_create_timer(1.0 / s); if(!timer) { return NULL; } queue = al_create_event_queue(); if(!queue) { return NULL; } al_register_event_source(queue, al_get_timer_event_source(timer)); while(!done) { al_wait_for_event(queue, &event); al_set_audio_stream_gain(t3f_stream, t3f_music_target_volume); t3f_music_target_volume -= s; if(t3f_music_target_volume <= 0.0) { t3f_stop_music(); done = true; } } return NULL; }
static int allua_audio_stream_set_gain(lua_State * L) { ALLUA_audio_stream audio_stream = allua_check_audio_stream(L, 1); float val = luaL_checknumber(L, 2); lua_pushboolean(L, al_set_audio_stream_gain(audio_stream, val)); return 1; }
void AllegroMusicSample5::SetVolume( float value ) { if ( !m_pInstance ) return; al_set_audio_stream_gain( m_pInstance, value ); m_volume = value; }
void t3f_set_music_volume(float volume) { t3f_music_volume = volume; t3f_new_music_volume = volume; // set this here so music new music will start at the desired volume if(t3f_stream) { al_set_audio_stream_gain(t3f_stream, t3f_music_volume * t3f_music_gain); } }
void SoundManager::Update() { if(music==NULL) return; if(musicEnabled && !paused) al_set_audio_stream_playing(music, true); else if(!musicEnabled || paused) al_set_audio_stream_playing(music, false); al_set_audio_stream_gain(music, musicVolume); }
void Prog::handle_event(const ALLEGRO_EVENT & event) { if (event.type == ALLEGRO_EVENT_AUDIO_STREAM_FRAGMENT) { ALLEGRO_AUDIO_STREAM *stream; Group *group; void *buf; float gain; float pan; stream = (ALLEGRO_AUDIO_STREAM *) event.any.source; buf = al_get_audio_stream_fragment(stream); if (!buf) { /* This is a normal condition that you must deal with. */ return; } if (stream == stream1) group = &group1; else if (stream == stream2) group = &group2; else if (stream == stream3) group = &group3; else if (stream == stream4) group = &group4; else if (stream == stream5) group = &group5; else group = NULL; ALLEGRO_ASSERT(group); if (group) { group->generate((float *) buf, SAMPLES_PER_BUFFER); if (group->get_gain_if_changed(&gain)) { al_set_audio_stream_gain(stream, gain); } if (group->get_pan_if_changed(&pan)) { al_set_audio_stream_pan(stream, pan); } } if (!al_set_audio_stream_fragment(stream, buf)) { log_printf("Error setting stream fragment.\n"); } } }
bool reload_sound(sound_t* sound) { ALLEGRO_AUDIO_STREAM* new_stream; if (!(new_stream = al_load_audio_stream(sound->path, 4, 1024))) return false; if (sound->stream != NULL) { al_set_audio_stream_playing(sound->stream, false); al_destroy_audio_stream(sound->stream); } sound->stream = new_stream; al_set_audio_stream_gain(sound->stream, 1.0); al_attach_audio_stream_to_mixer(sound->stream, al_get_default_mixer()); al_set_audio_stream_playing(sound->stream, false); return true; }
void FillPage(struct Game *game, int page) { char filename[30] = { }; sprintf(filename, "intro/%d.flac", page); game->intro.audiostream = al_load_audio_stream(GetDataFilePath(filename), 4, 1024); al_attach_audio_stream_to_mixer(game->intro.audiostream, game->audio.voice); al_set_audio_stream_playing(game->intro.audiostream, false); al_set_audio_stream_gain(game->intro.audiostream, 1.75); al_set_target_bitmap(game->intro.table); float y = 0.2; float oldx = -1; void draw_text(int page, char* text) { float x = 0.45; if (page!=oldx) { y=0.2; oldx=page; } al_draw_text_with_shadow(game->intro.font, al_map_rgb(255,255,255), game->viewportWidth*x, game->viewportHeight*y, ALLEGRO_ALIGN_LEFT, text); y+=0.07; }
bool Letter(struct Game *game, struct TM_Action *action, enum TM_ActionState state) { if (state == TM_ACTIONSTATE_INIT) { float* f = (float*)malloc(sizeof(float)); *f = 0; ALLEGRO_AUDIO_STREAM** stream = (ALLEGRO_AUDIO_STREAM**)malloc(sizeof(ALLEGRO_AUDIO_STREAM*)); *stream = al_load_audio_stream(GetDataFilePath(GetLevelFilename(game, "levels/?/letter.flac")), 4, 1024); al_attach_audio_stream_to_mixer(*stream, game->audio.voice); al_set_audio_stream_playing(*stream, false); al_set_audio_stream_gain(*stream, 2.00); action->arguments = TM_AddToArgs(action->arguments, (void*)f); action->arguments = TM_AddToArgs(action->arguments, (void*)stream); action->arguments->next->next = NULL; } else if (state == TM_ACTIONSTATE_DESTROY) { ALLEGRO_AUDIO_STREAM** stream = (ALLEGRO_AUDIO_STREAM**)action->arguments->next->value; al_set_audio_stream_playing(*stream, false); al_destroy_audio_stream(*stream); free(action->arguments->next->value); free(action->arguments->value); TM_DestroyArgs(action->arguments); } else if (state == TM_ACTIONSTATE_DRAW) { float* f = (float*)action->arguments->value; al_draw_tinted_bitmap(game->level.letter, al_map_rgba(*f,*f,*f,*f), (game->viewportWidth-al_get_bitmap_width(game->level.letter))/2.0, al_get_bitmap_height(game->level.letter)*-0.05, 0); return false; } else if (state == TM_ACTIONSTATE_PAUSE) { ALLEGRO_AUDIO_STREAM** stream = (ALLEGRO_AUDIO_STREAM**)action->arguments->next->value; al_set_audio_stream_playing(*stream, false); } else if ((state == TM_ACTIONSTATE_RESUME) || (state == TM_ACTIONSTATE_START)) { ALLEGRO_AUDIO_STREAM** stream = (ALLEGRO_AUDIO_STREAM**)action->arguments->next->value; al_set_audio_stream_playing(*stream, true); } if (state != TM_ACTIONSTATE_RUNNING) return false; float* f = (float*)action->arguments->value; *f+=5; if (*f>255) *f=255; al_draw_tinted_bitmap(game->level.letter, al_map_rgba(*f,*f,*f,*f), (game->viewportWidth-al_get_bitmap_width(game->level.letter))/2.0, al_get_bitmap_height(game->level.letter)*-0.05, 0); struct ALLEGRO_KEYBOARD_STATE keyboard; al_get_keyboard_state(&keyboard); // FIXME: do it the proper way if (al_key_down(&keyboard, ALLEGRO_KEY_ENTER)) { return true; } return false; }
stage *initStageWithNumber(int n){ stage *temp = malloc(sizeof(stage)); temp -> stageNum = n; temp -> stageBackground = NULL; temp -> stageAudio = NULL; temp -> bossAudio = NULL; int randomModifier = rand()%100; switch(n){ case 1: temp -> stageBackground = al_load_bitmap("Graphics/BeachSide.png"); if(!temp -> stageBackground) erro("Erro na alocação de stageBackground para stage 1\n"); temp -> stageAudio = al_load_audio_stream("Sound/BeachSide.ogg", 4, 1024); if(!temp -> stageAudio) erro("Erro na alocação de stageAudio para stage 1\n"); temp -> bossAudio = al_load_audio_stream("Sound/Marlingone.ogg", 4, 1024); if(!temp -> bossAudio) erro("Erro na alocação de bossAudio para stage 1\n"); al_set_audio_stream_gain(temp -> bossAudio, 1.5); temp -> targetKills = 20; temp -> limitSpawn = 4; break; case 2: temp -> stageBackground = al_load_bitmap("Graphics/RuinedVillage.png"); if(!temp -> stageBackground) erro("Erro na alocação de stageBackground para stage 2\n"); temp -> stageAudio = al_load_audio_stream("Sound/RuinedVillage.ogg", 4, 1024); if(!temp -> stageAudio) erro("Erro na alocação de stageAudio para stage 2\n"); temp -> bossAudio = al_load_audio_stream("Sound/Hueda.ogg", 4, 1024); if(!temp -> bossAudio) erro("Erro na alocação de bossAudio para stage 2\n"); temp -> targetKills = 40; temp -> limitSpawn = 5; randomModifier += 30; break; case 3: temp -> stageBackground = al_load_bitmap("Graphics/Macalania.png"); if(!temp -> stageBackground) erro("Erro na alocação de stageBackground para stage 3\n"); temp -> stageAudio = al_load_audio_stream("Sound/IceLake.ogg", 4, 1024); if(!temp -> stageAudio) erro("Erro na alocação de stageAudio para stage 3\n"); temp -> bossAudio = al_load_audio_stream("Sound/Cirno.ogg", 4, 1024); if(!temp -> bossAudio) erro("Erro na alocação de bossAudio para stage 3\n"); temp -> targetKills = 70; temp -> limitSpawn = 6; randomModifier += 40; break; case 4: temp -> stageBackground = al_load_bitmap("Graphics/Drangleic.png"); if(!temp -> stageBackground) erro("Erro na alocação de stageBackground para stage 4\n"); temp -> stageAudio = al_load_audio_stream("Sound/DrangleicCastle.ogg", 4, 1024); if(!temp -> stageAudio) erro("Erro na alocação de stageAudio para stage 4\n"); temp -> bossAudio = al_load_audio_stream("Sound/GuardianDragon.ogg", 4, 1024); if(!temp -> bossAudio) erro("Erro na alocação de bossAudio para stage 4\n"); temp -> targetKills = 100; temp -> limitSpawn = 6; randomModifier += 80; break; case 5: temp -> stageBackground = al_load_bitmap("Graphics/Moria.png"); if(!temp -> stageBackground) erro("Erro na alocação de stageBackground para stage 5\n"); temp -> stageAudio = al_load_audio_stream("Sound/DwarvenRuins.ogg", 4, 1024); if(!temp -> stageAudio) erro("Erro na alocação de stageAudio para stage 5\n"); temp -> bossAudio = al_load_audio_stream("Sound/Balrog.ogg", 4, 1024); if(!temp -> bossAudio) erro("Erro na alocação de bossAudio para stage 5\n"); temp -> targetKills = 100; temp -> limitSpawn = 6; randomModifier += 70; break; case 6: //MISSING OCEAN PALACE!!! temp -> stageBackground = al_load_bitmap("Graphics/BeachSide.png"); if(!temp -> stageBackground) erro("Erro na alocação de stageBackground para stage 6\n"); //MISSING OCEAN PALACE HEME!!! temp -> stageAudio = al_load_audio_stream("Sound/BeachSide.ogg", 4, 1024); if(!temp -> stageAudio) erro("Erro na alocação de stageAudio para stage 6\n"); temp -> bossAudio = al_load_audio_stream("Sound/Lavos.ogg", 4, 1024); if(!temp -> bossAudio) erro("Erro na alocação de bossAudio para stage 6\n"); temp -> targetKills = 150; temp -> limitSpawn = 7; randomModifier += 60; break; } if(randomModifier > 100){ temp -> darkPhantom = 30 + n; temp -> darkSpawn = rand()% temp -> targetKills + 1; } else{ temp -> darkPhantom = 0; temp -> darkSpawn = -1; } //temp -> darkPhantom = 30 + n; //temp -> darkSpawn = 1; al_set_audio_stream_playmode(temp -> stageAudio, ALLEGRO_PLAYMODE_LOOP); al_set_audio_stream_playmode(temp -> bossAudio, ALLEGRO_PLAYMODE_LOOP); return temp; }
static void * t3f_play_music_thread(void * arg) { const char * ext = NULL; ALLEGRO_PATH * path = NULL; int loop_points = 0; float loop_start = -1; float loop_end = -1; bool loop_disabled = false; const char * val = NULL; ALLEGRO_CONFIG * config = NULL; ALLEGRO_DEBUG("music thread start\n"); t3f_music_gain = 1.0; al_lock_mutex(t3f_music_mutex); if(t3f_stream) { t3f_stop_music(); } ALLEGRO_DEBUG("setting file interface\n"); al_set_new_file_interface(t3f_music_thread_file_interface); t3f_stream = al_load_audio_stream(t3f_music_thread_fn, 4, 4096); if(!t3f_stream) { al_unlock_mutex(t3f_music_mutex); t3f_set_music_state(T3F_MUSIC_STATE_OFF); return NULL; } ALLEGRO_DEBUG("configuring music\n"); /* look for loop data */ path = al_create_path(t3f_music_thread_fn); if(path) { al_set_path_extension(path, ".ini"); config = al_load_config_file(al_path_cstr(path, '/')); if(config) { val = al_get_config_value(config, "loop", "disabled"); if(val && !strcasecmp(val, "true")) { loop_disabled = true; } if(!loop_disabled) { val = al_get_config_value(config, "loop", "start"); if(val) { loop_start = atof(val); loop_points++; } val = al_get_config_value(config, "loop", "end"); if(val) { loop_end = atof(val); loop_points++; } } val = al_get_config_value(config, "settings", "gain"); if(val) { t3f_music_gain = atof(val); if(t3f_music_gain < 0.0) { t3f_music_gain = 0; } if(t3f_music_gain > 10.0) { t3f_music_gain = 10.0; } } al_destroy_config(config); } al_destroy_path(path); } if(loop_disabled) { al_set_audio_stream_playmode(t3f_stream, ALLEGRO_PLAYMODE_ONCE); } else { if(loop_points != 2) { /* loop entire song unless audio is MOD music */ ext = t3f_get_music_extension(t3f_music_thread_fn); if(strcmp(ext, ".xm") && strcmp(ext, ".it") && strcmp(ext, ".mod") && strcmp(ext, ".s3m")) { al_set_audio_stream_loop_secs(t3f_stream, 0.0, al_get_audio_stream_length_secs(t3f_stream)); al_set_audio_stream_playmode(t3f_stream, ALLEGRO_PLAYMODE_LOOP); } else { al_set_audio_stream_playmode(t3f_stream, ALLEGRO_PLAYMODE_LOOP); } } else { al_set_audio_stream_loop_secs(t3f_stream, loop_start, loop_end); al_set_audio_stream_playmode(t3f_stream, ALLEGRO_PLAYMODE_LOOP); } } ALLEGRO_DEBUG("start the music\n"); t3f_music_volume = t3f_new_music_volume; al_set_audio_stream_gain(t3f_stream, t3f_music_volume * t3f_music_gain); al_attach_audio_stream_to_mixer(t3f_stream, al_get_default_mixer()); al_unlock_mutex(t3f_music_mutex); t3f_set_music_state(T3F_MUSIC_STATE_PLAYING); return NULL; }
void set_sound_gain(sound_t* sound, float gain) { al_set_audio_stream_gain(sound->stream, gain); }