mackron / miniaudio

Audio playback and capture library written in C, in a single source file.
https://miniaud.io
Other
4.07k stars 361 forks source link

Start a playback from a specific point in millisecond ? #684

Closed Duddy67 closed 1 year ago

Duddy67 commented 1 year ago

Hi all, Is there a way to start a playback from a specific point in millisecond ? The only function I found so far to do this is:
ma_sound_seek_to_pcm_frame(&sound, someValue); but the required value is in pcm frames.

Thank you for enlightening me on this subject.

mackron commented 1 year ago

You can derive the position in frames using the sound's sample rate. Use ma_engine_get_sample_rate() to get the rate:

seekPointInFrames = (seekPointInMilliseconds * ma_engine_get_sample_rate(&engine)) / 1000;

The sample rate is in seconds, hence the division by 1000.