How to calculate audio frame duration:
The WAVEFORMATEX::nBlockAlign and dwSampleSize, dwScale/dwRate in the audio strh chunk decide the audio frame duration.
There are two audio type: CBR and VBR.
The dwSampleSize decide which is CBR or VBR.
If dwSampleSize is nozero, the audio is CBR:
The audio frame duration = chunk size / dwSampleSize * dwScale / dwRate.
but I found some streams must calculate on frame, then the audio chunk include multi-frames(if the dwSampleSize is non-zero, then multiple samples of data can be grouped into a single chunk within file):
The audio frame duration = (chunk size + dwSampleSize - 1) / dwSampleSize * dwScale / dwRate.
If dwSampleSize is zero, the audio is VBR:
There are two definition for dwScale/dwRate:
Microsoft: duration per sample
Others(avi format for dshow and some doc on net, some streams are true): duration per frame
Duration per sample:
dwScale: bytes of one sample.
dwRate: bytes per second.
nBlockAlign: the largest size of sample.
The audio frame duration = roundup(chunk size / nBlockAlign) * dwScale / dwRate.
So nBlockAlign >= dwScale.
Duration per frame:
dwScale: the number of samples in one frame.
dwRate: sample rate.
nBlockAlign: the largest size of frame.
The audio frame duration = roundup(chunk size / nBlockAlign) * dwScale / dwRate.
So nBlockAlign >= dwScale(sample size >=1).
There are same formula what ever the definition of dwScale / dwRate is duration per sample or duration per frame.
But there are restriction: nBlockAlign >= dwScale. The nBlockAlign is bad value if nBlockAlign < dwScale.