Commits

Anonymous committed d999a17

Fixed bug where audio device was set after the format.

Comments (0)

Files changed (1)

Audio/Output/OutputCoreAudio.m

 	
 	ioData->mBuffers[0].mDataByteSize = amountRead;
 	ioData->mBuffers[0].mNumberChannels = output->deviceFormat.mChannelsPerFrame;
- 
-	//NSLog(@"Amount read for output: (%i) %i %i/%i", ioData->mNumberBuffers, ioData->mBuffers[0].mNumberChannels, amountRead, amountToRead);
+	ioData->mNumberBuffers = 1;
 	
 	return err;
 }
 	OSStatus err;
 	
 	if (outputDevice == -1) {
+		NSLog(@"DEVICE IS -1");
 		UInt32 size = sizeof(AudioDeviceID);
 		err = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultOutputDevice,
 									  &size,
 		}
 	}
 
+	printf("DEVICE: %i\n", deviceID);
 	
 	err = AudioUnitSetProperty(outputUnit,
 							  kAudioOutputUnitProperty_CurrentDevice, 
-							  kAudioUnitScope_Global, 
+							  kAudioUnitScope_Output, 
 							  0, 
 							  &deviceID, 
 							  sizeof(AudioDeviceID));
 	err = AudioUnitInitialize(outputUnit);
 	if (err != noErr)
 		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);
 	Boolean outWritable;
 
 	[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);	
 }