• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Trying to so something that *should* be straightforward...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Trying to so something that *should* be straightforward...


  • Subject: Trying to so something that *should* be straightforward...
  • From: Jeff Heard <email@hidden>
  • Date: Wed, 30 Dec 2009 10:34:28 -0500

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);
}
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: AU embedded control never receives kEventControlDraw
  • Next by Date: Audio MixerUnit output writing problem.
  • Previous by thread: AU embedded control never receives kEventControlDraw
  • Next by thread: Audio MixerUnit output writing problem.
  • Index(es):
    • Date
    • Thread