XAudio2: how to convert seconds to samples

Started by
2 comments, last by Krohm 10 years, 12 months ago

hello,

in the Xaudio2 API you can specify the start and endposition only in samples.

but i require them to be set by seconds.

now i am looking for a way to convert seconds into samples but havent found much information on how to do that so far.

any help on this is highly appreciated!

Advertisement

When you got the sample rate (e.g. 48000), then just multiply this by the number of seconds:


float startInSeconds = ...
float endInSeconds = ...

startPosition = (int)((float)sampleRate * startInSeconds);
endPosition = (int)((float)sampleRate * endInSeconds);
 

thanks, but dont i have to take into account the number of channels?

Look at XAUDIO2_BUFFER. PlayBegin and PlayLength are specified in samples. No need to multiply by channel count, nor bit depth.

If you think at it, this makes sense, the sample is really meant to be the finest granularity entity. If you had to select the region by byte count, you could end up slicing a sample.

Previously "Krohm"

This topic is closed to new replies.

Advertisement