Repository: ExistentialAudio/BlackHole
Branch: master
Commit: 11efc147fef0
Files: 24
Total size: 306.7 KB
Directory structure:
gitextract_yyv4gyui/
├── .github/
│ ├── FUNDING.yml
│ └── ISSUE_TEMPLATE/
│ ├── bug_report.yml
│ └── config.yml
├── .gitignore
├── BlackHole/
│ ├── BlackHole.c
│ ├── BlackHole.icns
│ └── BlackHole.plist
├── BlackHole.xcodeproj/
│ ├── project.pbxproj
│ ├── project.xcworkspace/
│ │ ├── contents.xcworkspacedata
│ │ └── xcshareddata/
│ │ └── IDEWorkspaceChecks.plist
│ └── xcshareddata/
│ └── xcschemes/
│ └── BlackHole.xcscheme
├── BlackHoleTests/
│ └── main.c
├── CHANGELOG.md
├── Installer/
│ ├── conclusion.html
│ ├── create_installer.sh
│ ├── requirements.xml
│ ├── scripts/
│ │ ├── postinstall
│ │ └── preinstall
│ └── welcome.html
├── LICENSE
├── README.md
├── Uninstaller/
│ ├── Scripts/
│ │ └── postinstall
│ └── create_uninstaller.sh
└── VERSION
================================================
FILE CONTENTS
================================================
================================================
FILE: .github/FUNDING.yml
================================================
# These are supported funding model platforms
github: existentialaudio # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
================================================
FILE: .github/ISSUE_TEMPLATE/bug_report.yml
================================================
name: Bug report
description: Create a bug report about a reproducible problem.
labels: bug
body:
- type: checkboxes
id: searched-discussions
attributes:
label: Please Confirm
options:
- label: I have read the **[FAQ](https://github.com/ExistentialAudio/BlackHole#faq) and [Wiki](https://github.com/ExistentialAudio/BlackHole/wiki)** where most common issues can be resolved
required: true
- label: I have searched **[Discussions](https://github.com/ExistentialAudio/BlackHole/discussions)** to see if the same question has already been asked
required: true
- label: This is a **bug** and not a question about audio routing or configuration, which should be posted in [Discussions](https://github.com/ExistentialAudio/BlackHole/discussions)
required: true
- type: dropdown
id: operating-system
attributes:
label: "macOS Version"
multiple: false
options:
- "macOS 26 Tahoe"
- "macOS 15 Sequoia"
- "macOS 14 Sonoma"
- "macOS 13 Ventura"
- "macOS 12 Monterey"
- "macOS 11 Big Sur"
- "macOS 10.15 Catalina"
- "macOS 10.14 Mojave"
- "macOS 10.13 High Sierra"
- "macOS 10.12 Sierra"
- "macOS 10.11 El Capitan"
- "macOS 10.10 Yosemite"
- "macOS 10.9 Mavericks"
validations:
required: true
- type: checkboxes
id: blackhole-config
attributes:
label: "BlackHole Build(s) Affected"
options:
- label: "2 channel"
- label: "16 channel"
- label: "64 channel"
- label: "other/custom build"
validations:
required: true
- type: textarea
id: bug-description
attributes:
label: Describe the bug
description: "A clear and concise description of what the bug is."
validations:
required: true
- type: textarea
id: repro
attributes:
label: Reproduction Steps
description: "Please list steps to reproduce the bug. If exact steps are unknown, please describe what conditions cause the issue."
value: |
1.
2.
3.
etc...
validations:
required: true
- type: textarea
id: expected-behavior
attributes:
label: Expected Behavior
description: "A clear and concise description of what you expected to happen."
validations:
required: true
- type: textarea
id: screenshots
attributes:
label: Screenshots
description: "Please include screenshots of Audio MIDI Setup (BlackHole, your Multi-Output Device, etc.) and any app configuration windows in question. You can take screen shots by pressing ShiftCmd4, then attach the screenshot image files by dragging them onto the text entry area below:"
================================================
FILE: .github/ISSUE_TEMPLATE/config.yml
================================================
blank_issues_enabled: false
contact_links:
- name: Feature request
url: https://github.com/ExistentialAudio/BlackHole/discussions
about: Suggest an idea for a new feature.
- name: I need help setting up or troubleshooting BlackHole
url: https://github.com/ExistentialAudio/BlackHole/discussions
about: Questions about how to configure your favorite apps.
================================================
FILE: .gitignore
================================================
xcuserdata/
.DS_Store
*.pkg
================================================
FILE: BlackHole/BlackHole.c
================================================
/*
File: BlackHole.c
Copyright (C) 2019 Existential Audio Inc.
*/
/*==================================================================================================
BlackHole.c
==================================================================================================*/
//==================================================================================================
// Includes
//==================================================================================================
#include
#include
#include
#include
#include
#include
#include
#include
//==================================================================================================
#pragma mark -
#pragma mark Macros
//==================================================================================================
#if TARGET_RT_BIG_ENDIAN
#define FourCCToCString(the4CC) { ((char*)&the4CC)[0], ((char*)&the4CC)[1], ((char*)&the4CC)[2], ((char*)&the4CC)[3], 0 }
#else
#define FourCCToCString(the4CC) { ((char*)&the4CC)[3], ((char*)&the4CC)[2], ((char*)&the4CC)[1], ((char*)&the4CC)[0], 0 }
#endif
#ifndef __MAC_12_0
#define kAudioObjectPropertyElementMain kAudioObjectPropertyElementMaster
#endif
#if DEBUG
#define DebugMsg(inFormat, ...) syslog(LOG_NOTICE, inFormat, ## __VA_ARGS__)
#define FailIf(inCondition, inHandler, inMessage) \
if(inCondition) \
{ \
DebugMsg(inMessage); \
goto inHandler; \
}
#define FailWithAction(inCondition, inAction, inHandler, inMessage) \
if(inCondition) \
{ \
DebugMsg(inMessage); \
{ inAction; } \
goto inHandler; \
}
#else
#define DebugMsg(inFormat, ...)
#define FailIf(inCondition, inHandler, inMessage) \
if(inCondition) \
{ \
goto inHandler; \
}
#define FailWithAction(inCondition, inAction, inHandler, inMessage) \
if(inCondition) \
{ \
{ inAction; } \
goto inHandler; \
}
#endif
//==================================================================================================
#pragma mark -
#pragma mark BlackHole State
//==================================================================================================
// The driver has the following
// qualities:
// - a box
// - a device
// - supports 44100, 48000, 88200, 96000, 176400, 192000, 352800, 384000, 705600, 768000, 8000, 16000 sample rates
// - provides a rate scalar of 1.0 via hard coding
// - a single output stream
// - supports 16 channels of 32 bit float LPCM samples
// - writes to ring buffer
// - a single input stream
// - supports 16 channels of 32 bit float LPCM samples
// - reads from ring buffer
// - controls
// - master input volume
// - master output volume
// - master input mute
// - master output mute
// Declare the internal object ID numbers for all the objects this driver implements. Note that
// because the driver has fixed set of objects that never grows or shrinks. If this were not the
// case, the driver would need to have a means to dynamically allocate these IDs. It is important
// to realize that a lot of the structure of this driver is vastly simpler when the IDs are all
// known a priori. Comments in the code will try to identify some of these simplifications and
// point out what a more complicated driver will need to do.
enum
{
kObjectID_PlugIn = kAudioObjectPlugInObject,
kObjectID_Box = 2,
kObjectID_Device = 3,
kObjectID_Stream_Input = 4,
kObjectID_Volume_Input_Master = 5,
kObjectID_Mute_Input_Master = 6,
kObjectID_Stream_Output = 7,
kObjectID_Volume_Output_Master = 8,
kObjectID_Mute_Output_Master = 9,
kObjectID_Pitch_Adjust = 10,
kObjectID_ClockSource = 11,
kObjectID_Device2 = 12,
};
enum
{
ChangeAction_SetSampleRate = 1,
ChangeAction_EnablePitchControl = 2,
ChangeAction_DisablePitchControl = 3,
};
enum ObjectType
{
kObjectType_Stream,
kObjectType_Control
};
struct ObjectInfo {
AudioObjectID id;
enum ObjectType type;
AudioObjectPropertyScope scope;
};
// Declare the stuff that tracks the state of the plug-in, the device and its sub-objects.
// Note that we use global variables here because this driver only ever has a single device. If
// multiple devices were supported, this state would need to be encapsulated in one or more structs
// so that each object's state can be tracked individually.
// Note also that we share a single mutex across all objects to be thread safe for the same reason.
#ifndef kDriver_Name
#define kDriver_Name "BlackHole"
#endif
#ifndef kPlugIn_BundleID
#define kPlugIn_BundleID "audio.existential.BlackHole2ch"
#endif
#ifndef kPlugIn_Icon
#define kPlugIn_Icon "BlackHole.icns"
#endif
#ifndef kHas_Driver_Name_Format
#define kHas_Driver_Name_Format true
#endif
#if kHas_Driver_Name_Format
#define kDriver_Name_Format "%ich"
#define kBox_UID kDriver_Name kDriver_Name_Format "_UID"
#define kDevice_UID kDriver_Name kDriver_Name_Format "_UID"
#define kDevice2_UID kDriver_Name kDriver_Name_Format "_2_UID"
#define kDevice_ModelUID kDriver_Name kDriver_Name_Format "_ModelUID"
#ifndef kDevice_Name
#define kDevice_Name kDriver_Name " %ich"
#endif
#ifndef kDevice2_Name
#define kDevice2_Name kDriver_Name " %ich 2"
#endif
#else
#define kBox_UID kDriver_Name "_UID"
#define kDevice_UID kDriver_Name "_UID"
#define kDevice2_UID kDriver_Name "_2_UID"
#define kDevice_ModelUID kDriver_Name "_ModelUID"
#ifndef kDevice_Name
#define kDevice_Name kDriver_Name " "
#endif
#ifndef kDevice2_Name
#define kDevice2_Name kDriver_Name " Mirror"
#endif
#endif
#ifndef kDevice_IsHidden
#define kDevice_IsHidden false
#endif
#ifndef kDevice2_IsHidden
#define kDevice2_IsHidden true
#endif
#ifndef kDevice_HasInput
#define kDevice_HasInput true
#endif
#ifndef kDevice_HasOutput
#define kDevice_HasOutput true
#endif
#ifndef kDevice2_HasInput
#define kDevice2_HasInput true
#endif
#ifndef kDevice2_HasOutput
#define kDevice2_HasOutput true
#endif
#ifndef kManufacturer_Name
#define kManufacturer_Name "Existential Audio Inc."
#endif
#define kLatency_Frame_Size 0
#ifndef kNumber_Of_Channels
#define kNumber_Of_Channels 2
#endif
#ifndef kEnableVolumeControl
#define kEnableVolumeControl true
#endif
#ifndef kCanBeDefaultDevice
#define kCanBeDefaultDevice true
#endif
#ifndef kCanBeDefaultSystemDevice
#define kCanBeDefaultSystemDevice true
#endif
static pthread_mutex_t gPlugIn_StateMutex = PTHREAD_MUTEX_INITIALIZER;
static UInt32 gPlugIn_RefCount = 0;
static AudioServerPlugInHostRef gPlugIn_Host = NULL;
static CFStringRef gBox_Name = NULL;
#ifndef kBox_Aquired
#define kBox_Aquired true
#endif
static Boolean gBox_Acquired = kBox_Aquired;
static pthread_mutex_t gDevice_IOMutex = PTHREAD_MUTEX_INITIALIZER;
static Float64 gDevice_SampleRate = 48000.0;
static Float64 gDevice_RequestedSampleRate = 0.0;
static UInt64 gDevice_IOIsRunning = 0;
static UInt64 gDevice2_IOIsRunning = 0;
static const UInt32 kDevice_RingBufferSize = 16384;
static Float64 gDevice_HostTicksPerFrame = 0.0;
static Float64 gDevice_AdjustedTicksPerFrame = 0.0;
static Float64 gDevice_PreviousTicks = 0.0;
static UInt64 gDevice_NumberTimeStamps = 0;
static Float64 gDevice_AnchorSampleTime = 0.0;
static UInt64 gDevice_AnchorHostTime = 0;
static bool gStream_Input_IsActive = true;
static bool gStream_Output_IsActive = true;
static const Float32 kVolume_MinDB = -64.0;
static const Float32 kVolume_MaxDB = 0.0;
static Float32 gVolume_Master_Value = 1.0;
static Float32 gPitch_Adjust = 0.5;
static bool gMute_Master_Value = false;
static UInt32 kClockSource_NumberItems = 2;
#define kClockSource_InternalFixed "Internal Fixed"
#define kClockSource_InternalAdjustable "Internal Adjustable"
static UInt32 gClockSource_Value = 0;
static bool gPitch_Adjust_Enabled = false;
static struct ObjectInfo kDevice_ObjectList[] = {
#if kDevice_HasInput
{ kObjectID_Stream_Input, kObjectType_Stream, kAudioObjectPropertyScopeInput },
{ kObjectID_Volume_Input_Master, kObjectType_Control, kAudioObjectPropertyScopeInput },
{ kObjectID_Mute_Input_Master, kObjectType_Control, kAudioObjectPropertyScopeInput },
#endif
#if kDevice_HasOutput
{ kObjectID_Stream_Output, kObjectType_Stream, kAudioObjectPropertyScopeOutput },
{ kObjectID_Volume_Output_Master, kObjectType_Control, kAudioObjectPropertyScopeOutput },
{ kObjectID_Mute_Output_Master, kObjectType_Control, kAudioObjectPropertyScopeOutput },
{ kObjectID_Pitch_Adjust, kObjectType_Control, kAudioObjectPropertyScopeOutput },
#endif
{ kObjectID_ClockSource, kObjectType_Control, kAudioObjectPropertyScopeGlobal }
};
static struct ObjectInfo kDevice2_ObjectList[] = {
#if kDevice2_HasInput
{ kObjectID_Stream_Input, kObjectType_Stream, kAudioObjectPropertyScopeInput },
{ kObjectID_Volume_Input_Master, kObjectType_Control, kAudioObjectPropertyScopeInput },
{ kObjectID_Mute_Input_Master, kObjectType_Control, kAudioObjectPropertyScopeInput },
#endif
#if kDevice2_HasOutput
{ kObjectID_Stream_Output, kObjectType_Stream, kAudioObjectPropertyScopeOutput },
{ kObjectID_Volume_Output_Master, kObjectType_Control, kAudioObjectPropertyScopeOutput },
{ kObjectID_Mute_Output_Master, kObjectType_Control, kAudioObjectPropertyScopeOutput },
#endif
};
static const UInt32 kDevice_ObjectListSize = sizeof(kDevice_ObjectList) / sizeof(struct ObjectInfo);
static const UInt32 kDevice2_ObjectListSize = sizeof(kDevice2_ObjectList) / sizeof(struct ObjectInfo);
#ifndef kSampleRates
#define kSampleRates 8000, 16000, 24000, 44100, 48000, 88200, 96000, 176400, 192000, 352800, 384000, 705600, 768000
#endif
static Float64 kDevice_SampleRates[] = { kSampleRates };
static const UInt32 kDevice_SampleRatesSize = sizeof(kDevice_SampleRates) / sizeof(Float64);
#define kBits_Per_Channel 32
#define kBytes_Per_Channel (kBits_Per_Channel/ 8)
#define kBytes_Per_Frame (kNumber_Of_Channels * kBytes_Per_Channel)
#define kRing_Buffer_Frame_Size ((65536 + kLatency_Frame_Size))
static Float32* gRingBuffer = NULL;
//==================================================================================================
#pragma mark -
#pragma mark AudioServerPlugInDriverInterface Implementation
//==================================================================================================
#pragma mark Prototypes
// Entry points for the COM methods
void* BlackHole_Create(CFAllocatorRef inAllocator, CFUUIDRef inRequestedTypeUUID);
static HRESULT BlackHole_QueryInterface(void* inDriver, REFIID inUUID, LPVOID* outInterface);
static ULONG BlackHole_AddRef(void* inDriver);
static ULONG BlackHole_Release(void* inDriver);
static OSStatus BlackHole_Initialize(AudioServerPlugInDriverRef inDriver, AudioServerPlugInHostRef inHost);
static OSStatus BlackHole_CreateDevice(AudioServerPlugInDriverRef inDriver, CFDictionaryRef inDescription, const AudioServerPlugInClientInfo* inClientInfo, AudioObjectID* outDeviceObjectID);
static OSStatus BlackHole_DestroyDevice(AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID);
static OSStatus BlackHole_AddDeviceClient(AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID, const AudioServerPlugInClientInfo* inClientInfo);
static OSStatus BlackHole_RemoveDeviceClient(AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID, const AudioServerPlugInClientInfo* inClientInfo);
static OSStatus BlackHole_PerformDeviceConfigurationChange(AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID, UInt64 inChangeAction, void* inChangeInfo);
static OSStatus BlackHole_AbortDeviceConfigurationChange(AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID, UInt64 inChangeAction, void* inChangeInfo);
static Boolean BlackHole_HasProperty(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress);
static OSStatus BlackHole_IsPropertySettable(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, Boolean* outIsSettable);
static OSStatus BlackHole_GetPropertyDataSize(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32* outDataSize);
static OSStatus BlackHole_GetPropertyData(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, UInt32* outDataSize, void* outData);
static OSStatus BlackHole_SetPropertyData(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, const void* inData);
static OSStatus BlackHole_StartIO(AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID, UInt32 inClientID);
static OSStatus BlackHole_StopIO(AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID, UInt32 inClientID);
static OSStatus BlackHole_GetZeroTimeStamp(AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID, UInt32 inClientID, Float64* outSampleTime, UInt64* outHostTime, UInt64* outSeed);
static OSStatus BlackHole_WillDoIOOperation(AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID, UInt32 inClientID, UInt32 inOperationID, Boolean* outWillDo, Boolean* outWillDoInPlace);
static OSStatus BlackHole_BeginIOOperation(AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID, UInt32 inClientID, UInt32 inOperationID, UInt32 inIOBufferFrameSize, const AudioServerPlugInIOCycleInfo* inIOCycleInfo);
static OSStatus BlackHole_DoIOOperation(AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID, AudioObjectID inStreamObjectID, UInt32 inClientID, UInt32 inOperationID, UInt32 inIOBufferFrameSize, const AudioServerPlugInIOCycleInfo* inIOCycleInfo, void* ioMainBuffer, void* ioSecondaryBuffer);
static OSStatus BlackHole_EndIOOperation(AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID, UInt32 inClientID, UInt32 inOperationID, UInt32 inIOBufferFrameSize, const AudioServerPlugInIOCycleInfo* inIOCycleInfo);
// Implementation
static Boolean BlackHole_HasPlugInProperty(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress);
static OSStatus BlackHole_IsPlugInPropertySettable(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, Boolean* outIsSettable);
static OSStatus BlackHole_GetPlugInPropertyDataSize(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32* outDataSize);
static OSStatus BlackHole_GetPlugInPropertyData(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, UInt32* outDataSize, void* outData);
static OSStatus BlackHole_SetPlugInPropertyData(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, const void* inData, UInt32* outNumberPropertiesChanged, AudioObjectPropertyAddress outChangedAddresses[2]);
static Boolean BlackHole_HasBoxProperty(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress);
static OSStatus BlackHole_IsBoxPropertySettable(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, Boolean* outIsSettable);
static OSStatus BlackHole_GetBoxPropertyDataSize(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32* outDataSize);
static OSStatus BlackHole_GetBoxPropertyData(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, UInt32* outDataSize, void* outData);
static OSStatus BlackHole_SetBoxPropertyData(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, const void* inData, UInt32* outNumberPropertiesChanged, AudioObjectPropertyAddress outChangedAddresses[2]);
static Boolean BlackHole_HasDeviceProperty(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress);
static OSStatus BlackHole_IsDevicePropertySettable(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, Boolean* outIsSettable);
static OSStatus BlackHole_GetDevicePropertyDataSize(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32* outDataSize);
static OSStatus BlackHole_GetDevicePropertyData(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, UInt32* outDataSize, void* outData);
static OSStatus BlackHole_SetDevicePropertyData(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, const void* inData, UInt32* outNumberPropertiesChanged, AudioObjectPropertyAddress outChangedAddresses[2]);
static Boolean BlackHole_HasStreamProperty(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress);
static OSStatus BlackHole_IsStreamPropertySettable(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, Boolean* outIsSettable);
static OSStatus BlackHole_GetStreamPropertyDataSize(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32* outDataSize);
static OSStatus BlackHole_GetStreamPropertyData(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, UInt32* outDataSize, void* outData);
static OSStatus BlackHole_SetStreamPropertyData(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, const void* inData, UInt32* outNumberPropertiesChanged, AudioObjectPropertyAddress outChangedAddresses[2]);
static Boolean BlackHole_HasControlProperty(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress);
static OSStatus BlackHole_IsControlPropertySettable(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, Boolean* outIsSettable);
static OSStatus BlackHole_GetControlPropertyDataSize(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32* outDataSize);
static OSStatus BlackHole_GetControlPropertyData(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, UInt32* outDataSize, void* outData);
static OSStatus BlackHole_SetControlPropertyData(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, const void* inData, UInt32* outNumberPropertiesChanged, AudioObjectPropertyAddress outChangedAddresses[2]);
#pragma mark The Interface
static AudioServerPlugInDriverInterface gAudioServerPlugInDriverInterface =
{
NULL,
BlackHole_QueryInterface,
BlackHole_AddRef,
BlackHole_Release,
BlackHole_Initialize,
BlackHole_CreateDevice,
BlackHole_DestroyDevice,
BlackHole_AddDeviceClient,
BlackHole_RemoveDeviceClient,
BlackHole_PerformDeviceConfigurationChange,
BlackHole_AbortDeviceConfigurationChange,
BlackHole_HasProperty,
BlackHole_IsPropertySettable,
BlackHole_GetPropertyDataSize,
BlackHole_GetPropertyData,
BlackHole_SetPropertyData,
BlackHole_StartIO,
BlackHole_StopIO,
BlackHole_GetZeroTimeStamp,
BlackHole_WillDoIOOperation,
BlackHole_BeginIOOperation,
BlackHole_DoIOOperation,
BlackHole_EndIOOperation
};
static AudioServerPlugInDriverInterface* gAudioServerPlugInDriverInterfacePtr = &gAudioServerPlugInDriverInterface;
static AudioServerPlugInDriverRef gAudioServerPlugInDriverRef = &gAudioServerPlugInDriverInterfacePtr;
#define RETURN_FORMATTED_STRING(_string_fmt) \
if(kHas_Driver_Name_Format) \
{ \
return CFStringCreateWithFormat(NULL, NULL, CFSTR(_string_fmt), kNumber_Of_Channels); \
} \
else \
{ \
return CFStringCreateWithCString(NULL, _string_fmt, kCFStringEncodingUTF8); \
}
static CFStringRef get_box_uid(void) { RETURN_FORMATTED_STRING(kBox_UID) }
static CFStringRef get_device_uid(void) { RETURN_FORMATTED_STRING(kDevice_UID) }
static CFStringRef get_device_name(void) { RETURN_FORMATTED_STRING(kDevice_Name) }
static CFStringRef get_device2_uid(void) { RETURN_FORMATTED_STRING(kDevice2_UID) }
static CFStringRef get_device2_name(void) { RETURN_FORMATTED_STRING(kDevice2_Name) }
static CFStringRef get_device_model_uid(void) { RETURN_FORMATTED_STRING(kDevice_ModelUID) }
// Volume conversions
static Float32 volume_to_decibel(Float32 volume)
{
if (volume <= powf(10.0f, kVolume_MinDB / 20.0f))
return kVolume_MinDB;
else
return 20.0f * log10f(volume);
}
static Float32 volume_from_decibel(Float32 decibel)
{
if (decibel <= kVolume_MinDB)
return 0.0f;
else
return powf(10.0f, decibel / 20.0f);
}
static Float32 volume_to_scalar(Float32 volume)
{
Float32 decibel = volume_to_decibel(volume);
return (decibel - kVolume_MinDB) / (kVolume_MaxDB - kVolume_MinDB);
}
static Float32 volume_from_scalar(Float32 scalar)
{
Float32 decibel = scalar * (kVolume_MaxDB - kVolume_MinDB) + kVolume_MinDB;
return volume_from_decibel(decibel);
}
static UInt32 device_object_list_size(AudioObjectPropertyScope scope, AudioObjectID objectID) {
switch (objectID) {
case kObjectID_Device:
{
if (scope == kAudioObjectPropertyScopeGlobal)
{
return kDevice_ObjectListSize;
}
UInt32 count = 0;
for (UInt32 i = 0; i < kDevice_ObjectListSize; i++)
{
count += (kDevice_ObjectList[i].scope == scope);
}
return count;
}
break;
case kObjectID_Device2:
{
if (scope == kAudioObjectPropertyScopeGlobal)
{
return kDevice2_ObjectListSize;
}
UInt32 count = 0;
for (UInt32 i = 0; i < kDevice2_ObjectListSize; i++)
{
count += (kDevice2_ObjectList[i].scope == scope);
}
return count;
}
break;
default:
return 0;
break;
}
}
static UInt32 device_stream_list_size(AudioObjectPropertyScope scope, AudioObjectID objectID) {
switch (objectID) {
case kObjectID_Device:
{
UInt32 count = 0;
for (UInt32 i = 0; i < kDevice_ObjectListSize; i++)
{
count += (kDevice_ObjectList[i].type == kObjectType_Stream && (kDevice_ObjectList[i].scope == scope || scope == kAudioObjectPropertyScopeGlobal));
}
return count;
}
break;
case kObjectID_Device2:
{
UInt32 count = 0;
for (UInt32 i = 0; i < kDevice2_ObjectListSize; i++)
{
count += (kDevice2_ObjectList[i].type == kObjectType_Stream && (kDevice2_ObjectList[i].scope == scope || scope == kAudioObjectPropertyScopeGlobal));
}
return count;
}
break;
default:
return 0;
break;
}
}
static UInt32 device_control_list_size(AudioObjectPropertyScope scope, AudioObjectID objectID) {
switch (objectID) {
case kObjectID_Device:
{
UInt32 count = 0;
for (UInt32 i = 0; i < kDevice_ObjectListSize; i++)
{
count += (kDevice_ObjectList[i].type == kObjectType_Control && (kDevice_ObjectList[i].scope == scope || scope == kAudioObjectPropertyScopeGlobal));
}
return count;
}
break;
case kObjectID_Device2:
{
UInt32 count = 0;
for (UInt32 i = 0; i < kDevice2_ObjectListSize; i++)
{
count += (kDevice2_ObjectList[i].type == kObjectType_Control && (kDevice2_ObjectList[i].scope == scope || scope == kAudioObjectPropertyScopeGlobal));
}
return count;
}
break;
default:
return 0;
break;
}
}
static UInt32 minimum(UInt32 a, UInt32 b) {
return a < b ? a : b;
}
static bool is_valid_sample_rate(Float64 sample_rate)
{
for(UInt32 i = 0; i < kDevice_SampleRatesSize; i++)
{
if (sample_rate == kDevice_SampleRates[i])
{
return true;
}
}
return false;
}
#pragma mark Factory
void* BlackHole_Create(CFAllocatorRef inAllocator, CFUUIDRef inRequestedTypeUUID)
{
// This is the CFPlugIn factory function. Its job is to create the implementation for the given
// type provided that the type is supported. Because this driver is simple and all its
// initialization is handled via static initialization when the bundle is loaded, all that
// needs to be done is to return the AudioServerPlugInDriverRef that points to the driver's
// interface. A more complicated driver would create any base line objects it needs to satisfy
// the IUnknown methods that are used to discover that actual interface to talk to the driver.
// The majority of the driver's initialization should be handled in the Initialize() method of
// the driver's AudioServerPlugInDriverInterface.
#pragma unused(inAllocator)
void* theAnswer = NULL;
if(CFEqual(inRequestedTypeUUID, kAudioServerPlugInTypeUUID))
{
theAnswer = gAudioServerPlugInDriverRef;
}
return theAnswer;
}
#pragma mark Inheritance
static HRESULT BlackHole_QueryInterface(void* inDriver, REFIID inUUID, LPVOID* outInterface)
{
// This function is called by the HAL to get the interface to talk to the plug-in through.
// AudioServerPlugIns are required to support the IUnknown interface and the
// AudioServerPlugInDriverInterface. As it happens, all interfaces must also provide the
// IUnknown interface, so we can always just return the single interface we made with
// gAudioServerPlugInDriverInterfacePtr regardless of which one is asked for.
// declare the local variables
HRESULT theAnswer = 0;
CFUUIDRef theRequestedUUID = NULL;
// validate the arguments
FailWithAction(inDriver != gAudioServerPlugInDriverRef, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_QueryInterface: bad driver reference");
FailWithAction(outInterface == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_QueryInterface: no place to store the returned interface");
// make a CFUUIDRef from inUUID
theRequestedUUID = CFUUIDCreateFromUUIDBytes(NULL, inUUID);
FailWithAction(theRequestedUUID == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_QueryInterface: failed to create the CFUUIDRef");
// AudioServerPlugIns only support two interfaces, IUnknown (which has to be supported by all
// CFPlugIns and AudioServerPlugInDriverInterface (which is the actual interface the HAL will
// use).
if(CFEqual(theRequestedUUID, IUnknownUUID) || CFEqual(theRequestedUUID, kAudioServerPlugInDriverInterfaceUUID))
{
pthread_mutex_lock(&gPlugIn_StateMutex);
++gPlugIn_RefCount;
pthread_mutex_unlock(&gPlugIn_StateMutex);
*outInterface = gAudioServerPlugInDriverRef;
}
else
{
theAnswer = E_NOINTERFACE;
}
// make sure to release the UUID we created
CFRelease(theRequestedUUID);
Done:
return theAnswer;
}
static ULONG BlackHole_AddRef(void* inDriver)
{
// This call returns the resulting reference count after the increment.
// declare the local variables
ULONG theAnswer = 0;
// check the arguments
FailIf(inDriver != gAudioServerPlugInDriverRef, Done, "BlackHole_AddRef: bad driver reference");
// increment the refcount
pthread_mutex_lock(&gPlugIn_StateMutex);
if(gPlugIn_RefCount < UINT32_MAX)
{
++gPlugIn_RefCount;
}
theAnswer = gPlugIn_RefCount;
pthread_mutex_unlock(&gPlugIn_StateMutex);
Done:
return theAnswer;
}
static ULONG BlackHole_Release(void* inDriver)
{
// This call returns the resulting reference count after the decrement.
// declare the local variables
ULONG theAnswer = 0;
// check the arguments
FailIf(inDriver != gAudioServerPlugInDriverRef, Done, "BlackHole_Release: bad driver reference");
// decrement the refcount
pthread_mutex_lock(&gPlugIn_StateMutex);
if(gPlugIn_RefCount > 0)
{
--gPlugIn_RefCount;
// Note that we don't do anything special if the refcount goes to zero as the HAL
// will never fully release a plug-in it opens. We keep managing the refcount so that
// the API semantics are correct though.
}
theAnswer = gPlugIn_RefCount;
pthread_mutex_unlock(&gPlugIn_StateMutex);
Done:
return theAnswer;
}
#pragma mark Basic Operations
static OSStatus BlackHole_Initialize(AudioServerPlugInDriverRef inDriver, AudioServerPlugInHostRef inHost)
{
// The job of this method is, as the name implies, to get the driver initialized. One specific
// thing that needs to be done is to store the AudioServerPlugInHostRef so that it can be used
// later. Note that when this call returns, the HAL will scan the various lists the driver
// maintains (such as the device list) to get the initial set of objects the driver is
// publishing. So, there is no need to notify the HAL about any objects created as part of the
// execution of this method.
// declare the local variables
OSStatus theAnswer = 0;
// check the arguments
FailWithAction(inDriver != gAudioServerPlugInDriverRef, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_Initialize: bad driver reference");
// store the AudioServerPlugInHostRef
gPlugIn_Host = inHost;
// initialize the box acquired property from the settings
CFPropertyListRef theSettingsData = NULL;
gPlugIn_Host->CopyFromStorage(gPlugIn_Host, CFSTR("box acquired"), &theSettingsData);
if(theSettingsData != NULL)
{
if(CFGetTypeID(theSettingsData) == CFBooleanGetTypeID())
{
gBox_Acquired = CFBooleanGetValue((CFBooleanRef)theSettingsData);
}
else if(CFGetTypeID(theSettingsData) == CFNumberGetTypeID())
{
SInt32 theValue = 0;
CFNumberGetValue((CFNumberRef)theSettingsData, kCFNumberSInt32Type, &theValue);
gBox_Acquired = theValue ? 1 : 0;
}
CFRelease(theSettingsData);
}
// initialize the box name from the settings
gPlugIn_Host->CopyFromStorage(gPlugIn_Host, CFSTR("box acquired"), &theSettingsData);
if(theSettingsData != NULL)
{
if(CFGetTypeID(theSettingsData) == CFStringGetTypeID())
{
gBox_Name = (CFStringRef)theSettingsData;
CFRetain(gBox_Name);
}
CFRelease(theSettingsData);
}
// set the box name directly as a last resort
if(gBox_Name == NULL)
{
gBox_Name = CFSTR("BlackHole Box");
}
// calculate the host ticks per frame
struct mach_timebase_info theTimeBaseInfo;
mach_timebase_info(&theTimeBaseInfo);
Float64 theHostClockFrequency = (Float64)theTimeBaseInfo.denom / (Float64)theTimeBaseInfo.numer;
theHostClockFrequency *= 1000000000.0;
gDevice_HostTicksPerFrame = theHostClockFrequency / gDevice_SampleRate;
gDevice_AdjustedTicksPerFrame = gDevice_HostTicksPerFrame - gDevice_HostTicksPerFrame/100.0 * 2.0*(gPitch_Adjust - 0.5);
// DebugMsg("BlackHole theTimeBaseInfo.numer: %u \t theTimeBaseInfo.denom: %u", theTimeBaseInfo.numer, theTimeBaseInfo.denom);
Done:
return theAnswer;
}
static OSStatus BlackHole_CreateDevice(AudioServerPlugInDriverRef inDriver, CFDictionaryRef inDescription, const AudioServerPlugInClientInfo* inClientInfo, AudioObjectID* outDeviceObjectID)
{
// This method is used to tell a driver that implements the Transport Manager semantics to
// create an AudioEndpointDevice from a set of AudioEndpoints. Since this driver is not a
// Transport Manager, we just check the arguments and return
// kAudioHardwareUnsupportedOperationError.
#pragma unused(inDescription, inClientInfo, outDeviceObjectID)
// declare the local variables
OSStatus theAnswer = kAudioHardwareUnsupportedOperationError;
// check the arguments
FailWithAction(inDriver != gAudioServerPlugInDriverRef, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_CreateDevice: bad driver reference");
Done:
return theAnswer;
}
static OSStatus BlackHole_DestroyDevice(AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID)
{
// This method is used to tell a driver that implements the Transport Manager semantics to
// destroy an AudioEndpointDevice. Since this driver is not a Transport Manager, we just check
// the arguments and return kAudioHardwareUnsupportedOperationError.
#pragma unused(inDeviceObjectID)
// declare the local variables
OSStatus theAnswer = kAudioHardwareUnsupportedOperationError;
// check the arguments
FailWithAction(inDriver != gAudioServerPlugInDriverRef, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_DestroyDevice: bad driver reference");
Done:
return theAnswer;
}
static OSStatus BlackHole_AddDeviceClient(AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID, const AudioServerPlugInClientInfo* inClientInfo)
{
// This method is used to inform the driver about a new client that is using the given device.
// This allows the device to act differently depending on who the client is. This driver does
// not need to track the clients using the device, so we just check the arguments and return
// successfully.
#pragma unused(inClientInfo)
// declare the local variables
OSStatus theAnswer = 0;
// check the arguments
FailWithAction(inDriver != gAudioServerPlugInDriverRef, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_AddDeviceClient: bad driver reference");
FailWithAction(inDeviceObjectID != kObjectID_Device && inDeviceObjectID != kObjectID_Device2, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_AddDeviceClient: bad device ID");
Done:
return theAnswer;
}
static OSStatus BlackHole_RemoveDeviceClient(AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID, const AudioServerPlugInClientInfo* inClientInfo)
{
// This method is used to inform the driver about a client that is no longer using the given
// device. This driver does not track clients, so we just check the arguments and return
// successfully.
#pragma unused(inClientInfo)
// declare the local variables
OSStatus theAnswer = 0;
// check the arguments
FailWithAction(inDriver != gAudioServerPlugInDriverRef, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_RemoveDeviceClient: bad driver reference");
FailWithAction(inDeviceObjectID != kObjectID_Device && inDeviceObjectID != kObjectID_Device2, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_RemoveDeviceClient: bad device ID");
Done:
return theAnswer;
}
static OSStatus BlackHole_PerformDeviceConfigurationChange(AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID, UInt64 inChangeAction, void* inChangeInfo)
{
// This method is called to tell the device that it can perform the configuration change that it
// had requested via a call to the host method, RequestDeviceConfigurationChange(). The
// arguments, inChangeAction and inChangeInfo are the same as what was passed to
// RequestDeviceConfigurationChange().
//
// The HAL guarantees that IO will be stopped while this method is in progress. The HAL will
// also handle figuring out exactly what changed for the non-control related properties. This
// means that the only notifications that would need to be sent here would be for either
// custom properties the HAL doesn't know about or for controls.
//
// For the device implemented by this driver, sample rate changes and enabling/disabling
// the pitch adjust go through this process.
// These are the only states that can be changed for the device that aren't controls.
// Which change is requested is passed in the inChangeAction argument.
#pragma unused(inChangeInfo)
// declare the local variables
OSStatus theAnswer = 0;
Float64 newSampleRate = 0.0;
// check the arguments
FailWithAction(inDriver != gAudioServerPlugInDriverRef, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_PerformDeviceConfigurationChange: bad driver reference");
FailWithAction(inDeviceObjectID != kObjectID_Device && inDeviceObjectID != kObjectID_Device2, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_PerformDeviceConfigurationChange: bad device ID");
switch(inChangeAction)
{
case ChangeAction_EnablePitchControl:
pthread_mutex_lock(&gPlugIn_StateMutex);
gPitch_Adjust_Enabled = true;
pthread_mutex_unlock(&gPlugIn_StateMutex);
break;
case ChangeAction_DisablePitchControl:
pthread_mutex_lock(&gPlugIn_StateMutex);
gPitch_Adjust_Enabled = false;
pthread_mutex_unlock(&gPlugIn_StateMutex);
break;
case ChangeAction_SetSampleRate:
pthread_mutex_lock(&gPlugIn_StateMutex);
newSampleRate = gDevice_RequestedSampleRate;
pthread_mutex_unlock(&gPlugIn_StateMutex);
FailWithAction(!is_valid_sample_rate(newSampleRate), theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_PerformDeviceConfigurationChange: bad sample rate");
// lock the state mutex
pthread_mutex_lock(&gPlugIn_StateMutex);
// change the sample rate
gDevice_SampleRate = newSampleRate;
// recalculate the state that depends on the sample rate
struct mach_timebase_info theTimeBaseInfo;
mach_timebase_info(&theTimeBaseInfo);
Float64 theHostClockFrequency = (Float64)theTimeBaseInfo.denom / (Float64)theTimeBaseInfo.numer;
theHostClockFrequency *= 1000000000.0;
gDevice_HostTicksPerFrame = theHostClockFrequency / gDevice_SampleRate;
gDevice_AdjustedTicksPerFrame = gDevice_HostTicksPerFrame - gDevice_HostTicksPerFrame/100.0 * 2.0*(gPitch_Adjust - 0.5);
// unlock the state mutex
pthread_mutex_unlock(&gPlugIn_StateMutex);
// DebugMsg("BlackHole theTimeBaseInfo.numer: %u \t theTimeBaseInfo.denom: %u", theTimeBaseInfo.numer, theTimeBaseInfo.denom);
break;
};
Done:
return theAnswer;
}
static OSStatus BlackHole_AbortDeviceConfigurationChange(AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID, UInt64 inChangeAction, void* inChangeInfo)
{
// This method is called to tell the driver that a request for a config change has been denied.
// This provides the driver an opportunity to clean up any state associated with the request.
// For this driver, an aborted config change requires no action. So we just check the arguments
// and return
#pragma unused(inChangeAction, inChangeInfo)
// declare the local variables
OSStatus theAnswer = 0;
// check the arguments
FailWithAction(inDriver != gAudioServerPlugInDriverRef, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_PerformDeviceConfigurationChange: bad driver reference");
FailWithAction(inDeviceObjectID != kObjectID_Device && inDeviceObjectID != kObjectID_Device2, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_PerformDeviceConfigurationChange: bad device ID");
Done:
return theAnswer;
}
#pragma mark Property Operations
static Boolean BlackHole_HasProperty(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress)
{
// This method returns whether or not the given object has the given property.
// declare the local variables
Boolean theAnswer = false;
// check the arguments
FailIf(inDriver != gAudioServerPlugInDriverRef, Done, "BlackHole_HasProperty: bad driver reference");
FailIf(inAddress == NULL, Done, "BlackHole_HasProperty: no address");
// Note that for each object, this driver implements all the required properties plus a few
// extras that are useful but not required. There is more detailed commentary about each
// property in the BlackHole_GetPropertyData() method.
switch(inObjectID)
{
case kObjectID_PlugIn:
theAnswer = BlackHole_HasPlugInProperty(inDriver, inObjectID, inClientProcessID, inAddress);
break;
case kObjectID_Box:
theAnswer = BlackHole_HasBoxProperty(inDriver, inObjectID, inClientProcessID, inAddress);
break;
case kObjectID_Device:
case kObjectID_Device2:
theAnswer = BlackHole_HasDeviceProperty(inDriver, inObjectID, inClientProcessID, inAddress);
break;
case kObjectID_Stream_Input:
case kObjectID_Stream_Output:
theAnswer = BlackHole_HasStreamProperty(inDriver, inObjectID, inClientProcessID, inAddress);
break;
case kObjectID_Volume_Output_Master:
case kObjectID_Mute_Output_Master:
case kObjectID_Volume_Input_Master:
case kObjectID_Mute_Input_Master:
case kObjectID_Pitch_Adjust:
case kObjectID_ClockSource:
theAnswer = BlackHole_HasControlProperty(inDriver, inObjectID, inClientProcessID, inAddress);
break;
};
Done:
return theAnswer;
}
static OSStatus BlackHole_IsPropertySettable(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, Boolean* outIsSettable)
{
// This method returns whether or not the given property on the object can have its value
// changed.
// declare the local variables
OSStatus theAnswer = 0;
// check the arguments
FailWithAction(inDriver != gAudioServerPlugInDriverRef, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_IsPropertySettable: bad driver reference");
FailWithAction(inAddress == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_IsPropertySettable: no address");
FailWithAction(outIsSettable == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_IsPropertySettable: no place to put the return value");
// Note that for each object, this driver implements all the required properties plus a few
// extras that are useful but not required. There is more detailed commentary about each
// property in the BlackHole_GetPropertyData() method.
switch(inObjectID)
{
case kObjectID_PlugIn:
theAnswer = BlackHole_IsPlugInPropertySettable(inDriver, inObjectID, inClientProcessID, inAddress, outIsSettable);
break;
case kObjectID_Box:
theAnswer = BlackHole_IsBoxPropertySettable(inDriver, inObjectID, inClientProcessID, inAddress, outIsSettable);
break;
case kObjectID_Device:
case kObjectID_Device2:
theAnswer = BlackHole_IsDevicePropertySettable(inDriver, inObjectID, inClientProcessID, inAddress, outIsSettable);
break;
case kObjectID_Stream_Input:
case kObjectID_Stream_Output:
theAnswer = BlackHole_IsStreamPropertySettable(inDriver, inObjectID, inClientProcessID, inAddress, outIsSettable);
break;
case kObjectID_Volume_Output_Master:
case kObjectID_Mute_Output_Master:
case kObjectID_Volume_Input_Master:
case kObjectID_Mute_Input_Master:
case kObjectID_Pitch_Adjust:
case kObjectID_ClockSource:
theAnswer = BlackHole_IsControlPropertySettable(inDriver, inObjectID, inClientProcessID, inAddress, outIsSettable);
break;
default:
theAnswer = kAudioHardwareBadObjectError;
break;
};
Done:
return theAnswer;
}
static OSStatus BlackHole_GetPropertyDataSize(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32* outDataSize)
{
// This method returns the byte size of the property's data.
// declare the local variables
OSStatus theAnswer = 0;
// check the arguments
FailWithAction(inDriver != gAudioServerPlugInDriverRef, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_GetPropertyDataSize: bad driver reference");
FailWithAction(inAddress == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_GetPropertyDataSize: no address");
FailWithAction(outDataSize == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_GetPropertyDataSize: no place to put the return value");
// Note that for each object, this driver implements all the required properties plus a few
// extras that are useful but not required. There is more detailed commentary about each
// property in the BlackHole_GetPropertyData() method.
switch(inObjectID)
{
case kObjectID_PlugIn:
theAnswer = BlackHole_GetPlugInPropertyDataSize(inDriver, inObjectID, inClientProcessID, inAddress, inQualifierDataSize, inQualifierData, outDataSize);
break;
case kObjectID_Box:
theAnswer = BlackHole_GetBoxPropertyDataSize(inDriver, inObjectID, inClientProcessID, inAddress, inQualifierDataSize, inQualifierData, outDataSize);
break;
case kObjectID_Device:
case kObjectID_Device2:
theAnswer = BlackHole_GetDevicePropertyDataSize(inDriver, inObjectID, inClientProcessID, inAddress, inQualifierDataSize, inQualifierData, outDataSize);
break;
case kObjectID_Stream_Input:
case kObjectID_Stream_Output:
theAnswer = BlackHole_GetStreamPropertyDataSize(inDriver, inObjectID, inClientProcessID, inAddress, inQualifierDataSize, inQualifierData, outDataSize);
break;
case kObjectID_Volume_Output_Master:
case kObjectID_Mute_Output_Master:
case kObjectID_Volume_Input_Master:
case kObjectID_Mute_Input_Master:
case kObjectID_Pitch_Adjust:
case kObjectID_ClockSource:
theAnswer = BlackHole_GetControlPropertyDataSize(inDriver, inObjectID, inClientProcessID, inAddress, inQualifierDataSize, inQualifierData, outDataSize);
break;
default:
theAnswer = kAudioHardwareBadObjectError;
break;
};
Done:
return theAnswer;
}
static OSStatus BlackHole_GetPropertyData(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, UInt32* outDataSize, void* outData)
{
// declare the local variables
OSStatus theAnswer = 0;
// check the arguments
FailWithAction(inDriver != gAudioServerPlugInDriverRef, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_GetPropertyData: bad driver reference");
FailWithAction(inAddress == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_GetPropertyData: no address");
FailWithAction(outDataSize == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_GetPropertyData: no place to put the return value size");
FailWithAction(outData == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_GetPropertyData: no place to put the return value");
// Note that for each object, this driver implements all the required properties plus a few
// extras that are useful but not required.
//
// Also, since most of the data that will get returned is static, there are few instances where
// it is necessary to lock the state mutex.
switch(inObjectID)
{
case kObjectID_PlugIn:
theAnswer = BlackHole_GetPlugInPropertyData(inDriver, inObjectID, inClientProcessID, inAddress, inQualifierDataSize, inQualifierData, inDataSize, outDataSize, outData);
break;
case kObjectID_Box:
theAnswer = BlackHole_GetBoxPropertyData(inDriver, inObjectID, inClientProcessID, inAddress, inQualifierDataSize, inQualifierData, inDataSize, outDataSize, outData);
break;
case kObjectID_Device:
case kObjectID_Device2:
theAnswer = BlackHole_GetDevicePropertyData(inDriver, inObjectID, inClientProcessID, inAddress, inQualifierDataSize, inQualifierData, inDataSize, outDataSize, outData);
break;
case kObjectID_Stream_Input:
case kObjectID_Stream_Output:
theAnswer = BlackHole_GetStreamPropertyData(inDriver, inObjectID, inClientProcessID, inAddress, inQualifierDataSize, inQualifierData, inDataSize, outDataSize, outData);
break;
case kObjectID_Volume_Output_Master:
case kObjectID_Mute_Output_Master:
case kObjectID_Volume_Input_Master:
case kObjectID_Mute_Input_Master:
case kObjectID_Pitch_Adjust:
case kObjectID_ClockSource:
theAnswer = BlackHole_GetControlPropertyData(inDriver, inObjectID, inClientProcessID, inAddress, inQualifierDataSize, inQualifierData, inDataSize, outDataSize, outData);
break;
default:
theAnswer = kAudioHardwareBadObjectError;
break;
};
Done:
return theAnswer;
}
static OSStatus BlackHole_SetPropertyData(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, const void* inData)
{
// declare the local variables
OSStatus theAnswer = 0;
UInt32 theNumberPropertiesChanged = 0;
AudioObjectPropertyAddress theChangedAddresses[2];
// check the arguments
FailWithAction(inDriver != gAudioServerPlugInDriverRef, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_SetPropertyData: bad driver reference");
FailWithAction(inAddress == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_SetPropertyData: no address");
// Note that for each object, this driver implements all the required properties plus a few
// extras that are useful but not required. There is more detailed commentary about each
// property in the BlackHole_GetPropertyData() method.
switch(inObjectID)
{
case kObjectID_PlugIn:
theAnswer = BlackHole_SetPlugInPropertyData(inDriver, inObjectID, inClientProcessID, inAddress, inQualifierDataSize, inQualifierData, inDataSize, inData, &theNumberPropertiesChanged, theChangedAddresses);
break;
case kObjectID_Box:
theAnswer = BlackHole_SetBoxPropertyData(inDriver, inObjectID, inClientProcessID, inAddress, inQualifierDataSize, inQualifierData, inDataSize, inData, &theNumberPropertiesChanged, theChangedAddresses);
break;
case kObjectID_Device:
case kObjectID_Device2:
theAnswer = BlackHole_SetDevicePropertyData(inDriver, inObjectID, inClientProcessID, inAddress, inQualifierDataSize, inQualifierData, inDataSize, inData, &theNumberPropertiesChanged, theChangedAddresses);
break;
case kObjectID_Stream_Input:
case kObjectID_Stream_Output:
theAnswer = BlackHole_SetStreamPropertyData(inDriver, inObjectID, inClientProcessID, inAddress, inQualifierDataSize, inQualifierData, inDataSize, inData, &theNumberPropertiesChanged, theChangedAddresses);
break;
case kObjectID_Volume_Output_Master:
case kObjectID_Mute_Output_Master:
case kObjectID_Volume_Input_Master:
case kObjectID_Mute_Input_Master:
case kObjectID_Pitch_Adjust:
case kObjectID_ClockSource:
theAnswer = BlackHole_SetControlPropertyData(inDriver, inObjectID, inClientProcessID, inAddress, inQualifierDataSize, inQualifierData, inDataSize, inData, &theNumberPropertiesChanged, theChangedAddresses);
break;
default:
theAnswer = kAudioHardwareBadObjectError;
break;
};
// send any notifications
if(theNumberPropertiesChanged > 0)
{
gPlugIn_Host->PropertiesChanged(gPlugIn_Host, inObjectID, theNumberPropertiesChanged, theChangedAddresses);
}
Done:
return theAnswer;
}
#pragma mark PlugIn Property Operations
static Boolean BlackHole_HasPlugInProperty(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress)
{
// This method returns whether or not the plug-in object has the given property.
#pragma unused(inClientProcessID)
// declare the local variables
Boolean theAnswer = false;
// check the arguments
FailIf(inDriver != gAudioServerPlugInDriverRef, Done, "BlackHole_HasPlugInProperty: bad driver reference");
FailIf(inAddress == NULL, Done, "BlackHole_HasPlugInProperty: no address");
FailIf(inObjectID != kObjectID_PlugIn, Done, "BlackHole_HasPlugInProperty: not the plug-in object");
// Note that for each object, this driver implements all the required properties plus a few
// extras that are useful but not required. There is more detailed commentary about each
// property in the BlackHole_GetPlugInPropertyData() method.
switch(inAddress->mSelector)
{
case kAudioObjectPropertyBaseClass:
case kAudioObjectPropertyClass:
case kAudioObjectPropertyOwner:
case kAudioObjectPropertyManufacturer:
case kAudioObjectPropertyOwnedObjects:
case kAudioPlugInPropertyBoxList:
case kAudioPlugInPropertyTranslateUIDToBox:
case kAudioPlugInPropertyDeviceList:
case kAudioPlugInPropertyTranslateUIDToDevice:
case kAudioPlugInPropertyResourceBundle:
theAnswer = true;
break;
};
Done:
return theAnswer;
}
static OSStatus BlackHole_IsPlugInPropertySettable(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, Boolean* outIsSettable)
{
// This method returns whether or not the given property on the plug-in object can have its
// value changed.
#pragma unused(inClientProcessID)
// declare the local variables
OSStatus theAnswer = 0;
// check the arguments
FailWithAction(inDriver != gAudioServerPlugInDriverRef, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_IsPlugInPropertySettable: bad driver reference");
FailWithAction(inAddress == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_IsPlugInPropertySettable: no address");
FailWithAction(outIsSettable == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_IsPlugInPropertySettable: no place to put the return value");
FailWithAction(inObjectID != kObjectID_PlugIn, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_IsPlugInPropertySettable: not the plug-in object");
// Note that for each object, this driver implements all the required properties plus a few
// extras that are useful but not required. There is more detailed commentary about each
// property in the BlackHole_GetPlugInPropertyData() method.
switch(inAddress->mSelector)
{
case kAudioObjectPropertyBaseClass:
case kAudioObjectPropertyClass:
case kAudioObjectPropertyOwner:
case kAudioObjectPropertyManufacturer:
case kAudioObjectPropertyOwnedObjects:
case kAudioPlugInPropertyBoxList:
case kAudioPlugInPropertyTranslateUIDToBox:
case kAudioPlugInPropertyDeviceList:
case kAudioPlugInPropertyTranslateUIDToDevice:
case kAudioPlugInPropertyResourceBundle:
*outIsSettable = false;
break;
default:
theAnswer = kAudioHardwareUnknownPropertyError;
break;
};
Done:
return theAnswer;
}
static OSStatus BlackHole_GetPlugInPropertyDataSize(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32* outDataSize)
{
// This method returns the byte size of the property's data.
#pragma unused(inClientProcessID, inQualifierDataSize, inQualifierData)
// declare the local variables
OSStatus theAnswer = 0;
// check the arguments
FailWithAction(inDriver != gAudioServerPlugInDriverRef, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_GetPlugInPropertyDataSize: bad driver reference");
FailWithAction(inAddress == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_GetPlugInPropertyDataSize: no address");
FailWithAction(outDataSize == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_GetPlugInPropertyDataSize: no place to put the return value");
FailWithAction(inObjectID != kObjectID_PlugIn, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_GetPlugInPropertyDataSize: not the plug-in object");
// Note that for each object, this driver implements all the required properties plus a few
// extras that are useful but not required. There is more detailed commentary about each
// property in the BlackHole_GetPlugInPropertyData() method.
switch(inAddress->mSelector)
{
case kAudioObjectPropertyBaseClass:
*outDataSize = sizeof(AudioClassID);
break;
case kAudioObjectPropertyClass:
*outDataSize = sizeof(AudioClassID);
break;
case kAudioObjectPropertyOwner:
*outDataSize = sizeof(AudioObjectID);
break;
case kAudioObjectPropertyManufacturer:
*outDataSize = sizeof(CFStringRef);
break;
case kAudioObjectPropertyOwnedObjects:
if(gBox_Acquired)
{
*outDataSize = 2 * sizeof(AudioClassID);
}
else
{
*outDataSize = sizeof(AudioClassID);
}
break;
case kAudioPlugInPropertyBoxList:
*outDataSize = sizeof(AudioClassID);
break;
case kAudioPlugInPropertyTranslateUIDToBox:
*outDataSize = sizeof(AudioObjectID);
break;
case kAudioPlugInPropertyDeviceList:
if(gBox_Acquired)
{
*outDataSize = sizeof(AudioClassID)*2;
}
else
{
*outDataSize = 0;
}
break;
case kAudioPlugInPropertyTranslateUIDToDevice:
*outDataSize = sizeof(AudioObjectID);
break;
case kAudioPlugInPropertyResourceBundle:
*outDataSize = sizeof(CFStringRef);
break;
default:
theAnswer = kAudioHardwareUnknownPropertyError;
break;
};
Done:
return theAnswer;
}
static OSStatus BlackHole_GetPlugInPropertyData(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, UInt32* outDataSize, void* outData)
{
#pragma unused(inClientProcessID)
// declare the local variables
OSStatus theAnswer = 0;
UInt32 theNumberItemsToFetch;
// check the arguments
FailWithAction(inDriver != gAudioServerPlugInDriverRef, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_GetPlugInPropertyData: bad driver reference");
FailWithAction(inAddress == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_GetPlugInPropertyData: no address");
FailWithAction(outDataSize == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_GetPlugInPropertyData: no place to put the return value size");
FailWithAction(outData == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_GetPlugInPropertyData: no place to put the return value");
FailWithAction(inObjectID != kObjectID_PlugIn, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_GetPlugInPropertyData: not the plug-in object");
// Note that for each object, this driver implements all the required properties plus a few
// extras that are useful but not required.
//
// Also, since most of the data that will get returned is static, there are few instances where
// it is necessary to lock the state mutex.
switch(inAddress->mSelector)
{
case kAudioObjectPropertyBaseClass:
// The base class for kAudioPlugInClassID is kAudioObjectClassID
FailWithAction(inDataSize < sizeof(AudioClassID), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetPlugInPropertyData: not enough space for the return value of kAudioObjectPropertyBaseClass for the plug-in");
*((AudioClassID*)outData) = kAudioObjectClassID;
*outDataSize = sizeof(AudioClassID);
break;
case kAudioObjectPropertyClass:
// The class is always kAudioPlugInClassID for regular drivers
FailWithAction(inDataSize < sizeof(AudioClassID), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetPlugInPropertyData: not enough space for the return value of kAudioObjectPropertyClass for the plug-in");
*((AudioClassID*)outData) = kAudioPlugInClassID;
*outDataSize = sizeof(AudioClassID);
break;
case kAudioObjectPropertyOwner:
// The plug-in doesn't have an owning object
FailWithAction(inDataSize < sizeof(AudioObjectID), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetPlugInPropertyData: not enough space for the return value of kAudioObjectPropertyOwner for the plug-in");
*((AudioObjectID*)outData) = kAudioObjectUnknown;
*outDataSize = sizeof(AudioObjectID);
break;
case kAudioObjectPropertyManufacturer:
// This is the human readable name of the maker of the plug-in.
FailWithAction(inDataSize < sizeof(CFStringRef), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetPlugInPropertyData: not enough space for the return value of kAudioObjectPropertyManufacturer for the plug-in");
*((CFStringRef*)outData) = CFSTR("Apple Inc.");
*outDataSize = sizeof(CFStringRef);
break;
case kAudioObjectPropertyOwnedObjects:
// Calculate the number of items that have been requested. Note that this
// number is allowed to be smaller than the actual size of the list. In such
// case, only that number of items will be returned
theNumberItemsToFetch = inDataSize / sizeof(AudioObjectID);
// Clamp that to the number of boxes this driver implements (which is just 1)
if(theNumberItemsToFetch > (gBox_Acquired ? 2 : 1))
{
theNumberItemsToFetch = (gBox_Acquired ? 2 : 1);
}
// Write the devices' object IDs into the return value
if(theNumberItemsToFetch > 1)
{
((AudioObjectID*)outData)[0] = kObjectID_Box;
((AudioObjectID*)outData)[0] = kObjectID_Device;
}
else if(theNumberItemsToFetch > 0)
{
((AudioObjectID*)outData)[0] = kObjectID_Box;
}
// Return how many bytes we wrote to
*outDataSize = theNumberItemsToFetch * sizeof(AudioClassID);
break;
case kAudioPlugInPropertyBoxList:
// Calculate the number of items that have been requested. Note that this
// number is allowed to be smaller than the actual size of the list. In such
// case, only that number of items will be returned
theNumberItemsToFetch = inDataSize / sizeof(AudioObjectID);
// Clamp that to the number of boxes this driver implements (which is just 1)
if(theNumberItemsToFetch > 1)
{
theNumberItemsToFetch = 1;
}
// Write the devices' object IDs into the return value
if(theNumberItemsToFetch > 0)
{
((AudioObjectID*)outData)[0] = kObjectID_Box;
}
// Return how many bytes we wrote to
*outDataSize = theNumberItemsToFetch * sizeof(AudioClassID);
break;
case kAudioPlugInPropertyTranslateUIDToBox:
// This property takes the CFString passed in the qualifier and converts that
// to the object ID of the box it corresponds to. For this driver, there is
// just the one box. Note that it is not an error if the string in the
// qualifier doesn't match any devices. In such case, kAudioObjectUnknown is
// the object ID to return.
FailWithAction(inDataSize < sizeof(AudioObjectID), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetPlugInPropertyData: not enough space for the return value of kAudioPlugInPropertyTranslateUIDToBox");
FailWithAction(inQualifierDataSize == sizeof(CFStringRef), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetPlugInPropertyData: the qualifier is the wrong size for kAudioPlugInPropertyTranslateUIDToBox");
FailWithAction(inQualifierData == NULL, theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetPlugInPropertyData: no qualifier for kAudioPlugInPropertyTranslateUIDToBox");
CFStringRef boxUID = get_box_uid();
if(CFStringCompare(*((CFStringRef*)inQualifierData), boxUID, 0) == kCFCompareEqualTo)
{
CFStringRef formattedString = CFStringCreateWithFormat(NULL, NULL, CFSTR(kBox_UID), kNumber_Of_Channels);
if(CFStringCompare(*((CFStringRef*)inQualifierData), formattedString, 0) == kCFCompareEqualTo)
{
*((AudioObjectID*)outData) = kObjectID_Box;
}
else
{
*((AudioObjectID*)outData) = kAudioObjectUnknown;
}
*outDataSize = sizeof(AudioObjectID);
CFRelease(formattedString);
*((AudioObjectID*)outData) = kObjectID_Box;
}
else
{
*((AudioObjectID*)outData) = kAudioObjectUnknown;
}
*outDataSize = sizeof(AudioObjectID);
CFRelease(boxUID);
break;
case kAudioPlugInPropertyDeviceList:
// Calculate the number of items that have been requested. Note that this
// number is allowed to be smaller than the actual size of the list. In such
// case, only that number of items will be returned
theNumberItemsToFetch = inDataSize / sizeof(AudioObjectID);
// Clamp that to the number of devices this driver implements (which is just 1 if the
// box has been acquired)
if(theNumberItemsToFetch > (gBox_Acquired ? 2 : 0))
{
theNumberItemsToFetch = (gBox_Acquired ? 2 : 0);
}
// Write the devices' object IDs into the return value
if(theNumberItemsToFetch > 1)
{
((AudioObjectID*)outData)[0] = kObjectID_Device;
((AudioObjectID*)outData)[1] = kObjectID_Device2;
}
else if(theNumberItemsToFetch > 0)
{
((AudioObjectID*)outData)[0] = kObjectID_Device;
}
// Return how many bytes we wrote to
*outDataSize = theNumberItemsToFetch * sizeof(AudioClassID);
break;
case kAudioPlugInPropertyTranslateUIDToDevice:
// This property takes the CFString passed in the qualifier and converts that
// to the object ID of the device it corresponds to. For this driver, there is
// just the one device. Note that it is not an error if the string in the
// qualifier doesn't match any devices. In such case, kAudioObjectUnknown is
// the object ID to return.
FailWithAction(inDataSize < sizeof(AudioObjectID), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetPlugInPropertyData: not enough space for the return value of kAudioPlugInPropertyTranslateUIDToDevice");
FailWithAction(inQualifierDataSize == sizeof(CFStringRef), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetPlugInPropertyData: the qualifier is the wrong size for kAudioPlugInPropertyTranslateUIDToDevice");
FailWithAction(inQualifierData == NULL, theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetPlugInPropertyData: no qualifier for kAudioPlugInPropertyTranslateUIDToDevice");
CFStringRef deviceUID = get_device_uid();
CFStringRef device2UID = get_device2_uid();
if(CFStringCompare(*((CFStringRef*)inQualifierData), deviceUID, 0) == kCFCompareEqualTo)
{
*((AudioObjectID*)outData) = kObjectID_Device;
}
else if(CFStringCompare(*((CFStringRef*)inQualifierData), device2UID, 0) == kCFCompareEqualTo)
{
*((AudioObjectID*)outData) = kObjectID_Device2;
}
else
{
*((AudioObjectID*)outData) = kAudioObjectUnknown;
}
*outDataSize = sizeof(AudioObjectID);
CFRelease(deviceUID);
CFRelease(device2UID);
break;
case kAudioPlugInPropertyResourceBundle:
// The resource bundle is a path relative to the path of the plug-in's bundle.
// To specify that the plug-in bundle itself should be used, we just return the
// empty string.
FailWithAction(inDataSize < sizeof(AudioObjectID), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetPlugInPropertyData: not enough space for the return value of kAudioPlugInPropertyResourceBundle");
*((CFStringRef*)outData) = CFSTR("");
*outDataSize = sizeof(CFStringRef);
break;
default:
theAnswer = kAudioHardwareUnknownPropertyError;
break;
};
Done:
return theAnswer;
}
static OSStatus BlackHole_SetPlugInPropertyData(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, const void* inData, UInt32* outNumberPropertiesChanged, AudioObjectPropertyAddress outChangedAddresses[2])
{
#pragma unused(inClientProcessID, inQualifierDataSize, inQualifierData, inDataSize, inData)
// declare the local variables
OSStatus theAnswer = 0;
// check the arguments
FailWithAction(inDriver != gAudioServerPlugInDriverRef, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_SetPlugInPropertyData: bad driver reference");
FailWithAction(inAddress == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_SetPlugInPropertyData: no address");
FailWithAction(outNumberPropertiesChanged == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_SetPlugInPropertyData: no place to return the number of properties that changed");
FailWithAction(outChangedAddresses == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_SetPlugInPropertyData: no place to return the properties that changed");
FailWithAction(inObjectID != kObjectID_PlugIn, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_SetPlugInPropertyData: not the plug-in object");
// initialize the returned number of changed properties
*outNumberPropertiesChanged = 0;
// Note that for each object, this driver implements all the required properties plus a few
// extras that are useful but not required. There is more detailed commentary about each
// property in the BlackHole_GetPlugInPropertyData() method.
switch(inAddress->mSelector)
{
default:
theAnswer = kAudioHardwareUnknownPropertyError;
break;
};
Done:
return theAnswer;
}
#pragma mark Box Property Operations
static Boolean BlackHole_HasBoxProperty(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress)
{
// This method returns whether or not the box object has the given property.
#pragma unused(inClientProcessID)
// declare the local variables
Boolean theAnswer = false;
// check the arguments
FailIf(inDriver != gAudioServerPlugInDriverRef, Done, "BlackHole_HasBoxProperty: bad driver reference");
FailIf(inAddress == NULL, Done, "BlackHole_HasBoxProperty: no address");
FailIf(inObjectID != kObjectID_Box, Done, "BlackHole_HasBoxProperty: not the box object");
// Note that for each object, this driver implements all the required properties plus a few
// extras that are useful but not required. There is more detailed commentary about each
// property in the BlackHole_GetBoxPropertyData() method.
switch(inAddress->mSelector)
{
case kAudioObjectPropertyBaseClass:
case kAudioObjectPropertyClass:
case kAudioObjectPropertyOwner:
case kAudioObjectPropertyName:
case kAudioObjectPropertyModelName:
case kAudioObjectPropertyManufacturer:
case kAudioObjectPropertyOwnedObjects:
case kAudioObjectPropertyIdentify:
case kAudioObjectPropertySerialNumber:
case kAudioObjectPropertyFirmwareVersion:
case kAudioBoxPropertyBoxUID:
case kAudioBoxPropertyTransportType:
case kAudioBoxPropertyHasAudio:
case kAudioBoxPropertyHasVideo:
case kAudioBoxPropertyHasMIDI:
case kAudioBoxPropertyIsProtected:
case kAudioBoxPropertyAcquired:
case kAudioBoxPropertyAcquisitionFailed:
case kAudioBoxPropertyDeviceList:
theAnswer = true;
break;
};
Done:
return theAnswer;
}
static OSStatus BlackHole_IsBoxPropertySettable(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, Boolean* outIsSettable)
{
// This method returns whether or not the given property on the plug-in object can have its
// value changed.
#pragma unused(inClientProcessID)
// declare the local variables
OSStatus theAnswer = 0;
// check the arguments
FailWithAction(inDriver != gAudioServerPlugInDriverRef, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_IsBoxPropertySettable: bad driver reference");
FailWithAction(inAddress == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_IsBoxPropertySettable: no address");
FailWithAction(outIsSettable == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_IsBoxPropertySettable: no place to put the return value");
FailWithAction(inObjectID != kObjectID_Box, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_IsBoxPropertySettable: not the plug-in object");
// Note that for each object, this driver implements all the required properties plus a few
// extras that are useful but not required. There is more detailed commentary about each
// property in the BlackHole_GetBoxPropertyData() method.
switch(inAddress->mSelector)
{
case kAudioObjectPropertyBaseClass:
case kAudioObjectPropertyClass:
case kAudioObjectPropertyOwner:
case kAudioObjectPropertyModelName:
case kAudioObjectPropertyManufacturer:
case kAudioObjectPropertyOwnedObjects:
case kAudioObjectPropertySerialNumber:
case kAudioObjectPropertyFirmwareVersion:
case kAudioBoxPropertyBoxUID:
case kAudioBoxPropertyTransportType:
case kAudioBoxPropertyHasAudio:
case kAudioBoxPropertyHasVideo:
case kAudioBoxPropertyHasMIDI:
case kAudioBoxPropertyIsProtected:
case kAudioBoxPropertyAcquisitionFailed:
case kAudioBoxPropertyDeviceList:
*outIsSettable = false;
break;
case kAudioObjectPropertyName:
case kAudioObjectPropertyIdentify:
case kAudioBoxPropertyAcquired:
*outIsSettable = true;
break;
default:
theAnswer = kAudioHardwareUnknownPropertyError;
break;
};
Done:
return theAnswer;
}
static OSStatus BlackHole_GetBoxPropertyDataSize(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32* outDataSize)
{
// This method returns the byte size of the property's data.
#pragma unused(inClientProcessID, inQualifierDataSize, inQualifierData)
// declare the local variables
OSStatus theAnswer = 0;
// check the arguments
FailWithAction(inDriver != gAudioServerPlugInDriverRef, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_GetBoxPropertyDataSize: bad driver reference");
FailWithAction(inAddress == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_GetBoxPropertyDataSize: no address");
FailWithAction(outDataSize == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_GetBoxPropertyDataSize: no place to put the return value");
FailWithAction(inObjectID != kObjectID_Box, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_GetBoxPropertyDataSize: not the plug-in object");
// Note that for each object, this driver implements all the required properties plus a few
// extras that are useful but not required. There is more detailed commentary about each
// property in the BlackHole_GetBoxPropertyData() method.
switch(inAddress->mSelector)
{
case kAudioObjectPropertyBaseClass:
*outDataSize = sizeof(AudioClassID);
break;
case kAudioObjectPropertyClass:
*outDataSize = sizeof(AudioClassID);
break;
case kAudioObjectPropertyOwner:
*outDataSize = sizeof(AudioObjectID);
break;
case kAudioObjectPropertyName:
*outDataSize = sizeof(CFStringRef);
break;
case kAudioObjectPropertyModelName:
*outDataSize = sizeof(CFStringRef);
break;
case kAudioObjectPropertyManufacturer:
*outDataSize = sizeof(CFStringRef);
break;
case kAudioObjectPropertyOwnedObjects:
*outDataSize = 0;
break;
case kAudioObjectPropertyIdentify:
*outDataSize = sizeof(UInt32);
break;
case kAudioObjectPropertySerialNumber:
*outDataSize = sizeof(CFStringRef);
break;
case kAudioObjectPropertyFirmwareVersion:
*outDataSize = sizeof(CFStringRef);
break;
case kAudioBoxPropertyBoxUID:
*outDataSize = sizeof(CFStringRef);
break;
case kAudioBoxPropertyTransportType:
*outDataSize = sizeof(UInt32);
break;
case kAudioBoxPropertyHasAudio:
*outDataSize = sizeof(UInt32);
break;
case kAudioBoxPropertyHasVideo:
*outDataSize = sizeof(UInt32);
break;
case kAudioBoxPropertyHasMIDI:
*outDataSize = sizeof(UInt32);
break;
case kAudioBoxPropertyIsProtected:
*outDataSize = sizeof(UInt32);
break;
case kAudioBoxPropertyAcquired:
*outDataSize = sizeof(UInt32);
break;
case kAudioBoxPropertyAcquisitionFailed:
*outDataSize = sizeof(UInt32);
break;
case kAudioBoxPropertyDeviceList:
{
pthread_mutex_lock(&gPlugIn_StateMutex);
*outDataSize = gBox_Acquired ? sizeof(AudioObjectID) * 2 : 0;
pthread_mutex_unlock(&gPlugIn_StateMutex);
}
break;
default:
theAnswer = kAudioHardwareUnknownPropertyError;
break;
};
Done:
return theAnswer;
}
static OSStatus BlackHole_GetBoxPropertyData(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, UInt32* outDataSize, void* outData)
{
#pragma unused(inClientProcessID, inQualifierDataSize, inQualifierData)
// declare the local variables
OSStatus theAnswer = 0;
// check the arguments
FailWithAction(inDriver != gAudioServerPlugInDriverRef, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_GetBoxPropertyData: bad driver reference");
FailWithAction(inAddress == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_GetBoxPropertyData: no address");
FailWithAction(outDataSize == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_GetBoxPropertyData: no place to put the return value size");
FailWithAction(outData == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_GetBoxPropertyData: no place to put the return value");
FailWithAction(inObjectID != kObjectID_Box, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_GetBoxPropertyData: not the plug-in object");
// Note that for each object, this driver implements all the required properties plus a few
// extras that are useful but not required.
//
// Also, since most of the data that will get returned is static, there are few instances where
// it is necessary to lock the state mutex.
switch(inAddress->mSelector)
{
case kAudioObjectPropertyBaseClass:
// The base class for kAudioBoxClassID is kAudioObjectClassID
FailWithAction(inDataSize < sizeof(AudioClassID), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetBoxPropertyData: not enough space for the return value of kAudioObjectPropertyBaseClass for the box");
*((AudioClassID*)outData) = kAudioObjectClassID;
*outDataSize = sizeof(AudioClassID);
break;
case kAudioObjectPropertyClass:
// The class is always kAudioBoxClassID for regular drivers
FailWithAction(inDataSize < sizeof(AudioClassID), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetBoxPropertyData: not enough space for the return value of kAudioObjectPropertyClass for the box");
*((AudioClassID*)outData) = kAudioBoxClassID;
*outDataSize = sizeof(AudioClassID);
break;
case kAudioObjectPropertyOwner:
// The owner is the plug-in object
FailWithAction(inDataSize < sizeof(AudioObjectID), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetBoxPropertyData: not enough space for the return value of kAudioObjectPropertyOwner for the box");
*((AudioObjectID*)outData) = kObjectID_PlugIn;
*outDataSize = sizeof(AudioObjectID);
break;
case kAudioObjectPropertyName:
// This is the human readable name of the maker of the box.
FailWithAction(inDataSize < sizeof(CFStringRef), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetBoxPropertyData: not enough space for the return value of kAudioObjectPropertyManufacturer for the box");
pthread_mutex_lock(&gPlugIn_StateMutex);
*((CFStringRef*)outData) = gBox_Name;
pthread_mutex_unlock(&gPlugIn_StateMutex);
if(*((CFStringRef*)outData) != NULL)
{
CFRetain(*((CFStringRef*)outData));
}
*outDataSize = sizeof(CFStringRef);
break;
case kAudioObjectPropertyModelName:
// This is the human readable name of the maker of the box.
FailWithAction(inDataSize < sizeof(CFStringRef), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetBoxPropertyData: not enough space for the return value of kAudioObjectPropertyManufacturer for the box");
*((CFStringRef*)outData) = CFSTR("BlackHole");
*outDataSize = sizeof(CFStringRef);
break;
case kAudioObjectPropertyManufacturer:
// This is the human readable name of the maker of the box.
FailWithAction(inDataSize < sizeof(CFStringRef), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetBoxPropertyData: not enough space for the return value of kAudioObjectPropertyManufacturer for the box");
*((CFStringRef*)outData) = CFSTR("Existential Audio Inc.");
*outDataSize = sizeof(CFStringRef);
break;
case kAudioObjectPropertyOwnedObjects:
// This returns the objects directly owned by the object. Boxes don't own anything.
*outDataSize = 0;
break;
case kAudioObjectPropertyIdentify:
// This is used to highling the device in the UI, but it's value has no meaning
FailWithAction(inDataSize < sizeof(UInt32), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetBoxPropertyData: not enough space for the return value of kAudioObjectPropertyIdentify for the box");
*((UInt32*)outData) = 0;
*outDataSize = sizeof(UInt32);
break;
case kAudioObjectPropertySerialNumber:
// This is the human readable serial number of the box.
FailWithAction(inDataSize < sizeof(CFStringRef), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetBoxPropertyData: not enough space for the return value of kAudioObjectPropertySerialNumber for the box");
*((CFStringRef*)outData) = CFSTR("dd658747-4b9a-4de8-a001-c6a2ef1bb235");
*outDataSize = sizeof(CFStringRef);
break;
case kAudioObjectPropertyFirmwareVersion:
// This is the human readable firmware version of the box.
FailWithAction(inDataSize < sizeof(CFStringRef), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetBoxPropertyData: not enough space for the return value of kAudioObjectPropertyFirmwareVersion for the box");
*((CFStringRef*)outData) = CFSTR("0.5.1");
*outDataSize = sizeof(CFStringRef);
break;
case kAudioBoxPropertyBoxUID:
// Boxes have UIDs the same as devices
FailWithAction(inDataSize < sizeof(CFStringRef), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetBoxPropertyData: not enough space for the return value of kAudioObjectPropertyManufacturer for the box");
*((CFStringRef*)outData) = get_box_uid();
break;
case kAudioBoxPropertyTransportType:
// This value represents how the device is attached to the system. This can be
// any 32 bit integer, but common values for this property are defined in
//
FailWithAction(inDataSize < sizeof(UInt32), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetBoxPropertyData: not enough space for the return value of kAudioDevicePropertyTransportType for the box");
*((UInt32*)outData) = kAudioDeviceTransportTypeVirtual;
*outDataSize = sizeof(UInt32);
break;
case kAudioBoxPropertyHasAudio:
// Indicates whether or not the box has audio capabilities
FailWithAction(inDataSize < sizeof(UInt32), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetBoxPropertyData: not enough space for the return value of kAudioBoxPropertyHasAudio for the box");
*((UInt32*)outData) = 1;
*outDataSize = sizeof(UInt32);
break;
case kAudioBoxPropertyHasVideo:
// Indicates whether or not the box has video capabilities
FailWithAction(inDataSize < sizeof(UInt32), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetBoxPropertyData: not enough space for the return value of kAudioBoxPropertyHasVideo for the box");
*((UInt32*)outData) = 0;
*outDataSize = sizeof(UInt32);
break;
case kAudioBoxPropertyHasMIDI:
// Indicates whether or not the box has MIDI capabilities
FailWithAction(inDataSize < sizeof(UInt32), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetBoxPropertyData: not enough space for the return value of kAudioBoxPropertyHasMIDI for the box");
*((UInt32*)outData) = 0;
*outDataSize = sizeof(UInt32);
break;
case kAudioBoxPropertyIsProtected:
// Indicates whether or not the box has requires authentication to use
FailWithAction(inDataSize < sizeof(UInt32), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetBoxPropertyData: not enough space for the return value of kAudioBoxPropertyIsProtected for the box");
*((UInt32*)outData) = 0;
*outDataSize = sizeof(UInt32);
break;
case kAudioBoxPropertyAcquired:
// When set to a non-zero value, the device is acquired for use by the local machine
FailWithAction(inDataSize < sizeof(UInt32), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetBoxPropertyData: not enough space for the return value of kAudioBoxPropertyAcquired for the box");
pthread_mutex_lock(&gPlugIn_StateMutex);
*((UInt32*)outData) = gBox_Acquired ? 1 : 0;
pthread_mutex_unlock(&gPlugIn_StateMutex);
*outDataSize = sizeof(UInt32);
break;
case kAudioBoxPropertyAcquisitionFailed:
// This is used for notifications to say when an attempt to acquire a device has failed.
FailWithAction(inDataSize < sizeof(UInt32), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetBoxPropertyData: not enough space for the return value of kAudioBoxPropertyAcquisitionFailed for the box");
*((UInt32*)outData) = 0;
*outDataSize = sizeof(UInt32);
break;
case kAudioBoxPropertyDeviceList:
// This is used to indicate which devices came from this box
pthread_mutex_lock(&gPlugIn_StateMutex);
if(gBox_Acquired)
{
if(inDataSize < sizeof(AudioObjectID))
{
theAnswer = kAudioHardwareBadPropertySizeError;
*outDataSize = 0;
}
else
{
if (inDataSize >= sizeof(AudioObjectID) * 2)
{
((AudioObjectID*)outData)[0] = kObjectID_Device;
((AudioObjectID*)outData)[1] = kObjectID_Device2;
*outDataSize = sizeof(AudioObjectID) * 2;
}
else
{
((AudioObjectID*)outData)[0] = kObjectID_Device;
*outDataSize = sizeof(AudioObjectID) * 1;
}
}
}
else
{
*outDataSize = 0;
}
pthread_mutex_unlock(&gPlugIn_StateMutex);
break;
default:
theAnswer = kAudioHardwareUnknownPropertyError;
break;
};
Done:
return theAnswer;
}
static OSStatus BlackHole_SetBoxPropertyData(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, const void* inData, UInt32* outNumberPropertiesChanged, AudioObjectPropertyAddress outChangedAddresses[2])
{
#pragma unused(inClientProcessID, inQualifierDataSize, inQualifierData, inDataSize, inData)
// declare the local variables
OSStatus theAnswer = 0;
// check the arguments
FailWithAction(inDriver != gAudioServerPlugInDriverRef, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_SetBoxPropertyData: bad driver reference");
FailWithAction(inAddress == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_SetBoxPropertyData: no address");
FailWithAction(outNumberPropertiesChanged == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_SetBoxPropertyData: no place to return the number of properties that changed");
FailWithAction(outChangedAddresses == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_SetBoxPropertyData: no place to return the properties that changed");
FailWithAction(inObjectID != kObjectID_Box, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_SetBoxPropertyData: not the box object");
// initialize the returned number of changed properties
*outNumberPropertiesChanged = 0;
// Note that for each object, this driver implements all the required properties plus a few
// extras that are useful but not required. There is more detailed commentary about each
// property in the BlackHole_GetPlugInPropertyData() method.
switch(inAddress->mSelector)
{
case kAudioObjectPropertyName:
// Boxes should allow their name to be editable
{
FailWithAction(inData == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_SetBoxPropertyData: NULL data for kAudioObjectPropertyName");
FailWithAction(inDataSize != sizeof(CFStringRef), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_SetBoxPropertyData: wrong size for the data for kAudioObjectPropertyName");
CFStringRef* theNewName = (CFStringRef*)inData;
pthread_mutex_lock(&gPlugIn_StateMutex);
if((theNewName != NULL) && (*theNewName != NULL))
{
CFRetain(*theNewName);
}
if(gBox_Name != NULL)
{
CFRelease(gBox_Name);
}
gBox_Name = *theNewName;
pthread_mutex_unlock(&gPlugIn_StateMutex);
*outNumberPropertiesChanged = 1;
outChangedAddresses[0].mSelector = kAudioObjectPropertyName;
outChangedAddresses[0].mScope = kAudioObjectPropertyScopeGlobal;
outChangedAddresses[0].mElement = kAudioObjectPropertyElementMain;
}
break;
case kAudioObjectPropertyIdentify:
// since we don't have any actual hardware to flash, we will schedule a notification for
// this property off into the future as a testing thing. Note that a real implementation
// of this property should only send the notification if the hardware wants the app to
// flash it's UI for the device.
{
syslog(LOG_NOTICE, "The identify property has been set on the Box implemented by the BlackHole driver.");
FailWithAction(inDataSize != sizeof(UInt32), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_SetBoxPropertyData: wrong size for the data for kAudioObjectPropertyIdentify");
dispatch_after(dispatch_time(0, 2ULL * 1000ULL * 1000ULL * 1000ULL), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^()
{
AudioObjectPropertyAddress theAddress = { kAudioObjectPropertyIdentify, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMain };
gPlugIn_Host->PropertiesChanged(gPlugIn_Host, kObjectID_Box, 1, &theAddress);
});
}
break;
case kAudioBoxPropertyAcquired:
// When the box is acquired, it means the contents, namely the device, are available to the system
{
FailWithAction(inDataSize != sizeof(UInt32), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_SetBoxPropertyData: wrong size for the data for kAudioBoxPropertyAcquired");
pthread_mutex_lock(&gPlugIn_StateMutex);
if(gBox_Acquired != (*((UInt32*)inData) != 0))
{
// the new value is different from the old value, so save it
gBox_Acquired = *((UInt32*)inData) != 0;
gPlugIn_Host->WriteToStorage(gPlugIn_Host, CFSTR("box acquired"), gBox_Acquired ? kCFBooleanTrue : kCFBooleanFalse);
// and it means that this property and the device list property have changed
*outNumberPropertiesChanged = 2;
outChangedAddresses[0].mSelector = kAudioBoxPropertyAcquired;
outChangedAddresses[0].mScope = kAudioObjectPropertyScopeGlobal;
outChangedAddresses[0].mElement = kAudioObjectPropertyElementMain;
outChangedAddresses[1].mSelector = kAudioBoxPropertyDeviceList;
outChangedAddresses[1].mScope = kAudioObjectPropertyScopeGlobal;
outChangedAddresses[1].mElement = kAudioObjectPropertyElementMain;
// but it also means that the device list has changed for the plug-in too
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^()
{
AudioObjectPropertyAddress theAddress = { kAudioPlugInPropertyDeviceList, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMain };
gPlugIn_Host->PropertiesChanged(gPlugIn_Host, kObjectID_PlugIn, 1, &theAddress);
});
}
pthread_mutex_unlock(&gPlugIn_StateMutex);
}
break;
default:
theAnswer = kAudioHardwareUnknownPropertyError;
break;
};
Done:
return theAnswer;
}
#pragma mark Device Property Operations
static Boolean BlackHole_HasDeviceProperty(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress)
{
// This method returns whether or not the given object has the given property.
#pragma unused(inClientProcessID)
// declare the local variables
Boolean theAnswer = false;
// check the arguments
FailIf(inDriver != gAudioServerPlugInDriverRef, Done, "BlackHole_HasDeviceProperty: bad driver reference");
FailIf(inAddress == NULL, Done, "BlackHole_HasDeviceProperty: no address");
FailIf(inObjectID != kObjectID_Device && inObjectID != kObjectID_Device2, Done, "BlackHole_HasDeviceProperty: not the device object");
// Note that for each object, this driver implements all the required properties plus a few
// extras that are useful but not required. There is more detailed commentary about each
// property in the BlackHole_GetDevicePropertyData() method.
switch(inAddress->mSelector)
{
case kAudioObjectPropertyBaseClass:
case kAudioObjectPropertyClass:
case kAudioObjectPropertyOwner:
case kAudioObjectPropertyName:
case kAudioObjectPropertyManufacturer:
case kAudioObjectPropertyOwnedObjects:
case kAudioDevicePropertyDeviceUID:
case kAudioDevicePropertyModelUID:
case kAudioDevicePropertyTransportType:
case kAudioDevicePropertyRelatedDevices:
case kAudioDevicePropertyClockDomain:
case kAudioDevicePropertyDeviceIsAlive:
case kAudioDevicePropertyDeviceIsRunning:
case kAudioObjectPropertyControlList:
case kAudioDevicePropertyNominalSampleRate:
case kAudioDevicePropertyAvailableNominalSampleRates:
case kAudioDevicePropertyIsHidden:
case kAudioDevicePropertyZeroTimeStampPeriod:
case kAudioDevicePropertyIcon:
case kAudioDevicePropertyStreams:
theAnswer = true;
break;
case kAudioDevicePropertyDeviceCanBeDefaultDevice:
case kAudioDevicePropertyDeviceCanBeDefaultSystemDevice:
case kAudioDevicePropertyLatency:
case kAudioDevicePropertySafetyOffset:
case kAudioDevicePropertyPreferredChannelsForStereo:
case kAudioDevicePropertyPreferredChannelLayout:
theAnswer = (inAddress->mScope == kAudioObjectPropertyScopeInput) || (inAddress->mScope == kAudioObjectPropertyScopeOutput);
break;
};
Done:
return theAnswer;
}
static OSStatus BlackHole_IsDevicePropertySettable(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, Boolean* outIsSettable)
{
// This method returns whether or not the given property on the object can have its value
// changed.
#pragma unused(inClientProcessID)
// declare the local variables
OSStatus theAnswer = 0;
// check the arguments
FailWithAction(inDriver != gAudioServerPlugInDriverRef, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_IsDevicePropertySettable: bad driver reference");
FailWithAction(inAddress == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_IsDevicePropertySettable: no address");
FailWithAction(outIsSettable == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_IsDevicePropertySettable: no place to put the return value");
FailWithAction(inObjectID != kObjectID_Device && inObjectID != kObjectID_Device2, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_IsDevicePropertySettable: not the device object");
// Note that for each object, this driver implements all the required properties plus a few
// extras that are useful but not required. There is more detailed commentary about each
// property in the BlackHole_GetDevicePropertyData() method.
switch(inAddress->mSelector)
{
case kAudioObjectPropertyBaseClass:
case kAudioObjectPropertyClass:
case kAudioObjectPropertyOwner:
case kAudioObjectPropertyName:
case kAudioObjectPropertyManufacturer:
case kAudioObjectPropertyOwnedObjects:
case kAudioDevicePropertyDeviceUID:
case kAudioDevicePropertyModelUID:
case kAudioDevicePropertyTransportType:
case kAudioDevicePropertyRelatedDevices:
case kAudioDevicePropertyClockDomain:
case kAudioDevicePropertyDeviceIsAlive:
case kAudioDevicePropertyDeviceIsRunning:
case kAudioDevicePropertyDeviceCanBeDefaultDevice:
case kAudioDevicePropertyDeviceCanBeDefaultSystemDevice:
case kAudioDevicePropertyLatency:
case kAudioDevicePropertyStreams:
case kAudioObjectPropertyControlList:
case kAudioDevicePropertySafetyOffset:
case kAudioDevicePropertyAvailableNominalSampleRates:
case kAudioDevicePropertyIsHidden:
case kAudioDevicePropertyPreferredChannelsForStereo:
case kAudioDevicePropertyPreferredChannelLayout:
case kAudioDevicePropertyZeroTimeStampPeriod:
case kAudioDevicePropertyIcon:
*outIsSettable = false;
break;
case kAudioDevicePropertyNominalSampleRate:
*outIsSettable = true;
break;
default:
theAnswer = kAudioHardwareUnknownPropertyError;
break;
};
Done:
return theAnswer;
}
static OSStatus BlackHole_GetDevicePropertyDataSize(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32* outDataSize)
{
// This method returns the byte size of the property's data.
#pragma unused(inClientProcessID, inQualifierDataSize, inQualifierData)
// declare the local variables
OSStatus theAnswer = 0;
// check the arguments
FailWithAction(inDriver != gAudioServerPlugInDriverRef, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_GetDevicePropertyDataSize: bad driver reference");
FailWithAction(inAddress == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_GetDevicePropertyDataSize: no address");
FailWithAction(outDataSize == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_GetDevicePropertyDataSize: no place to put the return value");
FailWithAction(inObjectID != kObjectID_Device && inObjectID != kObjectID_Device2, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_GetDevicePropertyDataSize: not the device object");
// Note that for each object, this driver implements all the required properties plus a few
// extras that are useful but not required. There is more detailed commentary about each
// property in the BlackHole_GetDevicePropertyData() method.
switch(inAddress->mSelector)
{
case kAudioObjectPropertyBaseClass:
*outDataSize = sizeof(AudioClassID);
break;
case kAudioObjectPropertyClass:
*outDataSize = sizeof(AudioClassID);
break;
case kAudioObjectPropertyOwner:
*outDataSize = sizeof(AudioObjectID);
break;
case kAudioObjectPropertyName:
*outDataSize = sizeof(CFStringRef);
break;
case kAudioObjectPropertyManufacturer:
*outDataSize = sizeof(CFStringRef);
break;
case kAudioObjectPropertyOwnedObjects:
*outDataSize = device_object_list_size(inAddress->mScope, inObjectID) * sizeof(AudioObjectID);
break;
case kAudioDevicePropertyDeviceUID:
*outDataSize = sizeof(CFStringRef);
break;
case kAudioDevicePropertyModelUID:
*outDataSize = sizeof(CFStringRef);
break;
case kAudioDevicePropertyTransportType:
*outDataSize = sizeof(UInt32);
break;
case kAudioDevicePropertyRelatedDevices:
*outDataSize = sizeof(AudioObjectID);
break;
case kAudioDevicePropertyClockDomain:
*outDataSize = sizeof(UInt32);
break;
case kAudioDevicePropertyDeviceIsAlive:
*outDataSize = sizeof(AudioClassID);
break;
case kAudioDevicePropertyDeviceIsRunning:
*outDataSize = sizeof(UInt32);
break;
case kAudioDevicePropertyDeviceCanBeDefaultDevice:
*outDataSize = sizeof(UInt32);
break;
case kAudioDevicePropertyDeviceCanBeDefaultSystemDevice:
*outDataSize = sizeof(UInt32);
break;
case kAudioDevicePropertyLatency:
*outDataSize = sizeof(UInt32);
break;
case kAudioDevicePropertyStreams:
*outDataSize = device_stream_list_size(inAddress->mScope, inObjectID) * sizeof(AudioObjectID);
break;
case kAudioObjectPropertyControlList:
*outDataSize = device_control_list_size(inAddress->mScope, inObjectID) * sizeof(AudioObjectID);
break;
case kAudioDevicePropertySafetyOffset:
*outDataSize = sizeof(UInt32);
break;
case kAudioDevicePropertyNominalSampleRate:
*outDataSize = sizeof(Float64);
break;
case kAudioDevicePropertyAvailableNominalSampleRates:
*outDataSize = kDevice_SampleRatesSize * sizeof(AudioValueRange);
break;
case kAudioDevicePropertyIsHidden:
*outDataSize = sizeof(UInt32);
break;
case kAudioDevicePropertyPreferredChannelsForStereo:
*outDataSize = 2 * sizeof(UInt32);
break;
case kAudioDevicePropertyPreferredChannelLayout:
*outDataSize = offsetof(AudioChannelLayout, mChannelDescriptions) + (kNumber_Of_Channels * sizeof(AudioChannelDescription));
break;
case kAudioDevicePropertyZeroTimeStampPeriod:
*outDataSize = sizeof(UInt32);
break;
case kAudioDevicePropertyIcon:
*outDataSize = sizeof(CFURLRef);
break;
default:
theAnswer = kAudioHardwareUnknownPropertyError;
break;
};
Done:
return theAnswer;
}
static OSStatus BlackHole_GetDevicePropertyData(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, UInt32* outDataSize, void* outData)
{
#pragma unused(inClientProcessID, inQualifierDataSize, inQualifierData)
// declare the local variables
OSStatus theAnswer = 0;
UInt32 theNumberItemsToFetch;
UInt32 theItemIndex;
// check the arguments
FailWithAction(inDriver != gAudioServerPlugInDriverRef, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_GetDevicePropertyData: bad driver reference");
FailWithAction(inAddress == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_GetDevicePropertyData: no address");
FailWithAction(outDataSize == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_GetDevicePropertyData: no place to put the return value size");
FailWithAction(outData == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_GetDevicePropertyData: no place to put the return value");
FailWithAction(inObjectID != kObjectID_Device && inObjectID != kObjectID_Device2, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_GetDevicePropertyData: not the device object");
// Note that for each object, this driver implements all the required properties plus a few
// extras that are useful but not required.
//
// Also, since most of the data that will get returned is static, there are few instances where
// it is necessary to lock the state mutex.
switch(inAddress->mSelector)
{
case kAudioObjectPropertyBaseClass:
// The base class for kAudioDeviceClassID is kAudioObjectClassID
FailWithAction(inDataSize < sizeof(AudioClassID), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetDevicePropertyData: not enough space for the return value of kAudioObjectPropertyBaseClass for the device");
*((AudioClassID*)outData) = kAudioObjectClassID;
*outDataSize = sizeof(AudioClassID);
break;
case kAudioObjectPropertyClass:
// The class is always kAudioDeviceClassID for devices created by drivers
FailWithAction(inDataSize < sizeof(AudioClassID), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetDevicePropertyData: not enough space for the return value of kAudioObjectPropertyClass for the device");
*((AudioClassID*)outData) = kAudioDeviceClassID;
*outDataSize = sizeof(AudioClassID);
break;
case kAudioObjectPropertyOwner:
// The device's owner is the plug-in object
FailWithAction(inDataSize < sizeof(AudioObjectID), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetDevicePropertyData: not enough space for the return value of kAudioObjectPropertyOwner for the device");
*((AudioObjectID*)outData) = kObjectID_PlugIn;
*outDataSize = sizeof(AudioObjectID);
break;
case kAudioObjectPropertyName:
// This is the human readable name of the device.
FailWithAction(inDataSize < sizeof(CFStringRef), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetDevicePropertyData: not enough space for the return value of kAudioObjectPropertyManufacturer for the device");
switch (inObjectID) {
case kObjectID_Device:
*((CFStringRef*)outData) = get_device_name();
*outDataSize = sizeof(CFStringRef);
break;
case kObjectID_Device2:
*((CFStringRef*)outData) = get_device2_name();
*outDataSize = sizeof(CFStringRef);
break;
}
break;
case kAudioObjectPropertyManufacturer:
// This is the human readable name of the maker of the plug-in.
FailWithAction(inDataSize < sizeof(CFStringRef), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetDevicePropertyData: not enough space for the return value of kAudioObjectPropertyManufacturer for the device");
*((CFStringRef*)outData) = CFSTR(kManufacturer_Name);
*outDataSize = sizeof(CFStringRef);
break;
case kAudioObjectPropertyOwnedObjects:
// Calculate the number of items that have been requested. Note that this
// number is allowed to be smaller than the actual size of the list. In such
// case, only that number of items will be returned
theNumberItemsToFetch = minimum(inDataSize / sizeof(AudioObjectID), device_object_list_size(inAddress->mScope, inObjectID));
// fill out the list with the right objects
switch (inObjectID) {
case kObjectID_Device:
for (UInt32 i = 0, k = 0; k < theNumberItemsToFetch; i++)
{
if (kDevice_ObjectList[i].scope == inAddress->mScope || inAddress->mScope == kAudioObjectPropertyScopeGlobal)
{
((AudioObjectID*)outData)[k++] = kDevice_ObjectList[i].id;
}
}
break;
case kObjectID_Device2:
for (UInt32 i = 0, k = 0; k < theNumberItemsToFetch; i++)
{
if (kDevice2_ObjectList[i].scope == inAddress->mScope || inAddress->mScope == kAudioObjectPropertyScopeGlobal)
{
((AudioObjectID*)outData)[k++] = kDevice2_ObjectList[i].id;
}
}
break;
}
// report how much we wrote
*outDataSize = theNumberItemsToFetch * sizeof(AudioObjectID);
break;
case kAudioDevicePropertyDeviceUID:
// This is a CFString that is a persistent token that can identify the same
// audio device across boot sessions. Note that two instances of the same
// device must have different values for this property.
FailWithAction(inDataSize < sizeof(CFStringRef), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetDevicePropertyData: not enough space for the return value of kAudioDevicePropertyDeviceUID for the device");
switch (inObjectID) {
case kObjectID_Device:
*((CFStringRef*)outData) = get_device_uid();
*outDataSize = sizeof(CFStringRef);
break;
case kObjectID_Device2:
*((CFStringRef*)outData) = get_device2_uid();
*outDataSize = sizeof(CFStringRef);
break;
}
break;
case kAudioDevicePropertyModelUID:
// This is a CFString that is a persistent token that can identify audio
// devices that are the same kind of device. Note that two instances of the
// save device must have the same value for this property.
FailWithAction(inDataSize < sizeof(CFStringRef), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetDevicePropertyData: not enough space for the return value of kAudioDevicePropertyModelUID for the device");
*((CFStringRef*)outData) = get_device_model_uid();
*outDataSize = sizeof(CFStringRef);
break;
case kAudioDevicePropertyTransportType:
// This value represents how the device is attached to the system. This can be
// any 32 bit integer, but common values for this property are defined in
//
FailWithAction(inDataSize < sizeof(UInt32), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetDevicePropertyData: not enough space for the return value of kAudioDevicePropertyTransportType for the device");
*((UInt32*)outData) = kAudioDeviceTransportTypeVirtual;
*outDataSize = sizeof(UInt32);
break;
case kAudioDevicePropertyRelatedDevices:
// The related devices property identifys device objects that are very closely
// related. Generally, this is for relating devices that are packaged together
// in the hardware such as when the input side and the output side of a piece
// of hardware can be clocked separately and therefore need to be represented
// as separate AudioDevice objects. In such case, both devices would report
// that they are related to each other. Note that at minimum, a device is
// related to itself, so this list will always be at least one item long.
// Calculate the number of items that have been requested. Note that this
// number is allowed to be smaller than the actual size of the list. In such
// case, only that number of items will be returned
theNumberItemsToFetch = inDataSize / sizeof(AudioObjectID);
// we only have the one device...
if(theNumberItemsToFetch > 1)
{
theNumberItemsToFetch = 1;
}
// Write the devices' object IDs into the return value
if(theNumberItemsToFetch > 0)
{
switch (inObjectID) {
case kObjectID_Device:
((AudioObjectID*)outData)[0] = kObjectID_Device;
break;
case kObjectID_Device2:
((AudioObjectID*)outData)[0] = kObjectID_Device2;
break;
}
}
// report how much we wrote
*outDataSize = theNumberItemsToFetch * sizeof(AudioObjectID);
break;
case kAudioDevicePropertyClockDomain:
// This property allows the device to declare what other devices it is
// synchronized with in hardware. The way it works is that if two devices have
// the same value for this property and the value is not zero, then the two
// devices are synchronized in hardware. Note that a device that either can't
// be synchronized with others or doesn't know should return 0 for this
// property.
FailWithAction(inDataSize < sizeof(UInt32), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetDevicePropertyData: not enough space for the return value of kAudioDevicePropertyClockDomain for the device");
*((UInt32*)outData) = 0;
*outDataSize = sizeof(UInt32);
break;
case kAudioDevicePropertyDeviceIsAlive:
// This property returns whether or not the device is alive. Note that it is
// not uncommon for a device to be dead but still momentarily available in the
// device list. In the case of this device, it will always be alive.
FailWithAction(inDataSize < sizeof(UInt32), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetDevicePropertyData: not enough space for the return value of kAudioDevicePropertyDeviceIsAlive for the device");
*((UInt32*)outData) = 1;
*outDataSize = sizeof(UInt32);
break;
case kAudioDevicePropertyDeviceIsRunning:
// This property returns whether or not IO is running for the device. Note that
// we need to take both the state lock to check this value for thread safety.
FailWithAction(inDataSize < sizeof(UInt32), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetDevicePropertyData: not enough space for the return value of kAudioDevicePropertyDeviceIsRunning for the device");
pthread_mutex_lock(&gPlugIn_StateMutex);
if (inObjectID == kObjectID_Device) {
*((UInt32*)outData) = ((gDevice_IOIsRunning > 0) > 0) ? 1 : 0;
}
switch (inObjectID) {
case kObjectID_Device:
*((UInt32*)outData) = ((gDevice_IOIsRunning > 0) > 0) ? 1 : 0;
break;
case kObjectID_Device2:
*((UInt32*)outData) = ((gDevice2_IOIsRunning > 0) > 0) ? 1 : 0;
break;
default:
*((UInt32*)outData) = 0;
break;
}
pthread_mutex_unlock(&gPlugIn_StateMutex);
*outDataSize = sizeof(UInt32);
break;
case kAudioDevicePropertyDeviceCanBeDefaultDevice:
// This property returns whether or not the device wants to be able to be the
// default device for content. This is the device that iTunes and QuickTime
// will use to play their content on and FaceTime will use as it's microhphone.
// Nearly all devices should allow for this.
FailWithAction(inDataSize < sizeof(UInt32), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetDevicePropertyData: not enough space for the return value of kAudioDevicePropertyDeviceCanBeDefaultDevice for the device");
*((UInt32*)outData) = kCanBeDefaultDevice;
*outDataSize = sizeof(UInt32);
break;
case kAudioDevicePropertyDeviceCanBeDefaultSystemDevice:
// This property returns whether or not the device wants to be the system
// default device. This is the device that is used to play interface sounds and
// other incidental or UI-related sounds on. Most devices should allow this
// although devices with lots of latency may not want to.
FailWithAction(inDataSize < sizeof(UInt32), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetDevicePropertyData: not enough space for the return value of kAudioDevicePropertyDeviceCanBeDefaultSystemDevice for the device");
*((UInt32*)outData) = kCanBeDefaultSystemDevice;
*outDataSize = sizeof(UInt32);
break;
case kAudioDevicePropertyLatency:
// This property returns the presentation latency of the device. For this,
// device, the value is 0 due to the fact that it always vends silence.
FailWithAction(inDataSize < sizeof(UInt32), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetDevicePropertyData: not enough space for the return value of kAudioDevicePropertyLatency for the device");
*((UInt32*)outData) = 0;
*outDataSize = sizeof(UInt32);
break;
case kAudioDevicePropertyStreams:
// Calculate the number of items that have been requested. Note that this
// number is allowed to be smaller than the actual size of the list. In such
// case, only that number of items will be returned
theNumberItemsToFetch = minimum(inDataSize / sizeof(AudioObjectID), device_stream_list_size(inAddress->mScope, inObjectID));
// fill out the list with as many objects as requested
switch (inObjectID) {
case kObjectID_Device:
for (UInt32 i = 0, k = 0; k < theNumberItemsToFetch; i++)
{
if ((kDevice_ObjectList[i].type == kObjectType_Stream) &&
(kDevice_ObjectList[i].scope == inAddress->mScope || inAddress->mScope == kAudioObjectPropertyScopeGlobal))
{
((AudioObjectID*)outData)[k++] = kDevice_ObjectList[i].id;
}
}
break;
case kObjectID_Device2:
for (UInt32 i = 0, k = 0; k < theNumberItemsToFetch; i++)
{
if ((kDevice2_ObjectList[i].type == kObjectType_Stream) &&
(kDevice2_ObjectList[i].scope == inAddress->mScope || inAddress->mScope == kAudioObjectPropertyScopeGlobal))
{
((AudioObjectID*)outData)[k++] = kDevice2_ObjectList[i].id;
}
}
break;
}
// report how much we wrote
*outDataSize = theNumberItemsToFetch * sizeof(AudioObjectID);
break;
case kAudioObjectPropertyControlList:
// Calculate the number of items that have been requested. Note that this
// number is allowed to be smaller than the actual size of the list. In such
// case, only that number of items will be returned
theNumberItemsToFetch = minimum(inDataSize / sizeof(AudioObjectID), device_control_list_size(inAddress->mScope, inObjectID));
// fill out the list with as many objects as requested
switch (inObjectID) {
case kObjectID_Device:
pthread_mutex_lock(&gPlugIn_StateMutex);
for (UInt32 i = 0, k = 0; k < theNumberItemsToFetch; i++)
{
// TODO remove hack! There must be a better way than looking for a fixed i
if ((kDevice_ObjectList[i].type == kObjectType_Control) && !(!gPitch_Adjust_Enabled && kDevice_ObjectList[i].id==kObjectID_Pitch_Adjust))
{
((AudioObjectID*)outData)[k++] = kDevice_ObjectList[i].id;
}
}
pthread_mutex_unlock(&gPlugIn_StateMutex);
break;
case kObjectID_Device2:
for (UInt32 i = 0, k = 0; k < theNumberItemsToFetch; i++)
{
if ((kDevice_ObjectList[i].type == kObjectType_Control) && !(!gPitch_Adjust_Enabled && kDevice_ObjectList[i].id==kObjectID_Pitch_Adjust))
{
((AudioObjectID*)outData)[k++] = kDevice2_ObjectList[i].id;
}
}
break;
}
// report how much we wrote
*outDataSize = theNumberItemsToFetch * sizeof(AudioObjectID);
break;
case kAudioDevicePropertySafetyOffset:
// This property returns the how close to now the HAL can read and write. For
// this, device, the value is 0 due to the fact that it always vends silence.
FailWithAction(inDataSize < sizeof(UInt32), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetDevicePropertyData: not enough space for the return value of kAudioDevicePropertySafetyOffset for the device");
*((UInt32*)outData) = kLatency_Frame_Size;
*outDataSize = sizeof(UInt32);
break;
case kAudioDevicePropertyNominalSampleRate:
// This property returns the nominal sample rate of the device. Note that we
// only need to take the state lock to get this value.
FailWithAction(inDataSize < sizeof(Float64), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetDevicePropertyData: not enough space for the return value of kAudioDevicePropertyNominalSampleRate for the device");
pthread_mutex_lock(&gPlugIn_StateMutex);
*((Float64*)outData) = gDevice_SampleRate;
pthread_mutex_unlock(&gPlugIn_StateMutex);
*outDataSize = sizeof(Float64);
break;
case kAudioDevicePropertyAvailableNominalSampleRates:
// This returns all nominal sample rates the device supports as an array of
// AudioValueRangeStructs. Note that for discrete sampler rates, the range
// will have the minimum value equal to the maximum value.
// Calculate the number of items that have been requested. Note that this
// number is allowed to be smaller than the actual size of the list. In such
// case, only that number of items will be returned
theNumberItemsToFetch = inDataSize / sizeof(AudioValueRange);
// clamp it to the number of items we have
if(theNumberItemsToFetch > kDevice_SampleRatesSize)
{
theNumberItemsToFetch = kDevice_SampleRatesSize;
}
// fill out the return array
for(UInt32 i = 0; i < theNumberItemsToFetch; i++)
{
((AudioValueRange*)outData)[i].mMinimum = kDevice_SampleRates[i];
((AudioValueRange*)outData)[i].mMaximum = kDevice_SampleRates[i];
}
// report how much we wrote
*outDataSize = theNumberItemsToFetch * sizeof(AudioValueRange);
break;
case kAudioDevicePropertyIsHidden:
// This returns whether or not the device is visible to clients.
FailWithAction(inDataSize < sizeof(UInt32), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetDevicePropertyData: not enough space for the return value of kAudioDevicePropertyIsHidden for the device");
switch (inObjectID) {
case kObjectID_Device:
*((UInt32*)outData) = kDevice_IsHidden;
break;
case kObjectID_Device2:
*((UInt32*)outData) = kDevice2_IsHidden;
break;
}
*outDataSize = sizeof(UInt32);
break;
case kAudioDevicePropertyPreferredChannelsForStereo:
// This property returns which two channels to use as left/right for stereo
// data by default. Note that the channel numbers are 1-based.xz
FailWithAction(inDataSize < (2 * sizeof(UInt32)), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetDevicePropertyData: not enough space for the return value of kAudioDevicePropertyPreferredChannelsForStereo for the device");
((UInt32*)outData)[0] = 1;
((UInt32*)outData)[1] = 2;
*outDataSize = 2 * sizeof(UInt32);
break;
case kAudioDevicePropertyPreferredChannelLayout:
// This property returns the default AudioChannelLayout to use for the device
// by default. For this device, we return a stereo ACL.
{
// calculate how big the
UInt32 theACLSize = offsetof(AudioChannelLayout, mChannelDescriptions) + (kNumber_Of_Channels * sizeof(AudioChannelDescription));
FailWithAction(inDataSize < theACLSize, theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetDevicePropertyData: not enough space for the return value of kAudioDevicePropertyPreferredChannelLayout for the device");
((AudioChannelLayout*)outData)->mChannelLayoutTag = kAudioChannelLayoutTag_UseChannelDescriptions;
((AudioChannelLayout*)outData)->mChannelBitmap = 0;
((AudioChannelLayout*)outData)->mNumberChannelDescriptions = kNumber_Of_Channels;
for(theItemIndex = 0; theItemIndex < kNumber_Of_Channels; ++theItemIndex)
{
((AudioChannelLayout*)outData)->mChannelDescriptions[theItemIndex].mChannelLabel = kAudioChannelLabel_Left + theItemIndex;
((AudioChannelLayout*)outData)->mChannelDescriptions[theItemIndex].mChannelFlags = 0;
((AudioChannelLayout*)outData)->mChannelDescriptions[theItemIndex].mCoordinates[0] = 0;
((AudioChannelLayout*)outData)->mChannelDescriptions[theItemIndex].mCoordinates[1] = 0;
((AudioChannelLayout*)outData)->mChannelDescriptions[theItemIndex].mCoordinates[2] = 0;
}
*outDataSize = theACLSize;
}
break;
case kAudioDevicePropertyZeroTimeStampPeriod:
// This property returns how many frames the HAL should expect to see between
// successive sample times in the zero time stamps this device provides.
FailWithAction(inDataSize < sizeof(UInt32), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetDevicePropertyData: not enough space for the return value of kAudioDevicePropertyZeroTimeStampPeriod for the device");
*((UInt32*)outData) = kDevice_RingBufferSize;
*outDataSize = sizeof(UInt32);
break;
case kAudioDevicePropertyIcon:
{
// This is a CFURL that points to the device's Icon in the plug-in's resource bundle.
FailWithAction(inDataSize < sizeof(CFURLRef), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetDevicePropertyData: not enough space for the return value of kAudioDevicePropertyDeviceUID for the device");
CFBundleRef theBundle = CFBundleGetBundleWithIdentifier(CFSTR(kPlugIn_BundleID));
FailWithAction(theBundle == NULL, theAnswer = kAudioHardwareUnspecifiedError, Done, "BlackHole_GetDevicePropertyData: could not get the plug-in bundle for kAudioDevicePropertyIcon");
CFURLRef theURL = CFBundleCopyResourceURL(theBundle, CFSTR(kPlugIn_Icon), NULL, NULL);
FailWithAction(theURL == NULL, theAnswer = kAudioHardwareUnspecifiedError, Done, "BlackHole_GetDevicePropertyData: could not get the URL for kAudioDevicePropertyIcon");
*((CFURLRef*)outData) = theURL;
*outDataSize = sizeof(CFURLRef);
}
break;
default:
theAnswer = kAudioHardwareUnknownPropertyError;
break;
};
Done:
return theAnswer;
}
static OSStatus BlackHole_SetDevicePropertyData(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, const void* inData, UInt32* outNumberPropertiesChanged, AudioObjectPropertyAddress outChangedAddresses[2])
{
#pragma unused(inClientProcessID, inQualifierDataSize, inQualifierData)
// declare the local variables
OSStatus theAnswer = 0;
Float64 theOldSampleRate;
// check the arguments
FailWithAction(inDriver != gAudioServerPlugInDriverRef, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_SetDevicePropertyData: bad driver reference");
FailWithAction(inAddress == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_SetDevicePropertyData: no address");
FailWithAction(outNumberPropertiesChanged == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_SetDevicePropertyData: no place to return the number of properties that changed");
FailWithAction(outChangedAddresses == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_SetDevicePropertyData: no place to return the properties that changed");
FailWithAction(inObjectID != kObjectID_Device && inObjectID != kObjectID_Device2, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_SetDevicePropertyData: not the device object");
// initialize the returned number of changed properties
*outNumberPropertiesChanged = 0;
// Note that for each object, this driver implements all the required properties plus a few
// extras that are useful but not required. There is more detailed commentary about each
// property in the BlackHole_GetDevicePropertyData() method.
switch(inAddress->mSelector)
{
case kAudioDevicePropertyNominalSampleRate:
// Changing the sample rate needs to be handled via the
// RequestConfigChange/PerformConfigChange machinery.
// check the arguments
FailWithAction(inDataSize != sizeof(Float64), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_SetDevicePropertyData: wrong size for the data for kAudioDevicePropertyNominalSampleRate");
FailWithAction(!is_valid_sample_rate(*(const Float64*)inData), theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_SetDevicePropertyData: unsupported value for kAudioDevicePropertyNominalSampleRate");
// make sure that the new value is different than the old value
pthread_mutex_lock(&gPlugIn_StateMutex);
theOldSampleRate = gDevice_SampleRate;
gDevice_RequestedSampleRate = *((const Float64*)inData);
pthread_mutex_unlock(&gPlugIn_StateMutex);
if(*((const Float64*)inData) != theOldSampleRate)
{
// we dispatch this so that the change can happen asynchronously
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ gPlugIn_Host->RequestDeviceConfigurationChange(gPlugIn_Host, kObjectID_Device, ChangeAction_SetSampleRate, NULL); });
}
break;
default:
theAnswer = kAudioHardwareUnknownPropertyError;
break;
};
Done:
return theAnswer;
}
#pragma mark Stream Property Operations
static Boolean BlackHole_HasStreamProperty(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress)
{
// This method returns whether or not the given object has the given property.
#pragma unused(inClientProcessID)
// declare the local variables
Boolean theAnswer = false;
// check the arguments
FailIf(inDriver != gAudioServerPlugInDriverRef, Done, "BlackHole_HasStreamProperty: bad driver reference");
FailIf(inAddress == NULL, Done, "BlackHole_HasStreamProperty: no address");
FailIf((inObjectID != kObjectID_Stream_Input) && (inObjectID != kObjectID_Stream_Output), Done, "BlackHole_HasStreamProperty: not a stream object");
// Note that for each object, this driver implements all the required properties plus a few
// extras that are useful but not required. There is more detailed commentary about each
// property in the BlackHole_GetStreamPropertyData() method.
switch(inAddress->mSelector)
{
case kAudioObjectPropertyBaseClass:
case kAudioObjectPropertyClass:
case kAudioObjectPropertyOwner:
case kAudioObjectPropertyOwnedObjects:
case kAudioStreamPropertyIsActive:
case kAudioStreamPropertyDirection:
case kAudioStreamPropertyTerminalType:
case kAudioStreamPropertyStartingChannel:
case kAudioStreamPropertyLatency:
case kAudioStreamPropertyVirtualFormat:
case kAudioStreamPropertyPhysicalFormat:
case kAudioStreamPropertyAvailableVirtualFormats:
case kAudioStreamPropertyAvailablePhysicalFormats:
theAnswer = true;
break;
};
Done:
return theAnswer;
}
static OSStatus BlackHole_IsStreamPropertySettable(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, Boolean* outIsSettable)
{
// This method returns whether or not the given property on the object can have its value
// changed.
#pragma unused(inClientProcessID)
// declare the local variables
OSStatus theAnswer = 0;
// check the arguments
FailWithAction(inDriver != gAudioServerPlugInDriverRef, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_IsStreamPropertySettable: bad driver reference");
FailWithAction(inAddress == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_IsStreamPropertySettable: no address");
FailWithAction(outIsSettable == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_IsStreamPropertySettable: no place to put the return value");
FailWithAction((inObjectID != kObjectID_Stream_Input) && (inObjectID != kObjectID_Stream_Output), theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_IsStreamPropertySettable: not a stream object");
// Note that for each object, this driver implements all the required properties plus a few
// extras that are useful but not required. There is more detailed commentary about each
// property in the BlackHole_GetStreamPropertyData() method.
switch(inAddress->mSelector)
{
case kAudioObjectPropertyBaseClass:
case kAudioObjectPropertyClass:
case kAudioObjectPropertyOwner:
case kAudioObjectPropertyOwnedObjects:
case kAudioStreamPropertyDirection:
case kAudioStreamPropertyTerminalType:
case kAudioStreamPropertyStartingChannel:
case kAudioStreamPropertyLatency:
case kAudioStreamPropertyAvailableVirtualFormats:
case kAudioStreamPropertyAvailablePhysicalFormats:
*outIsSettable = false;
break;
case kAudioStreamPropertyIsActive:
case kAudioStreamPropertyVirtualFormat:
case kAudioStreamPropertyPhysicalFormat:
*outIsSettable = true;
break;
default:
theAnswer = kAudioHardwareUnknownPropertyError;
break;
};
Done:
return theAnswer;
}
static OSStatus BlackHole_GetStreamPropertyDataSize(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32* outDataSize)
{
// This method returns the byte size of the property's data.
#pragma unused(inClientProcessID, inQualifierDataSize, inQualifierData)
// declare the local variables
OSStatus theAnswer = 0;
// check the arguments
FailWithAction(inDriver != gAudioServerPlugInDriverRef, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_GetStreamPropertyDataSize: bad driver reference");
FailWithAction(inAddress == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_GetStreamPropertyDataSize: no address");
FailWithAction(outDataSize == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_GetStreamPropertyDataSize: no place to put the return value");
FailWithAction((inObjectID != kObjectID_Stream_Input) && (inObjectID != kObjectID_Stream_Output), theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_GetStreamPropertyDataSize: not a stream object");
// Note that for each object, this driver implements all the required properties plus a few
// extras that are useful but not required. There is more detailed commentary about each
// property in the BlackHole_GetStreamPropertyData() method.
switch(inAddress->mSelector)
{
case kAudioObjectPropertyBaseClass:
*outDataSize = sizeof(AudioClassID);
break;
case kAudioObjectPropertyClass:
*outDataSize = sizeof(AudioClassID);
break;
case kAudioObjectPropertyOwner:
*outDataSize = sizeof(AudioObjectID);
break;
case kAudioObjectPropertyOwnedObjects:
*outDataSize = 0 * sizeof(AudioObjectID);
break;
case kAudioStreamPropertyIsActive:
*outDataSize = sizeof(UInt32);
break;
case kAudioStreamPropertyDirection:
*outDataSize = sizeof(UInt32);
break;
case kAudioStreamPropertyTerminalType:
*outDataSize = sizeof(UInt32);
break;
case kAudioStreamPropertyStartingChannel:
*outDataSize = sizeof(UInt32);
break;
case kAudioStreamPropertyLatency:
*outDataSize = sizeof(UInt32);
break;
case kAudioStreamPropertyVirtualFormat:
case kAudioStreamPropertyPhysicalFormat:
*outDataSize = sizeof(AudioStreamBasicDescription);
break;
case kAudioStreamPropertyAvailableVirtualFormats:
case kAudioStreamPropertyAvailablePhysicalFormats:
*outDataSize = kDevice_SampleRatesSize * sizeof(AudioStreamRangedDescription);
break;
default:
theAnswer = kAudioHardwareUnknownPropertyError;
break;
};
Done:
return theAnswer;
}
static OSStatus BlackHole_GetStreamPropertyData(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, UInt32* outDataSize, void* outData)
{
#pragma unused(inClientProcessID, inQualifierDataSize, inQualifierData)
// declare the local variables
OSStatus theAnswer = 0;
UInt32 theNumberItemsToFetch;
// check the arguments
FailWithAction(inDriver != gAudioServerPlugInDriverRef, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_GetStreamPropertyData: bad driver reference");
FailWithAction(inAddress == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_GetStreamPropertyData: no address");
FailWithAction(outDataSize == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_GetStreamPropertyData: no place to put the return value size");
FailWithAction(outData == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_GetStreamPropertyData: no place to put the return value");
FailWithAction((inObjectID != kObjectID_Stream_Input) && (inObjectID != kObjectID_Stream_Output), theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_GetStreamPropertyData: not a stream object");
// Note that for each object, this driver implements all the required properties plus a few
// extras that are useful but not required.
//
// Also, since most of the data that will get returned is static, there are few instances where
// it is necessary to lock the state mutex.
switch(inAddress->mSelector)
{
case kAudioObjectPropertyBaseClass:
// The base class for kAudioStreamClassID is kAudioObjectClassID
FailWithAction(inDataSize < sizeof(AudioClassID), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetStreamPropertyData: not enough space for the return value of kAudioObjectPropertyBaseClass for the stream");
*((AudioClassID*)outData) = kAudioObjectClassID;
*outDataSize = sizeof(AudioClassID);
break;
case kAudioObjectPropertyClass:
// The class is always kAudioStreamClassID for streams created by drivers
FailWithAction(inDataSize < sizeof(AudioClassID), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetStreamPropertyData: not enough space for the return value of kAudioObjectPropertyClass for the stream");
*((AudioClassID*)outData) = kAudioStreamClassID;
*outDataSize = sizeof(AudioClassID);
break;
case kAudioObjectPropertyOwner:
// The stream's owner is the device object
FailWithAction(inDataSize < sizeof(AudioObjectID), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetStreamPropertyData: not enough space for the return value of kAudioObjectPropertyOwner for the stream");
*((AudioObjectID*)outData) = kObjectID_Device;
*outDataSize = sizeof(AudioObjectID);
break;
case kAudioObjectPropertyOwnedObjects:
// Streams do not own any objects
*outDataSize = 0 * sizeof(AudioObjectID);
break;
case kAudioStreamPropertyIsActive:
// This property tells the device whether or not the given stream is going to
// be used for IO. Note that we need to take the state lock to examine this
// value.
FailWithAction(inDataSize < sizeof(UInt32), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetStreamPropertyData: not enough space for the return value of kAudioStreamPropertyIsActive for the stream");
pthread_mutex_lock(&gPlugIn_StateMutex);
*((UInt32*)outData) = (inObjectID == kObjectID_Stream_Input) ? gStream_Input_IsActive : gStream_Output_IsActive;
pthread_mutex_unlock(&gPlugIn_StateMutex);
*outDataSize = sizeof(UInt32);
break;
case kAudioStreamPropertyDirection:
// This returns whether the stream is an input stream or an output stream.
FailWithAction(inDataSize < sizeof(UInt32), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetStreamPropertyData: not enough space for the return value of kAudioStreamPropertyDirection for the stream");
*((UInt32*)outData) = (inObjectID == kObjectID_Stream_Input) ? 1 : 0;
*outDataSize = sizeof(UInt32);
break;
case kAudioStreamPropertyTerminalType:
// This returns a value that indicates what is at the other end of the stream
// such as a speaker or headphones, or a microphone. Values for this property
// are defined in
FailWithAction(inDataSize < sizeof(UInt32), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetStreamPropertyData: not enough space for the return value of kAudioStreamPropertyTerminalType for the stream");
*((UInt32*)outData) = (inObjectID == kObjectID_Stream_Input) ? kAudioStreamTerminalTypeMicrophone : kAudioStreamTerminalTypeSpeaker;
*outDataSize = sizeof(UInt32);
break;
case kAudioStreamPropertyStartingChannel:
// This property returns the absolute channel number for the first channel in
// the stream. For example, if a device has two output streams with two
// channels each, then the starting channel number for the first stream is 1
// and the starting channel number fo the second stream is 3.
FailWithAction(inDataSize < sizeof(UInt32), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetStreamPropertyData: not enough space for the return value of kAudioStreamPropertyStartingChannel for the stream");
*((UInt32*)outData) = 1;
*outDataSize = sizeof(UInt32);
break;
case kAudioStreamPropertyLatency:
// This property returns any additional presentation latency the stream has.
FailWithAction(inDataSize < sizeof(UInt32), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetStreamPropertyData: not enough space for the return value of kAudioStreamPropertyStartingChannel for the stream");
*((UInt32*)outData) = kLatency_Frame_Size;
*outDataSize = sizeof(UInt32);
break;
case kAudioStreamPropertyVirtualFormat:
case kAudioStreamPropertyPhysicalFormat:
// This returns the current format of the stream in an
// AudioStreamBasicDescription. Note that we need to hold the state lock to get
// this value.
// Note that for devices that don't override the mix operation, the virtual
// format has to be the same as the physical format.
FailWithAction(inDataSize < sizeof(AudioStreamBasicDescription), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetStreamPropertyData: not enough space for the return value of kAudioStreamPropertyVirtualFormat for the stream");
pthread_mutex_lock(&gPlugIn_StateMutex);
((AudioStreamBasicDescription*)outData)->mSampleRate = gDevice_SampleRate;
((AudioStreamBasicDescription*)outData)->mFormatID = kAudioFormatLinearPCM;
((AudioStreamBasicDescription*)outData)->mFormatFlags = kAudioFormatFlagIsFloat | kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsPacked;
((AudioStreamBasicDescription*)outData)->mBytesPerPacket = kBytes_Per_Channel * kNumber_Of_Channels;
((AudioStreamBasicDescription*)outData)->mFramesPerPacket = 1;
((AudioStreamBasicDescription*)outData)->mBytesPerFrame = kBytes_Per_Channel * kNumber_Of_Channels;
((AudioStreamBasicDescription*)outData)->mChannelsPerFrame = kNumber_Of_Channels;
((AudioStreamBasicDescription*)outData)->mBitsPerChannel = kBits_Per_Channel;
pthread_mutex_unlock(&gPlugIn_StateMutex);
*outDataSize = sizeof(AudioStreamBasicDescription);
break;
case kAudioStreamPropertyAvailableVirtualFormats:
case kAudioStreamPropertyAvailablePhysicalFormats:
// This returns an array of AudioStreamRangedDescriptions that describe what
// formats are supported.
// Calculate the number of items that have been requested. Note that this
// number is allowed to be smaller than the actual size of the list. In such
// case, only that number of items will be returned
theNumberItemsToFetch = inDataSize / sizeof(AudioStreamRangedDescription);
// clamp it to the number of items we have
if(theNumberItemsToFetch > kDevice_SampleRatesSize)
{
theNumberItemsToFetch = kDevice_SampleRatesSize;
}
// fill out the return array
for(UInt32 i = 0; i < theNumberItemsToFetch; i++)
{
((AudioStreamRangedDescription*)outData)[i].mFormat.mSampleRate = kDevice_SampleRates[i];
((AudioStreamRangedDescription*)outData)[i].mFormat.mFormatID = kAudioFormatLinearPCM;
((AudioStreamRangedDescription*)outData)[i].mFormat.mFormatFlags = kAudioFormatFlagIsFloat | kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsPacked;
((AudioStreamRangedDescription*)outData)[i].mFormat.mBytesPerPacket = kBytes_Per_Frame;
((AudioStreamRangedDescription*)outData)[i].mFormat.mFramesPerPacket = 1;
((AudioStreamRangedDescription*)outData)[i].mFormat.mBytesPerFrame = kBytes_Per_Frame;
((AudioStreamRangedDescription*)outData)[i].mFormat.mChannelsPerFrame = kNumber_Of_Channels;
((AudioStreamRangedDescription*)outData)[i].mFormat.mBitsPerChannel = kBits_Per_Channel;
((AudioStreamRangedDescription*)outData)[i].mSampleRateRange.mMinimum = kDevice_SampleRates[i];
((AudioStreamRangedDescription*)outData)[i].mSampleRateRange.mMaximum = kDevice_SampleRates[i];
}
// report how much we wrote
*outDataSize = theNumberItemsToFetch * sizeof(AudioStreamRangedDescription);
break;
default:
theAnswer = kAudioHardwareUnknownPropertyError;
break;
};
Done:
return theAnswer;
}
static OSStatus BlackHole_SetStreamPropertyData(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, const void* inData, UInt32* outNumberPropertiesChanged, AudioObjectPropertyAddress outChangedAddresses[2])
{
#pragma unused(inClientProcessID, inQualifierDataSize, inQualifierData)
// declare the local variables
OSStatus theAnswer = 0;
Float64 theOldSampleRate;
// check the arguments
FailWithAction(inDriver != gAudioServerPlugInDriverRef, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_SetStreamPropertyData: bad driver reference");
FailWithAction(inAddress == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_SetStreamPropertyData: no address");
FailWithAction(outNumberPropertiesChanged == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_SetStreamPropertyData: no place to return the number of properties that changed");
FailWithAction(outChangedAddresses == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_SetStreamPropertyData: no place to return the properties that changed");
FailWithAction((inObjectID != kObjectID_Stream_Input) && (inObjectID != kObjectID_Stream_Output), theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_SetStreamPropertyData: not a stream object");
// initialize the returned number of changed properties
*outNumberPropertiesChanged = 0;
// Note that for each object, this driver implements all the required properties plus a few
// extras that are useful but not required. There is more detailed commentary about each
// property in the BlackHole_GetStreamPropertyData() method.
switch(inAddress->mSelector)
{
case kAudioStreamPropertyIsActive:
// Changing the active state of a stream doesn't affect IO or change the structure
// so we can just save the state and send the notification.
FailWithAction(inDataSize != sizeof(UInt32), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_SetStreamPropertyData: wrong size for the data for kAudioDevicePropertyNominalSampleRate");
pthread_mutex_lock(&gPlugIn_StateMutex);
if(inObjectID == kObjectID_Stream_Input)
{
if(gStream_Input_IsActive != (*((const UInt32*)inData) != 0))
{
gStream_Input_IsActive = *((const UInt32*)inData) != 0;
*outNumberPropertiesChanged = 1;
outChangedAddresses[0].mSelector = kAudioStreamPropertyIsActive;
outChangedAddresses[0].mScope = kAudioObjectPropertyScopeGlobal;
outChangedAddresses[0].mElement = kAudioObjectPropertyElementMain;
}
}
else
{
if(gStream_Output_IsActive != (*((const UInt32*)inData) != 0))
{
gStream_Output_IsActive = *((const UInt32*)inData) != 0;
*outNumberPropertiesChanged = 1;
outChangedAddresses[0].mSelector = kAudioStreamPropertyIsActive;
outChangedAddresses[0].mScope = kAudioObjectPropertyScopeGlobal;
outChangedAddresses[0].mElement = kAudioObjectPropertyElementMain;
}
}
pthread_mutex_unlock(&gPlugIn_StateMutex);
break;
case kAudioStreamPropertyVirtualFormat:
case kAudioStreamPropertyPhysicalFormat:
// Changing the stream format needs to be handled via the
// RequestConfigChange/PerformConfigChange machinery. Note that because this
// device only supports 2 channel 32 bit float data, the only thing that can
// change is the sample rate.
FailWithAction(inDataSize != sizeof(AudioStreamBasicDescription), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_SetStreamPropertyData: wrong size for the data for kAudioStreamPropertyPhysicalFormat");
FailWithAction(((const AudioStreamBasicDescription*)inData)->mFormatID != kAudioFormatLinearPCM, theAnswer = kAudioDeviceUnsupportedFormatError, Done, "BlackHole_SetStreamPropertyData: unsupported format ID for kAudioStreamPropertyPhysicalFormat");
FailWithAction(((const AudioStreamBasicDescription*)inData)->mFormatFlags != (kAudioFormatFlagIsFloat | kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsPacked), theAnswer = kAudioDeviceUnsupportedFormatError, Done, "BlackHole_SetStreamPropertyData: unsupported format flags for kAudioStreamPropertyPhysicalFormat");
FailWithAction(((const AudioStreamBasicDescription*)inData)->mBytesPerPacket != kBytes_Per_Frame, theAnswer = kAudioDeviceUnsupportedFormatError, Done, "BlackHole_SetStreamPropertyData: unsupported bytes per packet for kAudioStreamPropertyPhysicalFormat");
FailWithAction(((const AudioStreamBasicDescription*)inData)->mFramesPerPacket != 1, theAnswer = kAudioDeviceUnsupportedFormatError, Done, "BlackHole_SetStreamPropertyData: unsupported frames per packet for kAudioStreamPropertyPhysicalFormat");
FailWithAction(((const AudioStreamBasicDescription*)inData)->mBytesPerFrame != kBytes_Per_Frame, theAnswer = kAudioDeviceUnsupportedFormatError, Done, "BlackHole_SetStreamPropertyData: unsupported bytes per frame for kAudioStreamPropertyPhysicalFormat");
FailWithAction(((const AudioStreamBasicDescription*)inData)->mChannelsPerFrame != kNumber_Of_Channels, theAnswer = kAudioDeviceUnsupportedFormatError, Done, "BlackHole_SetStreamPropertyData: unsupported channels per frame for kAudioStreamPropertyPhysicalFormat");
FailWithAction(((const AudioStreamBasicDescription*)inData)->mBitsPerChannel != kBits_Per_Channel, theAnswer = kAudioDeviceUnsupportedFormatError, Done, "BlackHole_SetStreamPropertyData: unsupported bits per channel for kAudioStreamPropertyPhysicalFormat");
FailWithAction(!is_valid_sample_rate(((const AudioStreamBasicDescription*)inData)->mSampleRate), theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_SetStreamPropertyData: unsupported sample rate for kAudioStreamPropertyPhysicalFormat");
// If we made it this far, the requested format is something we support, so make sure the sample rate is actually different
pthread_mutex_lock(&gPlugIn_StateMutex);
theOldSampleRate = gDevice_SampleRate;
gDevice_RequestedSampleRate = ((const AudioStreamBasicDescription*)inData)->mSampleRate;
pthread_mutex_unlock(&gPlugIn_StateMutex);
if(((const AudioStreamBasicDescription*)inData)->mSampleRate != theOldSampleRate)
{
// we dispatch this so that the change can happen asynchronously
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ gPlugIn_Host->RequestDeviceConfigurationChange(gPlugIn_Host, kObjectID_Device, ChangeAction_SetSampleRate, NULL); });
}
break;
default:
theAnswer = kAudioHardwareUnknownPropertyError;
break;
};
Done:
return theAnswer;
}
#pragma mark Control Property Operations
static Boolean BlackHole_HasControlProperty(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress)
{
// This method returns whether or not the given object has the given property.
#pragma unused(inClientProcessID)
// declare the local variables
Boolean theAnswer = false;
// check the arguments
FailIf(inDriver != gAudioServerPlugInDriverRef, Done, "BlackHole_HasControlProperty: bad driver reference");
FailIf(inAddress == NULL, Done, "BlackHole_HasControlProperty: no address");
// Note that for each object, this driver implements all the required properties plus a few
// extras that are useful but not required. There is more detailed commentary about each
// property in the BlackHole_GetControlPropertyData() method.
switch(inObjectID)
{
case kObjectID_Volume_Input_Master:
case kObjectID_Volume_Output_Master:
switch(inAddress->mSelector)
{
case kAudioObjectPropertyBaseClass:
case kAudioObjectPropertyClass:
case kAudioObjectPropertyOwner:
case kAudioObjectPropertyOwnedObjects:
case kAudioControlPropertyScope:
case kAudioControlPropertyElement:
case kAudioLevelControlPropertyScalarValue:
case kAudioLevelControlPropertyDecibelValue:
case kAudioLevelControlPropertyDecibelRange:
case kAudioLevelControlPropertyConvertScalarToDecibels:
case kAudioLevelControlPropertyConvertDecibelsToScalar:
theAnswer = true;
break;
};
break;
case kObjectID_Mute_Input_Master:
case kObjectID_Mute_Output_Master:
switch(inAddress->mSelector)
{
case kAudioObjectPropertyBaseClass:
case kAudioObjectPropertyClass:
case kAudioObjectPropertyOwner:
case kAudioObjectPropertyOwnedObjects:
case kAudioControlPropertyScope:
case kAudioControlPropertyElement:
case kAudioBooleanControlPropertyValue:
theAnswer = true;
break;
};
break;
case kObjectID_Pitch_Adjust:
switch(inAddress->mSelector)
{
case kAudioObjectPropertyBaseClass:
case kAudioObjectPropertyClass:
case kAudioObjectPropertyOwner:
case kAudioObjectPropertyOwnedObjects:
case kAudioControlPropertyScope:
case kAudioControlPropertyElement:
case kAudioStereoPanControlPropertyValue:
theAnswer = true;
break;
};
break;
case kObjectID_ClockSource:
switch(inAddress->mSelector)
{
case kAudioObjectPropertyBaseClass:
case kAudioObjectPropertyClass:
case kAudioObjectPropertyOwner:
case kAudioObjectPropertyOwnedObjects:
case kAudioControlPropertyScope:
case kAudioControlPropertyElement:
case kAudioSelectorControlPropertyCurrentItem:
case kAudioSelectorControlPropertyAvailableItems:
case kAudioSelectorControlPropertyItemName:
theAnswer = true;
break;
};
break;
};
Done:
return theAnswer;
}
static OSStatus BlackHole_IsControlPropertySettable(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, Boolean* outIsSettable)
{
// This method returns whether or not the given property on the object can have its value
// changed.
#pragma unused(inClientProcessID)
// declare the local variables
OSStatus theAnswer = 0;
// check the arguments
FailWithAction(inDriver != gAudioServerPlugInDriverRef, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_IsControlPropertySettable: bad driver reference");
FailWithAction(inAddress == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_IsControlPropertySettable: no address");
FailWithAction(outIsSettable == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_IsControlPropertySettable: no place to put the return value");
// Note that for each object, this driver implements all the required properties plus a few
// extras that are useful but not required. There is more detailed commentary about each
// property in the BlackHole_GetControlPropertyData() method.
switch(inObjectID)
{
case kObjectID_Volume_Input_Master:
case kObjectID_Volume_Output_Master:
switch(inAddress->mSelector)
{
case kAudioObjectPropertyBaseClass:
case kAudioObjectPropertyClass:
case kAudioObjectPropertyOwner:
case kAudioObjectPropertyOwnedObjects:
case kAudioControlPropertyScope:
case kAudioControlPropertyElement:
case kAudioLevelControlPropertyDecibelRange:
case kAudioLevelControlPropertyConvertScalarToDecibels:
case kAudioLevelControlPropertyConvertDecibelsToScalar:
*outIsSettable = false;
break;
case kAudioLevelControlPropertyScalarValue:
case kAudioLevelControlPropertyDecibelValue:
*outIsSettable = true;
break;
default:
theAnswer = kAudioHardwareUnknownPropertyError;
break;
};
break;
case kObjectID_Mute_Input_Master:
case kObjectID_Mute_Output_Master:
switch(inAddress->mSelector)
{
case kAudioObjectPropertyBaseClass:
case kAudioObjectPropertyClass:
case kAudioObjectPropertyOwner:
case kAudioObjectPropertyOwnedObjects:
case kAudioControlPropertyScope:
case kAudioControlPropertyElement:
*outIsSettable = false;
break;
case kAudioBooleanControlPropertyValue:
*outIsSettable = true;
break;
default:
theAnswer = kAudioHardwareUnknownPropertyError;
break;
};
break;
case kObjectID_Pitch_Adjust:
switch(inAddress->mSelector)
{
case kAudioObjectPropertyBaseClass:
case kAudioObjectPropertyClass:
case kAudioObjectPropertyOwner:
case kAudioObjectPropertyOwnedObjects:
case kAudioControlPropertyScope:
case kAudioControlPropertyElement:
*outIsSettable = false;
break;
case kAudioStereoPanControlPropertyValue:
*outIsSettable = true;
break;
default:
theAnswer = kAudioHardwareUnknownPropertyError;
break;
};
break;
case kObjectID_ClockSource:
switch(inAddress->mSelector)
{
case kAudioObjectPropertyBaseClass:
case kAudioObjectPropertyClass:
case kAudioObjectPropertyOwner:
case kAudioObjectPropertyOwnedObjects:
case kAudioControlPropertyScope:
case kAudioControlPropertyElement:
*outIsSettable = false;
break;
case kAudioSelectorControlPropertyCurrentItem:
*outIsSettable = true;
break;
default:
theAnswer = kAudioHardwareUnknownPropertyError;
break;
};
break;
default:
theAnswer = kAudioHardwareBadObjectError;
break;
};
Done:
return theAnswer;
}
static OSStatus BlackHole_GetControlPropertyDataSize(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32* outDataSize)
{
// This method returns the byte size of the property's data.
#pragma unused(inClientProcessID, inQualifierDataSize, inQualifierData)
// declare the local variables
OSStatus theAnswer = 0;
// check the arguments
FailWithAction(inDriver != gAudioServerPlugInDriverRef, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_GetControlPropertyDataSize: bad driver reference");
FailWithAction(inAddress == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_GetControlPropertyDataSize: no address");
FailWithAction(outDataSize == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_GetControlPropertyDataSize: no place to put the return value");
// Note that for each object, this driver implements all the required properties plus a few
// extras that are useful but not required. There is more detailed commentary about each
// property in the BlackHole_GetControlPropertyData() method.
switch(inObjectID)
{
case kObjectID_Volume_Input_Master:
case kObjectID_Volume_Output_Master:
switch(inAddress->mSelector)
{
case kAudioObjectPropertyBaseClass:
*outDataSize = sizeof(AudioClassID);
break;
case kAudioObjectPropertyClass:
*outDataSize = sizeof(AudioClassID);
break;
case kAudioObjectPropertyOwner:
*outDataSize = sizeof(AudioObjectID);
break;
case kAudioObjectPropertyOwnedObjects:
*outDataSize = 0 * sizeof(AudioObjectID);
break;
case kAudioControlPropertyScope:
*outDataSize = sizeof(AudioObjectPropertyScope);
break;
case kAudioControlPropertyElement:
*outDataSize = sizeof(AudioObjectPropertyElement);
break;
case kAudioLevelControlPropertyScalarValue:
*outDataSize = sizeof(Float32);
break;
case kAudioLevelControlPropertyDecibelValue:
*outDataSize = sizeof(Float32);
break;
case kAudioLevelControlPropertyDecibelRange:
*outDataSize = sizeof(AudioValueRange);
break;
case kAudioLevelControlPropertyConvertScalarToDecibels:
*outDataSize = sizeof(Float32);
break;
case kAudioLevelControlPropertyConvertDecibelsToScalar:
*outDataSize = sizeof(Float32);
break;
default:
theAnswer = kAudioHardwareUnknownPropertyError;
break;
};
break;
case kObjectID_Mute_Input_Master:
case kObjectID_Mute_Output_Master:
switch(inAddress->mSelector)
{
case kAudioObjectPropertyBaseClass:
*outDataSize = sizeof(AudioClassID);
break;
case kAudioObjectPropertyClass:
*outDataSize = sizeof(AudioClassID);
break;
case kAudioObjectPropertyOwner:
*outDataSize = sizeof(AudioObjectID);
break;
case kAudioObjectPropertyOwnedObjects:
*outDataSize = 0 * sizeof(AudioObjectID);
break;
case kAudioControlPropertyScope:
*outDataSize = sizeof(AudioObjectPropertyScope);
break;
case kAudioControlPropertyElement:
*outDataSize = sizeof(AudioObjectPropertyElement);
break;
case kAudioBooleanControlPropertyValue:
*outDataSize = sizeof(UInt32);
break;
default:
theAnswer = kAudioHardwareUnknownPropertyError;
break;
};
break;
case kObjectID_Pitch_Adjust:
switch(inAddress->mSelector)
{
case kAudioObjectPropertyBaseClass:
*outDataSize = sizeof(AudioClassID);
break;
case kAudioObjectPropertyClass:
*outDataSize = sizeof(AudioClassID);
break;
case kAudioObjectPropertyOwner:
*outDataSize = sizeof(AudioObjectID);
break;
case kAudioObjectPropertyOwnedObjects:
*outDataSize = 0 * sizeof(AudioObjectID);
break;
case kAudioControlPropertyScope:
*outDataSize = sizeof(AudioObjectPropertyScope);
break;
case kAudioControlPropertyElement:
*outDataSize = sizeof(AudioObjectPropertyElement);
break;
case kAudioStereoPanControlPropertyValue:
*outDataSize = sizeof(Float32);
break;
default:
theAnswer = kAudioHardwareUnknownPropertyError;
break;
};
break;
case kObjectID_ClockSource:
switch(inAddress->mSelector)
{
case kAudioObjectPropertyBaseClass:
*outDataSize = sizeof(AudioClassID);
break;
case kAudioObjectPropertyClass:
*outDataSize = sizeof(AudioClassID);
break;
case kAudioObjectPropertyOwner:
*outDataSize = sizeof(AudioObjectID);
break;
case kAudioObjectPropertyOwnedObjects:
*outDataSize = 0 * sizeof(AudioObjectID);
break;
case kAudioControlPropertyScope:
*outDataSize = sizeof(AudioObjectPropertyScope);
break;
case kAudioControlPropertyElement:
*outDataSize = sizeof(AudioObjectPropertyElement);
break;
case kAudioSelectorControlPropertyCurrentItem:
*outDataSize = sizeof(UInt32);
break;
case kAudioSelectorControlPropertyAvailableItems:
*outDataSize = kClockSource_NumberItems * sizeof(UInt32);
break;
case kAudioSelectorControlPropertyItemName:
*outDataSize = sizeof(CFStringRef);
break;
default:
theAnswer = kAudioHardwareUnknownPropertyError;
break;
};
break;
default:
theAnswer = kAudioHardwareBadObjectError;
break;
};
Done:
return theAnswer;
}
static OSStatus BlackHole_GetControlPropertyData(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, UInt32* outDataSize, void* outData)
{
#pragma unused(inClientProcessID, inQualifierData, inQualifierDataSize)
// declare the local variables
OSStatus theAnswer = 0;
UInt32 theNumberItemsToFetch;
UInt32 theItemIndex;
// check the arguments
FailWithAction(inDriver != gAudioServerPlugInDriverRef, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_GetControlPropertyData: bad driver reference");
FailWithAction(inAddress == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_GetControlPropertyData: no address");
FailWithAction(outDataSize == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_GetControlPropertyData: no place to put the return value size");
FailWithAction(outData == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_GetControlPropertyData: no place to put the return value");
// Note that for each object, this driver implements all the required properties plus a few
// extras that are useful but not required.
//
// Also, since most of the data that will get returned is static, there are few instances where
// it is necessary to lock the state mutex.
switch(inObjectID)
{
case kObjectID_Volume_Input_Master:
case kObjectID_Volume_Output_Master:
switch(inAddress->mSelector)
{
case kAudioObjectPropertyBaseClass:
// The base class for kAudioVolumeControlClassID is kAudioLevelControlClassID
FailWithAction(inDataSize < sizeof(AudioClassID), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetControlPropertyData: not enough space for the return value of kAudioObjectPropertyBaseClass for the volume control");
*((AudioClassID*)outData) = kAudioLevelControlClassID;
*outDataSize = sizeof(AudioClassID);
break;
case kAudioObjectPropertyClass:
// Volume controls are of the class, kAudioVolumeControlClassID
FailWithAction(inDataSize < sizeof(AudioClassID), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetControlPropertyData: not enough space for the return value of kAudioObjectPropertyClass for the volume control");
*((AudioClassID*)outData) = kAudioVolumeControlClassID;
*outDataSize = sizeof(AudioClassID);
break;
case kAudioObjectPropertyOwner:
// The control's owner is the device object
FailWithAction(inDataSize < sizeof(AudioObjectID), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetControlPropertyData: not enough space for the return value of kAudioObjectPropertyOwner for the volume control");
*((AudioObjectID*)outData) = kObjectID_Device;
*outDataSize = sizeof(AudioObjectID);
break;
case kAudioObjectPropertyOwnedObjects:
// Controls do not own any objects
*outDataSize = 0 * sizeof(AudioObjectID);
break;
case kAudioControlPropertyScope:
// This property returns the scope that the control is attached to.
FailWithAction(inDataSize < sizeof(AudioObjectPropertyScope), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetControlPropertyData: not enough space for the return value of kAudioControlPropertyScope for the volume control");
*((AudioObjectPropertyScope*)outData) = (inObjectID == kObjectID_Volume_Input_Master) ? kAudioObjectPropertyScopeInput : kAudioObjectPropertyScopeOutput;
*outDataSize = sizeof(AudioObjectPropertyScope);
break;
case kAudioControlPropertyElement:
// This property returns the element that the control is attached to.
FailWithAction(inDataSize < sizeof(AudioObjectPropertyElement), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetControlPropertyData: not enough space for the return value of kAudioControlPropertyElement for the volume control");
*((AudioObjectPropertyElement*)outData) = kAudioObjectPropertyElementMain;
*outDataSize = sizeof(AudioObjectPropertyElement);
break;
case kAudioLevelControlPropertyScalarValue:
// This returns the value of the control in the normalized range of 0 to 1.
// Note that we need to take the state lock to examine the value.
FailWithAction(inDataSize < sizeof(Float32), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetControlPropertyData: not enough space for the return value of kAudioLevelControlPropertyScalarValue for the volume control");
pthread_mutex_lock(&gPlugIn_StateMutex);
*((Float32*)outData) = volume_to_scalar(gVolume_Master_Value);
pthread_mutex_unlock(&gPlugIn_StateMutex);
*outDataSize = sizeof(Float32);
break;
case kAudioLevelControlPropertyDecibelValue:
// This returns the dB value of the control.
// Note that we need to take the state lock to examine the value.
FailWithAction(inDataSize < sizeof(Float32), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetControlPropertyData: not enough space for the return value of kAudioLevelControlPropertyDecibelValue for the volume control");
pthread_mutex_lock(&gPlugIn_StateMutex);
*((Float32*)outData) = gVolume_Master_Value;
pthread_mutex_unlock(&gPlugIn_StateMutex);
*((Float32*)outData) = volume_to_decibel(*((Float32*)outData));
// report how much we wrote
*outDataSize = sizeof(Float32);
break;
case kAudioLevelControlPropertyDecibelRange:
// This returns the dB range of the control.
FailWithAction(inDataSize < sizeof(AudioValueRange), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetControlPropertyData: not enough space for the return value of kAudioLevelControlPropertyDecibelRange for the volume control");
((AudioValueRange*)outData)->mMinimum = kVolume_MinDB;
((AudioValueRange*)outData)->mMaximum = kVolume_MaxDB;
*outDataSize = sizeof(AudioValueRange);
break;
case kAudioLevelControlPropertyConvertScalarToDecibels:
// This takes the scalar value in outData and converts it to dB.
FailWithAction(inDataSize < sizeof(Float32), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetControlPropertyData: not enough space for the return value of kAudioLevelControlPropertyDecibelValue for the volume control");
// clamp the value to be between 0 and 1
if(*((Float32*)outData) < 0.0)
{
*((Float32*)outData) = 0;
}
if(*((Float32*)outData) > 1.0)
{
*((Float32*)outData) = 1.0;
}
// Note that we square the scalar value before converting to dB so as to
// provide a better curve for the slider
*((Float32*)outData) *= *((Float32*)outData);
*((Float32*)outData) = kVolume_MinDB + (*((Float32*)outData) * (kVolume_MaxDB - kVolume_MinDB));
// report how much we wrote
*outDataSize = sizeof(Float32);
break;
case kAudioLevelControlPropertyConvertDecibelsToScalar:
// This takes the dB value in outData and converts it to scalar.
FailWithAction(inDataSize < sizeof(Float32), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetControlPropertyData: not enough space for the return value of kAudioLevelControlPropertyDecibelValue for the volume control");
// clamp the value to be between kVolume_MinDB and kVolume_MaxDB
if(*((Float32*)outData) < kVolume_MinDB)
{
*((Float32*)outData) = kVolume_MinDB;
}
if(*((Float32*)outData) > kVolume_MaxDB)
{
*((Float32*)outData) = kVolume_MaxDB;
}
// Note that we square the scalar value before converting to dB so as to
// provide a better curve for the slider. We undo that here.
*((Float32*)outData) = *((Float32*)outData) - kVolume_MinDB;
*((Float32*)outData) /= kVolume_MaxDB - kVolume_MinDB;
*((Float32*)outData) = sqrtf(*((Float32*)outData));
// report how much we wrote
*outDataSize = sizeof(Float32);
break;
default:
theAnswer = kAudioHardwareUnknownPropertyError;
break;
};
break;
case kObjectID_Mute_Input_Master:
case kObjectID_Mute_Output_Master:
switch(inAddress->mSelector)
{
case kAudioObjectPropertyBaseClass:
// The base class for kAudioMuteControlClassID is kAudioBooleanControlClassID
FailWithAction(inDataSize < sizeof(AudioClassID), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetControlPropertyData: not enough space for the return value of kAudioObjectPropertyBaseClass for the mute control");
*((AudioClassID*)outData) = kAudioBooleanControlClassID;
*outDataSize = sizeof(AudioClassID);
break;
case kAudioObjectPropertyClass:
// Mute controls are of the class, kAudioMuteControlClassID
FailWithAction(inDataSize < sizeof(AudioClassID), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetControlPropertyData: not enough space for the return value of kAudioObjectPropertyClass for the mute control");
*((AudioClassID*)outData) = kAudioMuteControlClassID;
*outDataSize = sizeof(AudioClassID);
break;
case kAudioObjectPropertyOwner:
// The control's owner is the device object
FailWithAction(inDataSize < sizeof(AudioObjectID), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetControlPropertyData: not enough space for the return value of kAudioObjectPropertyOwner for the mute control");
*((AudioObjectID*)outData) = kObjectID_Device;
*outDataSize = sizeof(AudioObjectID);
break;
case kAudioObjectPropertyOwnedObjects:
// Controls do not own any objects
*outDataSize = 0 * sizeof(AudioObjectID);
break;
case kAudioControlPropertyScope:
// This property returns the scope that the control is attached to.
FailWithAction(inDataSize < sizeof(AudioObjectPropertyScope), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetControlPropertyData: not enough space for the return value of kAudioControlPropertyScope for the mute control");
*((AudioObjectPropertyScope*)outData) = (inObjectID == kObjectID_Mute_Input_Master) ? kAudioObjectPropertyScopeInput : kAudioObjectPropertyScopeOutput;
*outDataSize = sizeof(AudioObjectPropertyScope);
break;
case kAudioControlPropertyElement:
// This property returns the element that the control is attached to.
FailWithAction(inDataSize < sizeof(AudioObjectPropertyElement), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetControlPropertyData: not enough space for the return value of kAudioControlPropertyElement for the mute control");
*((AudioObjectPropertyElement*)outData) = kAudioObjectPropertyElementMain;
*outDataSize = sizeof(AudioObjectPropertyElement);
break;
case kAudioBooleanControlPropertyValue:
// This returns the value of the mute control where 0 means that mute is off
// and audio can be heard and 1 means that mute is on and audio cannot be heard.
// Note that we need to take the state lock to examine this value.
FailWithAction(inDataSize < sizeof(UInt32), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetControlPropertyData: not enough space for the return value of kAudioBooleanControlPropertyValue for the mute control");
pthread_mutex_lock(&gPlugIn_StateMutex);
*((UInt32*)outData) = gMute_Master_Value ? 1 : 0;
pthread_mutex_unlock(&gPlugIn_StateMutex);
*outDataSize = sizeof(UInt32);
break;
default:
theAnswer = kAudioHardwareUnknownPropertyError;
break;
};
break;
case kObjectID_Pitch_Adjust:
switch(inAddress->mSelector)
{
case kAudioObjectPropertyBaseClass:
// The base class for kAudioMuteControlClassID is kAudioBooleanControlClassID
FailWithAction(inDataSize < sizeof(AudioClassID), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetControlPropertyData: not enough space for the return value of kAudioObjectPropertyBaseClass for the pitch control");
*((AudioClassID*)outData) = kAudioStereoPanControlClassID;
*outDataSize = sizeof(AudioClassID);
break;
case kAudioObjectPropertyClass:
// Level controls are of the class, kAudioLevelControlClassID
FailWithAction(inDataSize < sizeof(AudioClassID), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetControlPropertyData: not enough space for the return value of kAudioObjectPropertyClass for the pitch control");
*((AudioClassID*)outData) = kAudioStereoPanControlClassID;
*outDataSize = sizeof(AudioClassID);
break;
case kAudioObjectPropertyOwner:
// The control's owner is the device object
FailWithAction(inDataSize < sizeof(AudioObjectID), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetControlPropertyData: not enough space for the return value of kAudioObjectPropertyOwner for the pitch control");
*((AudioObjectID*)outData) = kObjectID_Device;
*outDataSize = sizeof(AudioObjectID);
break;
case kAudioObjectPropertyOwnedObjects:
// Controls do not own any objects
*outDataSize = 0 * sizeof(AudioObjectID);
break;
case kAudioControlPropertyScope:
// This property returns the scope that the control is attached to.
FailWithAction(inDataSize < sizeof(AudioObjectPropertyScope), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetControlPropertyData: not enough space for the return value of kAudioControlPropertyScope for the pitch control");
*((AudioObjectPropertyScope*)outData) = kAudioObjectPropertyScopeOutput;
*outDataSize = sizeof(AudioObjectPropertyScope);
break;
case kAudioControlPropertyElement:
// This property returns the element that the control is attached to.
FailWithAction(inDataSize < sizeof(AudioObjectPropertyElement), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetControlPropertyData: not enough space for the return value of kAudioControlPropertyElement for the pitch control");
*((AudioObjectPropertyElement*)outData) = kAudioObjectPropertyElementMain;
*outDataSize = sizeof(AudioObjectPropertyElement);
break;
case kAudioStereoPanControlPropertyValue:
// This returns the value of the pitch control.
// Note that we need to take the state lock to examine this value.
FailWithAction(inDataSize < sizeof(Float32), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetControlPropertyData: not enough space for the return value of kAudioLevelControlScalarValue for the pitch control");
pthread_mutex_lock(&gPlugIn_StateMutex);
*((Float32*)outData) = (inObjectID == kObjectID_Pitch_Adjust) ? gPitch_Adjust : 0.5;
pthread_mutex_unlock(&gPlugIn_StateMutex);
*outDataSize = sizeof(Float32);
break;
default:
theAnswer = kAudioHardwareUnknownPropertyError;
break;
};
break;
case kObjectID_ClockSource:
switch(inAddress->mSelector)
{
case kAudioObjectPropertyBaseClass:
// The base class for kAudioDataSourceControlClassID is kAudioSelectorControlClassID
FailWithAction(inDataSize < sizeof(AudioClassID), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetControlPropertyData: not enough space for the return value of kAudioObjectPropertyBaseClass for the data source control");
*((AudioClassID*)outData) = kAudioSelectorControlClassID;
*outDataSize = sizeof(AudioClassID);
break;
case kAudioObjectPropertyClass:
// Data Source controls are of the class, kAudioDataSourceControlClassID
FailWithAction(inDataSize < sizeof(AudioClassID), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetControlPropertyData: not enough space for the return value of kAudioObjectPropertyClass for the data source control");
*((AudioClassID*)outData) = kAudioClockSourceControlClassID;
*outDataSize = sizeof(AudioClassID);
break;
case kAudioObjectPropertyOwner:
// The control's owner is the device object
FailWithAction(inDataSize < sizeof(AudioObjectID), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetControlPropertyData: not enough space for the return value of kAudioObjectPropertyOwner for the data source control");
*((AudioObjectID*)outData) = kObjectID_Device;
*outDataSize = sizeof(AudioObjectID);
break;
case kAudioObjectPropertyOwnedObjects:
// Controls do not own any objects
*outDataSize = 0 * sizeof(AudioObjectID);
break;
case kAudioControlPropertyScope:
// This property returns the scope that the control is attached to.
FailWithAction(inDataSize < sizeof(AudioObjectPropertyScope), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetControlPropertyData: not enough space for the return value of kAudioControlPropertyScope for the data source control");
*((AudioObjectPropertyScope*)outData) = kAudioObjectPropertyScopeGlobal;
*outDataSize = sizeof(AudioObjectPropertyScope);
break;
case kAudioControlPropertyElement:
// This property returns the element that the control is attached to.
FailWithAction(inDataSize < sizeof(AudioObjectPropertyElement), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetControlPropertyData: not enough space for the return value of kAudioControlPropertyElement for the data source control");
*((AudioObjectPropertyElement*)outData) = kAudioObjectPropertyElementMain;
*outDataSize = sizeof(AudioObjectPropertyElement);
break;
case kAudioSelectorControlPropertyCurrentItem:
// This returns the value of the data source selector.
// Note that we need to take the state lock to examine this value.
FailWithAction(inDataSize < sizeof(UInt32), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetControlPropertyData: not enough space for the return value of kAudioSelectorControlPropertyCurrentItem for the data source control");
pthread_mutex_lock(&gPlugIn_StateMutex);
*((UInt32*)outData) = gClockSource_Value;
pthread_mutex_unlock(&gPlugIn_StateMutex);
*outDataSize = sizeof(UInt32);
break;
case kAudioSelectorControlPropertyAvailableItems:
// This returns the IDs for all the items the data source control supports.
// Calculate the number of items that have been requested. Note that this
// number is allowed to be smaller than the actual size of the list. In such
// case, only that number of items will be returned
theNumberItemsToFetch = inDataSize / sizeof(UInt32);
// clamp it to the number of items we have
if(theNumberItemsToFetch > kClockSource_NumberItems)
{
theNumberItemsToFetch = kClockSource_NumberItems;
}
// fill out the return array
for(theItemIndex = 0; theItemIndex < theNumberItemsToFetch; ++theItemIndex)
{
((UInt32*)outData)[theItemIndex] = theItemIndex;
}
// report how much we wrote
*outDataSize = theNumberItemsToFetch * sizeof(UInt32);
break;
case kAudioSelectorControlPropertyItemName:
// This returns the user-readable name for the selector item in the qualifier
FailWithAction(inDataSize < sizeof(CFStringRef), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetControlPropertyData: not enough space for the return value of kAudioSelectorControlPropertyItemName for the clock source control");
FailWithAction(inQualifierDataSize != sizeof(UInt32), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_GetControlPropertyData: wrong size for the qualifier of kAudioSelectorControlPropertyItemName for the clock source control");
FailWithAction(*((const UInt32*)inQualifierData) >= kClockSource_NumberItems, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_GetControlPropertyData: the item in the qualifier is not valid for kAudioSelectorControlPropertyItemName for the data source control");
if (*(UInt32*)inQualifierData == 0) {
*(CFStringRef*)outData = CFSTR(kClockSource_InternalFixed);
}
else if (*(UInt32*)inQualifierData == 1) {
*(CFStringRef*)outData = CFSTR(kClockSource_InternalAdjustable);
}
//else {
// *(CFStringRef*)outData = CFSTR("Unknown");
//}
*outDataSize = sizeof(CFStringRef);
break;
default:
theAnswer = kAudioHardwareUnknownPropertyError;
break;
};
break;
default:
theAnswer = kAudioHardwareBadObjectError;
break;
};
Done:
return theAnswer;
}
static OSStatus BlackHole_SetControlPropertyData(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, const void* inData, UInt32* outNumberPropertiesChanged, AudioObjectPropertyAddress outChangedAddresses[2])
{
#pragma unused(inClientProcessID, inQualifierDataSize, inQualifierData)
// declare the local variables
OSStatus theAnswer = 0;
Float32 theNewVolume;
Float32 theNewPitch;
UInt32 theNewSource;
// check the arguments
FailWithAction(inDriver != gAudioServerPlugInDriverRef, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_SetControlPropertyData: bad driver reference");
FailWithAction(inAddress == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_SetControlPropertyData: no address");
FailWithAction(outNumberPropertiesChanged == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_SetControlPropertyData: no place to return the number of properties that changed");
FailWithAction(outChangedAddresses == NULL, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_SetControlPropertyData: no place to return the properties that changed");
// initialize the returned number of changed properties
*outNumberPropertiesChanged = 0;
// Note that for each object, this driver implements all the required properties plus a few
// extras that are useful but not required. There is more detailed commentary about each
// property in the BlackHole_GetControlPropertyData() method.
switch(inObjectID)
{
case kObjectID_Volume_Input_Master:
case kObjectID_Volume_Output_Master:
switch(inAddress->mSelector)
{
case kAudioLevelControlPropertyScalarValue:
// For the scalar volume, we clamp the new value to [0, 1]. Note that if this
// value changes, it implies that the dB value changed too.
FailWithAction(inDataSize != sizeof(Float32), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_SetControlPropertyData: wrong size for the data for kAudioLevelControlPropertyScalarValue");
theNewVolume = volume_from_scalar(*((const Float32*)inData));
if(theNewVolume < 0.0)
{
theNewVolume = 0.0;
}
else if(theNewVolume > 1.0)
{
theNewVolume = 1.0;
}
pthread_mutex_lock(&gPlugIn_StateMutex);
if(gVolume_Master_Value != theNewVolume)
{
gVolume_Master_Value = theNewVolume;
*outNumberPropertiesChanged = 2;
outChangedAddresses[0].mSelector = kAudioLevelControlPropertyScalarValue;
outChangedAddresses[0].mScope = kAudioObjectPropertyScopeGlobal;
outChangedAddresses[0].mElement = kAudioObjectPropertyElementMain;
outChangedAddresses[1].mSelector = kAudioLevelControlPropertyDecibelValue;
outChangedAddresses[1].mScope = kAudioObjectPropertyScopeGlobal;
outChangedAddresses[1].mElement = kAudioObjectPropertyElementMain;
}
pthread_mutex_unlock(&gPlugIn_StateMutex);
break;
case kAudioLevelControlPropertyDecibelValue:
// For the dB value, we first convert it to a scalar value since that is how
// the value is tracked. Note that if this value changes, it implies that the
// scalar value changes as well.
FailWithAction(inDataSize != sizeof(Float32), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_SetControlPropertyData: wrong size for the data for kAudioLevelControlPropertyScalarValue");
theNewVolume = *((const Float32*)inData);
if(theNewVolume < kVolume_MinDB)
{
theNewVolume = kVolume_MinDB;
}
else if(theNewVolume > kVolume_MaxDB)
{
theNewVolume = kVolume_MaxDB;
}
theNewVolume = volume_from_decibel(theNewVolume);
pthread_mutex_lock(&gPlugIn_StateMutex);
if(gVolume_Master_Value != theNewVolume)
{
gVolume_Master_Value = theNewVolume;
*outNumberPropertiesChanged = 2;
outChangedAddresses[0].mSelector = kAudioLevelControlPropertyScalarValue;
outChangedAddresses[0].mScope = kAudioObjectPropertyScopeGlobal;
outChangedAddresses[0].mElement = kAudioObjectPropertyElementMain;
outChangedAddresses[1].mSelector = kAudioLevelControlPropertyDecibelValue;
outChangedAddresses[1].mScope = kAudioObjectPropertyScopeGlobal;
outChangedAddresses[1].mElement = kAudioObjectPropertyElementMain;
}
pthread_mutex_unlock(&gPlugIn_StateMutex);
break;
default:
theAnswer = kAudioHardwareUnknownPropertyError;
break;
};
break;
case kObjectID_Mute_Input_Master:
case kObjectID_Mute_Output_Master:
switch(inAddress->mSelector)
{
case kAudioBooleanControlPropertyValue:
FailWithAction(inDataSize != sizeof(UInt32), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_SetControlPropertyData: wrong size for the data for kAudioBooleanControlPropertyValue");
pthread_mutex_lock(&gPlugIn_StateMutex);
if(gMute_Master_Value != (*((const UInt32*)inData) != 0))
{
gMute_Master_Value = *((const UInt32*)inData) != 0;
*outNumberPropertiesChanged = 1;
outChangedAddresses[0].mSelector = kAudioBooleanControlPropertyValue;
outChangedAddresses[0].mScope = kAudioObjectPropertyScopeGlobal;
outChangedAddresses[0].mElement = kAudioObjectPropertyElementMain;
}
pthread_mutex_unlock(&gPlugIn_StateMutex);
break;
default:
theAnswer = kAudioHardwareUnknownPropertyError;
break;
};
break;
case kObjectID_Pitch_Adjust:
switch(inAddress->mSelector)
{
case kAudioStereoPanControlPropertyValue:
// For the scalar pitch, we clamp the new value to [0, 1].
FailWithAction(inDataSize != sizeof(Float32), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_SetControlPropertyData: wrong size for the data for kAudioLevelControlPropertyScalarValue");
theNewPitch = *((const Float32*)inData);
if(theNewPitch < 0.0)
{
theNewPitch = 0.0;
}
else if(theNewPitch > 1.0)
{
theNewPitch = 1.0;
}
pthread_mutex_lock(&gPlugIn_StateMutex);
if(gPitch_Adjust != theNewPitch)
{
gPitch_Adjust = theNewPitch;
gDevice_AdjustedTicksPerFrame = gDevice_HostTicksPerFrame - gDevice_HostTicksPerFrame/100.0 * 2.0*(gPitch_Adjust - 0.5);
*outNumberPropertiesChanged = 1;
outChangedAddresses[0].mSelector = kAudioStereoPanControlPropertyValue;
outChangedAddresses[0].mScope = kAudioObjectPropertyScopeGlobal;
outChangedAddresses[0].mElement = kAudioObjectPropertyElementMain;
}
pthread_mutex_unlock(&gPlugIn_StateMutex);
break;
default:
theAnswer = kAudioHardwareUnknownPropertyError;
break;
};
break;
case kObjectID_ClockSource:
switch(inAddress->mSelector)
{
case kAudioSelectorControlPropertyCurrentItem:
FailWithAction(inDataSize != sizeof(UInt32), theAnswer = kAudioHardwareBadPropertySizeError, Done, "BlackHole_SetControlPropertyData: wrong size for the data for kAudioSelectorControlPropertyCurrentItem");
theNewSource = *((const UInt32*)inData);
if(theNewSource >= kClockSource_NumberItems)
{
theNewSource = kClockSource_NumberItems - 1;
}
pthread_mutex_lock(&gPlugIn_StateMutex);
if(gClockSource_Value != theNewSource)
{
gClockSource_Value = theNewSource;
UInt64 changeAction = (theNewSource > 0) ? ChangeAction_EnablePitchControl : ChangeAction_DisablePitchControl;
*outNumberPropertiesChanged = 1;
outChangedAddresses[0].mSelector = kAudioSelectorControlPropertyCurrentItem;
outChangedAddresses[0].mScope = kAudioObjectPropertyScopeGlobal;
outChangedAddresses[0].mElement = kAudioObjectPropertyElementMain;
// Notify HAL about device configuration change
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
gPlugIn_Host->RequestDeviceConfigurationChange(gPlugIn_Host, kObjectID_Device, changeAction, NULL);
});
}
pthread_mutex_unlock(&gPlugIn_StateMutex);
break;
default:
theAnswer = kAudioHardwareUnknownPropertyError;
break;
};
break;
default:
theAnswer = kAudioHardwareBadObjectError;
break;
};
Done:
return theAnswer;
}
#pragma mark IO Operations
static OSStatus BlackHole_StartIO(AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID, UInt32 inClientID)
{
// This call tells the device that IO is starting for the given client. When this routine
// returns, the device's clock is running and it is ready to have data read/written. It is
// important to note that multiple clients can have IO running on the device at the same time.
// So, work only needs to be done when the first client starts. All subsequent starts simply
// increment the counter.
DebugMsg("BlackHole_StartIO");
#pragma unused(inClientID, inDeviceObjectID)
// declare the local variables
OSStatus theAnswer = 0;
// check the arguments
FailWithAction(inDriver != gAudioServerPlugInDriverRef, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_StartIO: bad driver reference");
FailWithAction(inDeviceObjectID != kObjectID_Device && inDeviceObjectID != kObjectID_Device2, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_StartIO: bad device ID");
FailWithAction(inDeviceObjectID == kObjectID_Device && gDevice_IOIsRunning == UINT64_MAX, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_StartIO: overflow error.");
FailWithAction(inDeviceObjectID == kObjectID_Device2 && gDevice2_IOIsRunning == UINT64_MAX, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_StartIO: overflow error.");
// we need to hold the state lock
pthread_mutex_lock(&gPlugIn_StateMutex);
if (inDeviceObjectID == kObjectID_Device) { gDevice_IOIsRunning += 1; }
if (inDeviceObjectID == kObjectID_Device2) { gDevice2_IOIsRunning += 1; }
// allocate ring buffer
if ((gDevice_IOIsRunning || gDevice2_IOIsRunning) && gRingBuffer == NULL)
{
gDevice_NumberTimeStamps = 0;
gDevice_AnchorSampleTime = 0;
gDevice_AnchorHostTime = mach_absolute_time();
gDevice_PreviousTicks = 0;
gRingBuffer = calloc(kRing_Buffer_Frame_Size * kNumber_Of_Channels, sizeof(Float32));
}
// unlock the state lock
pthread_mutex_unlock(&gPlugIn_StateMutex);
Done:
return theAnswer;
}
static OSStatus BlackHole_StopIO(AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID, UInt32 inClientID)
{
// This call tells the device that the client has stopped IO. The driver can stop the hardware
// once all clients have stopped.
#pragma unused(inClientID, inDeviceObjectID)
// declare the local variables
OSStatus theAnswer = 0;
// check the arguments
FailWithAction(inDriver != gAudioServerPlugInDriverRef, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_StopIO: bad driver reference");
FailWithAction(inDeviceObjectID != kObjectID_Device && inDeviceObjectID != kObjectID_Device2, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_StopIO: bad device ID");
FailWithAction(inDeviceObjectID == kObjectID_Device && gDevice_IOIsRunning == 0, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_StartIO: underflow error.");
FailWithAction(inDeviceObjectID == kObjectID_Device2 && gDevice2_IOIsRunning == 0, theAnswer = kAudioHardwareIllegalOperationError, Done, "BlackHole_StartIO: underflow error.");
// we need to hold the state lock
pthread_mutex_lock(&gPlugIn_StateMutex);
if (inDeviceObjectID == kObjectID_Device) { gDevice_IOIsRunning -= 1; }
if (inDeviceObjectID == kObjectID_Device2) { gDevice2_IOIsRunning -= 1; }
// free the ring buffer
if (!gDevice_IOIsRunning && !gDevice2_IOIsRunning && gRingBuffer != NULL)
{
free(gRingBuffer);
gRingBuffer = NULL;
}
// unlock the state lock
pthread_mutex_unlock(&gPlugIn_StateMutex);
Done:
return theAnswer;
}
static OSStatus BlackHole_GetZeroTimeStamp(AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID, UInt32 inClientID, Float64* outSampleTime, UInt64* outHostTime, UInt64* outSeed)
{
// This method returns the current zero time stamp for the device. The HAL models the timing of
// a device as a series of time stamps that relate the sample time to a host time. The zero
// time stamps are spaced such that the sample times are the value of
// kAudioDevicePropertyZeroTimeStampPeriod apart. This is often modeled using a ring buffer
// where the zero time stamp is updated when wrapping around the ring buffer.
//
// For this device, the zero time stamps' sample time increments every kDevice_RingBufferSize
// frames and the host time increments by kDevice_RingBufferSize * gDevice_HostTicksPerFrame.
#pragma unused(inClientID, inDeviceObjectID)
// declare the local variables
OSStatus theAnswer = 0;
UInt64 theCurrentHostTime;
Float64 theHostTicksPerRingBuffer;
Float64 theAdjustedTicksPerRingBuffer;
Float64 theNextTickOffset;
UInt64 theNextHostTime;
// check the arguments
FailWithAction(inDriver != gAudioServerPlugInDriverRef, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_GetZeroTimeStamp: bad driver reference");
FailWithAction(inDeviceObjectID != kObjectID_Device && inDeviceObjectID != kObjectID_Device2, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_GetZeroTimeStamp: bad device ID");
// we need to hold the locks
pthread_mutex_lock(&gDevice_IOMutex);
// get the current host time
theCurrentHostTime = mach_absolute_time();
// calculate the next host time
theHostTicksPerRingBuffer = gDevice_HostTicksPerFrame * ((Float64)kDevice_RingBufferSize);
if (gClockSource_Value > 0) {
theAdjustedTicksPerRingBuffer = gDevice_AdjustedTicksPerFrame * ((Float64)kDevice_RingBufferSize);
}
else {
theAdjustedTicksPerRingBuffer = gDevice_HostTicksPerFrame * ((Float64)kDevice_RingBufferSize);
}
theNextTickOffset = gDevice_PreviousTicks + theAdjustedTicksPerRingBuffer;
theNextHostTime = gDevice_AnchorHostTime + ((UInt64)theNextTickOffset);
// go to the next time if the next host time is less than the current time
if(theNextHostTime <= theCurrentHostTime)
{
++gDevice_NumberTimeStamps;
gDevice_PreviousTicks = theNextTickOffset;
}
// set the return values
*outSampleTime = gDevice_NumberTimeStamps * kDevice_RingBufferSize;
*outHostTime = gDevice_AnchorHostTime + gDevice_PreviousTicks;
*outSeed = 1;
// DebugMsg("SampleTime: %f \t HostTime: %llu", *outSampleTime, *outHostTime);
// unlock the state lock
pthread_mutex_unlock(&gDevice_IOMutex);
Done:
return theAnswer;
}
static OSStatus BlackHole_WillDoIOOperation(AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID, UInt32 inClientID, UInt32 inOperationID, Boolean* outWillDo, Boolean* outWillDoInPlace)
{
// This method returns whether or not the device will do a given IO operation. For this device,
// we only support reading input data and writing output data.
#pragma unused(inClientID, inDeviceObjectID)
// declare the local variables
OSStatus theAnswer = 0;
// check the arguments
FailWithAction(inDriver != gAudioServerPlugInDriverRef, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_WillDoIOOperation: bad driver reference");
FailWithAction(inDeviceObjectID != kObjectID_Device && inDeviceObjectID != kObjectID_Device2, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_WillDoIOOperation: bad device ID");
// figure out if we support the operation
bool willDo = false;
bool willDoInPlace = true;
switch(inOperationID)
{
case kAudioServerPlugInIOOperationReadInput:
willDo = true;
willDoInPlace = true;
break;
case kAudioServerPlugInIOOperationWriteMix:
willDo = true;
willDoInPlace = true;
break;
};
// fill out the return values
if(outWillDo != NULL)
{
*outWillDo = willDo;
}
if(outWillDoInPlace != NULL)
{
*outWillDoInPlace = willDoInPlace;
}
Done:
return theAnswer;
}
static OSStatus BlackHole_BeginIOOperation(AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID, UInt32 inClientID, UInt32 inOperationID, UInt32 inIOBufferFrameSize, const AudioServerPlugInIOCycleInfo* inIOCycleInfo)
{
// This is called at the beginning of an IO operation. This device doesn't do anything, so just
// check the arguments and return.
#pragma unused(inClientID, inOperationID, inIOBufferFrameSize, inIOCycleInfo, inDeviceObjectID)
// declare the local variables
OSStatus theAnswer = 0;
// check the arguments
FailWithAction(inDriver != gAudioServerPlugInDriverRef, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_BeginIOOperation: bad driver reference");
FailWithAction(inDeviceObjectID != kObjectID_Device && inDeviceObjectID != kObjectID_Device2, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_BeginIOOperation: bad device ID");
Done:
return theAnswer;
}
static OSStatus BlackHole_DoIOOperation(AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID, AudioObjectID inStreamObjectID, UInt32 inClientID, UInt32 inOperationID, UInt32 inIOBufferFrameSize, const AudioServerPlugInIOCycleInfo* inIOCycleInfo, void* ioMainBuffer, void* ioSecondaryBuffer)
{
// This is called to actually perform a given operation.
#pragma unused(inClientID, inIOCycleInfo, ioSecondaryBuffer, inDeviceObjectID)
// declare the local variables
OSStatus theAnswer = 0;
// check the arguments
FailWithAction(inDriver != gAudioServerPlugInDriverRef, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_DoIOOperation: bad driver reference");
FailWithAction(inDeviceObjectID != kObjectID_Device && inDeviceObjectID != kObjectID_Device2, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_DoIOOperation: bad device ID");
FailWithAction((inStreamObjectID != kObjectID_Stream_Input) && (inStreamObjectID != kObjectID_Stream_Output), theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_DoIOOperation: bad stream ID");
// Calculate the ring buffer offsets and splits.
UInt64 mSampleTime = inOperationID == kAudioServerPlugInIOOperationReadInput ? inIOCycleInfo->mInputTime.mSampleTime : inIOCycleInfo->mOutputTime.mSampleTime;
UInt32 ringBufferFrameLocationStart = mSampleTime % kRing_Buffer_Frame_Size;
UInt32 firstPartFrameSize = kRing_Buffer_Frame_Size - ringBufferFrameLocationStart;
UInt32 secondPartFrameSize = 0;
if (firstPartFrameSize >= inIOBufferFrameSize)
{
firstPartFrameSize = inIOBufferFrameSize;
}
else
{
secondPartFrameSize = inIOBufferFrameSize - firstPartFrameSize;
}
// Keep track of last outputSampleTime and the cleared buffer status.
static Float64 lastOutputSampleTime = 0;
static Boolean isBufferClear = true;
// From BlackHole to Application
if(inOperationID == kAudioServerPlugInIOOperationReadInput)
{
// If mute is one let's just fill the buffer with zeros or if there's no apps outputting audio
if (gMute_Master_Value || lastOutputSampleTime - inIOBufferFrameSize < inIOCycleInfo->mInputTime.mSampleTime)
{
// Clear the ioMainBuffer
vDSP_vclr(ioMainBuffer, 1, inIOBufferFrameSize * kNumber_Of_Channels);
// Clear the ring buffer.
if (!isBufferClear)
{
vDSP_vclr(gRingBuffer, 1, kRing_Buffer_Frame_Size * kNumber_Of_Channels);
isBufferClear = true;
}
}
else
{
// Copy the buffers.
memcpy(ioMainBuffer, gRingBuffer + ringBufferFrameLocationStart * kNumber_Of_Channels, firstPartFrameSize * kNumber_Of_Channels * sizeof(Float32));
memcpy((Float32*)ioMainBuffer + firstPartFrameSize * kNumber_Of_Channels, gRingBuffer, secondPartFrameSize * kNumber_Of_Channels * sizeof(Float32));
// Finally we'll apply the output volume to the buffer.
if(kEnableVolumeControl)
{
vDSP_vsmul(ioMainBuffer, 1, &gVolume_Master_Value, ioMainBuffer, 1, inIOBufferFrameSize * kNumber_Of_Channels);
}
}
}
// From Application to BlackHole
if(inOperationID == kAudioServerPlugInIOOperationWriteMix)
{
// Overload error.
if (inIOCycleInfo->mCurrentTime.mSampleTime > inIOCycleInfo->mOutputTime.mSampleTime + inIOBufferFrameSize + kLatency_Frame_Size)
{
DebugMsg("BlackHole overload error. kAudioServerPlugInIOOperationWriteMix was unable to complete operation before the deadline. Try increasing the buffer frame size.");
return kAudioHardwareUnspecifiedError;
}
// Copy the buffers.
memcpy(gRingBuffer + ringBufferFrameLocationStart * kNumber_Of_Channels, ioMainBuffer, firstPartFrameSize * kNumber_Of_Channels * sizeof(Float32));
memcpy(gRingBuffer, (Float32*)ioMainBuffer + firstPartFrameSize * kNumber_Of_Channels, secondPartFrameSize * kNumber_Of_Channels * sizeof(Float32));
// Save the last output time.
lastOutputSampleTime = inIOCycleInfo->mOutputTime.mSampleTime + inIOBufferFrameSize;
isBufferClear = false;
}
Done:
return theAnswer;
}
static OSStatus BlackHole_EndIOOperation(AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID, UInt32 inClientID, UInt32 inOperationID, UInt32 inIOBufferFrameSize, const AudioServerPlugInIOCycleInfo* inIOCycleInfo)
{
// This is called at the end of an IO operation. This device doesn't do anything, so just check
// the arguments and return.
#pragma unused(inClientID, inOperationID, inIOBufferFrameSize, inIOCycleInfo, inDeviceObjectID)
// declare the local variables
OSStatus theAnswer = 0;
// check the arguments
FailWithAction(inDriver != gAudioServerPlugInDriverRef, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_EndIOOperation: bad driver reference");
FailWithAction(inDeviceObjectID != kObjectID_Device && inDeviceObjectID != kObjectID_Device2, theAnswer = kAudioHardwareBadObjectError, Done, "BlackHole_EndIOOperation: bad device ID");
Done:
return theAnswer;
}
================================================
FILE: BlackHole/BlackHole.plist
================================================
CFBundleDevelopmentRegion
English
CFBundleExecutable
${EXECUTABLE_NAME}
CFBundleIconFile
CFBundleIdentifier
$(PRODUCT_BUNDLE_IDENTIFIER)
CFBundleInfoDictionaryVersion
6.0
CFBundleName
${PRODUCT_NAME}
CFBundlePackageType
BNDL
CFBundleShortVersionString
$(MARKETING_VERSION)
CFBundleSignature
????
CFBundleVersion
596
CFPlugInFactories
e395c745-4eea-4d94-bb92-46224221047c
BlackHole_Create
CFPlugInTypes
443ABAB8-E7B3-491A-B985-BEB9187030DB
e395c745-4eea-4d94-bb92-46224221047c
================================================
FILE: BlackHole.xcodeproj/project.pbxproj
================================================
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 46;
objects = {
/* Begin PBXBuildFile section */
3D083818284A7F1200C69403 /* VERSION in Resources */ = {isa = PBXBuildFile; fileRef = 3D89662F2849BF1A002AB3F0 /* VERSION */; };
3D083819284A7F1500C69403 /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = 2DA8FA1515FEAAB000F04B50 /* README.md */; };
3D88D48F285BBA5800629399 /* main.c in Sources */ = {isa = PBXBuildFile; fileRef = 3D88D48E285BBA5800629399 /* main.c */; };
3D89663F2849C318002AB3F0 /* BlackHole.c in Sources */ = {isa = PBXBuildFile; fileRef = 2D616EF215B8C82500D598BD /* BlackHole.c */; };
3D8966412849C318002AB3F0 /* Accelerate.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3D6C8E45275E92B40030C104 /* Accelerate.framework */; };
3D8966422849C318002AB3F0 /* CoreAudio.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2D7477EC157823CF00412279 /* CoreAudio.framework */; };
3D8966432849C318002AB3F0 /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2D7477AC1578168D00412279 /* CoreFoundation.framework */; };
3D8966462849C318002AB3F0 /* LICENSE in Resources */ = {isa = PBXBuildFile; fileRef = 03FDCADB233FAE0500101681 /* LICENSE */; };
3D8966472849C318002AB3F0 /* BlackHole.icns in Resources */ = {isa = PBXBuildFile; fileRef = 03FDCAD9233F235500101681 /* BlackHole.icns */; };
3D8966482849C318002AB3F0 /* CHANGELOG.md in Resources */ = {isa = PBXBuildFile; fileRef = 039FF2572341B6E800400D7A /* CHANGELOG.md */; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
3D88D48A285BBA5800629399 /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = /usr/share/man/man1/;
dstSubfolderSpec = 0;
files = (
);
runOnlyForDeploymentPostprocessing = 1;
};
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
039FF2572341B6E800400D7A /* CHANGELOG.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = CHANGELOG.md; sourceTree = ""; };
03FDCAD9233F235500101681 /* BlackHole.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = BlackHole.icns; sourceTree = ""; };
03FDCADB233FAE0500101681 /* LICENSE */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LICENSE; sourceTree = ""; };
2D616EF215B8C82500D598BD /* BlackHole.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = BlackHole.c; sourceTree = ""; };
2D7477AC1578168D00412279 /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = System/Library/Frameworks/CoreFoundation.framework; sourceTree = SDKROOT; };
2D7477EC157823CF00412279 /* CoreAudio.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreAudio.framework; path = System/Library/Frameworks/CoreAudio.framework; sourceTree = SDKROOT; };
2DA8FA1515FEAAB000F04B50 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; };
2DD7AA9915EC572000C67AE1 /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = System/Library/Frameworks/IOKit.framework; sourceTree = SDKROOT; };
2DED183A15C357180091BE97 /* Kernel.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Kernel.framework; path = System/Library/Frameworks/Kernel.framework; sourceTree = SDKROOT; };
3D083806284A7BB000C69403 /* conclusion.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = conclusion.html; sourceTree = ""; };
3D083807284A7BB000C69403 /* requirements.xml */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = requirements.xml; sourceTree = ""; };
3D083808284A7BB000C69403 /* welcome.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = welcome.html; sourceTree = ""; };
3D08380E284A7DE100C69403 /* BlackHole.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = BlackHole.plist; sourceTree = ""; };
3D08381B284AA8EE00C69403 /* create_installer.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = create_installer.sh; sourceTree = ""; };
3D6C8E45275E92B40030C104 /* Accelerate.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Accelerate.framework; path = System/Library/Frameworks/Accelerate.framework; sourceTree = SDKROOT; };
3D88D48C285BBA5800629399 /* BlackHoleTests */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = BlackHoleTests; sourceTree = BUILT_PRODUCTS_DIR; };
3D88D48E285BBA5800629399 /* main.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = main.c; sourceTree = ""; };
3D89662F2849BF1A002AB3F0 /* VERSION */ = {isa = PBXFileReference; lastKnownFileType = text; path = VERSION; sourceTree = ""; };
3D89664D2849C318002AB3F0 /* BlackHole.driver */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = BlackHole.driver; sourceTree = BUILT_PRODUCTS_DIR; };
3D8966882849D45F002AB3F0 /* postinstall */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = postinstall; sourceTree = ""; };
3D8966892849D45F002AB3F0 /* preinstall */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = preinstall; sourceTree = ""; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
3D88D489285BBA5800629399 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
3D8966402849C318002AB3F0 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
3D8966412849C318002AB3F0 /* Accelerate.framework in Frameworks */,
3D8966422849C318002AB3F0 /* CoreAudio.framework in Frameworks */,
3D8966432849C318002AB3F0 /* CoreFoundation.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
2D616EF015B8C82500D598BD /* BlackHole */ = {
isa = PBXGroup;
children = (
3D08380E284A7DE100C69403 /* BlackHole.plist */,
03FDCAD9233F235500101681 /* BlackHole.icns */,
2D616EF215B8C82500D598BD /* BlackHole.c */,
);
path = BlackHole;
sourceTree = "";
};
2D74779B1578162B00412279 = {
isa = PBXGroup;
children = (
3D083805284A7BB000C69403 /* Installer */,
3D89662F2849BF1A002AB3F0 /* VERSION */,
2DA8FA1515FEAAB000F04B50 /* README.md */,
03FDCADB233FAE0500101681 /* LICENSE */,
039FF2572341B6E800400D7A /* CHANGELOG.md */,
2D616EF015B8C82500D598BD /* BlackHole */,
3D88D48D285BBA5800629399 /* BlackHoleTests */,
2D7477AB1578168D00412279 /* Frameworks */,
2D7477AA1578168D00412279 /* Products */,
);
sourceTree = "";
};
2D7477AA1578168D00412279 /* Products */ = {
isa = PBXGroup;
children = (
3D89664D2849C318002AB3F0 /* BlackHole.driver */,
3D88D48C285BBA5800629399 /* BlackHoleTests */,
);
name = Products;
sourceTree = "";
};
2D7477AB1578168D00412279 /* Frameworks */ = {
isa = PBXGroup;
children = (
3D6C8E45275E92B40030C104 /* Accelerate.framework */,
2D7477EC157823CF00412279 /* CoreAudio.framework */,
2D7477AC1578168D00412279 /* CoreFoundation.framework */,
2DD7AA9915EC572000C67AE1 /* IOKit.framework */,
2DED183A15C357180091BE97 /* Kernel.framework */,
);
name = Frameworks;
sourceTree = "";
};
3D083805284A7BB000C69403 /* Installer */ = {
isa = PBXGroup;
children = (
3D08381B284AA8EE00C69403 /* create_installer.sh */,
3D8966872849D45F002AB3F0 /* scripts */,
3D083806284A7BB000C69403 /* conclusion.html */,
3D083807284A7BB000C69403 /* requirements.xml */,
3D083808284A7BB000C69403 /* welcome.html */,
);
path = Installer;
sourceTree = "";
};
3D88D48D285BBA5800629399 /* BlackHoleTests */ = {
isa = PBXGroup;
children = (
3D88D48E285BBA5800629399 /* main.c */,
);
path = BlackHoleTests;
sourceTree = "";
};
3D8966872849D45F002AB3F0 /* scripts */ = {
isa = PBXGroup;
children = (
3D8966882849D45F002AB3F0 /* postinstall */,
3D8966892849D45F002AB3F0 /* preinstall */,
);
path = scripts;
sourceTree = "";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
3D88D48B285BBA5800629399 /* BlackHoleTests */ = {
isa = PBXNativeTarget;
buildConfigurationList = 3D88D493285BBA5800629399 /* Build configuration list for PBXNativeTarget "BlackHoleTests" */;
buildPhases = (
3D88D488285BBA5800629399 /* Sources */,
3D88D489285BBA5800629399 /* Frameworks */,
3D88D48A285BBA5800629399 /* CopyFiles */,
);
buildRules = (
);
dependencies = (
);
name = BlackHoleTests;
productName = BlackHoleTests;
productReference = 3D88D48C285BBA5800629399 /* BlackHoleTests */;
productType = "com.apple.product-type.tool";
};
3D89663D2849C318002AB3F0 /* BlackHole */ = {
isa = PBXNativeTarget;
buildConfigurationList = 3D8966492849C318002AB3F0 /* Build configuration list for PBXNativeTarget "BlackHole" */;
buildPhases = (
3D89663E2849C318002AB3F0 /* Sources */,
3D8966402849C318002AB3F0 /* Frameworks */,
3D8966452849C318002AB3F0 /* Resources */,
);
buildRules = (
);
dependencies = (
);
name = BlackHole;
productName = AudioNULLDriver;
productReference = 3D89664D2849C318002AB3F0 /* BlackHole.driver */;
productType = "com.apple.product-type.bundle";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
2D74779D1578162B00412279 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1220;
TargetAttributes = {
3D88D48B285BBA5800629399 = {
CreatedOnToolsVersion = 13.4;
DevelopmentTeam = Q5C99V536K;
ProvisioningStyle = Automatic;
};
3D89663D2849C318002AB3F0 = {
DevelopmentTeam = Q5C99V536K;
};
};
};
buildConfigurationList = 2D7477A01578162B00412279 /* Build configuration list for PBXProject "BlackHole" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = 2D74779B1578162B00412279;
productRefGroup = 2D7477AA1578168D00412279 /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (
3D89663D2849C318002AB3F0 /* BlackHole */,
3D88D48B285BBA5800629399 /* BlackHoleTests */,
);
};
/* End PBXProject section */
/* Begin PBXResourcesBuildPhase section */
3D8966452849C318002AB3F0 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
3D8966462849C318002AB3F0 /* LICENSE in Resources */,
3D8966472849C318002AB3F0 /* BlackHole.icns in Resources */,
3D8966482849C318002AB3F0 /* CHANGELOG.md in Resources */,
3D083818284A7F1200C69403 /* VERSION in Resources */,
3D083819284A7F1500C69403 /* README.md in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
3D88D488285BBA5800629399 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
3D88D48F285BBA5800629399 /* main.c in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
3D89663E2849C318002AB3F0 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
3D89663F2849C318002AB3F0 /* BlackHole.c in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin XCBuildConfiguration section */
2D7477A21578162B00412279 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_CXX_LANGUAGE_STANDARD = "c++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_IMPLICIT_SIGN_CONVERSION = NO;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CLANG_WARN__EXIT_TIME_DESTRUCTORS = YES;
DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = s;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES;
GCC_WARN_ABOUT_MISSING_NEWLINE = YES;
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = YES;
GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES;
GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES;
GCC_WARN_SHADOW = YES;
GCC_WARN_SIGN_COMPARE = YES;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNKNOWN_PRAGMAS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_LABEL = YES;
GCC_WARN_UNUSED_PARAMETER = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
SDKROOT = macosx;
};
name = Release;
};
2D7477A31578162B00412279 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_CXX_LANGUAGE_STANDARD = "c++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_IMPLICIT_SIGN_CONVERSION = NO;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CLANG_WARN__EXIT_TIME_DESTRUCTORS = YES;
DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES;
GCC_WARN_ABOUT_MISSING_NEWLINE = YES;
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = YES;
GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES;
GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES;
GCC_WARN_SHADOW = YES;
GCC_WARN_SIGN_COMPARE = YES;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNKNOWN_PRAGMAS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_LABEL = YES;
GCC_WARN_UNUSED_PARAMETER = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
};
name = Debug;
};
2D7477A41578164E00412279 /* Debug-Opt */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_CXX_LANGUAGE_STANDARD = "c++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_IMPLICIT_SIGN_CONVERSION = NO;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CLANG_WARN__EXIT_TIME_DESTRUCTORS = YES;
DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = s;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES;
GCC_WARN_ABOUT_MISSING_NEWLINE = YES;
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = YES;
GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES;
GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES;
GCC_WARN_SHADOW = YES;
GCC_WARN_SIGN_COMPARE = YES;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNKNOWN_PRAGMAS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_LABEL = YES;
GCC_WARN_UNUSED_PARAMETER = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
};
name = "Debug-Opt";
};
3D88D490285BBA5800629399 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++17";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_STYLE = Automatic;
COPY_PHASE_STRIP = NO;
DEVELOPMENT_TEAM = Q5C99V536K;
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_NS_ASSERTIONS = NO;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
MACOSX_DEPLOYMENT_TARGET = 12.3;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
};
3D88D491285BBA5800629399 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++17";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_STYLE = Automatic;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = dwarf;
DEVELOPMENT_TEAM = Q5C99V536K;
ENABLE_HARDENED_RUNTIME = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_DYNAMIC_NO_PIC = NO;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
MACOSX_DEPLOYMENT_TARGET = 12.3;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Debug;
};
3D88D492285BBA5800629399 /* Debug-Opt */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++17";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_STYLE = Automatic;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = dwarf;
DEVELOPMENT_TEAM = Q5C99V536K;
ENABLE_HARDENED_RUNTIME = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_DYNAMIC_NO_PIC = NO;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
MACOSX_DEPLOYMENT_TARGET = 12.3;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = "Debug-Opt";
};
3D89664A2849C318002AB3F0 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ENABLE_OBJC_WEAK = YES;
DEVELOPMENT_TEAM = Q5C99V536K;
GCC_PREPROCESSOR_DEFINITIONS = (
"$(inherited)",
"DEBUG=0",
);
INFOPLIST_FILE = BlackHole/BlackHole.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Audio/Plug-Ins/HAL";
MACOSX_DEPLOYMENT_TARGET = 10.10;
MARKETING_VERSION = 0.6.1;
PRODUCT_BUNDLE_IDENTIFIER = audio.existential.BlackHole;
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = driver;
};
name = Release;
};
3D89664B2849C318002AB3F0 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ENABLE_OBJC_WEAK = YES;
DEVELOPMENT_TEAM = Q5C99V536K;
GCC_PREPROCESSOR_DEFINITIONS = (
"$(inherited)",
"DEBUG=1",
);
INFOPLIST_FILE = BlackHole/BlackHole.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Audio/Plug-Ins/HAL";
MACOSX_DEPLOYMENT_TARGET = 10.10;
MARKETING_VERSION = 0.6.1;
PRODUCT_BUNDLE_IDENTIFIER = audio.existential.BlackHole;
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = driver;
};
name = Debug;
};
3D89664C2849C318002AB3F0 /* Debug-Opt */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ENABLE_OBJC_WEAK = YES;
DEVELOPMENT_TEAM = Q5C99V536K;
GCC_PREPROCESSOR_DEFINITIONS = (
"$(inherited)",
"DEBUG=1",
);
INFOPLIST_FILE = BlackHole/BlackHole.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Audio/Plug-Ins/HAL";
MACOSX_DEPLOYMENT_TARGET = 10.10;
MARKETING_VERSION = 0.6.1;
PRODUCT_BUNDLE_IDENTIFIER = audio.existential.BlackHole;
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = driver;
};
name = "Debug-Opt";
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
2D7477A01578162B00412279 /* Build configuration list for PBXProject "BlackHole" */ = {
isa = XCConfigurationList;
buildConfigurations = (
2D7477A21578162B00412279 /* Release */,
2D7477A31578162B00412279 /* Debug */,
2D7477A41578164E00412279 /* Debug-Opt */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
3D88D493285BBA5800629399 /* Build configuration list for PBXNativeTarget "BlackHoleTests" */ = {
isa = XCConfigurationList;
buildConfigurations = (
3D88D490285BBA5800629399 /* Release */,
3D88D491285BBA5800629399 /* Debug */,
3D88D492285BBA5800629399 /* Debug-Opt */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
3D8966492849C318002AB3F0 /* Build configuration list for PBXNativeTarget "BlackHole" */ = {
isa = XCConfigurationList;
buildConfigurations = (
3D89664A2849C318002AB3F0 /* Release */,
3D89664B2849C318002AB3F0 /* Debug */,
3D89664C2849C318002AB3F0 /* Debug-Opt */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = 2D74779D1578162B00412279 /* Project object */;
}
================================================
FILE: BlackHole.xcodeproj/project.xcworkspace/contents.xcworkspacedata
================================================
================================================
FILE: BlackHole.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
================================================
IDEDidComputeMac32BitWarning
================================================
FILE: BlackHole.xcodeproj/xcshareddata/xcschemes/BlackHole.xcscheme
================================================
================================================
FILE: BlackHoleTests/main.c
================================================
//
// main.cpp
// BlackHoleTests
//
// Created by Devin Roth on 2022-06-16.
//
#include
#define kDevice_HasInput false
#define kDevice_HasOutput true
#include "../BlackHole/BlackHole.c"
int main(int argc, const char * argv[]) {
#pragma unused(argc, argv)
// insert code here...
UInt32 size;
UInt32* data;
AudioObjectPropertyAddress address;
// Owned Objects
address.mSelector = kAudioObjectPropertyOwnedObjects;
address.mScope = kAudioObjectPropertyScopeGlobal;
assert(BlackHole_HasProperty(gAudioServerPlugInDriverRef, kObjectID_Device, 0, &address));
BlackHole_GetPropertyDataSize(gAudioServerPlugInDriverRef, kObjectID_Device, 0, &address, 0, NULL, &size);
assert(size == 12);
address.mScope = kAudioObjectPropertyScopeInput;
BlackHole_GetPropertyDataSize(gAudioServerPlugInDriverRef, kObjectID_Device, 0, &address, 0, NULL, &size);
assert(size == 0);
data = calloc(size, 1);
BlackHole_GetPropertyData(gAudioServerPlugInDriverRef, kObjectID_Device, 0, &address, 0, NULL, size, &size, data);
assert(data[0] == 0);
free(data);
address.mScope = kAudioObjectPropertyScopeOutput;
BlackHole_GetPropertyDataSize(gAudioServerPlugInDriverRef, kObjectID_Device, 0, &address, 0, NULL, &size);
assert(size == 12);
data = calloc(size, 1);
BlackHole_GetPropertyData(gAudioServerPlugInDriverRef, kObjectID_Device, 0, &address, 0, NULL, size, &size, data);
assert(data[0] == 7);
assert(data[1] == 8);
assert(data[2] == 9);
free(data);
// Streams
address.mSelector = kAudioDevicePropertyStreams;
address.mScope = kAudioObjectPropertyScopeGlobal;
assert(BlackHole_HasProperty(gAudioServerPlugInDriverRef, kObjectID_Device, 0, &address));
BlackHole_GetPropertyDataSize(gAudioServerPlugInDriverRef, kObjectID_Device, 0, &address, 0, NULL, &size);
assert(size == 4);
address.mScope = kAudioObjectPropertyScopeInput;
BlackHole_GetPropertyDataSize(gAudioServerPlugInDriverRef, kObjectID_Device, 0, &address, 0, NULL, &size);
assert(size == 0);
data = calloc(size, 1);
BlackHole_GetPropertyData(gAudioServerPlugInDriverRef, kObjectID_Device, 0, &address, 0, NULL, size, &size, data);
assert(data[0] == 0);
free(data);
address.mScope = kAudioObjectPropertyScopeOutput;
BlackHole_GetPropertyDataSize(gAudioServerPlugInDriverRef, kObjectID_Device, 0, &address, 0, NULL, &size);
assert(size == 4);
data = calloc(size, 1);
BlackHole_GetPropertyData(gAudioServerPlugInDriverRef, kObjectID_Device, 0, &address, 0, NULL, size, &size, data);
assert(data[0] == 7);
free(data);
// Controls
address.mSelector = kAudioClockDevicePropertyControlList;
address.mScope = kAudioObjectPropertyScopeGlobal;
assert(BlackHole_HasProperty(gAudioServerPlugInDriverRef, kObjectID_Device, 0, &address));
BlackHole_GetPropertyDataSize(gAudioServerPlugInDriverRef, kObjectID_Device, 0, &address, 0, NULL, &size);
assert(size == 8);
address.mScope = kAudioObjectPropertyScopeInput;
BlackHole_GetPropertyDataSize(gAudioServerPlugInDriverRef, kObjectID_Device, 0, &address, 0, NULL, &size);
assert(size == 0);
data = calloc(size, 1);
BlackHole_GetPropertyData(gAudioServerPlugInDriverRef, kObjectID_Device, 0, &address, 0, NULL, size, &size, data);
assert(data[0] == 0);
free(data);
address.mScope = kAudioObjectPropertyScopeOutput;
BlackHole_GetPropertyDataSize(gAudioServerPlugInDriverRef, kObjectID_Device, 0, &address, 0, NULL, &size);
assert(size == 8);
data = calloc(size, 1);
BlackHole_GetPropertyData(gAudioServerPlugInDriverRef, kObjectID_Device, 0, &address, 0, NULL, size, &size, data);
assert(data[0] == 8);
assert(data[1] == 9);
free(data);
return 0;
}
================================================
FILE: CHANGELOG.md
================================================
# BlackHole Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.1.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
### Feature Requests
- Add support for additional virtual formats. 24-bit, 16-bit.
- Sync BlackHole audio clock with any audio device.
- Create multi-output / aggregate device with installer.
- Keep track of which apps are connected to the driver.
## [Unreleased]
### Changed
## [0.6.1] - 2025-02-06
- Updated installer to force a computer reboot as recommended by Apple.
- Updated create_installer.sh script.
### Changed
## [0.6.0] - 2024-03-22
## Added
- Added precompiler constant for kCanBeDefaultDevice and kCanBeDefaultSystemDevice.
## Changed
- Updated postinstall script to use 'kill' instead of 'kickstart'.
- Updated strings for model name,
## [0.5.1] - 2023-11-06
### Changed
- Improved installer build script.
- Bumped minimum required operating system to macOS 10.10 Yosemite.
- Update kAudioDevicePropertyDeviceIsRunning separately for device1 and device2
## [0.5.0] - 2023-02-10
### Changed
- Various typo fixes.
### Added
- kObjectID_Pitch_Adjust and kObjectID_ClockSource to adjust clock speed.
## [0.4.1] - 2023-02-10
### Changed
- Merged BlackHole.h into BlackHole.c for easier testing.
- Fixed control size bugs.
### Added
- Added BlackHoleTests target and relevant files.
## [0.4.0] - 2021-06-10
### Added
- Hidden duplicate device.
- Ability to easily modify device streams.
- Builds multiple versions.
- create_installer.sh to easily build multiple channel versions.
### Changed
- Fix potential memory leak.
- Fix dropouts when experiencing minor loads.
## [0.3.0] - 2021-12-07
### Added
- Sample rates: 8kHz, 16kHz, 352.8kHz, 384kHz, 705.6kHz, 768kHz.
### Changed
- Improved performance.
- Fixed various bugs.
- Renamed constants and variables for consistency.
- Connect input and output volume.
- Connect input and output mute.
## [0.2.10] - 2021-08-21
### Changed
- Increased internal buffer size.
- Change kDataSource_NumberItems to zero.
## [0.2.9] - 2021-1-27
### Changed
- Fix clock bug. Fixes issues with BlackHole crashing on Apple Silicon.
## [0.2.8] - 2020-12-26
### Added
- Support for Apple Silicon.
### Changed
- Set deployment target to macOS 10.9.
- Fixed bug where there is a loud pop when audio starts.
- Fix bug that caused crashes in certain situations. (Issue #206)
- Disable Volume and Mute controls on input. They are only needed on the output.
- Fix clock bug.
- Automatically change UIDs to include the number of channels. Makes it easier to build and install multiple versions. Ex: BlackHole2ch_UID
## [0.2.7] - 2020-08-08
### Changed
- Improved Logarithmic Volume Control.
- Various updates to README.
### Added
- Added IOMutex to IO operations.
## [0.2.6] - 2020-02-09
### Changed
- Fixed BlackHole buffer allocation error when switching audio devices from DAW.
- Fixed BlackHole buffer allocation error when sleeping.
- Audio Midi Setup speaker configuration now saves preferences.
## [0.2.5] - 2019-11-29
### Changed
- Set default volume to 1.0.
## [0.2.4] - 2019-11-28
### Added
- Ability to mute and changed volume on input and out of BlackHole.
## [0.2.3] - 2019-11-22
### Changed
- Display number of channels in audio source name.
## [0.2.2] - 2019-10-02
### Fixed
- Fixed bugs when multiple devices are reading and writing simultaneously.
## [0.2.1] - 2019-09-30
### Changed
- Set deployment target to macOS 10.10 to include Yosemite and Sierra
## [0.2.0] - 2019-09-29
### Added
- Support for 88.2kHz, 96kHz, 176.4kHz and 192kHz.
- Sums audio from multiple sources.
- Changelog.
- Device Icon.
## [0.1.0] - 2019-09-27
### Added
- Ability to pass audio between applications.
- Support for 16 channels of audio.
- Support for 44.1kHz and 48kHz.
================================================
FILE: Installer/conclusion.html
================================================
BlackHole: Audio Loopback Driver
Donate
If you find this software useful please sponsor Existential Audio on GitHub.
Help and Support
Visit the BlackHole Help and Support page for help and guides.
FAQ
Where is BlackHole located?
BlackHole is an audio driver. You can find it in Audio MIDI Setup and within audio applications.
How can I listen to the audio and use BlackHole at the same time?
Set up a Multi-Output Device.
Why is nothing audible through BlackHole?
- Check System Preferences -> Security & Privacy -> Microphone to make sure your audio application has microphone access.
- Check that the volume is all the way up on BlackHole output in Audio MIDI Setup.
- If you are using a Multi-Output Device, due to issues with macOS a 2ch audio driver must be enabled and listed as the top device in the Multi-Output.
How do I uninstall BlackHole?
You can download the uninstaller from the BlackHole Help and Support page.
================================================
FILE: Installer/create_installer.sh
================================================
#!/usr/bin/env sh
set -euo pipefail
# Creates installer for different channel versions.
# Run this script from the local BlackHole repo's root directory.
# If this script is not executable from the Terminal,
# it may need execute permissions first by running this command:
# chmod +x create_installer.sh
driverName="BlackHole"
devTeamID="Q5C99V536K" # ⚠️ Replace this with your own developer team ID
notarize=true # To skip notarization, set this to false
notarizeProfile="notarize" # ⚠️ Replace this with your own notarytool keychain profile name
############################################################################
# Basic Validation
if [ ! -d BlackHole.xcodeproj ]; then
echo "This script must be run from the BlackHole repo root folder."
echo "For example:"
echo " cd /path/to/BlackHole"
echo " ./Installer/create_installer.sh"
exit 1
fi
version=`cat VERSION`
#Version Validation6
if [ -z "$version" ]; then
echo "Could not find version number. VERSION file is missing from repo root or is empty."
exit 1
fi
for channels in 2 16 64 128 256; do
# Env
ch=$channels"ch"
driverVartiantName=$driverName$ch
bundleID="audio.existential.$driverVartiantName"
# Build
xcodebuild \
-project BlackHole.xcodeproj \
-configuration Release \
-target BlackHole CONFIGURATION_BUILD_DIR=build \
PRODUCT_BUNDLE_IDENTIFIER=$bundleID \
GCC_PREPROCESSOR_DEFINITIONS='$GCC_PREPROCESSOR_DEFINITIONS
kNumber_Of_Channels='$channels'
kPlugIn_BundleID=\"'$bundleID'\"
kDriver_Name=\"'$driverName'\"'
# Generate a new UUID
uuid=$(uuidgen)
awk '{sub(/e395c745-4eea-4d94-bb92-46224221047c/,"'$uuid'")}1' build/BlackHole.driver/Contents/Info.plist > Temp.plist
mv Temp.plist build/BlackHole.driver/Contents/Info.plist
mkdir Installer/root
driverBundleName=$driverVartiantName.driver
mv build/BlackHole.driver Installer/root/$driverBundleName
rm -r build
# Sign
codesign \
--force \
--deep \
--options runtime \
--sign $devTeamID \
Installer/root/$driverBundleName
# Create package with pkgbuild
chmod 755 Installer/Scripts/preinstall
chmod 755 Installer/Scripts/postinstall
pkgbuild \
--sign $devTeamID \
--root Installer/root \
--scripts Installer/Scripts \
--install-location /Library/Audio/Plug-Ins/HAL \
"Installer/$driverName.pkg"
rm -r Installer/root
# Create installer with productbuild
cd Installer
echo "
$driverName: Audio Loopback Driver ($ch) $version
$driverName.pkg
" >> distribution.xml
# Build
installerPkgName="$driverVartiantName-$version.pkg"
productbuild \
--sign $devTeamID \
--distribution distribution.xml \
--resources . \
--package-path $driverName.pkg $installerPkgName
rm distribution.xml
rm -f $driverName.pkg
# Notarize and Staple
if [ "$notarize" = true ]; then
xcrun \
notarytool submit $installerPkgName \
--team-id $devTeamID \
--progress \
--wait \
--keychain-profile $notarizeProfile
xcrun stapler staple $installerPkgName
fi
cd ..
done
================================================
FILE: Installer/requirements.xml
================================================
os
10.10
================================================
FILE: Installer/scripts/postinstall
================================================
#!/bin/sh
sudo chown -R root:wheel /Library/Audio/Plug-Ins/HAL/BlackHole*ch.driver
================================================
FILE: Installer/scripts/preinstall
================================================
#!/bin/sh
sudo mkdir -p /Library/Audio/Plug-Ins/HAL
sudo chown root:wheel /Library/Audio/Plug-Ins/HAL
================================================
FILE: Installer/welcome.html
================================================
BlackHole: Audio Loopback Driver
BlackHole is a modern macOS virtual audio loopback driver that allows applications to pass audio to other applications with zero additional latency.
Please note that a system restart is required to complete the installation.
Features
- Supports 8kHz, 16kHz, 44.1kHz, 48kHz, 88.2kHz, 96kHz, 176.4kHz, 192kHz, 352.8kHz, 384kHz, 705.6kHz and 768kHz sample rates
- Zero additional driver latency
- Compatible with macOS 10.10 Yosemite and newer
- Built for Intel and Apple Silicon
- No kernel extensions or modifications to system security necessary
================================================
FILE: LICENSE
================================================
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
Copyright (C)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
Copyright (C)
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
.
================================================
FILE: README.md
================================================

# BlackHole: Audio Loopback Driver

[](https://github.com/ExistentialAudio/BlackHole/releases)
[](LICENSE)
[](https://twitter.com/ExistentialAI)
[](https://www.facebook.com/Existential-Audio-103423234434751)
BlackHole is a modern macOS virtual audio loopback driver that allows applications to pass audio to other applications with zero additional latency.
### [Download Installer](https://existential.audio/blackhole)
### [Join the Discord Server](https://discord.gg/y8BWfnWRnn)
## Sponsors
### Recall.ai - API for desktop recording
If you’re looking for a desktop recording API, consider checking out [Recall.ai](https://www.recall.ai/product/desktop-recording-sdk?utm_source=github&utm_medium=sponsorship&utm_campaign=existentialaudio-blackhole), an API that records video, audio, and transcripts from Zoom, Google Meet, Microsoft Teams, in-person meetings, and more.
To sponsor this project visit https://github.com/sponsors/ExistentialAudio
## Table of Contents
- [Features](#features)
- [Installation Instructions](#installation-instructions)
- [Uninstallation Instructions](#uninstallation-instructions)
- [User Guides](#user-guides)
- [Developer Guides](#developer-guides)
- [Feature Requests](#feature-requests)
- [FAQ](#faq)
- [Wiki](https://github.com/ExistentialAudio/BlackHole/wiki)
## Features
- Builds 2, 16, 64, 128, and 256 audio channels versions
- Customizable channel count, latency, hidden devices
- Customizable mirror device to allow for a hidden input or output
- Supports 8kHz, 16kHz, 44.1kHz, 48kHz, 88.2kHz, 96kHz, 176.4kHz, 192kHz, 352.8kHz, 384kHz, 705.6kHz and 768kHz sample rates
- Zero additional driver latency
- Compatible with macOS 10.10 Yosemite and newer
- Builds for Intel and Apple Silicon
- No kernel extensions or modifications to system security necessary

## Installation Instructions
### Option 1: Download Installer
1. [Download the latest installer](https://existential.audio/blackhole)
2. Close all running audio applications
3. Open and install package
4. Restart your system when prompted
### Option 2: Install via Homebrew
- 2ch: `brew install blackhole-2ch`
- 16ch: `brew install blackhole-16ch`
- 64ch: `brew install blackhole-64ch`
## Uninstallation Instructions
### Option 1: Use Uninstaller
- [Download BlackHole 2ch Uninstaller](https://existential.audio/downloads/BlackHole2chUninstaller.pkg)
- [Download BlackHole 16ch Uninstaller](https://existential.audio/downloads/BlackHole16chUninstaller.pkg)
- [Download BlackHole 64ch Uninstaller](https://existential.audio/downloads/BlackHole64chUninstaller.pkg)
### Option 2: Manually Uninstall
1. Delete the BlackHole driver with the terminal command:
`rm -R /Library/Audio/Plug-Ins/HAL/BlackHoleXch.driver`
Be sure to replace `X` with either `2`, `16`, or `64`.
Note that the directory is the root `/Library` not `/Users/user/Library`.
2. Restart CoreAudio with the terminal command:
`sudo killall -9 coreaudiod`
For more specific details [visit the Wiki](https://github.com/ExistentialAudio/BlackHole/wiki/Uninstallation).
## User Guides
### Logic Pro X
- [Logic Pro X to FaceTime](https://existential.audio/howto/StreamFromLogicProXtoFaceTime.php)
- [Logic Pro X to Google Meet](https://existential.audio/howto/StreamFromLogicProXtoGoogleMeet.php)
- [Logic Pro X to Skype](https://existential.audio/howto/StreamFromLogicProXtoSkype.php)
- [Logic Pro X to Zoom](https://existential.audio/howto/StreamFromLogicProXtoZoom.php)
### GarageBand
- [GarageBand to FaceTime](https://existential.audio/howto/StreamFromGarageBandToFaceTime.php)
- [GarageBand to Google Meet](https://existential.audio/howto/StreamFromGarageBandToGoogleMeet.php)
- [GarageBand to Skype](https://existential.audio/howto/StreamFromGarageBandToSkype.php)
- [GarageBand to Zoom](https://existential.audio/howto/StreamFromGarageBandToZoom.php)
### Audacity
- [Audacity Setup](https://github.com/ExistentialAudio/BlackHole/wiki/Audacity)
### Reaper
- [Reaper to Zoom](https://noahliebman.net/2020/12/telephone-colophon-or-how-i-overengineered-my-call-audio/) by Noah Liebman
### Record System Audio
1. [Setup Multi-Output Device](https://github.com/ExistentialAudio/BlackHole/wiki/Multi-Output-Device)
2. In `Audio MIDI Setup` → `Audio Devices` right-click on the newly created Multi-Output and select "Use This Device For Sound Output"
3. Open digital audio workstation (DAW) such as GarageBand and set input device to "BlackHole"
4. Set track to input from channel 1-2
5. Play audio from another application and monitor or record in your DAW
### Route Audio Between Applications
1. Set output driver to "BlackHole" in sending application
2. Output audio to any channel
3. Open receiving application and set input device to "BlackHole"
4. Input audio from the corresponding output channels
## Developer Guides
### A license is required for all non-GPLv3 projects
Please support our hard work and continued development. To request a license [contact Existential Audio](mailto:devinroth@existential.audio).
### Build & Install
After building, to install BlackHole:
1. Copy or move the built `BlackHoleXch.driver` bundle to `/Library/Audio/Plug-Ins/HAL`
2. Restart CoreAudio using `sudo killall -9 coreaudiod`
### Customizing BlackHole
The following pre-compiler constants may be used to easily customize a build of BlackHole.
```
kDriver_Name
kPlugIn_BundleID
kPlugIn_Icon
kDevice_Name
kDevice_IsHidden
kDevice_HasInput
kDevice_HasOutput
kDevice2_Name
kDevice2_IsHidden
kDevice2_HasInput
kDevice2_HasOutput
kLatency_Frame_Size
kNumber_Of_Channels
kSampleRates
```
They can be specified at build time with `xcodebuild` using `GCC_PREPROCESSOR_DEFINITIONS`.
Example:
```bash
xcodebuild \
-project BlackHole.xcodeproj \
GCC_PREPROCESSOR_DEFINITIONS='$GCC_PREPROCESSOR_DEFINITIONS kSomeConstant=value'
```
Be sure to escape any quotation marks when using strings.
### Renaming BlackHole
To customize BlackHole it is required to change the following constants.
- `kDriver_Name`
- `kPlugIn_BundleID` (note that this must match the target bundleID)
- `kPlugIn_Icon`
These can specified as pre-compiler constants using ```xcodebuild```.
```bash
driverName="BlackHole"
bundleID="audio.existential.BlackHole"
icon="BlackHole.icns"
xcodebuild \
-project BlackHole.xcodeproj \
-configuration Release \
PRODUCT_BUNDLE_IDENTIFIER=$bundleID \
GCC_PREPROCESSOR_DEFINITIONS='$GCC_PREPROCESSOR_DEFINITIONS
kDriver_Name=\"'$driverName'\"
kPlugIn_BundleID=\"'$bundleID'\"
kPlugIn_Icon=\"'$icon'\"'
```
### Customizing Channels, Latency, and Sample Rates
`kNumber_Of_Channels` is used to set the number of channels. Be careful when specifying high channel counts. Although BlackHole is designed to be extremely efficient at higher channel counts it's possible that your computer might not be able to keep up. Sample rates play a role as well. Don't use high sample rates with a high number of channels. Some applications don't know how to handle high channel counts. Proceed with caution.
`kLatency_Frame_Size` is how much time in frames that the driver has to process incoming and outgoing audio. It can be used to delay the audio inside of BlackHole up to a maximum of 65536 frames. This may be helpful if using BlackHole with a high channel count.
`kSampleRates` set the sample rate or sample rates of the audio device. If using multiple sample rates separate each with a comma (`,`). For example: `kSampleRates='44100,48000'`.
### Mirror Device
By default BlackHole has a hidden mirrored audio device. The devices may be customized using the following constants.
```
// Original Device
kDevice_IsHidden
kDevice_HasInput
kDevice_HasOutput
// Mirrored Device
kDevice2_IsHidden
kDevice2_HasInput
kDevice2_HasOutput
```
When all are set to true a 2nd BlackHole will show up that works exactly the same. The inputs and outputs are mirrored so the outputs from both devices go to the inputs of both devices.
This is useful if you need a separate device for input and output.
Example
```
// Original Device
kDevice_IsHidden=false
kDevice_HasInput=true
kDevice_HasOutput=false
// Mirrored Device
kDevice2_IsHidden=false
kDevice2_HasInput=false
kDevice2_HasOutput=true
```
In this situation we have two BlackHole devices. One will have inputs only and the other will have outputs only.
One way to use this in projects is to hide the mirrored device and use it behind the scenes. That way the user will see an input only device while routing audio through to the output behind them scenes.
Hidden audio devices can be accessed using `kAudioHardwarePropertyTranslateUIDToDevice`.
### Continuous Integration / Continuous Deployment
BlackHole can be integrated into your CI/CD. Take a look at the [create_installer.sh](https://github.com/ExistentialAudio/BlackHole/blob/master/Installer/create_installer.sh) shell script to see how the installer is built, signed and notarized.
## Feature Requests
If you are interested in any of the following features please leave a comment in the linked issue. To request a features not listed please create a new issue.
- [Sync Clock with other Audio Devices](https://github.com/ExistentialAudio/BlackHole/issues/27) in development see v0.3.0
- [Output Blackhole to other Audio Device](https://github.com/ExistentialAudio/BlackHole/issues/40)
- [Add Support for AU Plug-ins](https://github.com/ExistentialAudio/BlackHole/issues/18)
- [Inter-channel routing](https://github.com/ExistentialAudio/BlackHole/issues/13)
- [Record Directly to File](https://github.com/ExistentialAudio/BlackHole/issues/8)
- [Configuration Options Menu](https://github.com/ExistentialAudio/BlackHole/issues/7)
- [Support for Additional Bit Depths](https://github.com/ExistentialAudio/BlackHole/issues/42)
## FAQ
### Why isn't BlackHole showing up in the Applications folder?
BlackHole is a virtual audio loopback driver. It only shows up in `Audio MIDI Setup`, `Sound Preferences`, or other audio applications.
### How can I listen to the audio and use BlackHole at the same time?
See [Setup a Multi-Output Device](https://github.com/ExistentialAudio/BlackHole/wiki/Multi-Output-Device).
### What bit depth does BlackHole use, and can I change it?
BlackHole uses 32-bit float bit depth since macOS Core Audio natively uses 32-bit at the system level. This provides the broadest compatibility and greatest audio headroom.
This format is lossless for up to 24-bit integer. All applications should be able to playback and record audio, and do not require adjusting bit depth at the BlackHole driver level.
### How can I change the volume of a Multi-Output device?
Unfortunately macOS does not support changing the volume of a Multi-Output device but you can set the volume of individual devices in Audio MIDI Setup.
### Why is nothing playing through BlackHole?
- Check `System Preferences` → `Security & Privacy` → `Privacy` → `Microphone` to make sure your digital audio workstation (DAW) application has microphone access.
- Check that the volume is all the way up on BlackHole input and output in ``Audio MIDI Setup``.
- If you are using a multi-output device, due to issues with macOS the Built-in Output must be enabled and listed as the top device in the Multi-Output. [See here for details](https://github.com/ExistentialAudio/BlackHole/wiki/Multi-Output-Device#4-select-output-devices).
### Why is audio glitching after X minutes when using a multi-output or an aggregate?
- You need to enable drift correction for all devices except the Clock Source also known as Master Device or Primary Device.
### Why is the Installer failing?
- Certain versions of macOS have a known issue where install packages may fail to install when the install package is located in certain folders. If you downloaded the .pkg file to your Downloads folder, try moving it to the Desktop and open the .pkg again (or vice-versa).
### What Apps Don't Work with Multi-Outputs?
Unfortunately multi-outputs can be buggy and some apps won't work with them at all. Here is a list of known ones. If additional incompatible applications are found, please report them by opening an [issue](https://github.com/ExistentialAudio/BlackHole/issues).
- Apple Podcasts
- Apple Messages
- HDHomeRun
### AirPods with an Aggregate/Multi-Output is not working.
The microphone from AirPods runs at a lower sample rate which means it should not be used as the primary/clock device in an Aggregate or Multi-Output device. The solution is to use your built-in speakers (and just mute them) or BlackHole 2ch as the primary/clock device. BlackHole 16ch will not work as the primary since the primary needs to have 2ch.
Read [this discussion](https://github.com/ExistentialAudio/BlackHole/issues/146) for more details.
### Can I integrate BlackHole into my app?
BlackHole is licensed under GPL-3.0. You can use BlackHole as long as your app is also licensed as GPL-3.0. For all other applications please [contact Existential Audio directly](mailto:devinroth@existential.audio).
## Links and Resources
### [MultiSoundChanger](https://github.com/rlxone/MultiSoundChanger)
A small tool for changing sound volume even for aggregate devices cause native sound volume controller can't change volume of aggregate devices
### [BackgroundMusic](https://github.com/kyleneideck/BackgroundMusic)
Background Music, a macOS audio utility: automatically pause your music, set individual apps' volumes and record system audio.
================================================
FILE: Uninstaller/Scripts/postinstall
================================================
#!/bin/bash
file="/Library/Audio/Plug-Ins/HAL/BlackHole256ch.driver"
if [ -d "$file" ] ; then
sudo rm -R "$file"
sudo killall coreaudiod
fi
================================================
FILE: Uninstaller/create_uninstaller.sh
================================================
#!/bin/bash
set -euo pipefail
devTeamID="Q5C99V536K" # ⚠️ Replace this with your own developer team ID
notarize=true # To skip notarization, set this to false
notarizeProfile="notarize" # ⚠️ Replace this with your own notarytool keychain profile name
# Basic Validation
if [ ! -d BlackHole.xcodeproj ]; then
echo "This script must be run from the BlackHole repo root folder."
echo "For example:"
echo " cd /path/to/BlackHole"
echo " ./Uninstaller/create_uninstaller.sh"
exit 1
fi
for channels in 2 16 64 128 256; do
# create script
echo \
'#!/bin/bash
file="/Library/Audio/Plug-Ins/HAL/BlackHole'$channels'ch.driver"
if [ -d "$file" ] ; then
sudo rm -R "$file"
sudo killall coreaudiod
fi' > Uninstaller/Scripts/postinstall
chmod 755 Uninstaller/Scripts/postinstall
# Build .pkg
packageName='Uninstaller/BlackHole'$channels'ch-Uninstaller.pkg'
pkgbuild --nopayload --scripts Uninstaller/Scripts --sign $devTeamID --identifier 'audio.existential.BlackHole'$channels'ch.Uninstaller' $packageName
# Notarize and Staple
if [ "$notarize" = true ]; then
# Submit the package for notarization and capture output, also displaying it simultaneously
output=$(xcrun notarytool submit "$packageName" --progress --wait --keychain-profile "notarize" 2>&1 | tee /dev/tty)
# Extract the submission ID
submission_id=$(echo "$output" | grep -o -E 'id: [a-f0-9-]+' | awk '{print $2}' | head -n1)
if [ -z "$submission_id" ]; then
echo "Failed to extract submission ID. ❌"
exit 1
fi
# Check the captured output for the "status: Invalid" indicator
if echo "$output" | grep -q "status: Invalid"; then
echo "Error detected during notarization: Submission Invalid ❌"
# Fetch and display notarization logs
echo -e "\nFetching logs for submission ID: $submission_id"
xcrun notarytool log --keychain-profile "notarize" "$submission_id"
exit 1
else
echo "Notarization submitted successfully ✅"
fi
xcrun stapler staple $packageName
fi
done
rm Uninstaller/Scripts/postinstall
================================================
FILE: VERSION
================================================
0.6.1