• Advertisement
Sign in to follow this  

XAudio2: how to convert seconds to samples

This topic is 1738 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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);
 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement