Jump to content

  • Log In with Google      Sign In   
  • Create Account


XAudio2: how to convert seconds to samples


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 ehmdjii   Members   -  Reputation: 234

Like
0Likes
Like

Posted 18 April 2013 - 02:59 AM

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!



Sponsor:

#2 Ashaman73   Crossbones+   -  Reputation: 7122

Like
0Likes
Like

Posted 18 April 2013 - 05:00 AM

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);
 


#3 ehmdjii   Members   -  Reputation: 234

Like
0Likes
Like

Posted 18 April 2013 - 06:26 AM

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



#4 Krohm   Crossbones+   -  Reputation: 3049

Like
0Likes
Like

Posted 19 April 2013 - 02:01 AM

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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS