0

I'm trying to invert sound waves coming in through my iPhone's microphone before they go to the headphones, but I can't find a function for this. Any ideas?

jscs
  • 63,694
  • 13
  • 151
  • 195
OmerPines
  • 1
  • 2

3 Answers3

3

There is no built-in audio function for this. Potentially you might be able to use a vDSP vector scaling, with a scale of -1, if you already have a vector of samples.

Note that humans can't normally hear the difference between a sound and an inverted sound. As for potential cancellations, the iPhone audio phase delay and headphone phase response isn't specified, or even necessarily constant.

hotpaw2
  • 70,107
  • 14
  • 90
  • 153
1

Inverting the signal is easy once you have access to the audio buffer. To illustrate:

void invert_audio_buffer(t_audio_sample* const output,
                         const t_audio_sample* const input,
                         const size_t count) {
  for (size_t i = 0; i < count; ++i) {
    output[i] = -input[i];
  }
}

(where t_audio_sample is your floating point or integer sample type)

justin
  • 104,054
  • 14
  • 179
  • 226
0

sounds like you need to read up on remoteIO audio unit. this lets you retrieve a buffer coming in from the microphone, optionally process it and spit it out through the speakers. look at AurioTouch's render callback for the syntax on how ot pull data from the microphone.

P i
  • 29,020
  • 36
  • 159
  • 267