Fixed bug where audio device was set after the format.
parent
5422a1cddd
commit
170c8cb2f3
|
@ -53,8 +53,7 @@ static OSStatus Sound_Renderer(void *inRefCon, AudioUnitRenderActionFlags *ioAc
|
||||||
|
|
||||||
ioData->mBuffers[0].mDataByteSize = amountRead;
|
ioData->mBuffers[0].mDataByteSize = amountRead;
|
||||||
ioData->mBuffers[0].mNumberChannels = output->deviceFormat.mChannelsPerFrame;
|
ioData->mBuffers[0].mNumberChannels = output->deviceFormat.mChannelsPerFrame;
|
||||||
|
ioData->mNumberBuffers = 1;
|
||||||
//NSLog(@"Amount read for output: (%i) %i %i/%i", ioData->mNumberBuffers, ioData->mBuffers[0].mNumberChannels, amountRead, amountToRead);
|
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -80,6 +79,7 @@ static OSStatus Sound_Renderer(void *inRefCon, AudioUnitRenderActionFlags *ioAc
|
||||||
OSStatus err;
|
OSStatus err;
|
||||||
|
|
||||||
if (outputDevice == -1) {
|
if (outputDevice == -1) {
|
||||||
|
NSLog(@"DEVICE IS -1");
|
||||||
UInt32 size = sizeof(AudioDeviceID);
|
UInt32 size = sizeof(AudioDeviceID);
|
||||||
err = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultOutputDevice,
|
err = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultOutputDevice,
|
||||||
&size,
|
&size,
|
||||||
|
@ -92,10 +92,11 @@ static OSStatus Sound_Renderer(void *inRefCon, AudioUnitRenderActionFlags *ioAc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printf("DEVICE: %i\n", deviceID);
|
||||||
|
|
||||||
err = AudioUnitSetProperty(outputUnit,
|
err = AudioUnitSetProperty(outputUnit,
|
||||||
kAudioOutputUnitProperty_CurrentDevice,
|
kAudioOutputUnitProperty_CurrentDevice,
|
||||||
kAudioUnitScope_Global,
|
kAudioUnitScope_Output,
|
||||||
0,
|
0,
|
||||||
&deviceID,
|
&deviceID,
|
||||||
sizeof(AudioDeviceID));
|
sizeof(AudioDeviceID));
|
||||||
|
@ -136,6 +137,21 @@ static OSStatus Sound_Renderer(void *inRefCon, AudioUnitRenderActionFlags *ioAc
|
||||||
if (err != noErr)
|
if (err != noErr)
|
||||||
return NO;
|
return NO;
|
||||||
|
|
||||||
|
// Setup the output device before mucking with settings
|
||||||
|
NSDictionary *device = [[[NSUserDefaultsController sharedUserDefaultsController] defaults] objectForKey:@"outputDevice"];
|
||||||
|
if (device) {
|
||||||
|
BOOL ok = [self setOutputDevice:[[device objectForKey:@"deviceID"] longValue]];
|
||||||
|
if (!ok) {
|
||||||
|
//Ruh roh.
|
||||||
|
[self setOutputDevice: -1];
|
||||||
|
|
||||||
|
[[[NSUserDefaultsController sharedUserDefaultsController] defaults] removeObjectForKey:@"outputDevice"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
[self setOutputDevice: -1];
|
||||||
|
}
|
||||||
|
|
||||||
UInt32 size = sizeof (AudioStreamBasicDescription);
|
UInt32 size = sizeof (AudioStreamBasicDescription);
|
||||||
Boolean outWritable;
|
Boolean outWritable;
|
||||||
//Gets the size of the Stream Format Property and if it is writable
|
//Gets the size of the Stream Format Property and if it is writable
|
||||||
|
@ -187,21 +203,6 @@ static OSStatus Sound_Renderer(void *inRefCon, AudioUnitRenderActionFlags *ioAc
|
||||||
|
|
||||||
[outputController setFormat:&deviceFormat];
|
[outputController setFormat:&deviceFormat];
|
||||||
|
|
||||||
NSDictionary *device = [[[NSUserDefaultsController sharedUserDefaultsController] defaults] objectForKey:@"outputDevice"];
|
|
||||||
|
|
||||||
if (device) {
|
|
||||||
BOOL ok = [self setOutputDevice:[[device objectForKey:@"deviceID"] longValue]];
|
|
||||||
if (!ok) {
|
|
||||||
//Ruh roh.
|
|
||||||
[self setOutputDevice: -1];
|
|
||||||
|
|
||||||
[[[NSUserDefaultsController sharedUserDefaultsController] defaults] removeObjectForKey:@"outputDevice"];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
[self setOutputDevice: -1];
|
|
||||||
}
|
|
||||||
|
|
||||||
return (err == noErr);
|
return (err == noErr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue