dimanche 8 février 2015

Mixing two audio in Windows Media Foundation

I am trying to mix two audio in Windows media foundation. In MATLAB I did it adding sample by sample from each audio. In windows media foundation I can access the samples using IMFSourceReader and IMFSample which gives me a chunk of data for some duration. For example first call to sourceReader->ReadSample() gives me first t duration of data. next call to it gives me next t turation of data. Each t duration of data lies in buffer size of L.


When I tried to access the audio samples using media foundation this way I expected that the duration t and buffer length L would be same each time I call ReadSample(). But I get different t and L each time I call ReadSample() for the audios. For example some times I get buffer length 16384, duration 928798 (in 100 nanosecond unit) and sometimes I get buffer length 8192 with duration 464399.


This is a huge problem for me as I cannot add two audio with different buffer length and duration. Is it possible to get fixed size buffer and fixed duration of IMFSamples? If not how can I mix two audio in media foundation?


For reading audio I am using this code.



CHECK_HR(MFCreateMediaType(&spMFTypeIn));
CHECK_HR(spMFTypeIn->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Audio));
CHECK_HR(spMFTypeIn->SetGUID(MF_MT_SUBTYPE, MFAudioFormat_PCM));
CHECK_HR(spMFTypeIn->SetUINT32(MF_MT_AUDIO_BITS_PER_SAMPLE, BITS_PER_SAMPLE));
CHECK_HR(spMFTypeIn->SetUINT32(MF_MT_AUDIO_SAMPLES_PER_SECOND, 44100));
CHECK_HR(spMFTypeIn->SetUINT32(MF_MT_AUDIO_NUM_CHANNELS, 2));
CHECK_HR(spMFTypeIn->SetUINT32(MF_MT_AUDIO_PREFER_WAVEFORMATEX, 1));
CHECK_HR(spMFTypeIn->SetUINT32(MF_MT_AUDIO_BLOCK_ALIGNMENT, 16 / 8 * 2));
CHECK_HR(spMFTypeIn->SetUINT32(MF_MT_AUDIO_AVG_BYTES_PER_SECOND, 16 / 8 * 2 * 44100));

Aucun commentaire:

Enregistrer un commentaire