Memorystream: fast looping - small delay at first play #471
-
so after my mixer is working PERFECTLY !!! so for my little game the user presses the fire button and the firing sound is played - if he keeps pushing the button then it is set to "autofire" - so every 125ms i reset the sound by calling begin() BUT: the first sound is played longer (maybe 200ms) and then it repeats correctly with 125ms. i logged everything, it is always triggered at 125. AND: if i let go of the button and do not wait until the sound has finished and press the button again - it is also perfect. after the sound finished the behavior is the same as before. sorry it is easy to hear but not easy to describe ;-) expected: but it is: here my code from the loop ( i debounce by setting a timestamp in an interrupt. and i have a mixer for a sound if i get hit or something else)
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Here are my 2 cents: Audio is only played smoothly if all the necessary audio data is provided in time. If you put everthing into one big fat loop there is a risk that this might not be the case. If I would design a game, I would put the audio output into a separate task and manage the output via an audio queue. If you want to move into this direction, I suggest to have a look at this library which should be pretty easy to use. Alternatively you can call copier.copyAll() which plays the whole "file" - but blocks the user from doing any actions, while the audio is processed. Your logic with all the state variables is quite difficult to understand and to reason about. I would recommend to use a much more declarative approach like in this example |
Beta Was this translation helpful? Give feedback.
-
I am sorry but I dont quite understand what the problem is. |
Beta Was this translation helpful? Give feedback.
Here are my 2 cents: Audio is only played smoothly if all the necessary audio data is provided in time. If you put everthing into one big fat loop there is a risk that this might not be the case.
If I would design a game, I would put the audio output into a separate task and manage the output via an audio queue. If you want to move into this direction, I suggest to have a look at this library which should be pretty easy to use.
Alternatively you can call copier.copyAll() which plays the whole "file" - but blocks the user from doing any actions, while the audio is processed.
Your logic with all the state variables is quite difficult to understand and to reason about. I would recommend to u…