Hi,
I’m hoping someone can help me out with a method to achieve these goals:
- I have a stream of PCM samples generated procedurally at runtime.
- I don’t know how many samples there are or length of stream at fmod “createSound/playSound” time
- I would like to play the stream back, and then have the channel stop once all the samples are played (ie, once the generator tells me that no more samples will be coming).
So far, I have tried:
A looping streaming sound with a pcmread callback to pull samples from the input buffer - once no more samples are coming, I tried various ways of stopping the looping/stopping the sound etc… but nothing stops “cleanly” at the end of the samples - either the stream is cut off (if fmod channel is stopped after the last sample is supplied to fmod), or loops over the last samples a couple of times (depending on decode buffer size etc).
A custom codec: mostly works. Return an error code (eg FMOD_ERR_FILE_ENDOFDATA ) from the codec read callback, but again has issues at the end of the stream - some of the samples at the end of the stream don’t playback correctly once the error is returned from the read function.
A custom DSP - I haven’t tried this yet, but I can’t see anything in the documentation about how to tell fmod the DSP is “finished” (so that the channel stops) from within the DSP callback functions. It seems I would also have to deal with resampling and mixing differing number of input channels to output channels etc if I went down this route.
I did find another piece of info today that I could apparently set the sound length to -1 in createSound, which means I wouldn’t have to use looping for the stream to continuously play, but I’m still not sure how to get the channel to stop after all the samples have played.
None of the samples I have seen deal with this situation - they all seem to stop the channel “manually” at an arbitrary point (eg, on a button press), rather than stopping automatically when “all samples have played”
Does anyone have any advice please?
Thanks,
Damian.