locked
Change the volume of an IMFSample containing audio data

    Question

  • I have a windows store app where I use Media Foundation to work with audio. In the app I use a SourceReader to read samples from an audio file and then use a SinkWriter to write the samples to another file. This all works fine. Now I want to be able to change the volume of the audio samples in order to create a fade out effect. How would I have to do that?

    Thanks in advanhce!

    Ronald

    Friday, February 1, 2013 2:15 PM

Answers

  • Hello Ronald,

    In your current scenario when using the SourceReader / SinkWriter, there is no simple solution to your problem. This is due to the fact that the SourceReader / SinkWriter are implemented at a very low level and do not use the standard MF Session Manger implementation. Because of this you will need to implement your own volume attenuation code. This should be extremely easy to do if you have access to the raw PCM audio data. Remember that each sample equates to a "volumetric magnitude" of the signal at the given point in time. Because of this you can create a simple linear algorithm to calculate the decrease in magnitude over the time interval you choose.

    I hope this helps,

    James


    Windows SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Wednesday, February 20, 2013 10:12 PM
    Moderator

All replies


  • Hi,

    I found IMFSimpleAudioVolume interface API in MF, but it cannot be used in Windows Store App
    http://msdn.microsoft.com/en-us/library/windows/desktop/ms693496(v=vs.85).aspx

    Best regards,
    Jesse


    Jesse Jiang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, February 4, 2013 5:59 AM
  • Jesse,

    Do you mean that there is no easy way of achieving this in a Windows Store app?

    What about directly changing the data of the buffer in the sample. For example by decreasing all the BYTE values in the buffer with a factor, or with a fixed amount. I have have no knowledge at all of how audio data looks like, so this might not make sense what I am suggesting.

    Ronald

    Monday, February 4, 2013 7:41 AM
  • Hello Ronald,

    In your current scenario when using the SourceReader / SinkWriter, there is no simple solution to your problem. This is due to the fact that the SourceReader / SinkWriter are implemented at a very low level and do not use the standard MF Session Manger implementation. Because of this you will need to implement your own volume attenuation code. This should be extremely easy to do if you have access to the raw PCM audio data. Remember that each sample equates to a "volumetric magnitude" of the signal at the given point in time. Because of this you can create a simple linear algorithm to calculate the decrease in magnitude over the time interval you choose.

    I hope this helps,

    James


    Windows SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Wednesday, February 20, 2013 10:12 PM
    Moderator
  • I want to create a visual representation of the left and right volume levels of the sample - once I have a  IMFSample, what do I do with that to get a numeric value of the sample's volume?

    I want to create a graphical view of the samples.

    Thanks,

    Michael


    <p>Michael S. Scherotter<br/> Media Experience Evangelist, Microsoft Corporation<br/> <a href="http://blogs.msdn.com/synergist">Blog</a>, <a href="http://twitter.com/synergist"> Twitter</a>, <a href="http://facebook.com/synergist">Facebook</a> </p>

    Monday, April 7, 2014 9:27 PM