Re: Fwd: AudioConverterFillBuffer - resampling
Re: Fwd: AudioConverterFillBuffer - resampling
- Subject: Re: Fwd: AudioConverterFillBuffer - resampling
- From: "Harry Mahoney" <email@hidden>
- Date: Wed, 10 Jul 2002 08:42:57 -0600
Chris,
As you suggested, OSType worked. There are still other problems with AudioConverters though.
I am passing in 8000, 16-bit, 2-channel samples with an 8k sample rate (1 second of audio data). This works out to a buffer of 32000 bytes. I want AudioConverter to convert it to the 44.1k normalized floating point the audio system wants.
Problem #1:
When I pass this info into AudioConverterGetProperty with kAudioConverterPropertyCalculateOutputBufferSize, I get back 64000. Clearly, it is not calculating for the upsample, only for the floating point conversion.
So I do my own calculation and come up with 352800 bytes (44100 * 4-bytes * 2-channels) and allocate an output buffer this size.
Problem #2:
With the successful setting of the polyphase algorithm, when I pass this info into AudioConverterConvertBuffer, it returns kAudioConverterErr_InvalidOutputSize. This cannot be right since it should still only produce 1 second of audio. One additional piece of information: the default SRC algorithm does not give an error; it just doesn't do a very good job on the upsample.
Any suggestions?
Harry Mahoney
>
>> Chris Rogers <email@hidden> 07/09/02 06:02PM >>>
Instead of:
int srcAlgorithm = kAudioUnitSRCAlgorithm_Polyphase;
try:
OSType srcAlgorithm = kAudioUnitSRCAlgorithm_Polyphase;
This has worked for me. The size of the property needs to be an "OSType"
Good Luck,
Chris Rogers
Core Audio Engineer
Apple Computer
>
I tried to set this property for my AudioConverter using the following code:
>
>
int srcAlgorithm =
>
kAudioUnitSRCAlgorithm_Polyphase; // sample rate conversion
>
algorithm = Polyphase (i.e., higher-quality)
>
err = AudioConverterSetProperty(audioConverter,
>
>
kAudioConverterSampleRateConverterAlgorithm,
>
>
sizeof(srcAlgorithm),
>
>
&srcAlgorithm);
>
>
It returns with err == kAudioConverterErr_PropertyNotSupported. I
>
take it I am doing something wrong, but what?
>
>
Thanks,
>
Harry Mahoney
>
>
>>> Chris Rogers <email@hidden> 07/03/02 17:28 PM >>>
>
>There *is* audible aliasing when doing extreme sample-rate conversion
>
>(like from 44.1KHz down to 8KHz) when using the medium quality conversion
>
>algorithm which is the default algorithm. In order to use the high-quality
>
>one you need to set a property on the converter. Have a look in
>
>AudioConverter.h at the kAudioConverterSampleRateConverterAlgorithm
>
>property. Defined in AudioUnitProperties.h is the
>
>kAudioUnitSRCAlgorithm_Polyphase constant for the higher-quality
>
>algorithm. This should sound much better for your purposes. We *are*
>
>interested in your impressions and opinions about the quality of
>
>these algorithms as this is one area we may want to focus our
>
>attention to improve quality and performance.
>
>
>
>Chris Rogers
>
>Core Audio
>
>Apple Computer
>
>
>
>
>
>
>
>
>
>>
>
>>Well, I couldn't use AudioConverterConvertBuffer because it
>
>>returned -50 as an error code. I didn't know what this meant until
>
>>someone else on the list mentioned that AudioConverterConvertBuffer
>
>>expects integral decimation or interpolation factors. Which makes
>
>>sense, since you pass in a fixed-size buffer and get out a
>
>>fixed-size buffer.
>
>>
>
>>So I tried calling AudioConverterFillBuffer whenever I needed the
>
>>next block of 8kHz samples. I registered an AudioDeviceIOProc with
>
>>the default input device and just dumped the raw data into a ring
>
>>buffer (a trick someone else mentioned on here to avoid
>
>>synchronization problems). Then the AudioConverterFillBuffer source
>
>>callback would read out of that ring buffer. I saw that
>
>>AudioConverterFillBuffer was calling the source callback a couple
>
>>of times each time I needed another block of 8kHz samples. But the
>
>>resulting audio sounded like it had aliasing problems.
>
>>
>
>>Maybe it's because the filter used is not aggressive enough? I had
>
>>to make my lowpass FIR filter have 1.5dB of passband ripple
>
>>(0-3.7kHz) and 60dB of stopband attenuation (4.3kHz-...) with an
>
>>input frequency of 44100 * 80 Hz. I was previously trying 2.5dB of
>
>>passband ripple and 30dB of stopband attenuation but the aliasing
>
>>was still bad.
>
>>
>
>>Out of curiousity, how are the filters used by the resampling
>
>>procedures decided upon? Is there a set of pre-defined filter
>
>>coefficients used for common resampling choices? Or does one get
>
>>dynamically generated the first time a specific sample rate
>
>>conversion is attempted?
>
>>
>
>>Also, what do you mean by high and medium quality resampling
>
>>algorithms? I didn't find any reference to different quality
>
>>resampling algorithms in the AudioConverter headers.
>
>>
>
>
>
>>>Date: Tue, 2 Jul 2002 16:48:15 -0700
>
>>>From: Chris Rogers <email@hidden>
>
>>>
>
>>>Actually, both of our resampling algorithms (high and medium quality)
>
>>>perform filtering operations. I'm interested to learn more details
>
>>>about the kind of problem you encountered.
>
>>>>I just ran into this problem. The AudioConverterConvertBuffer and
>
>>>>AudioConverterFillBuffer functions didn't work for me. (The former
>
>>>>because it only does integral resampling, the latter because it
>
>>>>doesn't pass the data through a filter before resampling. (I suppose
>
>>>>I could put the filter in the input callback, but it was easier for
>
>>>>me to just grab the library I mention in the next paragraph.)
>
>>>>
>
>>>>So, to convert 44.1kHz down to 8kHz, I used a combination of the
>
>>>>open-source dspGuru resampling algorithms (http://www.dspguru.com/)
>
>>>>and Matlab to create a lowpass FIR filter. If you want to see my
>
>>>>efforts, along with the Matlab instructions, checkout Open Mash
>
>>>>(http://www.openmash.org/) from CVS and look in the
>
>>>>mash/audio/audio-macosx.[h|cc] and mash/audio/decim_3528kHz_8kHz.inc
>
>>>>files.
>
>>>>
>
>>--
>
>>Wesley Miaw, Berkeley Multimedia Research Center
>
>>email@hidden
>
>>_______________________________________________
>
>>coreaudio-api mailing list | email@hidden
>
>>Help/Unsubscribe/Archives:
>
>>http://www.lists.apple.com/mailman/listinfo/coreaudio-api
>
>>Do not post admin requests to the list. They will be ignored.
>
_______________________________________________
>
coreaudio-api mailing list | email@hidden
>
Help/Unsubscribe/Archives:
>
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
>
Do not post admin requests to the list. They will be ignored.
>
_______________________________________________
>
coreaudio-api mailing list | email@hidden
>
Help/Unsubscribe/Archives:
>
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
>
Do not post admin requests to the list. They will be ignored.
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.