title: Could muting the system volume cause coreadiuod to use lots of CPU?
body: <p>I mute and later unmute the OS X system volume with the following code:</p>
  
  <pre><code>void SetMute(AudioDeviceID device, BOOL mute)
  {
      UInt32 muteVal = (UInt32)mute;
  
      AudioObjectPropertyAddress address = {
          kAudioDevicePropertyMute,
          kAudioDevicePropertyScopeOutput,
          0
      };
  
      OSStatus err;
      err = AudioObjectSetPropertyData(device,
                                       &amp;address,
                                       0,
                                       NULL,
                                       sizeof(UInt32),
                                       &amp;muteVal);
      if (err)
      {
          NSString * message;
          /* big switch statement on err to set message */
          NSLog(@"error while %@muting: %@", (mute ? @"" : @"un"), message);
      }
  }
  </code></pre>
  
  <p>The value of <code>device</code> is determined with</p>
  
  <pre><code>AudioDeviceID GetDefaultAudioDevice()
  {
      OSStatus err;
      AudioDeviceID device = 0;
      UInt32 size = sizeof(AudioDeviceID);
      AudioObjectPropertyAddress address = {
          kAudioHardwarePropertyDefaultOutputDevice,
          kAudioObjectPropertyScopeGlobal,
          kAudioObjectPropertyElementMaster
      };
  
      err = AudioObjectGetPropertyData(kAudioObjectSystemObject,
                                       &amp;address,
                                       0,
                                       NULL,
                                       &amp;size,
                                       &amp;device);
      if (err)
      {
          NSLog(@"could not get default audio output device");
      }
  
      return device;
  }
  </code></pre>
  
  <p>And I also check whether the system volume is currently muted, with:</p>
  
  <pre><code>BOOL GetMute(AudioDeviceID device)
  {
      UInt32 size = sizeof(UInt32);
      UInt32 muteVal;
  
      AudioObjectPropertyAddress address = {
          kAudioDevicePropertyMute,
          kAudioDevicePropertyScopeOutput,
          0
      };
  
      OSStatus err;
      err = AudioObjectGetPropertyData(device,
                                       &amp;address,
                                       0,
                                       NULL,
                                       &amp;size,
                                       &amp;muteVal);
      if (err)
      {
          NSString * message;
          /* big switch to set message */
          NSLog(@"error while getting mute status: %@", message);
      }
  
      return (BOOL)muteVal;
  }
  </code></pre>
  
  <p>All of this seems to work fine -- the system mutes and unmutes with the same behavior as if the user hit the mute key on the keyboard (unmuting restores the last volume set before muting, etc).</p>
  
  <p>I have noticed that at some unspecified time after my program does this, <code>coreaudiod</code> begins to consume a lot more CPU than normal (in my case, this is only around 5-7%, but ordinarily it reports 0.0% in Activity Monitor). As far as I can tell, I'm using the Core Audio APIs correctly there, and nothing looks like it should be causing any glitches in <code>coreaudiod</code>, so I'm hoping that someone can either point out an issue with my code, or point me towards what else (possibly unrelated?) might be causing the CPU usage in <code>coreaudiod</code>. I should also note that when I observe <code>coreaudiod</code> using more CPU than normal, there's no sound playing, and the system is unmuted.</p>