Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adds preliminary support for audio output device selection per issue #…

…546. The cog menu in the HUD controls bar now contains a Select Audio Output Device submenu. There’s still no preference and the menu doesn’t show the audio device that’s being used for output, but it should be functional.
  • Loading branch information...
commit e4e06b0201fc3103eebbaac354fec526d0b41b2c 1 parent 5fb667a
@bavarious bavarious authored
View
1  OpenEmu/OEGameAudio.h
@@ -42,6 +42,7 @@
}
@property float volume;
+@property AudioDeviceID outputDeviceID;
- (id)initWithCore:(OEGameCore *)core;
View
24 OpenEmu/OEGameAudio.m
@@ -107,6 +107,7 @@ OSStatus RenderCallback(void *in,
@interface OEGameAudio ()
{
OEGameAudioContext *_contexts;
+ NSNumber *_outputDeviceID; // nil if no output device has been set (use default)
}
@end
@@ -258,7 +259,11 @@ - (void)createGraph
//AudioUnitSetParameter(mOutputUnit, kAudioUnitParameterUnit_LinearGain, kAudioUnitScope_Global, 0, [[[GameDocumentController sharedDocumentController] preferenceController] volume] ,0);
AudioUnitSetParameter(mOutputUnit, kAudioUnitParameterUnit_LinearGain, kAudioUnitScope_Global, 0, 1.0 ,0);
-
+
+ AudioDeviceID outputDeviceID = [_outputDeviceID unsignedIntValue];
+ if(outputDeviceID != 0)
+ AudioUnitSetProperty(mOutputUnit, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, 0, &outputDeviceID, sizeof(outputDeviceID));
+
err = AUGraphInitialize(mGraph);
if(err) NSLog(@"couldn't initialize graph");
@@ -269,6 +274,23 @@ - (void)createGraph
[self setVolume:[self volume]];
}
+- (AudioDeviceID)outputDeviceID
+{
+ return [_outputDeviceID unsignedIntValue];
+}
+
+- (void)setOutputDeviceID:(AudioDeviceID)outputDeviceID
+{
+ AudioDeviceID currentID = [self outputDeviceID];
+ if(outputDeviceID != currentID)
+ {
+ _outputDeviceID = (outputDeviceID == 0 ? nil : @(outputDeviceID));
+
+ if(mOutputUnit)
+ AudioUnitSetProperty(mOutputUnit, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, 0, &outputDeviceID, sizeof(outputDeviceID));
+ }
+}
+
- (float)volume
{
return volume;
View
23 OpenEmu/OEGameControlsBar.m
@@ -44,6 +44,7 @@
#import "OEDBSaveState.h"
#import "OEGameIntegralScalingDelegate.h"
+#import "OEAudioDeviceManager.h"
#import "OECheats.h"
@@ -365,6 +366,28 @@ - (void)showOptionsMenu:(id)sender
else
[item setEnabled:NO];
+ // Setup audio output
+ NSMenu *audioOutputMenu = [NSMenu new];
+ [audioOutputMenu setTitle:NSLocalizedString(@"Select Audio Output Device", @"")];
+ item = [NSMenuItem new];
+ [item setTitle:[audioOutputMenu title]];
+ [menu addItem:item];
+ [item setSubmenu:audioOutputMenu];
+
+ NSPredicate *outputPredicate = [NSPredicate predicateWithBlock:^BOOL(OEAudioDevice *device, NSDictionary *bindings) {
+ return [device numberOfOutputChannels] > 0;
+ }];
+ NSArray *audioOutputDevices = [[[OEAudioDeviceManager sharedAudioDeviceManager] audioDevices] filteredArrayUsingPredicate:outputPredicate];
+ if([audioOutputDevices count] == 0)
+ [item setEnabled:NO];
+ else
+ for(OEAudioDevice *device in audioOutputDevices)
+ {
+ NSMenuItem *deviceItem = [[NSMenuItem alloc] initWithTitle:[device deviceName] action:@selector(changeAudioOutputDevice:) keyEquivalent:@""];
+ [deviceItem setRepresentedObject:device];
+ [audioOutputMenu addItem:deviceItem];
+ }
+
// Create OEMenu and display it
[menu setDelegate:self];
View
2  OpenEmu/OEGameCoreHelper.h
@@ -27,6 +27,7 @@
#import <Cocoa/Cocoa.h>
+#import <CoreAudio/CoreAudio.h>
#import "OEGameCore.h"
@class OEGameCoreController;
@@ -46,6 +47,7 @@
- (oneway void)volumeUp;
- (oneway void)volumeDown;
- (oneway void)setPauseEmulation:(BOOL)flag;
+- (oneway void)setAudioOutputDeviceID:(AudioDeviceID)deviceID;
// gamecore attributes
@property(readonly) OEIntSize screenSize;
View
19 OpenEmu/OEGameViewController.m
@@ -48,6 +48,7 @@
#import "OEGameCore.h"
#import "OEGameDocument.h"
+#import "OEAudioDeviceManager.h"
#import "OEHUDAlert+DefaultAlertsAdditions.h"
@@ -620,6 +621,24 @@ - (void)selectFilter:(id)sender
[[NSUserDefaults standardUserDefaults] setObject:filterName forKey:[NSString stringWithFormat:OEGameSystemVideoFilterKeyFormat, [self systemIdentifier]]];
}
+- (void)changeAudioOutputDevice:(id)sender
+{
+ OEAudioDevice *device = nil;
+
+ if([sender isKindOfClass:[OEAudioDevice class]])
+ device = sender;
+ else if ([sender respondsToSelector:@selector(representedObject)] && [[sender representedObject] isKindOfClass:[OEAudioDevice class]])
+ device = [sender representedObject];
+
+ if(!device)
+ {
+ DLog(@"Invalid argument: %@", sender);
+ return;
+ }
+
+ [rootProxy setAudioOutputDeviceID:[device deviceID]];
+}
+
#pragma mark - Volume
- (void)setVolume:(float)volume asDefault:(BOOL)defaultFlag
View
8 OpenEmu/OpenEmuHelperApp.m
@@ -877,6 +877,14 @@ - (void)didRenderFrameOnAlternateThread
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, tempFBO);
}
+#pragma mark - Audio
+
+- (oneway void)setAudioOutputDeviceID:(AudioDeviceID)deviceID
+{
+ NSLog(@"---------- will set output device id to %lu", (unsigned long)deviceID);
+ [gameAudio setOutputDeviceID:deviceID];
+}
+
#pragma mark - OEAudioDelegate
- (void)audioSampleRateDidChange
Please sign in to comment.
Something went wrong with that request. Please try again.