![]() |
|
Audio Stream: Seeking doesn't work |
schollexpos
Member #16,751
October 2017
|
Hello, But the simple call to al_seek_audio_stream_secs() fails. I have tried stopping the song before the call, or disabling the looping of the song, but with no luck. Does anyone know why the function could return false? Changing the looping points works without a problem. The basic structure of my code: Thanks in advance! |
Edgar Reynaldo
Major Reynaldo
May 2007
![]() |
Hello schollexpos Can you produce a simple code example that demonstrates this? Does seeking not work with any audio stream? My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
schollexpos
Member #16,751
October 2017
|
Hello Edgar, thanks for your quick reply! 1int main() {
2 al_init();
3
4 al_install_keyboard();
5
6 ALLEGRO_EVENT_QUEUE *queue = al_create_event_queue();
7
8 ALLEGRO_DISPLAY *display = nullptr;
9 int requiredFlags = ALLEGRO_OPENGL | ALLEGRO_PROGRAMMABLE_PIPELINE;
10 al_set_new_display_flags(requiredFlags);
11
12 display = al_create_display(1280, 720);
13 al_register_event_source(queue, al_get_display_event_source(display));
14 al_register_event_source(queue, al_get_keyboard_event_source());
15
16 if(!al_install_audio()) {
17 std::cout << "[ERR.] Failed to load the Audio System!" << std::endl;
18 return 0;
19 } else {
20 std::cout << "Loaded the Audio System!" << std::endl;
21 }
22 al_init_acodec_addon();
23
24 ALLEGRO_VOICE *voice = al_create_voice(44100, ALLEGRO_AUDIO_DEPTH_INT16, ALLEGRO_CHANNEL_CONF_2);
25
26 if(!voice) {
27 std::cout << "Failed to create Voice!" << std::endl;
28 exit(-1);
29 }
30
31 ALLEGRO_MIXER *mix_final = al_create_mixer(44100, ALLEGRO_AUDIO_DEPTH_INT16, ALLEGRO_CHANNEL_CONF_2);
32
33 al_reserve_samples(16);
34
35 al_attach_mixer_to_voice(mix_final, voice);
36
37 ALLEGRO_AUDIO_STREAM *stream = al_load_audio_stream("res/theme.ogg", 4, 2048);
38 al_attach_audio_stream_to_mixer(stream, mix_final);
39 al_set_audio_stream_playmode(stream, ALLEGRO_PLAYMODE_LOOP);
40 al_set_audio_stream_loop_secs(stream, 0, 47.2);
41
42 bool running = true;
43 while(running) {
44 ALLEGRO_EVENT ev;
45 al_wait_for_event(queue, &ev);
46 do {
47 switch(ev.type) {
48 case ALLEGRO_EVENT_DISPLAY_CLOSE:
49 running = false;
50 break;
51 case ALLEGRO_EVENT_KEY_DOWN:
52 if(ev.keyboard.keycode == ALLEGRO_KEY_N) {
53 std::cout << "We should get something here" << std::endl;
54 al_seek_audio_stream_secs(stream, 60);
55 }
56 }
57 } while(al_get_next_event(queue, &ev));
58 }
59
60 return 0;
61}
I'm amazed that the problem is not some kind of side effect from somewhere else in my engine The audio file is over 5 minutes long, so I'm not trying to go over it's length here. I'm developing on Windows with Visual Studio 2017 and Allegro 5.2.5.2 |
Edgar Reynaldo
Major Reynaldo
May 2007
![]() |
Can you post the audio file as an attachment please? I will test this on my Win10 MinGW-W64 setup with Allegro 5.2.6. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
schollexpos
Member #16,751
October 2017
|
The Music kind of gives away what I'm working on |
Edgar Reynaldo
Major Reynaldo
May 2007
![]() |
What I'm getting at is that the ogg container that holds the audio file has a stream adjuster. I don't know if they're common for all formats. Can you load the file in VLC and tell me what the audio codec in use is? EDIT My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
schollexpos
Member #16,751
October 2017
|
The codec is just plain Vorbis Audio, according to VLC. I've exported the file from audacity, so I don't think there should be anything wrong about it(?) No I haven't, I've relied on al_load_audio_stream automatically starting the file. But now I've tried to setting the stream to play manually, that didn't change anything. Edit: |
Peter Hull
Member #1,136
March 2001
|
I had a very quick look at the Allegro code. It seems that you can only seek to within the loop you set in al_set_audio_stream_loop_secs. You set that to 0..47.2secs then tried to seek outside it. You could maybe try resetting the loop to whatever and then seeking. Relevant part is here: static bool ogg_stream_seek(ALLEGRO_AUDIO_STREAM *stream, double time) { AL_OV_DATA *extra = (AL_OV_DATA *) stream->extra; if (time >= extra->loop_end) return false; #ifndef TREMOR return (lib.ov_time_seek_lap(extra->vf, time) != -1); #else return lib.ov_time_seek(extra->vf, time*1000) != -1; #endif }
|
schollexpos
Member #16,751
October 2017
|
Of course, that was it! I haven't even thought about that I should be changing the loop-points first and only seek after that. Thank you! |
Peter Hull
Member #1,136
March 2001
|
Strangely it's OK to seek before the looped section (you can see in the code snippet there's no check against loop_start) - in which case it plays through to the loop end and then starts to repeat. I don't know if that's a bug or useful behaviour, what do you think?
|
|