InputUnit Buffer Structure

I wrote a simple audio univer, which should change the left and right channels of a stereo source. The ported version of this code worked fine in C for the command line, which used the BASS library, but I had a problem with the same code working in Xcode for an audio device.

To enter a buffer, for example, {1, 2, 3, 4, 5, 6}, I expect stereo reversal to be {2, 1, 4, 3, 6, 5}.

My code correctly changes the samples in this way, but all I hear is a kind of low-pass filtering, not a stereo-reversal of the samples.

The first 4 values ​​in my input buffer are: 0.000104 0.000101 0.000080 0.000113

Output: 0.000101 0.000104 0.000113 0.000080

Did I not understand something about how I / O buffers are structured?

void        First::FirstKernel::Process(    const Float32   *inSourceP,
                                                Float32         *inDestP,
                                                UInt32          inSamplesToProcess,
                                                UInt32          inNumChannels, 
                                                bool            &ioSilence )
{


if (!ioSilence) {                                                 

    const Float32 *sourceP = inSourceP;  
    Float32  *destP = inDestP;  
    for (int i = inSamplesToProcess/2; i>0; --i) { 


        *(destP+1) = *sourceP;
        *destP = *(sourceP+1);

        sourceP = sourceP +2;
        destP = destP +2;
}   
}   
}
+5
1

, , , AudioUnit, ( ). , , . - ?

, AUEffectBase ProcessBufferLists(). AudioBufferList, . , .

Edit: , , 1 . , Render(), , . AUEffectBase.h:

N-N , , NewKernel . , NewKernel ProcessBufferLists.

AUEffectBase "" AudioUnit, cpp/h . AudioUnit SDK AudioUnits/AUPublic/OtherBases. :

MyEffect.h:

#include "AUEffectBase.h"

class MyEffect : public AUEffectBase {
public:
  // Constructor, other overridden methods, etc.
  virtual OSStatus ProcessBufferLists(AudioUnitRenderActionFlags &ioActionFlags,
                                      const AudioBufferList &inBuffer,
                                      AudioBufferList &outBuffer,
                                      UInt32 inFramesToProcess);


private:
  // Private member variables, methods
};

MyEffect.cpp:

// Other stuff ....

OSStatus MyEffect::ProcessBufferLists(AudioUnitRenderActionFlags &ioActionFlags,
                                      const AudioBufferList &inBuffer,
                                      AudioBufferList &outBuffer,
                                      UInt32 inFramesToProcess) {
  const float *srcBufferL = (Float32 *)inBuffer.mBuffers[0].mData;
  const float *srcBufferR = (Float32 *)inBuffer.mBuffers[1].mData;
  float *destBufferL = (Float32 *)outBuffer.mBuffers[0].mData;
  float *destBufferR = (Float32 *)outBuffer.mBuffers[1].mData;

  for(UInt32 frame = 0; frame < inFramesToProcess; ++frame) {
    *destBufferL++ = *srcBufferL++;
    *destBufferR++ = *srcBufferR++;
  }
}
+6

All Articles