Jump to content

View more

Image of the Day

Inventory ! Va falloir trouver une autre couleur pour le cadre D: #AzTroScreenshot #screenshotsaturday https://t.co/PvxhGL7cOH
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

XAudio2: how to convert seconds to samples

4: Adsense

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 terri12   Members   

238
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!



#2 Ashaman73   Members   

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

Ashaman

 

Gnoblins: Website - Facebook - Twitter - Youtube - Steam Greenlit - IndieDB - Gamedev Log


#3 terri12   Members   

238
Like
0Likes
Like

Posted 18 April 2013 - 06:26 AM

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



#4 MaxDZ8   Members   

5008
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.


Previously "Krohm"





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.