Since this is the Cocoa list, you'll probably have better luck asking on
something more appropriate like the Core Audio list.
On 29 Dec 2009, at 00:58, Jeff Heard wrote:
> Okay, I've created two audio queues, one output and one input. And no, I
> don't have them both on at once, because I know well that wont' work. All I
> want to do is sample sound from the input and then replay the frequency of
> that sound as the output. Can anyone help me? It seems to work if I try to
> get it to play a constant 440hZ, but when it starts after finding the new
> frequency, it plays 1/2 second of audio and then I get silence. My code,
> which seems sane looks like this:
>
> // MainViewController.m:
>
> - (void) onPressed { // should pause the output and listen for new sound
> AudioQueuePause(aqc->outQueue); // stop the input so the mic can listen
> AudioQueueEnqueueBuffer(aqc->inQueue, aqc->mBuffers[0], 0, NULL); //
> enqueue an input buffer to the mic queue
> AudioQueueStart(aqc->inQueue, NULL); // start the input queue
> }
>
> - (void) onReleased { // should stop recording and start replaying the
> frequency
> AudioQueueStop(aqc->inQueue,TRUE); // stop the input queue
> AudioQueueStart(aqc->outQueue, NULL);
> }
>
> // Audio.c
>
> AQCallbackStruct *SetupAudioQueues() {
> AQCallbackStruct *aqc = malloc(sizeof(AQCallbackStruct));
> int i;
> int aqniStatus;
>
> aqc->mDataFormat.mSampleRate = 44100.0;
> aqc->mDataFormat.mFormatID = kAudioFormatLinearPCM;
> aqc->mDataFormat.mFormatFlags =
> kLinearPCMFormatFlagIsSignedInteger |
> kLinearPCMFormatFlagIsPacked;
> aqc->mDataFormat.mBytesPerPacket = 4;
> aqc->mDataFormat.mFramesPerPacket = 1;
> aqc->mDataFormat.mBytesPerFrame = 4;
> aqc->mDataFormat.mChannelsPerFrame = 2;
> aqc->mDataFormat.mBitsPerChannel = 16;
> aqc->frameCount = 4410;
> aqc->frameSize = aqc->frameCount * aqc->mDataFormat.mBytesPerFrame;
> aqc->frequency = 0;
> aqc->amplitude = 4096;
> aqc->check = FALSE;
>
>
> aqniStatus = AudioQueueNewInput(
> &(aqc->mDataFormat)
> , AQInputCallback
> , aqc
> , NULL
> , kCFRunLoopCommonModes
> , 0
> , &(aqc->inQueue));
>
>
> aqniStatus = AudioQueueNewOutput(
> &(aqc->mDataFormat)
> , AQOutputCallback
> , aqc
> , NULL
> , kCFRunLoopCommonModes
> , 0
> , &(aqc->outQueue));
>
>
> for(i=0; i< AUDIO_BUFFERS / 2; i++) {
> AudioQueueAllocateBuffer(aqc->inQueue, aqc->frameSize,
> &(aqc->mBuffers[i]));
> }
> for(i=AUDIO_BUFFERS/2; i < AUDIO_BUFFERS; i++) {
> aqniStatus = AudioQueueAllocateBuffer(aqc->outQueue,
> aqc->frameSize, &(aqc->mBuffers[i]));
> AQOutputCallback(aqc, aqc->outQueue, aqc->mBuffers[i]);
> }
>
> aqniStatus = AudioQueueStart(aqc->outQueue, NULL);
> return aqc;
> }
>
> static void AQInputCallback
> (void *aqr,
> AudioQueueRef inQ,
> AudioQueueBufferRef inQB,
> const AudioTimeStamp *timestamp,
> UInt32 frameSize,
> const AudioStreamPacketDescription *mDataFormat)
> {
> AQCallbackStruct *aqc = (AQCallbackStruct*)aqr;
>
> // should find the frequency of the input sound and store it in
> frequency
> aqc->frequency = autoCorrelation(&(((SInt16*)inQB->mAudioData)[0]),
> aqc->frameCount*2);
> }
>
> // this I've confirmed works by subsituting 440 in for the frequency...
>
> static void AQOutputCallback
> (void *aqr,
> AudioQueueRef inQ,
> AudioQueueBufferRef outQB)
> {
> AQCallbackStruct *aqc = (AQCallbackStruct*)aqr;
>
> SInt16 *CoreAudioBuffer = outQB->mAudioData;
> outQB->mAudioDataByteSize = 4*aqc->frameCount;
>
> for (int i=0; i<aqc->frameCount*2; i+=2) {
> CoreAudioBuffer[i] = waveform(i,
> aqc->mDataFormat.mSampleRate/2, aqc->frequency, aqc->amplitude, 0, 0);
> CoreAudioBuffer[i+1] = waveform(i,
> aqc->mDataFormat.mSampleRate/2, aqc->frequency, aqc->amplitude, 0, 0);
> }
> AudioQueueEnqueueBuffer(inQ, outQB, 0, NULL);
> }
>
>
> _______________________________________________
>
> Cocoa-dev mailing list ([email protected])
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/cocoadev%40mikeabdullah.net
>
> This email sent to [email protected]
_______________________________________________
Cocoa-dev mailing list ([email protected])
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]