# IMFSample audio sample count

• ### Question

• Hi,

a IMFSample represents a container for video or audio media data. For video, a sample typically contains one video frame. For audio data, a sample typically contains multiple audio samples, rather than a single sample of audio.

How can I get the information about the correct sample count in an IMFSample?

best regards

saoirse

Thursday, October 15, 2015 7:59 AM

• Why are you dividing by 8 ?

Your Block Alignment is 4, which means 198212 divided by 4 is 49553 ( Frames ).

The equation is :

Frames = 198212 / ((2 * 16) / 8)

Regards,

Francis

• Marked as answer by Friday, October 16, 2015 2:21 PM
• Edited by Tuesday, May 31, 2016 3:29 PM Edit
Friday, October 16, 2015 12:42 PM

### All replies

• You can get the bits per sample using

`IMFMediaType * mediaType;m_sourceReader->GetCurrentMediaType(MF_SOURCE_READER_FIRST_AUDIO_STREAM, &mediaType);UINT32 bitsPerSample = MFGetAttributeUINT32(mediaType, MF_MT_AUDIO_BITS_PER_SAMPLE, 16);`

and you get the buffer size when you lock to get the data

`buffer->Lock(&audioData, NULL, &bufferSize);`
I calculate from that. (Well, I only actually tried with 16 bits per sample.)
• Marked as answer by Friday, October 16, 2015 9:52 AM
• Unmarked as answer by Friday, October 16, 2015 10:20 AM
Thursday, October 15, 2015 2:59 PM
• I`m not sure if I understand everything.

In my example, I get a "bufferSize" of 198212 from the IMFMediaBuffer. The sample rate is 48000, 2 channels, 16 bits per sample...

To get the number of samples in the IMFMediaBuffer, I devide 198212 by 8. Unfortunately this is not a whole number - the result is 24776.5. It seems to me that there is something wrong with my interpretation of the IMFMediaBuffer. I also convert the IMFSample to a contiguous buffer.

The sample duration is 10323541, which is also very strange.

0,
&streamIndexGetBack,
&flags,
&llTimeStamp,
sample);

LONGLONG duration;
sample->GetSampleDuration (&duration);

hr = sample->ConvertToContiguousBuffer (&mediaBuffer);

hr = mediaBuffer->Lock (&pAudioData, NULL, &cbBuffer);

Friday, October 16, 2015 10:28 AM
• Why are you dividing by 8 ?

Your Block Alignment is 4, which means 198212 divided by 4 is 49553 ( Frames ).

The equation is :

Frames = 198212 / ((2 * 16) / 8)

Regards,

Francis

• Marked as answer by Friday, October 16, 2015 2:21 PM
• Edited by Tuesday, May 31, 2016 3:29 PM Edit
Friday, October 16, 2015 12:42 PM