Skip to content

Commit

Permalink
Merge pull request #182 from syedhali/recorder_rewriter
Browse files Browse the repository at this point in the history
Rewrote EZRecorder
  • Loading branch information
syedhali committed Jul 4, 2015
2 parents dcaadd4 + cf9dafc commit 9516768
Show file tree
Hide file tree
Showing 24 changed files with 1,816 additions and 674 deletions.
20 changes: 16 additions & 4 deletions EZAudio/EZAudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,34 @@

#import <Foundation/Foundation.h>

//------------------------------------------------------------------------------
#pragma mark - Core Components
//------------------------------------------------------------------------------

#import "EZAudioDevice.h"
#import "EZAudioFile.h"
#import "EZAudioFloatData.h"
#import "EZMicrophone.h"
#import "EZOutput.h"
#import "EZRecorder.h"
#import "EZAudioUtilities.h"

#pragma mark - Extended Components
#import "EZAudioPlayer.h"

//------------------------------------------------------------------------------
#pragma mark - Interface Components
//------------------------------------------------------------------------------

#import "EZPlot.h"
#import "EZAudioDisplayLink.h"
#import "EZAudioPlot.h"
#import "EZAudioPlotGL.h"

//------------------------------------------------------------------------------
#pragma mark - Utility Components
//------------------------------------------------------------------------------

#import "EZAudioFloatConverter.h"
#import "EZAudioFloatData.h"
#import "EZAudioUtilities.h"

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

/**
Expand Down
18 changes: 15 additions & 3 deletions EZAudio/EZAudioFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,23 @@ typedef void (^EZAudioWaveformDataCompletionBlock)(float **waveformData, int len

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

/**
Occurs when the audio file's internal seek position has been updated by the EZAudioFile functions `readFrames:audioBufferList:bufferSize:eof:` or `audioFile:updatedPosition:`. As of 0.8.0 this is the preferred method of listening for position updates on the audio file since a user may want the pull the currentTime, formattedCurrentTime, or the frame index from the EZAudioFile instance provided.
@param audioFile The instance of the EZAudio in which the change occured.
*/
- (void)audioFileUpdatedPosition:(EZAudioFile *)audioFile;

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

/**
Occurs when the audio file's internal seek position has been updated by the EZAudioFile functions `readFrames:audioBufferList:bufferSize:eof:` or `audioFile:updatedPosition:`.
@param audioFile The instance of the EZAudio in which the change occured
@param framePosition The new frame index as a 64-bit signed integer
@deprecated This property is deprecated starting in version 0.8.0.
@note Please use `audioFileUpdatedPosition:` property instead.
*/
- (void)audioFile:(EZAudioFile *)audioFile updatedPosition:(SInt64)framePosition;
- (void)audioFile:(EZAudioFile *)audioFile
updatedPosition:(SInt64)framePosition __attribute__((deprecated));

@end

Expand All @@ -85,6 +96,7 @@ typedef void (^EZAudioWaveformDataCompletionBlock)(float **waveformData, int len
//------------------------------------------------------------------------------
#pragma mark - Properties
//------------------------------------------------------------------------------

/**
A EZAudioFileDelegate for the audio file that is used to return events such as new seek positions within the file and the read audio data as a float array.
*/
Expand Down Expand Up @@ -232,7 +244,7 @@ typedef void (^EZAudioWaveformDataCompletionBlock)(float **waveformData, int len
*/

/**
Provides the AudioStreamBasicDescription structure used within the app. The file's format will be converted to this format and then sent back as either a float array or a `AudioBufferList` pointer. For instance, the file on disk could be a 22.5 kHz, float format, but we might have an audio processing graph that has a 44.1 kHz, signed integer format that we'd like to interact with. The client format lets us set that 44.1 kHz format on the audio file to properly read samples from it with any interpolation or format conversion that must take place done automatically within the EZAudioFile `readFrames:audioBufferList:bufferSize:eof:` method. Default is stereo, non-interleaved, 44.1 kHz.
Provides the common AudioStreamBasicDescription that will be used for in-app interaction. The file's format will be converted to this format and then sent back as either a float array or a `AudioBufferList` pointer. For instance, the file on disk could be a 22.5 kHz, float format, but we might have an audio processing graph that has a 44.1 kHz, signed integer format that we'd like to interact with. The client format lets us set that 44.1 kHz format on the audio file to properly read samples from it with any interpolation or format conversion that must take place done automatically within the EZAudioFile `readFrames:audioBufferList:bufferSize:eof:` method. Default is stereo, non-interleaved, 44.1 kHz.
@warning This must be a linear PCM format!
@return An AudioStreamBasicDescription structure describing the format of the audio file.
*/
Expand Down Expand Up @@ -299,7 +311,7 @@ typedef void (^EZAudioWaveformDataCompletionBlock)(float **waveformData, int len
@note Please use `duration` property instead.
@return The total duration of the audio file as a Float32.
*/
@property (readonly) NSTimeInterval totalDuration __attribute__((deprecated));;
@property (readonly) NSTimeInterval totalDuration __attribute__((deprecated));

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

Expand Down
35 changes: 30 additions & 5 deletions EZAudio/EZAudioFile.m
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,24 @@ - (void)readFrames:(UInt32)frames
*bufferSize = frames;
*eof = frames == 0;

// notify delegate
//
// Notify delegate
//
if ([self.delegate respondsToSelector:@selector(audioFileUpdatedPosition:)])
{
[self.delegate audioFileUpdatedPosition:self];
}

//
// Deprecated, but supported until 1.0
//
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
if ([self.delegate respondsToSelector:@selector(audioFile:updatedPosition:)])
{
[self.delegate audioFile:self updatedPosition:self.frameIndex];
[self.delegate audioFile:self updatedPosition:[self frameIndex]];
}
#pragma GCC diagnostic pop

if ([self.delegate respondsToSelector:@selector(audioFile:readAudio:withBufferSize:withNumberOfChannels:)])
{
Expand Down Expand Up @@ -351,12 +364,24 @@ - (void)seekToFrame:(SInt64)frame

pthread_mutex_unlock(&_lock);

// notify delegate
//
// Notify delegate
//
if ([self.delegate respondsToSelector:@selector(audioFileUpdatedPosition:)])
{
[self.delegate audioFileUpdatedPosition:self];
}

//
// Deprecated, but supported until 1.0
//
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
if ([self.delegate respondsToSelector:@selector(audioFile:updatedPosition:)])
{
[self.delegate audioFile:self
updatedPosition:self.frameIndex];
[self.delegate audioFile:self updatedPosition:[self frameIndex]];
}
#pragma GCC diagnostic pop
}
}

Expand Down
4 changes: 2 additions & 2 deletions EZAudio/EZAudioPlayer.m
Original file line number Diff line number Diff line change
Expand Up @@ -391,12 +391,12 @@ - (OSStatus) output:(EZOutput *)output
#pragma mark - EZAudioFileDelegate
//------------------------------------------------------------------------------

- (void)audioFile:(EZAudioFile *)audioFile updatedPosition:(SInt64)framePosition
- (void)audioFileUpdatedPosition:(EZAudioFile *)audioFile
{
if ([self.delegate respondsToSelector:@selector(audioPlayer:updatedPosition:inAudioFile:)])
{
[self.delegate audioPlayer:self
updatedPosition:framePosition
updatedPosition:[audioFile frameIndex]
inAudioFile:audioFile];
}
}
Expand Down
2 changes: 1 addition & 1 deletion EZAudio/EZAudioUtilities.m
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ + (AudioStreamBasicDescription)iLBCFormatWithSampleRate:(float)sampleRate
NULL,
&propSize,
&asbd)
operation:"Failed to fill out the rest of the m4a AudioStreamBasicDescription"];
operation:"Failed to fill out the rest of the iLBC AudioStreamBasicDescription"];

return asbd;
}
Expand Down
9 changes: 9 additions & 0 deletions EZAudio/EZMicrophone.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@
/// @name Audio Data Description
///-----------------------------------------------------------

/**
Called anytime the EZMicrophone starts or stops.
@param output The instance of the EZMicrophone that triggered the event.
@param isPlaying A BOOL indicating whether the EZMicrophone instance is playing or not.
*/
- (void)microphone:(EZMicrophone *)microphone changedPlayingState:(BOOL)isPlaying;

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

/**
Called anytime the input device changes on an `EZMicrophone` instance.
@param microphone The instance of the EZMicrophone that triggered the event.
Expand Down
22 changes: 22 additions & 0 deletions EZAudio/EZMicrophone.m
Original file line number Diff line number Diff line change
Expand Up @@ -346,16 +346,38 @@ - (void)microphoneRouteChanged:(NSNotification *)notification

-(void)startFetchingAudio
{
//
// Start output unit
//
[EZAudioUtilities checkResult:AudioOutputUnitStart(self.info->audioUnit)
operation:"Failed to start microphone audio unit"];

//
// Notify delegate
//
if ([self.delegate respondsToSelector:@selector(microphone:changedPlayingState:)])
{
[self.delegate microphone:self changedPlayingState:YES];
}
}

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

-(void)stopFetchingAudio
{
//
// Stop output unit
//
[EZAudioUtilities checkResult:AudioOutputUnitStop(self.info->audioUnit)
operation:"Failed to stop microphone audio unit"];

//
// Notify delegate
//
if ([self.delegate respondsToSelector:@selector(microphone:changedPlayingState:)])
{
[self.delegate microphone:self changedPlayingState:NO];
}
}

//------------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 9516768

Please sign in to comment.