Beispiel #1
0
void SoundManager::PlayMusic(int num, bool loop)
{
	DestroyMusic();
	if(num==-1)
		return;
	else if(num==0)
		music = al_load_audio_stream("music/menu.ogg", 4, 2048);
	else if(num==1)
		music = al_load_audio_stream("music/level1.ogg", 4, 2048);

	if(music==NULL)
	{
		al_show_native_message_box(DisplayManager::GetInstance().GetDisplay(),
			"Error!", "SoundManager", "Couldn't load music", "ok sok", ALLEGRO_MESSAGEBOX_ERROR);
		return;
	}

	if(music==NULL)
		return;

	al_set_audio_stream_loop_secs(music, .0f, al_get_audio_stream_length_secs(music));
	if(loop)
		al_set_audio_stream_playmode(music, ALLEGRO_PLAYMODE_LOOP);
	else
		al_set_audio_stream_playmode(music, ALLEGRO_PLAYMODE_ONCE);
	al_attach_audio_stream_to_mixer(music, mixer);
	al_attach_mixer_to_voice(mixer,voice);

}
Beispiel #2
0
int main(int argc, char * argv[])
{
   ALLEGRO_CONFIG *config;
   ALLEGRO_EVENT event;
   unsigned buffer_count;
   unsigned samples;
   const char *s;

   initialize();

   if (argc < 2) {
      log_printf("This example needs to be run from the command line.\nUsage: %s {audio_files}\n", argv[0]);
      goto done;
   }

   buffer_count = 0;
   samples = 0;
   config = al_load_config_file("ex_stream_seek.cfg");
   if (config) {
      if ((s = al_get_config_value(config, "", "buffer_count"))) {
         buffer_count = atoi(s);
      }
      if ((s = al_get_config_value(config, "", "samples"))) {
         samples = atoi(s);
      }
      al_destroy_config(config);
   }
   if (buffer_count == 0) {
      buffer_count = 4;
   }
   if (samples == 0) {
      samples = 1024;
   }

   stream_filename = argv[1];
   music_stream = al_load_audio_stream(stream_filename, buffer_count, samples);
   if (!music_stream) {
      abort_example("Stream error!\n");
   }

   loop_start = 0.0;
   loop_end = al_get_audio_stream_length_secs(music_stream);
   al_set_audio_stream_loop_secs(music_stream, loop_start, loop_end);

   al_set_audio_stream_playmode(music_stream, ALLEGRO_PLAYMODE_LOOP);
   al_attach_audio_stream_to_mixer(music_stream, al_get_default_mixer());
   al_start_timer(timer);

   while (!exiting) {
      al_wait_for_event(queue, &event);
      event_handler(&event);
   }

done:
   myexit();
   al_destroy_display(display);
   close_log(true);
   return 0;
}
Beispiel #3
0
static int allua_audio_stream_set_loop_secs(lua_State * L)
{
   ALLUA_audio_stream audio_stream = allua_check_audio_stream(L, 1);
   double start = luaL_checknumber(L, 2);
   double end = luaL_checknumber(L, 3);
   lua_pushboolean(L, al_set_audio_stream_loop_secs(audio_stream, start, end));
   return 1;
}
int main(int argc, char * argv[])
{
   ALLEGRO_CONFIG *config;
   ALLEGRO_EVENT event;
   unsigned buffer_count;
   unsigned samples;
   const char *s;

   if (argc < 2) {
      printf("Usage: ex_stream_seek <filename>\n");
      return -1;
   }

   if (!initialize())
      return 1;

   buffer_count = 0;
   samples = 0;
   config = al_load_config_file("ex_stream_seek.cfg");
   if (config) {
      if ((s = al_get_config_value(config, "", "buffer_count"))) {
         buffer_count = atoi(s);
      }
      if ((s = al_get_config_value(config, "", "samples"))) {
         samples = atoi(s);
      }
      al_destroy_config(config);
   }
   if (buffer_count == 0) {
      buffer_count = 4;
   }
   if (samples == 0) {
      samples = 1024;
   }

   stream_filename = argv[1];
   music_stream = al_load_audio_stream(stream_filename, buffer_count, samples);
   if (!music_stream) {
      printf("Stream error!\n");
      return 1;
   }

   loop_start = 0.0;
   loop_end = al_get_audio_stream_length_secs(music_stream);
   al_set_audio_stream_loop_secs(music_stream, loop_start, loop_end);

   al_set_audio_stream_playmode(music_stream, ALLEGRO_PLAYMODE_LOOP);
   al_attach_audio_stream_to_mixer(music_stream, al_get_default_mixer());
   al_start_timer(timer);

   while (!exiting) {
      al_wait_for_event(queue, &event);
      event_handler(&event);
   }

   myexit();
   return 0;
}
static void maybe_fiddle_sliders(int mx, int my)
{
   double seek_pos;
   double w = al_get_display_width(display) - 20;

   if (!(mx >= 10 && mx < 10 + w && my >= 48 && my < 64)) {
      return;
   }

   seek_pos = al_get_audio_stream_length_secs(music_stream) * ((mx - 10) / w);
   if (mouse_button[1]) {
      al_seek_audio_stream_secs(music_stream, seek_pos);
   }
   else if (mouse_button[2]) {
      loop_end = seek_pos;
      al_set_audio_stream_loop_secs(music_stream, loop_start, loop_end);
   }
   else if (mouse_button[3]) {
      loop_start = seek_pos;
      al_set_audio_stream_loop_secs(music_stream, loop_start, loop_end);
   }
}
int main(int argc, char *argv[])
{
   ALLEGRO_CONFIG *config;
   ALLEGRO_EVENT event;
   unsigned buffer_count;
   unsigned samples;
   const char *s;
   ALLEGRO_PLAYMODE playmode = ALLEGRO_PLAYMODE_LOOP;

   initialize();

   if (argc > 1) {
      stream_filename = argv[1];
   }

   buffer_count = 0;
   samples = 0;
   config = al_load_config_file("ex_stream_seek.cfg");
   if (config) {
      if ((s = al_get_config_value(config, "", "buffer_count"))) {
         buffer_count = atoi(s);
      }
      if ((s = al_get_config_value(config, "", "samples"))) {
         samples = atoi(s);
      }
      if ((s = al_get_config_value(config, "", "playmode"))) {
         if (!strcmp(s, "loop")) {
            playmode = ALLEGRO_PLAYMODE_LOOP;
         }
         else if (!strcmp(s, "once")) {
            playmode = ALLEGRO_PLAYMODE_ONCE;
         }
      }
      al_destroy_config(config);
   }
   if (buffer_count == 0) {
      buffer_count = 4;
   }
   if (samples == 0) {
      samples = 1024;
   }

   music_stream = al_load_audio_stream(stream_filename, buffer_count, samples);
   if (!music_stream) {
      abort_example("Stream error!\n");
   }
   al_register_event_source(queue, al_get_audio_stream_event_source(music_stream));

   loop_start = 0.0;
   loop_end = al_get_audio_stream_length_secs(music_stream);
   al_set_audio_stream_loop_secs(music_stream, loop_start, loop_end);

   al_set_audio_stream_playmode(music_stream, playmode);
   al_attach_audio_stream_to_mixer(music_stream, al_get_default_mixer());
   al_start_timer(timer);

   while (!exiting) {
      al_wait_for_event(queue, &event);
      event_handler(&event);
   }

   myexit();
   al_destroy_display(display);
   close_log(true);
   return 0;
}
Beispiel #7
0
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;
}