macOS: paring down NullAudio example to not have output

Viewed 326
1 Answers

I also wanted to disable the output of the NullAudio device some time ago and the only way I managed to do it is by making the following changes in the NullAudio.c:

  • In NullAudio_HasDeviceProperty() function disable the output scope in the preferred channel layout case, like this:

      case kAudioDevicePropertyPreferredChannelLayout:
          theAnswer = inAddress->mScope == kAudioObjectPropertyScopeInput;
    
  • In NullAudio_GetDevicePropertyDataSize() function return 1 object size for the global scope and zero size for the output scope for the stream property case, and leave the input scope case as is:

      case kAudioDevicePropertyStreams:
          switch(inAddress->mScope)
          {
              case kAudioObjectPropertyScopeGlobal:
                  *outDataSize = 1 * sizeof(AudioObjectID);
                  break;
    
              case kAudioObjectPropertyScopeOutput:
                  *outDataSize = 0 * sizeof(AudioObjectID);
                  break;
          };
          break;
    

I haven't fully tested this, though. I assumed it worked, because I could see that the NullAudio device had a format of 2ins/0outs in Audio MIDI Setup app. Maybe only one of these changes is needed. Maybe more changes are need.

You should probably use it as a starting point rather as a solution, because I think that in order to make this fully and correctly functional you would need to do more changes like this throughout the code. Find where the output scope/stream is referenced (if it's active, how many owned objects the device has etc.) and try to make logical changes to disable the output stream. At least that's how I tried to find my way through this code base.

Good luck and let me know if it works, or if you found another/better (or the correct) way!

Related