Audio Signal Processing using Directshow(ISampleGrabber)
-
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...
-
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...
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:
-
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...
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:
-
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:
-
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:
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