Hello,
I have started to work on a "smart" music system. I just have different versions of a song, and every time, the player level increases, the corresponding version of a song gets to play. All versions are stored in one audio file and thus in one stream, I only readjust the position and the looping points. To avoid straight cuts but also not having to wait through the entire length of the song to change it, the game knows the position of the sections in the song, and then waits for the current section to end and then jumps to the next section, but this time of course in the new version of the song.
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:
I have an Audio Manager that recieves a Message from the Gameplay section, when a level-up occurs. This AudioManager has an object containing the ALLEGRO_STREAM of the currently playing track. With this it computes the amount of seconds to wait until the current section ends and where to jump to, and then starts an ALLEGRO_THREAD that waits and then calls the stream functions mentioned above. The thread doesn't seem to be a problem, the seeking fails even without it (the rest of my code is single threaded).
Thanks in advance!
]]>Hello schollexpos
Can you produce a simple code example that demonstrates this? Does seeking not work with any audio stream?
]]>Hello Edgar, thanks for your quick reply!
Here, is a condensed example:
I'm amazed that the problem is not some kind of side effect from somewhere else in my engine The console shows the output when pressing N, but the audio stream plays as if nothing had happened.
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
]]>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.
]]>The Music kind of gives away what I'm working on
]]>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
Did you ever call al_set_audio_stream_playing(true) or false?? I don't see that in the example.
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:
I've tried to replace my music file with the menu music from the allegro skater demo, but al_seek_audio_stream_secs() still returns false
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:
https://github.com/liballeg/allegro5/blob/50460b7fc48d6bafff2db309fe3cd5def80e3863/addons/acodec/ogg.c#L309-L319
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 }
]]>
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!
]]>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?
]]>