Skip to content

Commit

Permalink
Flag to override output to iphone speaker
Browse files Browse the repository at this point in the history
  • Loading branch information
ndonald2 committed Jun 12, 2013
1 parent 5d46854 commit 465b7b2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 89 deletions.
8 changes: 6 additions & 2 deletions Novocaine/Novocaine.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -101,8 +101,12 @@ typedef void (^NovocaineInputBlock)(float *data, UInt32 numFrames, UInt32 numCha


// ------ These properties/methods are used for configuration ------- // ------ These properties/methods are used for configuration -------


@property (nonatomic, copy) NSString *inputRoute; @property (nonatomic, copy) NSString *inputRoute;
@property (nonatomic, assign) BOOL inputEnabled; @property (nonatomic, assign) BOOL inputEnabled;

#ifdef USING_IOS
@property (nonatomic, assign) BOOL forceOutputToSpeaker;
#endif


// ND: Exposing the block setters this way will create the correct block signature for auto-complete. // ND: Exposing the block setters this way will create the correct block signature for auto-complete.
// These will map to "copy" property setters in class continuation in source file // These will map to "copy" property setters in class continuation in source file
Expand Down
114 changes: 27 additions & 87 deletions Novocaine/Novocaine.m
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ - (id)init


// Fire up the audio session ( with steady error checking ... ) // Fire up the audio session ( with steady error checking ... )
[self setupAudioSession]; [self setupAudioSession];

// start audio units
[self setupAudioUnits];


return self; return self;


Expand Down Expand Up @@ -179,111 +182,48 @@ - (void)freeBuffers


- (void)setInputEnabled:(BOOL)inputEnabled - (void)setInputEnabled:(BOOL)inputEnabled
{ {
if (inputEnabled != _inputEnabled){

_inputEnabled = inputEnabled;
if (inputEnabled){ }

if (self.inputAvailable) {

// Enable input
UInt32 one = 1;
OSStatus err = AudioUnitSetProperty(_inputUnit,
kAudioOutputUnitProperty_EnableIO,
kAudioUnitScope_Input,
kInputBus,
&one,
sizeof(one));

if (err){

}
else{
_inputEnabled = YES;
}
}

// If we don't have input, then ask the user to provide some
else
{

// TODO: Not sure a
#if defined ( USING_IOS )
UIAlertView *noInputAlert =
[[UIAlertView alloc] initWithTitle:@"No Audio Input"
message:@"Couldn't find any audio input. Plug in your Apple headphones or another microphone."
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];

[noInputAlert show];
#endif

}
}
else
{
// Disable input
UInt32 zero = 0;
OSStatus err = AudioUnitSetProperty(_inputUnit,
kAudioOutputUnitProperty_EnableIO,
kAudioUnitScope_Input,
kInputBus,
&zero,
sizeof(zero));

if (err){

}
else{
_inputEnabled = NO;
}
}


#ifdef USING_IOS
- (void)setForceOutputToSpeaker:(BOOL)forceOutputToSpeaker
{
UInt32 value = forceOutputToSpeaker ? 1 : 0;

#if !TARGET_IPHONE_SIMULATOR
// should not be fatal error
OSStatus err = AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryDefaultToSpeaker, sizeof(UInt32), &value);
if (err != noErr){
NSLog(@"Could not override audio output route to speaker");
}
else{
_forceOutputToSpeaker = forceOutputToSpeaker;
} }
#else
_forceOutputToSpeaker = forceOutputToSpeaker;
#endif
} }

#endif


#pragma mark - Audio Methods #pragma mark - Audio Methods




- (void)setupAudioSession - (void)setupAudioSession
{ {

// Initialize and configure the audio session, and add an interuption listener // Initialize and configure the audio session, and add an interuption listener


#if defined ( USING_IOS ) #if defined ( USING_IOS )
CheckError( AudioSessionInitialize(NULL, NULL, sessionInterruptionListener, (__bridge void *)(self)), "Couldn't initialize audio session"); NSError *err = nil;
if (![[AVAudioSession sharedInstance] setActive:YES error:&err]){
NSLog(@"Could not activate audio session: %@", err);
}
[self checkAudioSource]; [self checkAudioSource];
#elif defined ( USING_OSX ) #elif defined ( USING_OSX )
// TODO: grab the audio device // TODO: grab the audio device
[self enumerateAudioDevices]; [self enumerateAudioDevices];
self.inputAvailable = YES; self.inputAvailable = YES;
#endif #endif


// Check the session properties (available input routes, number of channels, etc)

// If we do have input, then let's rock 'n roll.
// if (self.inputAvailable) {
// [self setupAudio];
// [self play];
// }
//
// // If we don't have input, then ask the user to provide some
// else
// {
//#if defined ( USING_IOS )
// UIAlertView *noInputAlert =
// [[UIAlertView alloc] initWithTitle:@"No Audio Input"
// message:@"Couldn't find any audio input. Plug in your Apple headphones or another microphone."
// delegate:self
// cancelButtonTitle:@"OK"
// otherButtonTitles:nil];
//
// [noInputAlert show];
//#endif
//
// }
} }




Expand Down

0 comments on commit 465b7b2

Please sign in to comment.