tags:

views:

97

answers:

1

I am looking at the iPhone aurioTouch example specifically on the following code:

static OSStatus PerformThru(
                        void                        *inRefCon, 
                        AudioUnitRenderActionFlags  *ioActionFlags, 
                        const AudioTimeStamp        *inTimeStamp, 
                        UInt32                      inBusNumber, 
                        UInt32                      inNumberFrames, 
                        AudioBufferList             *ioData)

{ aurioTouchAppDelegate *THIS = (aurioTouchAppDelegate *)inRefCon; OSStatus err = AudioUnitRender(THIS->rioUnit, ioActionFlags, inTimeStamp, 1, inNumberFrames, ioData); if (err) { printf("PerformThru: error %d\n", (int)err); return err; }

**// Remove DC component**
for(UInt32 i = 0; i < ioData->mNumberBuffers; ++i)
    THIS->dcFilter[i].InplaceFilter((SInt32*)(ioData->mBuffers[i].mData), inNumberFrames, 1);
    ...

Beginner question: What does the "Remove DC component" do? Any pointer to tutorial article about it is appreciated.

Thanks in advance for your help.

+1  A: 

Here is the code for the InplaceFilter method:

void DCRejectionFilter::InplaceFilter(SInt32* ioData, UInt32 numFrames, UInt32 strides) 
{ 
    register SInt32 y1 = mY1, x1 = mX1; 
    for (UInt32 i=0; i < numFrames; i++) 
    { 
        register SInt32 x0, y0; 
        x0 = ioData[i*strides]; 
        y0 = smul32by16(y1, mA1); 
        y1 = smulAdd32by16(x0 - x1, mGain, y0) << 1; 
        ioData[i*strides] = y1; 
        x1 = x0; 
    } 
    mY1 = y1; 
    mX1 = x1; 
} 

Basically, the code is doing a high-pass filter on the audio to remove the DC component of the frequency spectrum which is also referred to as the DC offset. The coefficient (alpha in the wikipedia article) for the filter is set by default in the code to be 0.975 and typical values for DC removal filters are between 0.9 and 1.0. If you adjust the sampling rate then you might want to adjust that coefficient, but I wouldn't worry too much about it.

Justin Peel