Skip to content

Commit

Permalink
Added getter for AudioStreamBasicDescription for EZOutput and made EZ…
Browse files Browse the repository at this point in the history
…Recorder erase file if it already exists
  • Loading branch information
syedhali committed Mar 15, 2014
1 parent 7eac04b commit a957fed
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 43 deletions.
10 changes: 10 additions & 0 deletions EZAudio/EZOutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,16 @@ inNumberFrames:(UInt32)inNumberFrames
-(void)stopPlayback;

#pragma mark - Getters
///-----------------------------------------------------------
/// @name Getting The Output Audio Format
///-----------------------------------------------------------

/**
Provides the AudioStreamBasicDescription structure containing the format of the microphone's audio.
@return An AudioStreamBasicDescription structure describing the format of the microphone's audio.
*/
-(AudioStreamBasicDescription)audioStreamBasicDescription;

///-----------------------------------------------------------
/// @name Getting The State Of The Output
///-----------------------------------------------------------
Expand Down
32 changes: 20 additions & 12 deletions EZAudio/EZOutput.m
Original file line number Diff line number Diff line change
Expand Up @@ -342,26 +342,34 @@ -(void)stopPlayback {
}

#pragma mark - Getters
-(AudioStreamBasicDescription)audioStreamBasicDescription {
return _outputASBD;
}

-(BOOL)isPlaying {
return _isPlaying;
}

#pragma mark - Setters
-(void)setAudioStreamBasicDescription:(AudioStreamBasicDescription)asbd {
BOOL wasPlaying = NO;
if( self.isPlaying ){
NSAssert(self.isPlaying,@"Cannot set the AudioStreamBasicDescription while output is performing playback");
[self stopPlayback];
wasPlaying = YES;
}
else {
_customASBD = YES;
_outputASBD = asbd;
// Set the format for output
[EZAudio checkResult:AudioUnitSetProperty(_outputUnit,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Input,
0,
&_outputASBD,
sizeof(_outputASBD))
operation:"Couldn't set the ASBD for input scope/bos 0"];
_customASBD = YES;
_outputASBD = asbd;
// Set the format for output
[EZAudio checkResult:AudioUnitSetProperty(_outputUnit,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Input,
0,
&_outputASBD,
sizeof(_outputASBD))
operation:"Couldn't set the ASBD for input scope/bos 0"];
if( wasPlaying )
{
[self startPlayback];
}
}

Expand Down
62 changes: 31 additions & 31 deletions EZAudio/EZRecorder.m
Original file line number Diff line number Diff line change
Expand Up @@ -90,40 +90,40 @@ -(void)_configureRecorderForNewFile {

-(void)_configureRecorder {

// Create the extended audio file
OSStatus result = ExtAudioFileCreateWithURL(_destinationFileURL,
kAudioFileCAFType,
&_destinationFormat,
NULL,
0,
&_destinationFile);
// [EZAudio checkResult:ExtAudioFileCreateWithURL(_destinationFileURL,
// // Create the extended audio file
// OSStatus result = ExtAudioFileCreateWithURL(_destinationFileURL,
// kAudioFileCAFType,
// &_destinationFormat,
// NULL,
// kAudioFileFlags_EraseFile,
// &_destinationFile)
// operation:"Could not open audio file"];

if( result != noErr )
{

// Open the existing audio file for writing
AudioFileID audioFileID;

[EZAudio checkResult:AudioFileOpenURL(_destinationFileURL,
kAudioFileWritePermission|kAudioFileReadPermission,
kAudioFileCAFType,
&audioFileID)
operation:"Failed to open existing audio file"];

// Wrap the audio file with an extended audio file reference
[EZAudio checkResult:ExtAudioFileWrapAudioFileID(audioFileID,
true,
&_destinationFile)
operation:"Failed to wrap audio file reference with extended audio file"];

}
// 0,
// &_destinationFile);
[EZAudio checkResult:ExtAudioFileCreateWithURL(_destinationFileURL,
kAudioFileCAFType,
&_destinationFormat,
NULL,
kAudioFileFlags_EraseFile,
&_destinationFile)
operation:"Could not open audio file"];

// if( result != noErr )
// {
//
// // Open the existing audio file for writing
// AudioFileID audioFileID;
//
// [EZAudio checkResult:AudioFileOpenURL(_destinationFileURL,
// kAudioFileWritePermission|kAudioFileReadPermission,
// kAudioFileCAFType,
// &audioFileID)
// operation:"Failed to open existing audio file"];
//
// // Wrap the audio file with an extended audio file reference
// [EZAudio checkResult:ExtAudioFileWrapAudioFileID(audioFileID,
// true,
// &_destinationFile)
// operation:"Failed to wrap audio file reference with extended audio file"];
//
// }

// Set the client format
_clientFormat = _destinationFormat;
Expand Down

0 comments on commit a957fed

Please sign in to comment.