static void *stream_audio(ALLEGRO_THREAD *thread, void *data) { ALLEGRO_EVENT_QUEUE *queue; VideoState *is = data; ALLEGRO_AUDIO_STREAM *audio_stream = is->video->audio; queue = al_create_event_queue(); if (is->video->mixer) al_attach_audio_stream_to_mixer(audio_stream, is->video->mixer); else if (is->video->voice) al_attach_audio_stream_to_voice(audio_stream, is->video->voice); else al_attach_audio_stream_to_mixer(audio_stream, al_get_default_mixer()); al_register_event_source(queue, al_get_audio_stream_event_source(audio_stream)); while (1) { ALLEGRO_EVENT event; al_wait_for_event(queue, &event); if (event.type == ALLEGRO_EVENT_AUDIO_STREAM_FRAGMENT) { void *buf = al_get_audio_stream_fragment(audio_stream); if (!buf) continue; audio_callback(is, buf, AUDIO_BUFFER_SIZE); al_set_audio_stream_fragment(audio_stream, buf); } } return thread; }
AudioStream::AudioStream(const char *path, ALLEGRO_PLAYMODE playmode) { // load stream from file m_stream = al_load_audio_stream(path, 4, 2048); assert(m_stream); // create voice for the stream m_voice = al_create_voice(44100, al_get_audio_stream_depth(m_stream), ALLEGRO_CHANNEL_CONF_2); al_attach_audio_stream_to_voice(m_stream, m_voice); this->playmode(playmode); //al_detach_voice(m_voice); //assert(m_stream != 0); }