Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Audio Signal Processing using Directshow(ISampleGrabber)

Audio Signal Processing using Directshow(ISampleGrabber)

Scheduled Pinned Locked Moved C / C++ / MFC
questionalgorithmsdata-structureshelptutorial
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Akin Ocal
    wrote on last edited by
    #1

    Hello I want to build an audio processing application using ISampleGrabber interface. 1. How can I learn sampling rates of audio streams ? Its callback function gives me "SampleTime"s and size of buffers. I guess I can get sampling rate as kbps. By the way after I get sampling rate as kbps how can I express in Hz\kHz ? 2. I know that your buffer size must be power of 2 to implement FFT algorithm ( at least Radix2 , I'm new on that area). So size of buffers ISamplegrabber gives are not always (almost never) powers of 2. So how should I handle this problem ? 3.Callback function gives a buffer of samples as BYTE* (array of unsigned chars). So to make an audio process , how should I get double or float values instead of unsigned chars ? For example should it be like this ? : double realSampleValue -> pBuffer[0].......pBuffer[7] ( Here I mean to make this programtically using bit operators) Thank you very much...

    M 2 Replies Last reply
    0
    • A Akin Ocal

      Hello I want to build an audio processing application using ISampleGrabber interface. 1. How can I learn sampling rates of audio streams ? Its callback function gives me "SampleTime"s and size of buffers. I guess I can get sampling rate as kbps. By the way after I get sampling rate as kbps how can I express in Hz\kHz ? 2. I know that your buffer size must be power of 2 to implement FFT algorithm ( at least Radix2 , I'm new on that area). So size of buffers ISamplegrabber gives are not always (almost never) powers of 2. So how should I handle this problem ? 3.Callback function gives a buffer of samples as BYTE* (array of unsigned chars). So to make an audio process , how should I get double or float values instead of unsigned chars ? For example should it be like this ? : double realSampleValue -> pBuffer[0].......pBuffer[7] ( Here I mean to make this programtically using bit operators) Thank you very much...

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      Akin Ocal wrote:

      How can I learn sampling rates of audio streams ?

      If you use the sample callback, you'll get a new media type with the sample every time it changes.  You can also get the media type on the sample grabber filter's input pin after the graph is built. It sounds like you're using the buffered callback, which isn't recommended. You'll have better results using the sample callback.  You'll get even better results if you implement your own grabber filter.

      Akin Ocal wrote:

      2. I know that your buffer size must be power of 2 to implement FFT algorithm ( at least Radix2 , I'm new on that area). So size of buffers ISamplegrabber gives are not always (almost never) powers of 2. So how should I handle this problem ?

      You'll need to buffer enough data to feed your processing algorithm if necessary.  That's dependent on your implementation.

      Akin Ocal wrote:

      3.Callback function gives a buffer of samples as BYTE* (array of unsigned chars). So to make an audio process , how should I get double or float values instead of unsigned chars ?

      You need to convert the PCM sample data to whatever format your processing code needs. For example, you may need to convert signed 16-bit PCM samples to doubles between -1.0 and 1.0. Your code will need to do that math.

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      1 Reply Last reply
      0
      • A Akin Ocal

        Hello I want to build an audio processing application using ISampleGrabber interface. 1. How can I learn sampling rates of audio streams ? Its callback function gives me "SampleTime"s and size of buffers. I guess I can get sampling rate as kbps. By the way after I get sampling rate as kbps how can I express in Hz\kHz ? 2. I know that your buffer size must be power of 2 to implement FFT algorithm ( at least Radix2 , I'm new on that area). So size of buffers ISamplegrabber gives are not always (almost never) powers of 2. So how should I handle this problem ? 3.Callback function gives a buffer of samples as BYTE* (array of unsigned chars). So to make an audio process , how should I get double or float values instead of unsigned chars ? For example should it be like this ? : double realSampleValue -> pBuffer[0].......pBuffer[7] ( Here I mean to make this programtically using bit operators) Thank you very much...

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3

        Akin Ocal wrote:

        I guess I can get sampling rate as kbps. By the way after I get sampling rate as kbps how can I express in Hz\kHz ?

        I forgot about this question... When you get the media format from the filter, ISample, or graph, you will have a WAVEFORMATEX structure.  In that structure is a nSamplesPerSec member.  That value is in Hz, and when divided by 1000, KHz. Mark

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        A 2 Replies Last reply
        0
        • M Mark Salsbery

          Akin Ocal wrote:

          I guess I can get sampling rate as kbps. By the way after I get sampling rate as kbps how can I express in Hz\kHz ?

          I forgot about this question... When you get the media format from the filter, ISample, or graph, you will have a WAVEFORMATEX structure.  In that structure is a nSamplesPerSec member.  That value is in Hz, and when divided by 1000, KHz. Mark

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          A Offline
          A Offline
          Akin Ocal
          wrote on last edited by
          #4

          Thank you very much indeed...

          1 Reply Last reply
          0
          • M Mark Salsbery

            Akin Ocal wrote:

            I guess I can get sampling rate as kbps. By the way after I get sampling rate as kbps how can I express in Hz\kHz ?

            I forgot about this question... When you get the media format from the filter, ISample, or graph, you will have a WAVEFORMATEX structure.  In that structure is a nSamplesPerSec member.  That value is in Hz, and when divided by 1000, KHz. Mark

            Mark Salsbery Microsoft MVP - Visual C++ :java:

            A Offline
            A Offline
            Akin Ocal
            wrote on last edited by
            #5

            Thank you very much for your answers. But I have some questions again : 1. I can succesfully get AM_MEDIA_TYPE from output pin of my source filter (I use audio files as sources in my case ) But unfotunately I cannot get pbFormat even formattype of AM_MEDIA_TYPE (pbFormat -> bad pointer, formattype-> GUID_NULL ) I use the code below to get AM_MEDIA_TYPE , I can get other parameters succesfully :( BOOL MyClass::GetMediaTypeOfConnectedPin (IBaseFilter* pFilter,PIN_DIRECTION pDir,AM_MEDIA_TYPE* pMediaType,int index) { HRESULT hr ; IPin* fPin ; hr = this->GetPin(pFilter,pDir,index,&fPin); if(hr != S_OK ) return FALSE ; if ( (fPin->ConnectionMediaType(pMediaType)) != S_OK) return FALSE ; if ( pMediaType->formattype == FORMAT_WaveFormatEx) { WAVEFORMATEX* temp = (WAVEFORMATEX*) malloc(sizeof(WAVEFORMATEX)); temp = ( WAVEFORMATEX *)pMediaType->pbFormat; ... free(temp); } return TRUE ; } 2. What is the order of samples if there are 2 channels. For example is it something like : Left Channel -> pBuffer[0] ... pBuffer[n/2] Right Channel -> pBuffer[n/2+1] .... pBuffer[n] or Left Channel-> pBuffer[even_indexes] Right Channel -> pBuffer[odd_indexes] 3. After I get my samples as WORDs(unsigned shorts) , what should I do to get floats from them ? Thank you very much Regards

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups