• 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
Re: Static when playing back buffers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Static when playing back buffers


  • Subject: Re: Static when playing back buffers
  • From: Gregory Wieber <email@hidden>
  • Date: Sun, 11 Nov 2012 11:23:14 -0800

In my experience, you have to do a lot of converting with audio units -- float to int, etc.

Typecasting is definitely expensive and to be avoided wherever possible. 

Try to architect your graph so you minimize where the typecast happens.

Sent from my iPhone

On Nov 10, 2012, at 9:37 PM, Pier <email@hidden> wrote:

Hi Kevin, 

Thanks for the tip on memsetting the buffers to 0 so that I play silence instead of rubbish if there is a glitch. 

My problem is somewhat resolved -  the sample type being returned by the AudioUnit is SInt32 (AudioSampleType). I was using SInt16,
I had to do some conversion to convert from SInt32 to SInt16. 

My audio was mono so it was ok to take from one of the buffers.. ioData.mBuffer[0]. Worked. 

I have 2 additional questions here - 

1) Am I able to get my mixer AudioUnit to return SInt16 instead? (so that I don't need to convert it) 
2) Am I able to get AudioUnit to return mono (one buffer)? 
2) Is converting from SInt32 to SInt16 within the render callback considered expensive? 

My alternative is to use SInt32 (AudioSampleType) for my buffers, but it'll take up more memory in that case, at not much audible improvement imo. 

Thanks for all the help. 

Pier. 




On Sat, Nov 10, 2012 at 8:42 AM, Kevin Dixon <email@hidden> wrote:
If you are getting static, its probably because your buffers are uninitialized.
In my render callback, I always do a memset to zeros on the buffer
supplied in ioData. That way, even in the case of starvation, you just
play silence instead of noise.

Since you are getting two buffers, then it is probably one for each
channel (NON interleaved). If you put your data in one of them, but
not the other, then the right channel will be noise, and the left
channel your data.
If the data in TPCircularBuffer is interleaved, then you should hear
something between your playback rate cut in half (lower pitch,etc) and
noise, depending on the content.

If you need to de-interleave the data from TPCircularBuffer, you can
use a simple for loop like this

AudioSampleType * outL = (AudioSampleType*)ioData->mBuffers[0].mData;
AudioSampleType * outR = (AudioSampleType*)ioData->mBuffers[1].mData;

for(int i = 0; i < inNumberFrames; i++)
{
    outL[i] = bufferTail[i * 2];
    outR[i] = bufferTail[i * 2 + 1];
}


where bufferTail is the pointer returned from TPCircularBufferTail.
Make sure that there is enough data in your buffer to satisfy
inNumberFrames. In case there isn't, then make sure the remainder of
the buffer is zeros. Sure your audio will glitch, but at least you
won't blow your users's ears

Hope that helps

-Kevin

On Thu, Nov 8, 2012 at 7:31 PM, Pier <email@hidden> wrote:
> hi all,
>
> I noticed that Mr Craig Bakalian had the same problem..
> http://www.mailinglistarchive.com/html/email@hidden/2006-10/msg00017.html
>
> Apparently the reason I have 2 buffers is that the Audio Unit returns an
> interleaved format. (left, right channels)
> To write to a file, I can do this
> AudioUnitGetProperty(mAudioUnit, kAudioUnitProperty_StreamFormat,
> kAudioUnitScope_Output, mBusNumber, &clientFormat, &size);
>
> ExtAudioFileSetProperty(mExtAudioFile,
> kExtAudioFileProperty_ClientDataFormat, size, &clientFormat);
>
> to set the extAudioFile to be the same format as the interleaved output of
> the AudioUnit. And it works producing a file recording of the mixed output
> from the mixer AudioUnit.
>
> However in my case I wish to directly manipulate the buffers and save it
> into TPCircularBuffer for use later. I feel like I'm really close to getting
> this but I'm still hearing static when I pull from these buffers and put
> them in TPCircularBuffer and play them back later.
>
>
> How can I do so? :/
>
>
> Thanks.
>
>
> Pier.
>
>
>
> On Thu, Nov 8, 2012 at 5:16 PM, Pier <email@hidden> wrote:
>>
>> Hi,
>>
>> I used
>>
>>         AURenderCallbackStruct mcallbackStruct;
>>
>>         mcallbackStruct.inputProc = mixedRecordingCallback;
>>
>>         mcallbackStruct.inputProcRefCon = &rio;
>>
>>         status = AudioUnitAddRenderNotify(_mixerUnit,
>> mcallbackStruct.inputProc,  mcallbackStruct.inputProcRefCon);
>>
>> to add the callback to my mixer AudioUnit.
>>
>> I'm getting static when trying to playback finalOutputBuffer (captured
>> below).
>> I've noticed that there are 2 buffers in ioData this time round - that
>> never happened before. I suspect that this could be the problem, has anyone
>> had any experience with this?
>>
>> Thanks.
>>
>> Pier.
>>
>> static OSStatus mixedRecordingCallback(void *inRefCon,
>>
>>                                          AudioUnitRenderActionFlags
>> *ioActionFlags,
>>
>>                                          const AudioTimeStamp
>> *inTimeStamp,
>>
>>                                          UInt32 inBusNumber,
>>
>>                                          UInt32 inNumberFrames,
>>
>>                                          AudioBufferList *ioData)
>>
>> {
>>
>>
>>
>>     if (*ioActionFlags & kAudioUnitRenderAction_PostRender) {
>>
>>
>>
>>         RIO *rio = (RIO*)inRefCon;
>>
>>         static int TEMP_kAudioUnitRenderAction_PostRenderError = (1 << 8);
>>
>>         SInt16 *targetBuffer;
>>
>>
>>
>>
>>
>>         if (rio->recordingMixed)
>>
>>         {
>>
>>             if (0 == inBusNumber && !(*ioActionFlags &
>> TEMP_kAudioUnitRenderAction_PostRenderError)) {
>>
>>             NSLog(@"Recording Mixed Output : Bus %ld", inBusNumber);
>>
>>
>>
>>             for (int i=0; i < ioData->mNumberBuffers; i++)
>>
>>             {
>>
>>                 targetBuffer= (SInt16*)ioData->mBuffers[i].mData;
>>
>>                 TPCircularBufferProduceBytes(&rio->finalOutputBuffer,
>> targetBuffer, inNumberFrames  * sizeof(SInt16));
>>
>>             }
>>
>>
>>
>>
>>             }
>>
>>         }
>>
>>     }
>>
>>     return noErr;
>>
>> }
>
>
>
>  _______________________________________________
> 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
>

 _______________________________________________
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

References: 
 >Static when playing back buffers (From: Pier <email@hidden>)
 >Re: Static when playing back buffers (From: Pier <email@hidden>)
 >Re: Static when playing back buffers (From: Kevin Dixon <email@hidden>)
 >Re: Static when playing back buffers (From: Pier <email@hidden>)

  • Prev by Date: Re: Static when playing back buffers
  • Next by Date: Forwarding Audio from an Output Device to a different output device
  • Previous by thread: Re: Static when playing back buffers
  • Next by thread: USB High-Speed uFrame Limitations
  • Index(es):
    • Date
    • Thread