alexbw / novocaine

Painless high-performance audio on iOS and Mac OS X
http://alexbw.github.com/novocaine/
MIT License
2.23k stars 274 forks source link

Adjusting phase #103

Open peterfealey opened 9 years ago

peterfealey commented 9 years ago

I'm currently learning iOS development (as a bit of a hobby mainly) I have a deep interest in Audio and Music, and was just playing around with trying to put something together for a basic recording app that I could use to make phase adjustments to microphone input. I've used the basic playthru example as a starting point and wondered if someone might give me some pointers as to how to achieve phase inversion, thus far my attempts haven't yielded anything. On the fly would be cool so people could 'preview' and adjust settings as necessary. Here's my snippet:

    // Trying Phase cancellation
    [self.audioManager setInputBlock:^(float *data, UInt32 numFrames, UInt32 numChannels) {
        float volume = 10;
        vDSP_vsmul(data, 1, &volume, data, 1, numFrames*numChannels);
        for (int i = 0; i < numFrames * numChannels; i++) {
            printf("Data in: %f\n", data[i]);
     // This should flip the phase 180 degrees, in principle?
            data[i] = -data[i];
            printf("Data Out: %f\n", data[i]);
        }
        wself.ringBuffer->AddNewInterleavedFloatData(data, numFrames, numChannels);
    }];

    [self.audioManager setOutputBlock:^(float *outData, UInt32 numFrames, UInt32 numChannels) {
        wself.ringBuffer->FetchInterleavedData(outData, numFrames, numChannels);
    }];

Any help would be gratefully received! Thanks!