Skip to content

Commit

Permalink
Used EZOutputDelegate for audio received callback and fixed minor bgs
Browse files Browse the repository at this point in the history
  • Loading branch information
syedhali committed Jun 30, 2015
1 parent c85d1d9 commit 6a44909
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
<outlet property="audioPlot" destination="kt3-hw-eFY" id="9mm-d1-vJk"/>
<outlet property="filePathLabel" destination="i5r-ex-ukW" id="GRl-ld-nWi"/>
<outlet property="framePositionSlider" destination="Oc2-kU-kAJ" id="z0M-Q9-JAb"/>
<outlet property="rollingHistorySlider" destination="2qJ-Va-Qht" id="yf8-JW-5yM"/>
<outlet property="view" destination="PED-9r-Xub" id="Xxb-En-D2X"/>
<outlet property="volumeSlider" destination="d3R-ct-df2" id="pAW-BF-AFa"/>
</connections>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
Using the EZOutputDataSource to provide output data to the EZOutput component.
*/
@interface PlayFileViewController : UIViewController <EZAudioFileDelegate,
EZOutputDataSource>
EZOutputDataSource,
EZOutputDelegate>

#pragma mark - Components
/**
Expand All @@ -36,19 +37,23 @@
/**
The CoreGraphics based audio plot
*/
@property (nonatomic,weak) IBOutlet EZAudioPlot *audioPlot;
@property (nonatomic, weak) IBOutlet EZAudioPlot *audioPlot;

#pragma mark - UI Extras
/**
A label to display the current file path with the waveform shown
*/
@property (nonatomic,weak) IBOutlet UILabel *filePathLabel;
@property (nonatomic, weak) IBOutlet UILabel *filePathLabel;

/**
A slider to indicate the current frame position in the audio file
*/
@property (nonatomic,weak) IBOutlet UISlider *framePositionSlider;
@property (nonatomic, weak) IBOutlet UISlider *framePositionSlider;

/**
A slider to indicate the current rolling history length of the audio plot.
*/
@property (nonatomic, weak) IBOutlet UISlider *rollingHistorySlider;

/**
A slider to indicate the volume on the audio player
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ - (void)viewDidLoad
// Create an EZOutput instance
//
self.output = [EZOutput outputWithDataSource:self];
self.output.delegate = self;

//
// Customize UI controls
//
self.volumeSlider.value = [self.output volume];
self.rollingHistorySlider.value = [self.audioPlot rollingHistoryLength];

//
// Try opening the sample file
Expand Down Expand Up @@ -183,30 +190,6 @@ - (void)drawRollingPlot
#pragma mark - EZAudioFileDelegate
//------------------------------------------------------------------------------

- (void) audioFile:(EZAudioFile *)audioFile
readAudio:(float **)buffer
withBufferSize:(UInt32)bufferSize
withNumberOfChannels:(UInt32)numberOfChannels
{
__weak typeof (self) weakSelf = self;
dispatch_async(dispatch_get_main_queue(), ^{
if ([self.output isPlaying])
{
if (weakSelf.audioPlot.plotType == EZPlotTypeBuffer &&
weakSelf.audioPlot.shouldFill == YES &&
weakSelf.audioPlot.shouldMirror == YES)
{
weakSelf.audioPlot.shouldFill = NO;
weakSelf.audioPlot.shouldMirror = NO;
}
[weakSelf.audioPlot updateBuffer:buffer[0]
withBufferSize:bufferSize];
}
});
}

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

- (void)audioFile:(EZAudioFile *)audioFile
updatedPosition:(SInt64)framePosition
{
Expand Down Expand Up @@ -244,6 +227,32 @@ - (OSStatus) output:(EZOutput *)output
return noErr;
}

//------------------------------------------------------------------------------
#pragma mark - EZOutputDelegate
//------------------------------------------------------------------------------

- (void) output:(EZOutput *)output
playedAudio:(float **)buffer
withBufferSize:(UInt32)bufferSize
withNumberOfChannels:(UInt32)numberOfChannels
{
__weak typeof (self) weakSelf = self;
dispatch_async(dispatch_get_main_queue(), ^{
if ([self.output isPlaying])
{
if (weakSelf.audioPlot.plotType == EZPlotTypeBuffer &&
weakSelf.audioPlot.shouldFill == YES &&
weakSelf.audioPlot.shouldMirror == YES)
{
weakSelf.audioPlot.shouldFill = NO;
weakSelf.audioPlot.shouldMirror = NO;
}
[weakSelf.audioPlot updateBuffer:buffer[0]
withBufferSize:bufferSize];
}
});
}

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

@end

0 comments on commit 6a44909

Please sign in to comment.