I want to set the Loop End to the exact end of a WAV file. However, set_loop_end() requires the sample length. How do I calculate the total sample size of a WAV file?
set_loop_end()
Probably a matter of calculating the samples per second and multiplying by the seconds. But sounds also emit a signal when they finish, so you can listen for that and choose what to do (whether to loop or do something else in a function). You can also set the WAV to either always loop or only play once in the import settings.
Thanks, the looping has to be done dynamically so I can't use the import method. There should be a simple function that returns the sample count of the audio.
Ok. Here is what I have done:
AudioStreamSample a = (AudioStreamSample)audAudio.Stream; a.LoopMode = AudioStreamSample.LoopModeEnum.Forward; a.LoopBegin = 0; a.LoopEnd = (int)(a.MixRate * a.GetLength());
This seems to work.
Okay. Still doesn't make sense to me since you can listen for the signal when the music ends.
You can listen for the finished() signal, but that requires another function and sometimes there can be a brief delay from what I hear. AudioStreamSample already has a Loop built-in ability. You just have to know how many samples are in the WAV file.
Okay, I see what you are saying.