-
Hi, I have a song that has two parts: 'A' and 'B'. A is the kick-in of the song and joins seamlessly with B. B is loopable. I tried chaining the data_sources with pointers as described in this example. loadSound(sound.mainMenu_start, "data/main_menu_start.ogg", &sound.mainMenuGroup);
loadSound(sound.mainMenu_loop, "data/main_menu_loop.ogg", &sound.mainMenuGroup);
ma_sound_set_looping(&sound.mainMenu_loop, true);
ma_data_source_set_next(sound.mainMenu_start.pDataSource, sound.mainMenu_loop.pDataSource); This is the music for the main menu of my game. There is a kick-in music part, then the loopable part of the song.
The problem is that it only works the first time I enter the main menu. When I return to the main menu the music keeps playing from where it left in the loopable sound, instead of playing from the start the kick-in sound. What should I do? Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You need to reset the chain's current data source: To give you some background, |
Beta Was this translation helpful? Give feedback.
You need to reset the chain's current data source:
ma_data_source_set_current(mainMenu_Start.pDataSource, mainMenu_Start.pDataSource);
To give you some background,
ma_sound_seek_to_pcm_frame()
is just a wrapper aroundma_data_source_seek_to_pcm_frame()
. That function will only update the cursor of the data source you specify at a local level, meaning it does not consider the entire chain. Since your chain has moved onto the looping section, that looping section becomes the "current" data source in the chain, and since the "current" data source has not been reset, miniaudio will assume that it's still on the looping part of the chain.