• 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: AudioOutputUnitStart very slow... any ideas?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: AudioOutputUnitStart very slow... any ideas?


  • Subject: Re: AudioOutputUnitStart very slow... any ideas?
  • From: Aran Mulholland <email@hidden>
  • Date: Sat, 14 Apr 2012 19:38:35 +1000

Why don't you just leave it running? Only provide samples when
playback is necessary.

On Fri, Apr 13, 2012 at 11:33 PM, Jean-Yves Avenard <email@hidden> wrote:
> Hi there
>
> I have a code that plays mono audio event (short beeps at various
> frequencies). I create an AudioOutputUnit, stop it, and whenever I
> need to play the audio. I start it. When I've played it for the
> required time, I stop it.
>
> Sounds simple enough.
>
> However, AudioOutputUnitStart will take usually 180ms to return on my
> iPhone 4S (with iOS 5.1), this is way too much.
>
> Here is the creation/initialisation of the AudioOutputUnit
>
> void createAOU()
> {
>    m_init = false;
>    // find the default playback output unit
>    AudioComponentDescription defaultOutputDescription;
>    defaultOutputDescription.componentType = kAudioUnitType_Output;
>    defaultOutputDescription.componentSubType = kAudioUnitSubType_RemoteIO;
>    defaultOutputDescription.componentManufacturer =
> kAudioUnitManufacturer_Apple;
>    defaultOutputDescription.componentFlags = 0;
>    defaultOutputDescription.componentFlagsMask = 0;
>
>    // Get the default playback output unit
>    AudioComponent defaultOutput = AudioComponentFindNext(NULL,
> &defaultOutputDescription);
>    if (defaultOutput == NULL)
>        return;
>
>    OSErr err = AudioComponentInstanceNew(defaultOutput, &m_toneUnit);
>    if (err != noErr)
>        return;
>
>    // single channel, floating point, linear PCM
>    AudioStreamBasicDescription streamFormat;
>    streamFormat.mSampleRate = m_framerate;
>    streamFormat.mFormatID = kAudioFormatLinearPCM;
>    streamFormat.mFormatFlags =
>    kLinearPCMFormatFlagIsFloat |
>    kAudioFormatFlagsNativeEndian | kLinearPCMFormatFlagIsPacked;
>    streamFormat.mBytesPerPacket = sizeof(float);
>    streamFormat.mFramesPerPacket = 1;
>    streamFormat.mBytesPerFrame = sizeof(float);
>    streamFormat.mChannelsPerFrame = 1;
>    streamFormat.mBitsPerChannel = sizeof(float) * 8;
>    err = AudioUnitSetProperty (m_toneUnit,
>                                kAudioUnitProperty_StreamFormat,
>                                kAudioUnitScope_Input,
>                                0,
>                                &streamFormat,
>                                sizeof(AudioStreamBasicDescription));
>    if (err != noErr)
>        return;
>
>    // Attach callback to default output
>    AURenderCallbackStruct input;
>    input.inputProc = RenderTone;
>    input.inputProcRefCon = this;
>    err = AudioUnitSetProperty(m_toneUnit,
>                               kAudioUnitProperty_SetRenderCallback,
>                               kAudioUnitScope_Input,
>                               0,
>                               &input,
>                               sizeof(input));
>    if (err != noErr)
>        return;
>
>    float aBufferLength = 0.001; // In seconds
>    AudioSessionSetProperty(kAudioSessionProperty_PreferredHardwareIOBufferDuration,
>                            sizeof(aBufferLength), &aBufferLength);
>
>    err = AudioUnitInitialize(m_toneUnit);
>    if (err != noErr)
>        return;
>    reset();
>    m_init = true;
> }
>
> To start it, I would simply call:
>
> OSErr err = AudioOutputUnitStart(m_toneUnit);
>
> When done:
>
> OSErr err = AudioOutputUnitStop(m_toneUnit);
>
> I've tried various things: making the
> kAudioSessionProperty_PreferredHardwareIOBufferDuration property to a
> very small value (like 5ms) Reduce the framerate (tried 48kHz,
> 44.1kHz, 8kHz)
>
> No matter what I do... First time the audiounit is started,
> AudioOutputUnitStart only returns after 160-180ms. If I stop and start
> it right away, then it only takes about 5m which is much more
> acceptable.
>
> Latency in my application is rather important, and 180ms is definitely
> not acceptable.
>
> Any suggestions? I've seen a few people asking similar questions, but
> they usually never got an answer.
>
> I'm hoping this time things will be different :)
>  _______________________________________________
> 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


  • Follow-Ups:
    • Re: AudioOutputUnitStart very slow... any ideas?
      • From: Jean-Yves Avenard <email@hidden>
    • Re: AudioOutputUnitStart very slow... any ideas?
      • From: tahome izwah <email@hidden>
References: 
 >AudioOutputUnitStart very slow... any ideas? (From: Jean-Yves Avenard <email@hidden>)

  • Prev by Date: Audio Unit multi channel mixer output metering, OS X
  • Next by Date: Re: AudioOutputUnitStart very slow... any ideas?
  • Previous by thread: AudioOutputUnitStart very slow... any ideas?
  • Next by thread: Re: AudioOutputUnitStart very slow... any ideas?
  • Index(es):
    • Date
    • Thread