[Openal] How to calculate duration of play in openal

Daniel PEACOCK dpeacock at creativelabs.com
Fri Jun 22 09:11:19 PDT 2007





Hi Anand,

To compute the duration of a sample you need to know the byte length of the
audio data and the average bytes per second (and the playback pitch if it
not going to be equal to 1.0).

For a PCM wavefile, the average bytes-per-second is one of the parameters
in the wave header and the byte length of the audio data immediately
follows the 'data' RIFF ID chunk.

// dwDataSize is number of bytes of audio data
// nAvgBytesPerSec is the average bytes per second read from wave header
(or computed using SamplesPerSecond * Number of Channels * Bits Per Sample
/ 8)
// flPlayback pitch is the pitch parameter set on the Source (default is
1.0)

float flDurationSeconds = ((float)dwDataSize / nAvgBytesPerSec ) /
flPlaybackPitch;

NOTE : If you are using Doppler then that will affect the duration of
playback too ... and things get more complicated if you want to include
that in your calculations ;0)

Dan
Creative Labs, Inc.

Notice
The information in this message is confidential and may be legally
privileged.  It is intended solely for the addressee.  Access to this
message by anyone else is unauthorized.  If you are not the intended
recipient,  any disclosure,  copying or distribution of the message,  or
any action taken by you in reliance on it,  is prohibited and may be
unlawful.  If you have received this message in error,  please delete it
and contact the sender immediately.  Thank you.




                                                                           
             anand                                                         
             <anand.cs at robosof                                             
             tin.com>                                                   To 
             Sent by:                  <openal at opensource.creative.com>    
             openal-bounces at op                                          cc 
             ensource.creative                                             
             .com                                                  Subject 
                                       [Openal] How to calculate duration  
                                       of play in openal                   
             06/21/2007 11:35                                              
             PM                                                            
                                                                           
                                                                           
                                                                           
                                                                           




Hi All,

I am new to this openal can any one tell me how to calculate time duration
for audio file.well in core audio
Float64 fileDuration= (nPackets * fileFormat.mFramesPerPacket) /
fileFormat.mSampleRate;
this works. But how to calculate in openal:(
any help will be greatly appreciated.

Thanks in advance
-----------------
Anand



-----------------------------------------------
Robosoft Technologies - Come home to Technology

Disclaimer: This email may contain confidential material. If you were not
an intended recipient, please notify the sender and delete all copies.
Emails to and from our network may be logged and monitored. This email and
its attachments are scanned for virus by our scanners and are believed to
be safe. However, no warranty is given that this email is free of malicious
content or virus.



_______________________________________________
Openal mailing list
Openal at opensource.creative.com
http://opensource.creative.com/mailman/listinfo/openal

ForwardSourceID:NT0004336E



More information about the Openal mailing list