mirror of https://github.com/procxx/kepka.git
Remove type mismatch
This commit is contained in:
parent
fa344a9a47
commit
0f1254586c
|
@ -23,7 +23,7 @@ using namespace tgvoip::audio;
|
||||||
AudioInputAudioUnitLegacy::AudioInputAudioUnitLegacy(std::string deviceID) : AudioInput(deviceID){
|
AudioInputAudioUnitLegacy::AudioInputAudioUnitLegacy(std::string deviceID) : AudioInput(deviceID){
|
||||||
remainingDataSize=0;
|
remainingDataSize=0;
|
||||||
isRecording=false;
|
isRecording=false;
|
||||||
|
|
||||||
OSStatus status;
|
OSStatus status;
|
||||||
AudioComponentDescription inputDesc={
|
AudioComponentDescription inputDesc={
|
||||||
.componentType = kAudioUnitType_Output, .componentSubType = /*kAudioUnitSubType_HALOutput*/kAudioUnitSubType_VoiceProcessingIO, .componentFlags = 0, .componentFlagsMask = 0,
|
.componentType = kAudioUnitType_Output, .componentSubType = /*kAudioUnitSubType_HALOutput*/kAudioUnitSubType_VoiceProcessingIO, .componentFlags = 0, .componentFlagsMask = 0,
|
||||||
|
@ -32,27 +32,27 @@ AudioInputAudioUnitLegacy::AudioInputAudioUnitLegacy(std::string deviceID) : Aud
|
||||||
AudioComponent component=AudioComponentFindNext(NULL, &inputDesc);
|
AudioComponent component=AudioComponentFindNext(NULL, &inputDesc);
|
||||||
status=AudioComponentInstanceNew(component, &unit);
|
status=AudioComponentInstanceNew(component, &unit);
|
||||||
CHECK_AU_ERROR(status, "Error creating AudioUnit");
|
CHECK_AU_ERROR(status, "Error creating AudioUnit");
|
||||||
|
|
||||||
UInt32 flag=0;
|
UInt32 flag=0;
|
||||||
status = AudioUnitSetProperty(unit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Output, kOutputBus, &flag, sizeof(flag));
|
status = AudioUnitSetProperty(unit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Output, kOutputBus, &flag, sizeof(flag));
|
||||||
CHECK_AU_ERROR(status, "Error enabling AudioUnit output");
|
CHECK_AU_ERROR(status, "Error enabling AudioUnit output");
|
||||||
flag=1;
|
flag=1;
|
||||||
status = AudioUnitSetProperty(unit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, kInputBus, &flag, sizeof(flag));
|
status = AudioUnitSetProperty(unit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, kInputBus, &flag, sizeof(flag));
|
||||||
CHECK_AU_ERROR(status, "Error enabling AudioUnit input");
|
CHECK_AU_ERROR(status, "Error enabling AudioUnit input");
|
||||||
|
|
||||||
SetCurrentDevice(deviceID);
|
SetCurrentDevice(deviceID);
|
||||||
|
|
||||||
CFRunLoopRef theRunLoop = NULL;
|
CFRunLoopRef theRunLoop = NULL;
|
||||||
AudioObjectPropertyAddress propertyAddress = { kAudioHardwarePropertyRunLoop,
|
AudioObjectPropertyAddress propertyAddress = { kAudioHardwarePropertyRunLoop,
|
||||||
kAudioObjectPropertyScopeGlobal,
|
kAudioObjectPropertyScopeGlobal,
|
||||||
kAudioObjectPropertyElementMaster };
|
kAudioObjectPropertyElementMaster };
|
||||||
status = AudioObjectSetPropertyData(kAudioObjectSystemObject, &propertyAddress, 0, NULL, sizeof(CFRunLoopRef), &theRunLoop);
|
status = AudioObjectSetPropertyData(kAudioObjectSystemObject, &propertyAddress, 0, NULL, sizeof(CFRunLoopRef), &theRunLoop);
|
||||||
|
|
||||||
propertyAddress.mSelector = kAudioHardwarePropertyDefaultInputDevice;
|
propertyAddress.mSelector = kAudioHardwarePropertyDefaultInputDevice;
|
||||||
propertyAddress.mScope = kAudioObjectPropertyScopeGlobal;
|
propertyAddress.mScope = kAudioObjectPropertyScopeGlobal;
|
||||||
propertyAddress.mElement = kAudioObjectPropertyElementMaster;
|
propertyAddress.mElement = kAudioObjectPropertyElementMaster;
|
||||||
AudioObjectAddPropertyListener(kAudioObjectSystemObject, &propertyAddress, AudioInputAudioUnitLegacy::DefaultDeviceChangedCallback, this);
|
AudioObjectAddPropertyListener(kAudioObjectSystemObject, &propertyAddress, AudioInputAudioUnitLegacy::DefaultDeviceChangedCallback, this);
|
||||||
|
|
||||||
AURenderCallbackStruct callbackStruct;
|
AURenderCallbackStruct callbackStruct;
|
||||||
callbackStruct.inputProc = AudioInputAudioUnitLegacy::BufferCallback;
|
callbackStruct.inputProc = AudioInputAudioUnitLegacy::BufferCallback;
|
||||||
callbackStruct.inputProcRefCon=this;
|
callbackStruct.inputProcRefCon=this;
|
||||||
|
@ -60,7 +60,7 @@ AudioInputAudioUnitLegacy::AudioInputAudioUnitLegacy(std::string deviceID) : Aud
|
||||||
CHECK_AU_ERROR(status, "Error setting input buffer callback");
|
CHECK_AU_ERROR(status, "Error setting input buffer callback");
|
||||||
status=AudioUnitInitialize(unit);
|
status=AudioUnitInitialize(unit);
|
||||||
CHECK_AU_ERROR(status, "Error initializing unit");
|
CHECK_AU_ERROR(status, "Error initializing unit");
|
||||||
|
|
||||||
inBufferList.mBuffers[0].mData=malloc(10240);
|
inBufferList.mBuffers[0].mData=malloc(10240);
|
||||||
inBufferList.mBuffers[0].mDataByteSize=10240;
|
inBufferList.mBuffers[0].mDataByteSize=10240;
|
||||||
inBufferList.mNumberBuffers=1;
|
inBufferList.mNumberBuffers=1;
|
||||||
|
@ -72,7 +72,7 @@ AudioInputAudioUnitLegacy::~AudioInputAudioUnitLegacy(){
|
||||||
propertyAddress.mScope = kAudioObjectPropertyScopeGlobal;
|
propertyAddress.mScope = kAudioObjectPropertyScopeGlobal;
|
||||||
propertyAddress.mElement = kAudioObjectPropertyElementMaster;
|
propertyAddress.mElement = kAudioObjectPropertyElementMaster;
|
||||||
AudioObjectRemovePropertyListener(kAudioObjectSystemObject, &propertyAddress, AudioInputAudioUnitLegacy::DefaultDeviceChangedCallback, this);
|
AudioObjectRemovePropertyListener(kAudioObjectSystemObject, &propertyAddress, AudioInputAudioUnitLegacy::DefaultDeviceChangedCallback, this);
|
||||||
|
|
||||||
AudioUnitUninitialize(unit);
|
AudioUnitUninitialize(unit);
|
||||||
AudioComponentInstanceDispose(unit);
|
AudioComponentInstanceDispose(unit);
|
||||||
free(inBufferList.mBuffers[0].mData);
|
free(inBufferList.mBuffers[0].mData);
|
||||||
|
@ -130,19 +130,19 @@ void AudioInputAudioUnitLegacy::EnumerateDevices(std::vector<AudioInputDevice>&
|
||||||
kAudioObjectPropertyScopeGlobal,
|
kAudioObjectPropertyScopeGlobal,
|
||||||
kAudioObjectPropertyElementMaster
|
kAudioObjectPropertyElementMaster
|
||||||
};
|
};
|
||||||
|
|
||||||
UInt32 dataSize = 0;
|
UInt32 dataSize = 0;
|
||||||
OSStatus status = AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, &propertyAddress, 0, NULL, &dataSize);
|
OSStatus status = AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, &propertyAddress, 0, NULL, &dataSize);
|
||||||
if(kAudioHardwareNoError != status) {
|
if(kAudioHardwareNoError != status) {
|
||||||
LOGE("AudioObjectGetPropertyDataSize (kAudioHardwarePropertyDevices) failed: %i", status);
|
LOGE("AudioObjectGetPropertyDataSize (kAudioHardwarePropertyDevices) failed: %i", status);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt32 deviceCount = (UInt32)(dataSize / sizeof(AudioDeviceID));
|
UInt32 deviceCount = (UInt32)(dataSize / sizeof(AudioDeviceID));
|
||||||
|
|
||||||
|
|
||||||
AudioDeviceID *audioDevices = (AudioDeviceID*)(malloc(dataSize));
|
AudioDeviceID *audioDevices = (AudioDeviceID*)(malloc(dataSize));
|
||||||
|
|
||||||
status = AudioObjectGetPropertyData(kAudioObjectSystemObject, &propertyAddress, 0, NULL, &dataSize, audioDevices);
|
status = AudioObjectGetPropertyData(kAudioObjectSystemObject, &propertyAddress, 0, NULL, &dataSize, audioDevices);
|
||||||
if(kAudioHardwareNoError != status) {
|
if(kAudioHardwareNoError != status) {
|
||||||
LOGE("AudioObjectGetPropertyData (kAudioHardwarePropertyDevices) failed: %i", status);
|
LOGE("AudioObjectGetPropertyData (kAudioHardwarePropertyDevices) failed: %i", status);
|
||||||
|
@ -150,8 +150,8 @@ void AudioInputAudioUnitLegacy::EnumerateDevices(std::vector<AudioInputDevice>&
|
||||||
audioDevices = NULL;
|
audioDevices = NULL;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Iterate through all the devices and determine which are input-capable
|
// Iterate through all the devices and determine which are input-capable
|
||||||
propertyAddress.mScope = kAudioDevicePropertyScopeInput;
|
propertyAddress.mScope = kAudioDevicePropertyScopeInput;
|
||||||
for(UInt32 i = 0; i < deviceCount; ++i) {
|
for(UInt32 i = 0; i < deviceCount; ++i) {
|
||||||
|
@ -164,7 +164,7 @@ void AudioInputAudioUnitLegacy::EnumerateDevices(std::vector<AudioInputDevice>&
|
||||||
LOGE("AudioObjectGetPropertyData (kAudioDevicePropertyDeviceUID) failed: %i", status);
|
LOGE("AudioObjectGetPropertyData (kAudioDevicePropertyDeviceUID) failed: %i", status);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Query device name
|
// Query device name
|
||||||
CFStringRef deviceName = NULL;
|
CFStringRef deviceName = NULL;
|
||||||
dataSize = sizeof(deviceName);
|
dataSize = sizeof(deviceName);
|
||||||
|
@ -174,7 +174,7 @@ void AudioInputAudioUnitLegacy::EnumerateDevices(std::vector<AudioInputDevice>&
|
||||||
LOGE("AudioObjectGetPropertyData (kAudioDevicePropertyDeviceNameCFString) failed: %i", status);
|
LOGE("AudioObjectGetPropertyData (kAudioDevicePropertyDeviceNameCFString) failed: %i", status);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine if the device is an input device (it is an input device if it has input channels)
|
// Determine if the device is an input device (it is an input device if it has input channels)
|
||||||
dataSize = 0;
|
dataSize = 0;
|
||||||
propertyAddress.mSelector = kAudioDevicePropertyStreamConfiguration;
|
propertyAddress.mSelector = kAudioDevicePropertyStreamConfiguration;
|
||||||
|
@ -183,9 +183,9 @@ void AudioInputAudioUnitLegacy::EnumerateDevices(std::vector<AudioInputDevice>&
|
||||||
LOGE("AudioObjectGetPropertyDataSize (kAudioDevicePropertyStreamConfiguration) failed: %i", status);
|
LOGE("AudioObjectGetPropertyDataSize (kAudioDevicePropertyStreamConfiguration) failed: %i", status);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioBufferList *bufferList = (AudioBufferList*)(malloc(dataSize));
|
AudioBufferList *bufferList = (AudioBufferList*)(malloc(dataSize));
|
||||||
|
|
||||||
status = AudioObjectGetPropertyData(audioDevices[i], &propertyAddress, 0, NULL, &dataSize, bufferList);
|
status = AudioObjectGetPropertyData(audioDevices[i], &propertyAddress, 0, NULL, &dataSize, bufferList);
|
||||||
if(kAudioHardwareNoError != status || 0 == bufferList->mNumberBuffers) {
|
if(kAudioHardwareNoError != status || 0 == bufferList->mNumberBuffers) {
|
||||||
if(kAudioHardwareNoError != status)
|
if(kAudioHardwareNoError != status)
|
||||||
|
@ -194,10 +194,10 @@ void AudioInputAudioUnitLegacy::EnumerateDevices(std::vector<AudioInputDevice>&
|
||||||
bufferList = NULL;
|
bufferList = NULL;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(bufferList);
|
free(bufferList);
|
||||||
bufferList = NULL;
|
bufferList = NULL;
|
||||||
|
|
||||||
AudioInputDevice dev;
|
AudioInputDevice dev;
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
CFStringGetCString(deviceName, buf, 1024, kCFStringEncodingUTF8);
|
CFStringGetCString(deviceName, buf, 1024, kCFStringEncodingUTF8);
|
||||||
|
@ -206,16 +206,16 @@ void AudioInputAudioUnitLegacy::EnumerateDevices(std::vector<AudioInputDevice>&
|
||||||
dev.id=std::string(buf);
|
dev.id=std::string(buf);
|
||||||
devs.push_back(dev);
|
devs.push_back(dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(audioDevices);
|
free(audioDevices);
|
||||||
audioDevices = NULL;
|
audioDevices = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioInputAudioUnitLegacy::SetCurrentDevice(std::string deviceID){
|
void AudioInputAudioUnitLegacy::SetCurrentDevice(std::string deviceID){
|
||||||
UInt32 size=sizeof(AudioDeviceID);
|
UInt32 size=sizeof(AudioDeviceID);
|
||||||
AudioDeviceID inputDevice=NULL;
|
AudioDeviceID inputDevice=0;
|
||||||
OSStatus status;
|
OSStatus status;
|
||||||
|
|
||||||
if(deviceID=="default"){
|
if(deviceID=="default"){
|
||||||
AudioObjectPropertyAddress propertyAddress;
|
AudioObjectPropertyAddress propertyAddress;
|
||||||
propertyAddress.mSelector = kAudioHardwarePropertyDefaultInputDevice;
|
propertyAddress.mSelector = kAudioHardwarePropertyDefaultInputDevice;
|
||||||
|
@ -258,7 +258,7 @@ void AudioInputAudioUnitLegacy::SetCurrentDevice(std::string deviceID){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
status =AudioUnitSetProperty(unit,
|
status =AudioUnitSetProperty(unit,
|
||||||
kAudioOutputUnitProperty_CurrentDevice,
|
kAudioOutputUnitProperty_CurrentDevice,
|
||||||
kAudioUnitScope_Global,
|
kAudioUnitScope_Global,
|
||||||
|
@ -266,25 +266,25 @@ void AudioInputAudioUnitLegacy::SetCurrentDevice(std::string deviceID){
|
||||||
&inputDevice,
|
&inputDevice,
|
||||||
size);
|
size);
|
||||||
CHECK_AU_ERROR(status, "Error setting input device");
|
CHECK_AU_ERROR(status, "Error setting input device");
|
||||||
|
|
||||||
AudioStreamBasicDescription hardwareFormat;
|
AudioStreamBasicDescription hardwareFormat;
|
||||||
size=sizeof(hardwareFormat);
|
size=sizeof(hardwareFormat);
|
||||||
status=AudioUnitGetProperty(unit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, kInputBus, &hardwareFormat, &size);
|
status=AudioUnitGetProperty(unit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, kInputBus, &hardwareFormat, &size);
|
||||||
CHECK_AU_ERROR(status, "Error getting hardware format");
|
CHECK_AU_ERROR(status, "Error getting hardware format");
|
||||||
hardwareSampleRate=hardwareFormat.mSampleRate;
|
hardwareSampleRate=hardwareFormat.mSampleRate;
|
||||||
|
|
||||||
AudioStreamBasicDescription desiredFormat={
|
AudioStreamBasicDescription desiredFormat={
|
||||||
.mSampleRate=hardwareFormat.mSampleRate, .mFormatID=kAudioFormatLinearPCM, .mFormatFlags=kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked | kAudioFormatFlagsNativeEndian,
|
.mSampleRate=hardwareFormat.mSampleRate, .mFormatID=kAudioFormatLinearPCM, .mFormatFlags=kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked | kAudioFormatFlagsNativeEndian,
|
||||||
.mFramesPerPacket=1, .mChannelsPerFrame=1, .mBitsPerChannel=16, .mBytesPerPacket=2, .mBytesPerFrame=2
|
.mFramesPerPacket=1, .mChannelsPerFrame=1, .mBitsPerChannel=16, .mBytesPerPacket=2, .mBytesPerFrame=2
|
||||||
};
|
};
|
||||||
|
|
||||||
status=AudioUnitSetProperty(unit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, kInputBus, &desiredFormat, sizeof(desiredFormat));
|
status=AudioUnitSetProperty(unit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, kInputBus, &desiredFormat, sizeof(desiredFormat));
|
||||||
CHECK_AU_ERROR(status, "Error setting format");
|
CHECK_AU_ERROR(status, "Error setting format");
|
||||||
|
|
||||||
LOGD("Switched capture device, new sample rate %d", hardwareSampleRate);
|
LOGD("Switched capture device, new sample rate %d", hardwareSampleRate);
|
||||||
|
|
||||||
this->currentDevice=deviceID;
|
this->currentDevice=deviceID;
|
||||||
|
|
||||||
AudioObjectPropertyAddress propertyAddress = {
|
AudioObjectPropertyAddress propertyAddress = {
|
||||||
kAudioDevicePropertyBufferFrameSize,
|
kAudioDevicePropertyBufferFrameSize,
|
||||||
kAudioObjectPropertyScopeGlobal,
|
kAudioObjectPropertyScopeGlobal,
|
||||||
|
|
|
@ -23,8 +23,8 @@ using namespace tgvoip::audio;
|
||||||
AudioOutputAudioUnitLegacy::AudioOutputAudioUnitLegacy(std::string deviceID){
|
AudioOutputAudioUnitLegacy::AudioOutputAudioUnitLegacy(std::string deviceID){
|
||||||
remainingDataSize=0;
|
remainingDataSize=0;
|
||||||
isPlaying=false;
|
isPlaying=false;
|
||||||
sysDevID=NULL;
|
sysDevID=0;
|
||||||
|
|
||||||
OSStatus status;
|
OSStatus status;
|
||||||
AudioComponentDescription inputDesc={
|
AudioComponentDescription inputDesc={
|
||||||
.componentType = kAudioUnitType_Output, .componentSubType = kAudioUnitSubType_HALOutput, .componentFlags = 0, .componentFlagsMask = 0,
|
.componentType = kAudioUnitType_Output, .componentSubType = kAudioUnitSubType_HALOutput, .componentFlags = 0, .componentFlagsMask = 0,
|
||||||
|
@ -33,14 +33,14 @@ AudioOutputAudioUnitLegacy::AudioOutputAudioUnitLegacy(std::string deviceID){
|
||||||
AudioComponent component=AudioComponentFindNext(NULL, &inputDesc);
|
AudioComponent component=AudioComponentFindNext(NULL, &inputDesc);
|
||||||
status=AudioComponentInstanceNew(component, &unit);
|
status=AudioComponentInstanceNew(component, &unit);
|
||||||
CHECK_AU_ERROR(status, "Error creating AudioUnit");
|
CHECK_AU_ERROR(status, "Error creating AudioUnit");
|
||||||
|
|
||||||
UInt32 flag=1;
|
UInt32 flag=1;
|
||||||
status = AudioUnitSetProperty(unit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Output, kOutputBus, &flag, sizeof(flag));
|
status = AudioUnitSetProperty(unit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Output, kOutputBus, &flag, sizeof(flag));
|
||||||
CHECK_AU_ERROR(status, "Error enabling AudioUnit output");
|
CHECK_AU_ERROR(status, "Error enabling AudioUnit output");
|
||||||
flag=0;
|
flag=0;
|
||||||
status = AudioUnitSetProperty(unit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, kInputBus, &flag, sizeof(flag));
|
status = AudioUnitSetProperty(unit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, kInputBus, &flag, sizeof(flag));
|
||||||
CHECK_AU_ERROR(status, "Error enabling AudioUnit input");
|
CHECK_AU_ERROR(status, "Error enabling AudioUnit input");
|
||||||
|
|
||||||
char model[128];
|
char model[128];
|
||||||
memset(model, 0, sizeof(model));
|
memset(model, 0, sizeof(model));
|
||||||
size_t msize=sizeof(model);
|
size_t msize=sizeof(model);
|
||||||
|
@ -49,28 +49,28 @@ AudioOutputAudioUnitLegacy::AudioOutputAudioUnitLegacy(std::string deviceID){
|
||||||
LOGV("Mac model: %s", model);
|
LOGV("Mac model: %s", model);
|
||||||
isMacBookPro=(strncmp("MacBookPro", model, 10)==0);
|
isMacBookPro=(strncmp("MacBookPro", model, 10)==0);
|
||||||
}
|
}
|
||||||
|
|
||||||
SetCurrentDevice(deviceID);
|
SetCurrentDevice(deviceID);
|
||||||
|
|
||||||
CFRunLoopRef theRunLoop = NULL;
|
CFRunLoopRef theRunLoop = NULL;
|
||||||
AudioObjectPropertyAddress propertyAddress = { kAudioHardwarePropertyRunLoop,
|
AudioObjectPropertyAddress propertyAddress = { kAudioHardwarePropertyRunLoop,
|
||||||
kAudioObjectPropertyScopeGlobal,
|
kAudioObjectPropertyScopeGlobal,
|
||||||
kAudioObjectPropertyElementMaster };
|
kAudioObjectPropertyElementMaster };
|
||||||
status = AudioObjectSetPropertyData(kAudioObjectSystemObject, &propertyAddress, 0, NULL, sizeof(CFRunLoopRef), &theRunLoop);
|
status = AudioObjectSetPropertyData(kAudioObjectSystemObject, &propertyAddress, 0, NULL, sizeof(CFRunLoopRef), &theRunLoop);
|
||||||
|
|
||||||
propertyAddress.mSelector = kAudioHardwarePropertyDefaultOutputDevice;
|
propertyAddress.mSelector = kAudioHardwarePropertyDefaultOutputDevice;
|
||||||
propertyAddress.mScope = kAudioObjectPropertyScopeGlobal;
|
propertyAddress.mScope = kAudioObjectPropertyScopeGlobal;
|
||||||
propertyAddress.mElement = kAudioObjectPropertyElementMaster;
|
propertyAddress.mElement = kAudioObjectPropertyElementMaster;
|
||||||
AudioObjectAddPropertyListener(kAudioObjectSystemObject, &propertyAddress, AudioOutputAudioUnitLegacy::DefaultDeviceChangedCallback, this);
|
AudioObjectAddPropertyListener(kAudioObjectSystemObject, &propertyAddress, AudioOutputAudioUnitLegacy::DefaultDeviceChangedCallback, this);
|
||||||
|
|
||||||
AudioStreamBasicDescription desiredFormat={
|
AudioStreamBasicDescription desiredFormat={
|
||||||
.mSampleRate=/*hardwareFormat.mSampleRate*/48000, .mFormatID=kAudioFormatLinearPCM, .mFormatFlags=kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked | kAudioFormatFlagsNativeEndian,
|
.mSampleRate=/*hardwareFormat.mSampleRate*/48000, .mFormatID=kAudioFormatLinearPCM, .mFormatFlags=kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked | kAudioFormatFlagsNativeEndian,
|
||||||
.mFramesPerPacket=1, .mChannelsPerFrame=1, .mBitsPerChannel=16, .mBytesPerPacket=2, .mBytesPerFrame=2
|
.mFramesPerPacket=1, .mChannelsPerFrame=1, .mBitsPerChannel=16, .mBytesPerPacket=2, .mBytesPerFrame=2
|
||||||
};
|
};
|
||||||
|
|
||||||
status=AudioUnitSetProperty(unit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, kOutputBus, &desiredFormat, sizeof(desiredFormat));
|
status=AudioUnitSetProperty(unit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, kOutputBus, &desiredFormat, sizeof(desiredFormat));
|
||||||
CHECK_AU_ERROR(status, "Error setting format");
|
CHECK_AU_ERROR(status, "Error setting format");
|
||||||
|
|
||||||
AURenderCallbackStruct callbackStruct;
|
AURenderCallbackStruct callbackStruct;
|
||||||
callbackStruct.inputProc = AudioOutputAudioUnitLegacy::BufferCallback;
|
callbackStruct.inputProc = AudioOutputAudioUnitLegacy::BufferCallback;
|
||||||
callbackStruct.inputProcRefCon=this;
|
callbackStruct.inputProcRefCon=this;
|
||||||
|
@ -86,7 +86,7 @@ AudioOutputAudioUnitLegacy::~AudioOutputAudioUnitLegacy(){
|
||||||
propertyAddress.mScope = kAudioObjectPropertyScopeGlobal;
|
propertyAddress.mScope = kAudioObjectPropertyScopeGlobal;
|
||||||
propertyAddress.mElement = kAudioObjectPropertyElementMaster;
|
propertyAddress.mElement = kAudioObjectPropertyElementMaster;
|
||||||
AudioObjectRemovePropertyListener(kAudioObjectSystemObject, &propertyAddress, AudioOutputAudioUnitLegacy::DefaultDeviceChangedCallback, this);
|
AudioObjectRemovePropertyListener(kAudioObjectSystemObject, &propertyAddress, AudioOutputAudioUnitLegacy::DefaultDeviceChangedCallback, this);
|
||||||
|
|
||||||
AudioObjectPropertyAddress dataSourceProp={
|
AudioObjectPropertyAddress dataSourceProp={
|
||||||
kAudioDevicePropertyDataSource,
|
kAudioDevicePropertyDataSource,
|
||||||
kAudioDevicePropertyScopeOutput,
|
kAudioDevicePropertyScopeOutput,
|
||||||
|
@ -95,7 +95,7 @@ AudioOutputAudioUnitLegacy::~AudioOutputAudioUnitLegacy(){
|
||||||
if(isMacBookPro && sysDevID && AudioObjectHasProperty(sysDevID, &dataSourceProp)){
|
if(isMacBookPro && sysDevID && AudioObjectHasProperty(sysDevID, &dataSourceProp)){
|
||||||
AudioObjectRemovePropertyListener(sysDevID, &dataSourceProp, AudioOutputAudioUnitLegacy::DefaultDeviceChangedCallback, this);
|
AudioObjectRemovePropertyListener(sysDevID, &dataSourceProp, AudioOutputAudioUnitLegacy::DefaultDeviceChangedCallback, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioUnitUninitialize(unit);
|
AudioUnitUninitialize(unit);
|
||||||
AudioComponentInstanceDispose(unit);
|
AudioComponentInstanceDispose(unit);
|
||||||
}
|
}
|
||||||
|
@ -153,19 +153,19 @@ void AudioOutputAudioUnitLegacy::EnumerateDevices(std::vector<AudioOutputDevice>
|
||||||
kAudioObjectPropertyScopeGlobal,
|
kAudioObjectPropertyScopeGlobal,
|
||||||
kAudioObjectPropertyElementMaster
|
kAudioObjectPropertyElementMaster
|
||||||
};
|
};
|
||||||
|
|
||||||
UInt32 dataSize = 0;
|
UInt32 dataSize = 0;
|
||||||
OSStatus status = AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, &propertyAddress, 0, NULL, &dataSize);
|
OSStatus status = AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, &propertyAddress, 0, NULL, &dataSize);
|
||||||
if(kAudioHardwareNoError != status) {
|
if(kAudioHardwareNoError != status) {
|
||||||
LOGE("AudioObjectGetPropertyDataSize (kAudioHardwarePropertyDevices) failed: %i", status);
|
LOGE("AudioObjectGetPropertyDataSize (kAudioHardwarePropertyDevices) failed: %i", status);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt32 deviceCount = (UInt32)(dataSize / sizeof(AudioDeviceID));
|
UInt32 deviceCount = (UInt32)(dataSize / sizeof(AudioDeviceID));
|
||||||
|
|
||||||
|
|
||||||
AudioDeviceID *audioDevices = (AudioDeviceID*)(malloc(dataSize));
|
AudioDeviceID *audioDevices = (AudioDeviceID*)(malloc(dataSize));
|
||||||
|
|
||||||
status = AudioObjectGetPropertyData(kAudioObjectSystemObject, &propertyAddress, 0, NULL, &dataSize, audioDevices);
|
status = AudioObjectGetPropertyData(kAudioObjectSystemObject, &propertyAddress, 0, NULL, &dataSize, audioDevices);
|
||||||
if(kAudioHardwareNoError != status) {
|
if(kAudioHardwareNoError != status) {
|
||||||
LOGE("AudioObjectGetPropertyData (kAudioHardwarePropertyDevices) failed: %i", status);
|
LOGE("AudioObjectGetPropertyData (kAudioHardwarePropertyDevices) failed: %i", status);
|
||||||
|
@ -173,8 +173,8 @@ void AudioOutputAudioUnitLegacy::EnumerateDevices(std::vector<AudioOutputDevice>
|
||||||
audioDevices = NULL;
|
audioDevices = NULL;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Iterate through all the devices and determine which are input-capable
|
// Iterate through all the devices and determine which are input-capable
|
||||||
propertyAddress.mScope = kAudioDevicePropertyScopeOutput;
|
propertyAddress.mScope = kAudioDevicePropertyScopeOutput;
|
||||||
for(UInt32 i = 0; i < deviceCount; ++i) {
|
for(UInt32 i = 0; i < deviceCount; ++i) {
|
||||||
|
@ -187,7 +187,7 @@ void AudioOutputAudioUnitLegacy::EnumerateDevices(std::vector<AudioOutputDevice>
|
||||||
LOGE("AudioObjectGetPropertyData (kAudioDevicePropertyDeviceUID) failed: %i", status);
|
LOGE("AudioObjectGetPropertyData (kAudioDevicePropertyDeviceUID) failed: %i", status);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Query device name
|
// Query device name
|
||||||
CFStringRef deviceName = NULL;
|
CFStringRef deviceName = NULL;
|
||||||
dataSize = sizeof(deviceName);
|
dataSize = sizeof(deviceName);
|
||||||
|
@ -197,7 +197,7 @@ void AudioOutputAudioUnitLegacy::EnumerateDevices(std::vector<AudioOutputDevice>
|
||||||
LOGE("AudioObjectGetPropertyData (kAudioDevicePropertyDeviceNameCFString) failed: %i", status);
|
LOGE("AudioObjectGetPropertyData (kAudioDevicePropertyDeviceNameCFString) failed: %i", status);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine if the device is an input device (it is an input device if it has input channels)
|
// Determine if the device is an input device (it is an input device if it has input channels)
|
||||||
dataSize = 0;
|
dataSize = 0;
|
||||||
propertyAddress.mSelector = kAudioDevicePropertyStreamConfiguration;
|
propertyAddress.mSelector = kAudioDevicePropertyStreamConfiguration;
|
||||||
|
@ -206,9 +206,9 @@ void AudioOutputAudioUnitLegacy::EnumerateDevices(std::vector<AudioOutputDevice>
|
||||||
LOGE("AudioObjectGetPropertyDataSize (kAudioDevicePropertyStreamConfiguration) failed: %i", status);
|
LOGE("AudioObjectGetPropertyDataSize (kAudioDevicePropertyStreamConfiguration) failed: %i", status);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioBufferList *bufferList = (AudioBufferList*)(malloc(dataSize));
|
AudioBufferList *bufferList = (AudioBufferList*)(malloc(dataSize));
|
||||||
|
|
||||||
status = AudioObjectGetPropertyData(audioDevices[i], &propertyAddress, 0, NULL, &dataSize, bufferList);
|
status = AudioObjectGetPropertyData(audioDevices[i], &propertyAddress, 0, NULL, &dataSize, bufferList);
|
||||||
if(kAudioHardwareNoError != status || 0 == bufferList->mNumberBuffers) {
|
if(kAudioHardwareNoError != status || 0 == bufferList->mNumberBuffers) {
|
||||||
if(kAudioHardwareNoError != status)
|
if(kAudioHardwareNoError != status)
|
||||||
|
@ -217,10 +217,10 @@ void AudioOutputAudioUnitLegacy::EnumerateDevices(std::vector<AudioOutputDevice>
|
||||||
bufferList = NULL;
|
bufferList = NULL;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(bufferList);
|
free(bufferList);
|
||||||
bufferList = NULL;
|
bufferList = NULL;
|
||||||
|
|
||||||
AudioOutputDevice dev;
|
AudioOutputDevice dev;
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
CFStringGetCString(deviceName, buf, 1024, kCFStringEncodingUTF8);
|
CFStringGetCString(deviceName, buf, 1024, kCFStringEncodingUTF8);
|
||||||
|
@ -229,25 +229,25 @@ void AudioOutputAudioUnitLegacy::EnumerateDevices(std::vector<AudioOutputDevice>
|
||||||
dev.id=std::string(buf);
|
dev.id=std::string(buf);
|
||||||
devs.push_back(dev);
|
devs.push_back(dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(audioDevices);
|
free(audioDevices);
|
||||||
audioDevices = NULL;
|
audioDevices = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioOutputAudioUnitLegacy::SetCurrentDevice(std::string deviceID){
|
void AudioOutputAudioUnitLegacy::SetCurrentDevice(std::string deviceID){
|
||||||
UInt32 size=sizeof(AudioDeviceID);
|
UInt32 size=sizeof(AudioDeviceID);
|
||||||
AudioDeviceID outputDevice=NULL;
|
AudioDeviceID outputDevice=0;
|
||||||
OSStatus status;
|
OSStatus status;
|
||||||
AudioObjectPropertyAddress dataSourceProp={
|
AudioObjectPropertyAddress dataSourceProp={
|
||||||
kAudioDevicePropertyDataSource,
|
kAudioDevicePropertyDataSource,
|
||||||
kAudioDevicePropertyScopeOutput,
|
kAudioDevicePropertyScopeOutput,
|
||||||
kAudioObjectPropertyElementMaster
|
kAudioObjectPropertyElementMaster
|
||||||
};
|
};
|
||||||
|
|
||||||
if(isMacBookPro && sysDevID && AudioObjectHasProperty(sysDevID, &dataSourceProp)){
|
if(isMacBookPro && sysDevID && AudioObjectHasProperty(sysDevID, &dataSourceProp)){
|
||||||
AudioObjectRemovePropertyListener(sysDevID, &dataSourceProp, AudioOutputAudioUnitLegacy::DefaultDeviceChangedCallback, this);
|
AudioObjectRemovePropertyListener(sysDevID, &dataSourceProp, AudioOutputAudioUnitLegacy::DefaultDeviceChangedCallback, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(deviceID=="default"){
|
if(deviceID=="default"){
|
||||||
AudioObjectPropertyAddress propertyAddress;
|
AudioObjectPropertyAddress propertyAddress;
|
||||||
propertyAddress.mSelector = kAudioHardwarePropertyDefaultOutputDevice;
|
propertyAddress.mSelector = kAudioHardwarePropertyDefaultOutputDevice;
|
||||||
|
@ -290,7 +290,7 @@ void AudioOutputAudioUnitLegacy::SetCurrentDevice(std::string deviceID){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
status =AudioUnitSetProperty(unit,
|
status =AudioUnitSetProperty(unit,
|
||||||
kAudioOutputUnitProperty_CurrentDevice,
|
kAudioOutputUnitProperty_CurrentDevice,
|
||||||
kAudioUnitScope_Global,
|
kAudioUnitScope_Global,
|
||||||
|
@ -298,26 +298,26 @@ void AudioOutputAudioUnitLegacy::SetCurrentDevice(std::string deviceID){
|
||||||
&outputDevice,
|
&outputDevice,
|
||||||
size);
|
size);
|
||||||
CHECK_AU_ERROR(status, "Error setting output device");
|
CHECK_AU_ERROR(status, "Error setting output device");
|
||||||
|
|
||||||
AudioStreamBasicDescription hardwareFormat;
|
AudioStreamBasicDescription hardwareFormat;
|
||||||
size=sizeof(hardwareFormat);
|
size=sizeof(hardwareFormat);
|
||||||
status=AudioUnitGetProperty(unit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, kOutputBus, &hardwareFormat, &size);
|
status=AudioUnitGetProperty(unit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, kOutputBus, &hardwareFormat, &size);
|
||||||
CHECK_AU_ERROR(status, "Error getting hardware format");
|
CHECK_AU_ERROR(status, "Error getting hardware format");
|
||||||
hardwareSampleRate=hardwareFormat.mSampleRate;
|
hardwareSampleRate=hardwareFormat.mSampleRate;
|
||||||
|
|
||||||
AudioStreamBasicDescription desiredFormat={
|
AudioStreamBasicDescription desiredFormat={
|
||||||
.mSampleRate=48000, .mFormatID=kAudioFormatLinearPCM, .mFormatFlags=kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked | kAudioFormatFlagsNativeEndian,
|
.mSampleRate=48000, .mFormatID=kAudioFormatLinearPCM, .mFormatFlags=kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked | kAudioFormatFlagsNativeEndian,
|
||||||
.mFramesPerPacket=1, .mChannelsPerFrame=1, .mBitsPerChannel=16, .mBytesPerPacket=2, .mBytesPerFrame=2
|
.mFramesPerPacket=1, .mChannelsPerFrame=1, .mBitsPerChannel=16, .mBytesPerPacket=2, .mBytesPerFrame=2
|
||||||
};
|
};
|
||||||
|
|
||||||
status=AudioUnitSetProperty(unit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, kOutputBus, &desiredFormat, sizeof(desiredFormat));
|
status=AudioUnitSetProperty(unit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, kOutputBus, &desiredFormat, sizeof(desiredFormat));
|
||||||
CHECK_AU_ERROR(status, "Error setting format");
|
CHECK_AU_ERROR(status, "Error setting format");
|
||||||
|
|
||||||
LOGD("Switched playback device, new sample rate %d", hardwareSampleRate);
|
LOGD("Switched playback device, new sample rate %d", hardwareSampleRate);
|
||||||
|
|
||||||
this->currentDevice=deviceID;
|
this->currentDevice=deviceID;
|
||||||
sysDevID=outputDevice;
|
sysDevID=outputDevice;
|
||||||
|
|
||||||
AudioObjectPropertyAddress propertyAddress = {
|
AudioObjectPropertyAddress propertyAddress = {
|
||||||
kAudioDevicePropertyBufferFrameSize,
|
kAudioDevicePropertyBufferFrameSize,
|
||||||
kAudioObjectPropertyScopeGlobal,
|
kAudioObjectPropertyScopeGlobal,
|
||||||
|
@ -330,7 +330,7 @@ void AudioOutputAudioUnitLegacy::SetCurrentDevice(std::string deviceID){
|
||||||
estimatedDelay=bufferFrameSize/48;
|
estimatedDelay=bufferFrameSize/48;
|
||||||
LOGD("CoreAudio buffer size for output device is %u frames (%u ms)", bufferFrameSize, estimatedDelay);
|
LOGD("CoreAudio buffer size for output device is %u frames (%u ms)", bufferFrameSize, estimatedDelay);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isMacBookPro){
|
if(isMacBookPro){
|
||||||
if(AudioObjectHasProperty(outputDevice, &dataSourceProp)){
|
if(AudioObjectHasProperty(outputDevice, &dataSourceProp)){
|
||||||
UInt32 dataSource;
|
UInt32 dataSource;
|
||||||
|
|
|
@ -33,7 +33,7 @@ AudioUnitIO::AudioUnitIO(){
|
||||||
inBufferList.mBuffers[0].mData=malloc(10240);
|
inBufferList.mBuffers[0].mData=malloc(10240);
|
||||||
inBufferList.mBuffers[0].mDataByteSize=10240;
|
inBufferList.mBuffers[0].mDataByteSize=10240;
|
||||||
inBufferList.mNumberBuffers=1;
|
inBufferList.mNumberBuffers=1;
|
||||||
|
|
||||||
OSStatus status;
|
OSStatus status;
|
||||||
AudioComponentDescription desc;
|
AudioComponentDescription desc;
|
||||||
AudioComponent inputComponent;
|
AudioComponent inputComponent;
|
||||||
|
@ -44,7 +44,7 @@ AudioUnitIO::AudioUnitIO(){
|
||||||
desc.componentManufacturer = kAudioUnitManufacturer_Apple;
|
desc.componentManufacturer = kAudioUnitManufacturer_Apple;
|
||||||
inputComponent = AudioComponentFindNext(NULL, &desc);
|
inputComponent = AudioComponentFindNext(NULL, &desc);
|
||||||
status = AudioComponentInstanceNew(inputComponent, &unit);
|
status = AudioComponentInstanceNew(inputComponent, &unit);
|
||||||
|
|
||||||
UInt32 flag=1;
|
UInt32 flag=1;
|
||||||
#if TARGET_OS_IPHONE
|
#if TARGET_OS_IPHONE
|
||||||
status = AudioUnitSetProperty(unit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Output, kOutputBus, &flag, sizeof(flag));
|
status = AudioUnitSetProperty(unit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Output, kOutputBus, &flag, sizeof(flag));
|
||||||
|
@ -52,7 +52,7 @@ AudioUnitIO::AudioUnitIO(){
|
||||||
status = AudioUnitSetProperty(unit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, kInputBus, &flag, sizeof(flag));
|
status = AudioUnitSetProperty(unit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, kInputBus, &flag, sizeof(flag));
|
||||||
CHECK_AU_ERROR(status, "Error enabling AudioUnit input");
|
CHECK_AU_ERROR(status, "Error enabling AudioUnit input");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if TARGET_OS_IPHONE
|
#if TARGET_OS_IPHONE
|
||||||
flag=ServerConfig::GetSharedInstance()->GetBoolean("use_ios_vpio_agc", true) ? 1 : 0;
|
flag=ServerConfig::GetSharedInstance()->GetBoolean("use_ios_vpio_agc", true) ? 1 : 0;
|
||||||
#else
|
#else
|
||||||
|
@ -60,7 +60,7 @@ AudioUnitIO::AudioUnitIO(){
|
||||||
#endif
|
#endif
|
||||||
status=AudioUnitSetProperty(unit, kAUVoiceIOProperty_VoiceProcessingEnableAGC, kAudioUnitScope_Global, kInputBus, &flag, sizeof(flag));
|
status=AudioUnitSetProperty(unit, kAUVoiceIOProperty_VoiceProcessingEnableAGC, kAudioUnitScope_Global, kInputBus, &flag, sizeof(flag));
|
||||||
CHECK_AU_ERROR(status, "Error disabling AGC");
|
CHECK_AU_ERROR(status, "Error disabling AGC");
|
||||||
|
|
||||||
AudioStreamBasicDescription audioFormat;
|
AudioStreamBasicDescription audioFormat;
|
||||||
audioFormat.mSampleRate = 48000;
|
audioFormat.mSampleRate = 48000;
|
||||||
audioFormat.mFormatID = kAudioFormatLinearPCM;
|
audioFormat.mFormatID = kAudioFormatLinearPCM;
|
||||||
|
@ -77,28 +77,28 @@ AudioUnitIO::AudioUnitIO(){
|
||||||
#endif
|
#endif
|
||||||
audioFormat.mFramesPerPacket = 1;
|
audioFormat.mFramesPerPacket = 1;
|
||||||
audioFormat.mChannelsPerFrame = 1;
|
audioFormat.mChannelsPerFrame = 1;
|
||||||
|
|
||||||
status = AudioUnitSetProperty(unit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, kOutputBus, &audioFormat, sizeof(audioFormat));
|
status = AudioUnitSetProperty(unit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, kOutputBus, &audioFormat, sizeof(audioFormat));
|
||||||
CHECK_AU_ERROR(status, "Error setting output format");
|
CHECK_AU_ERROR(status, "Error setting output format");
|
||||||
status = AudioUnitSetProperty(unit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, kInputBus, &audioFormat, sizeof(audioFormat));
|
status = AudioUnitSetProperty(unit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, kInputBus, &audioFormat, sizeof(audioFormat));
|
||||||
CHECK_AU_ERROR(status, "Error setting input format");
|
CHECK_AU_ERROR(status, "Error setting input format");
|
||||||
|
|
||||||
AURenderCallbackStruct callbackStruct;
|
AURenderCallbackStruct callbackStruct;
|
||||||
|
|
||||||
callbackStruct.inputProc = AudioUnitIO::BufferCallback;
|
callbackStruct.inputProc = AudioUnitIO::BufferCallback;
|
||||||
callbackStruct.inputProcRefCon = this;
|
callbackStruct.inputProcRefCon = this;
|
||||||
status = AudioUnitSetProperty(unit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Global, kOutputBus, &callbackStruct, sizeof(callbackStruct));
|
status = AudioUnitSetProperty(unit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Global, kOutputBus, &callbackStruct, sizeof(callbackStruct));
|
||||||
CHECK_AU_ERROR(status, "Error setting output buffer callback");
|
CHECK_AU_ERROR(status, "Error setting output buffer callback");
|
||||||
status = AudioUnitSetProperty(unit, kAudioOutputUnitProperty_SetInputCallback, kAudioUnitScope_Global, kInputBus, &callbackStruct, sizeof(callbackStruct));
|
status = AudioUnitSetProperty(unit, kAudioOutputUnitProperty_SetInputCallback, kAudioUnitScope_Global, kInputBus, &callbackStruct, sizeof(callbackStruct));
|
||||||
CHECK_AU_ERROR(status, "Error setting input buffer callback");
|
CHECK_AU_ERROR(status, "Error setting input buffer callback");
|
||||||
|
|
||||||
#if TARGET_OS_OSX
|
#if TARGET_OS_OSX
|
||||||
CFRunLoopRef theRunLoop = NULL;
|
CFRunLoopRef theRunLoop = NULL;
|
||||||
AudioObjectPropertyAddress propertyAddress = { kAudioHardwarePropertyRunLoop,
|
AudioObjectPropertyAddress propertyAddress = { kAudioHardwarePropertyRunLoop,
|
||||||
kAudioObjectPropertyScopeGlobal,
|
kAudioObjectPropertyScopeGlobal,
|
||||||
kAudioObjectPropertyElementMaster };
|
kAudioObjectPropertyElementMaster };
|
||||||
status = AudioObjectSetPropertyData(kAudioObjectSystemObject, &propertyAddress, 0, NULL, sizeof(CFRunLoopRef), &theRunLoop);
|
status = AudioObjectSetPropertyData(kAudioObjectSystemObject, &propertyAddress, 0, NULL, sizeof(CFRunLoopRef), &theRunLoop);
|
||||||
|
|
||||||
propertyAddress.mSelector = kAudioHardwarePropertyDefaultOutputDevice;
|
propertyAddress.mSelector = kAudioHardwarePropertyDefaultOutputDevice;
|
||||||
propertyAddress.mScope = kAudioObjectPropertyScopeGlobal;
|
propertyAddress.mScope = kAudioObjectPropertyScopeGlobal;
|
||||||
propertyAddress.mElement = kAudioObjectPropertyElementMaster;
|
propertyAddress.mElement = kAudioObjectPropertyElementMaster;
|
||||||
|
@ -143,7 +143,7 @@ void AudioUnitIO::Release(){
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioUnitIO::Configure(uint32_t sampleRate, uint32_t bitsPerSample, uint32_t channels){
|
void AudioUnitIO::Configure(uint32_t sampleRate, uint32_t bitsPerSample, uint32_t channels){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
OSStatus AudioUnitIO::BufferCallback(void *inRefCon, AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList *ioData){
|
OSStatus AudioUnitIO::BufferCallback(void *inRefCon, AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList *ioData){
|
||||||
|
@ -236,9 +236,9 @@ void AudioUnitIO::SetCurrentDevice(bool input, std::string deviceID){
|
||||||
AudioUnitUninitialize(unit);
|
AudioUnitUninitialize(unit);
|
||||||
}
|
}
|
||||||
UInt32 size=sizeof(AudioDeviceID);
|
UInt32 size=sizeof(AudioDeviceID);
|
||||||
AudioDeviceID device=NULL;
|
AudioDeviceID device=0;
|
||||||
OSStatus status;
|
OSStatus status;
|
||||||
|
|
||||||
if(deviceID=="default"){
|
if(deviceID=="default"){
|
||||||
AudioObjectPropertyAddress propertyAddress;
|
AudioObjectPropertyAddress propertyAddress;
|
||||||
propertyAddress.mSelector = input ? kAudioHardwarePropertyDefaultInputDevice : kAudioHardwarePropertyDefaultOutputDevice;
|
propertyAddress.mSelector = input ? kAudioHardwarePropertyDefaultInputDevice : kAudioHardwarePropertyDefaultOutputDevice;
|
||||||
|
@ -281,7 +281,7 @@ void AudioUnitIO::SetCurrentDevice(bool input, std::string deviceID){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
status=AudioUnitSetProperty(unit,
|
status=AudioUnitSetProperty(unit,
|
||||||
kAudioOutputUnitProperty_CurrentDevice,
|
kAudioOutputUnitProperty_CurrentDevice,
|
||||||
kAudioUnitScope_Global,
|
kAudioUnitScope_Global,
|
||||||
|
@ -289,13 +289,13 @@ void AudioUnitIO::SetCurrentDevice(bool input, std::string deviceID){
|
||||||
&device,
|
&device,
|
||||||
size);
|
size);
|
||||||
CHECK_AU_ERROR(status, "Error setting input device");
|
CHECK_AU_ERROR(status, "Error setting input device");
|
||||||
|
|
||||||
if(input)
|
if(input)
|
||||||
currentInputDevice=deviceID;
|
currentInputDevice=deviceID;
|
||||||
else
|
else
|
||||||
currentOutputDevice=deviceID;
|
currentOutputDevice=deviceID;
|
||||||
|
|
||||||
|
|
||||||
/*AudioObjectPropertyAddress propertyAddress = {
|
/*AudioObjectPropertyAddress propertyAddress = {
|
||||||
kAudioDevicePropertyBufferFrameSize,
|
kAudioDevicePropertyBufferFrameSize,
|
||||||
kAudioObjectPropertyScopeGlobal,
|
kAudioObjectPropertyScopeGlobal,
|
||||||
|
|
Loading…
Reference in New Issue