title: OSX: CoreAudio API for setting IO Buffer length?
body: <p>This is a follow-up to a previous question: 
  <a href="https://stackoverflow.com/questions/35875886/osx-coreaudio-getting-innumberframes-in-advance-on-initialization">OSX CoreAudio: Getting inNumberFrames in advance - on initialization?</a></p>
  
  <p>I am trying to figure out what will be the AudioUnit API for possibly setting <strong><em>inNumberFrames</em></strong> or <em>preffered IO buffer duration</em> of an input callback for a single <strong>HAL</strong> audio component instance in <strong>OSX</strong> (not a plug-in!).
  While I understand there is a comprehensive documentation on how this can be achieved in iOS, by means of <strong><em>AVAudioSession</em></strong> API, I can neither figure out nor find documentation on setting these values in OSX, whichever API.
  The web is full of expert, yet conflicting statements ranging from "<em>There is an Audio Unit API to request a sample rate and a preferred buffer duration...</em>", to "<em>You can definitely get the number of frames, but only for the current callback call...</em>".</p>
  
  <p>Is there a way of at least getting (and adapting to) the <strong><em>inNumberFrames</em></strong> or the <strong>audio buffer length</strong> offerd by the system, for the input-selected sampling rates in OSX? For example, for 44.1k and its multiples (this seems to work partly), as well as for 48k and its multiples (this doesn't seem to work at all, I don't know where's the hack which allows for adapting the buffer lenfth to these values)? Here's the console printout:</p>
  
  <pre><code>Available 7 Sample Rates
  Available Sample Rate value : 8000.000000
  Available Sample Rate value : 16000.000000
  Available Sample Rate value : 32000.000000
  Available Sample Rate value : 44100.000000
  Available Sample Rate value : 48000.000000
  Available Sample Rate value : 88200.000000
  Available Sample Rate value : 96000.000000
  
  .mSampleRate          =   48000.00
  .mFormatID            = 1819304813
  .mBytesPerPacket      = 8
  .mFramesPerPacket     = 1
  .mBytesPerFrame       = 8
  .mChannelsPerFrame    = 2
  .mBitsPerChannel      = 32
  .mFormatFlags         = 9
  _mFormatHumanReadable = kAudioFormatFlagIsFloat 
      kAudioFormatFlagIsPacked 
      kLinearPCMFormatFlagIsFloat 
      kLinearPCMFormatFlagIsPacked 
      kLinearPCMFormatFlagsSampleFractionShift 
      kAppleLosslessFormatFlag_16BitSourceData 
      kAppleLosslessFormatFlag_24BitSourceData 
  
  expectedInNumberFrames = 512
  
  Couldn't render in current context (Error -10863)
  </code></pre>
  
  <p>The expected inNumberFrames is read from the system:</p>
  
  
  
  <pre><code>UInt32 expectedInNumberFrames = 0;
  UInt32 propSize = sizeof(UInt32);
  AudioUnitGetProperty(gInputUnitComponentInstance,
                       kAudioDevicePropertyBufferFrameSize,
                       kAudioUnitScope_Global,
                       0,
                       &amp;expectedInNumberFrames,
                       &amp;propSize);
  </code></pre>
  
  <p>Thanks in advance for pointing me at the right direction!</p>