Friday, June 1, 2012

Calculating PCM Duration From Size

First step is to calculate the number of samples. This would be:

numSamples: number of samples
numBytes: size of data in bytes
numChannels: number of channels e.g. 1 for mono, 2 for stereo
numBytesPerSample: number of bytes per sample e.g. 1 for PCM 8-bit, 2 for PCM 16-bit
sampleRate: the sample rate of the PCM

numSamples = (numBytes / numChannels) / numBytesPerSample

Duration (milliseconds) = (numSamples * 1000) / sampleRate

No comments:

Post a Comment