示例#1
0
文件: audio.c 项目: EQ4/MSF
void init_audio(void)
{
	al_reserve_samples(num_samples); // Sets up the default mixer
	// Set up the audio stream and mixer attachment
	if (stream)
	{
		if (al_get_mixer_attached(al_get_default_mixer()))
		{
			al_detach_mixer(al_get_default_mixer());
		}
		al_destroy_audio_stream(stream);
	}

	stream = al_create_audio_stream(
		num_fragments,
		size_fragment,
		audio_rate,
		AUDIO_DEPTH,
		CHANNEL_CONF);

	al_attach_audio_stream_to_mixer(stream, al_get_default_mixer());

	al_register_event_source(event_queue, 
		al_get_audio_stream_event_source(stream));

}
示例#2
0
inline void SoundManager::DestroyMixer()
{
	if(mixer!=NULL)
	{
		al_detach_mixer(mixer);
		al_destroy_mixer(mixer);
	}
}
示例#3
0
		void AudioWrappers::finalize_audio(void)
		{
			if (!AudioWrappers::is_enabled()) return;

			if (mixer != NULL)
			{
				al_detach_mixer(mixer);
				al_destroy_mixer(mixer);
			}

			if (voice != NULL)
				al_destroy_voice(voice);
		}
示例#4
0
void Framework::ShutdownAudioSystem()
{
#ifdef WRITE_LOG
  printf( "Framework: Shutdown Audio\n" );
#endif

  if( mixer != 0 )
  {
		al_detach_mixer( mixer );
		al_destroy_mixer( mixer );
		mixer = 0;
  }
  if( voice != 0 )
  {
    al_destroy_voice( voice );
    voice = 0;
  }
}
示例#5
0
/* Creates the default voice and mixer if they haven't been created yet. */
static bool create_default_mixer(void)
{
   int voice_frequency = 44100;
   int voice_depth = ALLEGRO_AUDIO_DEPTH_INT16;
   int mixer_frequency = 44100;
   int mixer_depth = ALLEGRO_AUDIO_DEPTH_FLOAT32;

   ALLEGRO_CONFIG *config = al_get_system_config();
   const char *p;
   p = al_get_config_value(config, "audio", "primary_voice_frequency");
   if (p && p[0] != '\0') {
      voice_frequency = atoi(p);
   }
   p = al_get_config_value(config, "audio", "primary_mixer_frequency");
   if (p && p[0] != '\0') {
      mixer_frequency = atoi(p);
   }
   p = al_get_config_value(config, "audio", "primary_voice_depth");
   if (p && p[0] != '\0') {
      voice_depth = string_to_depth(p);
   }
   p = al_get_config_value(config, "audio", "primary_mixer_depth");
   if (p && p[0] != '\0') {
      mixer_depth = string_to_depth(p);
   }

   if (!allegro_voice) {
      allegro_voice = al_create_voice(voice_frequency, voice_depth,
         ALLEGRO_CHANNEL_CONF_2);
      if (!allegro_voice) {
         ALLEGRO_ERROR("al_create_voice failed\n");
         goto Error;
      }
   }

   if (!allegro_mixer) {
      allegro_mixer = al_create_mixer(mixer_frequency, mixer_depth,
         ALLEGRO_CHANNEL_CONF_2);
      if (!allegro_mixer) {
         ALLEGRO_ERROR("al_create_voice failed\n");
         goto Error;
      }
   }

   /* In case this function is called multiple times. */
   al_detach_mixer(allegro_mixer);

   if (!al_attach_mixer_to_voice(allegro_mixer, allegro_voice)) {
      ALLEGRO_ERROR("al_attach_mixer_to_voice failed\n");
      goto Error;
   }

   return true;

Error:

   if (allegro_mixer) {
      al_destroy_mixer(allegro_mixer);
      allegro_mixer = NULL;
   }

   if (allegro_voice) {
      al_destroy_voice(allegro_voice);
      allegro_voice = NULL;
   }

   return false;
}