Re: iPhone Custom Audio Unit: why buzz?
Re: iPhone Custom Audio Unit: why buzz?
- Subject: Re: iPhone Custom Audio Unit: why buzz?
- From: Hamilton Feltman <email@hidden>
- Date: Sun, 7 Mar 2010 01:30:27 -0800
All the things already mentioned, and there is another problem is in this line of code alone:
for (UInt32 frame; frame<inNumberFrames; ++frame)
On Mar 6, 2010, at 6:23 AM, Sung wrote: Thanks for the reply.
Making 'j' static didn't make a difference. In AudioQueue, I can definitely hear 'clicks' if I don't keep track of starting frame count of each callbacks. AU seems different, strange.
I checked inNumberFrames = 512. Either way, it didn't help.
You're also right about being safe with 32767. No change though.
static OSStatus renderInput(void *inRefCon, AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList *ioData) { double frequency = 440.0; static double j = 0.0; double cycleLength = kGraphSampleRate / frequency;
SInt16 *toneBuffer = (SInt16 *)ioData->mBuffers[0].mData for (UInt32 frame; frame<inNumberFrames; ++frame) { Float32 nextFloat = sin(j/cycleLength * (M_PI*2.0)) ; toneBuffer[frame] = 32767.0*nextFloat; j += 1.0; if (j>cycleLength) { j = j - cycleLength; } }
return noErr; }
On Sat, Mar 6, 2010 at 2:03 AM, tahome izwah <email@hidden> wrote: Of course it buzzes if your cycle length doesn't coincide with inNumberFrames. You need to remember your "j" across calls (make it static to see if it solves your problem). Also, why are you using 512 instead of inNumberFrames in your loop? That doesn't make much sense to me as there is no reason to believe that inNumberFrames will always be 512 frames. In addition, your sine wave will cause digital clipping (wrapping) when you multiply the result of the sin() call by 32768. Make sure you limit your output to the range -32768...32767 to be on the safe side. HTH --th
|
_______________________________________________
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