Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Channel Mapping #233

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions EZAudio/EZOutput.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,16 @@ FOUNDATION_EXPORT Float64 const EZOutputDefaultSampleRate;
*/
@property (nonatomic, strong, readwrite) EZAudioDevice *device;


///-----------------------------------------------------------
/// @name Getting/Setting The Output's Channel Mapping
///-----------------------------------------------------------

/**
The receiver’s audio-channel–to–device–channel mappings.
*/
@property (nonatomic, strong, readwrite) NSArray *channelMapping;

//------------------------------------------------------------------------------
#pragma mark - Actions
//------------------------------------------------------------------------------
Expand Down
60 changes: 60 additions & 0 deletions EZAudio/EZOutput.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ - (void)setDevice:(EZAudioDevice *)device
&deviceId,
sizeof(AudioDeviceID))
operation:"Couldn't set default device on I/O unit"];

#endif

// store device
Expand All @@ -551,6 +552,65 @@ - (void)setDevice:(EZAudioDevice *)device

//------------------------------------------------------------------------------

- (void)setChannelMapping:(NSArray *)channelMapping {

#if TARGET_OS_MAC

if (channelMapping && _device) {

//
// Channel mapping
//

NSInteger channelCount = _device.outputChannelCount;

if ([channelMapping count]<= channelCount) {



// create the C array which will contain the channel mapping table
UInt32 channelMap[channelCount];

// first of all clear the current mapping table
for (NSInteger i=0;i<_device.outputChannelCount;i++) {

channelMap[i] = -1;

}

// set the new values
for (int i=0;i<[channelMapping count];i++) {

channelMap[[[channelMapping objectAtIndex:i] unsignedIntValue]] = i;

}

UInt32 propertySize = (int)channelCount*sizeof(UInt32);

[EZAudioUtilities checkResult:AudioUnitSetProperty(self.info->outputNodeInfo.audioUnit,
kAudioOutputUnitProperty_ChannelMap,
kAudioUnitScope_Global,
0,
&channelMap,
propertySize)
operation:"Couldn't set channel mapping"];


// store channel mapping
_channelMapping = channelMapping;

}


}


#endif

}

//------------------------------------------------------------------------------

- (void)setInputFormat:(AudioStreamBasicDescription)inputFormat
{
self.info->inputFormat = inputFormat;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@
*/
@property (nonatomic, weak) IBOutlet NSPopUpButton *outputDevicePopUpButton;

/**
The microphone pop up button (contains the menu for choosing a microphone input)
*/
@property (nonatomic, weak) IBOutlet NSPopUpButton *outputChannelMappingPopUpButton;

#pragma mark - Actions
/**
Switches the plot drawing type between a buffer plot (visualizes the current stream of audio data from the update function) or a rolling plot (visualizes the audio data over time, this is the classic waveform look)
Expand Down
42 changes: 41 additions & 1 deletion EZAudioExamples/OSX/EZAudioPlayFileExample/EZAudioPlayFileExample/PlayFileViewController.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ - (void)awakeFromNib
// Reload the menu for the output device selector popup button
//
[self reloadOutputDevicePopUpButtonMenu];
[self reloadOutputChannelMappingPopUpButtonMenu];

//
// Configure UI components
Expand All @@ -89,7 +90,8 @@ - (void)awakeFromNib
//
// Try opening the sample file
//
[self openFileWithFilePathURL:[NSURL fileURLWithPath:kAudioFileDefault]];
// [self openFileWithFilePathURL:[NSURL fileURLWithPath:kAudioFileDefault]];
[self openFileWithFilePathURL:[NSURL fileURLWithPath:@"/Users/tamasnagy/Desktop/asztal/testloops/Mitti Test Loops/Hebopula Hap HD.mov"]];
}

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -158,10 +160,23 @@ - (void)changedOutput:(NSMenuItem *)item
{
EZAudioDevice *device = [item representedObject];
[self.player setDevice:device];

[self reloadOutputChannelMappingPopUpButtonMenu];
}

//------------------------------------------------------------------------------

- (void)changedChannelMapping:(NSMenuItem *)item
{

NSArray *mapping = [item representedObject];
[self.player.output setChannelMapping:mapping];

}

//------------------------------------------------------------------------------


- (void)changePlotType:(id)sender
{
NSInteger selectedSegment = [sender selectedSegment];
Expand Down Expand Up @@ -368,6 +383,31 @@ - (void)reloadOutputDevicePopUpButtonMenu
[self.outputDevicePopUpButton selectItem:defaultOutputDeviceItem];
}

- (void)reloadOutputChannelMappingPopUpButtonMenu {

[[self outputChannelMappingPopUpButton] removeAllItems];

NSInteger outputchannels = [[self.player device] outputChannelCount];

NSMenu *menu = [[NSMenu alloc] init];

for (NSInteger i=0;i<outputchannels;i+=2) {

NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@"%ld & %ld", i+1, i+2]
action:@selector(changedChannelMapping:)
keyEquivalent:@""];

item.representedObject = [NSArray arrayWithObjects:[NSNumber numberWithInteger:i],[NSNumber numberWithInteger:i+1], nil];
item.target = self;
[menu addItem:item];
}


self.outputChannelMappingPopUpButton.menu = menu;
[self.outputChannelMappingPopUpButton selectItem:[[menu itemArray] firstObject]];

}

//------------------------------------------------------------------------------
#pragma mark - EZAudioPlayerDelegate
//------------------------------------------------------------------------------
Expand Down
Loading