5

for an iphone voice changing app (objective c), i am trying to take the sampled integer values from the recording audio queue buffer, process them in a function and write the modified values back to the play back buffer. At the moment i use something like this

AudioBuffer audioBuffer = bufferList->mBuffers[0];
int bufferSize = audioBuffer.mDataByteSize / sizeof(SInt32);
SInt32 *frame = audioBuffer.mData;
SInt32  signalInput[22050];
for( int i=0; i<bufferSize; i++ ) {
    SInt32 currentSample = frame[i];
    *(signalInput +i) = currentSample;
}

to extract the sampled values and seems to work pretty fine (signalinput is supposed to be the target vector for writing the integer samples). but writing them back to a buffer is still a problem... i searched the documentation and lots of forums to find a solution, but didnt succeed yet.

so id be very thankful for any advice, thanks in advance, lukas

WrightsCS
  • 50,551
  • 22
  • 134
  • 186
Lukas
  • 115
  • 1
  • 5

1 Answers1

4

If you want to modify audio in real-time you might want to try using RemoteIO Audio Unit instead.

When using audio queues, you have to save the data from the recording queue callback and later feed the processed data to the play queue callback, in a different callback at a different time. For this you probably have to use an intermediate queue or data buffer(s). To get this working, it might help to try to get a recording sound app running, and then a sample playing app running, then combining the two.

Added:

Here are some source code example's of writing sample values into an audio output queue:

http://lists.apple.com/archives/coreaudio-api/2008/Dec/msg00173.html https://bitbucket.org/ddribin/a440/wiki/Home

Just use your own pre-processed samples instead of a sine wave.

hotpaw2
  • 70,107
  • 14
  • 90
  • 153
  • Thanks for your fast response. - The recording part is already working. I wanted to change the callback somehow to modify the recorded samples before writing them to a file for example. Whatever, is it possible, and in case it is, how can I directly access the recorded samples of an audio buffer (no matter audio-queue or audio-unit). – Lukas Jan 28 '11 at 20:12
  • Make sure the PCM data types you specify, get and use are all consistent. Did you ask for 16 or 32-bit samples? Integer or float? Big or little-endian? etc. – hotpaw2 Jan 28 '11 at 21:38
  • OK, thanks so far. Ill check that immediately. But basically, the function declared above is right?! If thats the case, how can I write the values (which type ever..) back to an audio buffer. I couldnt find any sample-code anywhere...? – Lukas Jan 28 '11 at 23:05