rewrote EZOuput and added output device support for iOS and OSX
This commit is contained in:
+6
-1
@@ -26,7 +26,12 @@
|
||||
/**
|
||||
The EZAudioFile representing of the currently selected audio file
|
||||
*/
|
||||
@property (nonatomic,strong) EZAudioFile *audioFile;
|
||||
@property (nonatomic, strong) EZAudioFile *audioFile;
|
||||
|
||||
/**
|
||||
The EZOutput representing the output currently being used to play the audio file.
|
||||
*/
|
||||
@property (nonatomic, strong) EZOutput *output;
|
||||
|
||||
/**
|
||||
The CoreGraphics based audio plot
|
||||
|
||||
+44
-46
@@ -19,27 +19,31 @@
|
||||
#pragma mark - Customize the Audio Plot
|
||||
- (void)viewDidLoad
|
||||
{
|
||||
[super viewDidLoad];
|
||||
|
||||
/*
|
||||
Customizing the audio plot's look
|
||||
*/
|
||||
// Background color
|
||||
self.audioPlot.backgroundColor = [UIColor colorWithRed: 0.816 green: 0.349 blue: 0.255 alpha: 1];
|
||||
// Waveform color
|
||||
self.audioPlot.color = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0];
|
||||
// Plot type
|
||||
self.audioPlot.plotType = EZPlotTypeBuffer;
|
||||
// Fill
|
||||
self.audioPlot.shouldFill = YES;
|
||||
// Mirror
|
||||
self.audioPlot.shouldMirror = YES;
|
||||
|
||||
/*
|
||||
Try opening the sample file
|
||||
*/
|
||||
[self openFileWithFilePathURL:[NSURL fileURLWithPath:kAudioFileDefault]];
|
||||
|
||||
[super viewDidLoad];
|
||||
|
||||
//
|
||||
// Customize the plot's look
|
||||
//
|
||||
// Background color
|
||||
self.audioPlot.backgroundColor = [UIColor colorWithRed: 0.816 green: 0.349 blue: 0.255 alpha: 1];
|
||||
// Waveform color
|
||||
self.audioPlot.color = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0];
|
||||
// Plot type
|
||||
self.audioPlot.plotType = EZPlotTypeBuffer;
|
||||
// Fill
|
||||
self.audioPlot.shouldFill = YES;
|
||||
// Mirror
|
||||
self.audioPlot.shouldMirror = YES;
|
||||
|
||||
//
|
||||
// Create an EZOutput instance
|
||||
//
|
||||
self.output = [EZOutput outputWithDataSource:self];
|
||||
|
||||
//
|
||||
// Try opening the sample file
|
||||
//
|
||||
[self openFileWithFilePathURL:[NSURL fileURLWithPath:kAudioFileDefault]];
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -75,15 +79,15 @@
|
||||
- (void)openFileWithFilePathURL:(NSURL *)filePathURL
|
||||
{
|
||||
// Stop playback
|
||||
[[EZOutput sharedOutput] stopPlayback];
|
||||
[self.output stopPlayback];
|
||||
|
||||
self.audioFile = [EZAudioFile audioFileWithURL:filePathURL delegate:self];
|
||||
self.eof = NO;
|
||||
self.filePathLabel.text = filePathURL.lastPathComponent;
|
||||
self.framePositionSlider.maximumValue = (float)self.audioFile.totalFrames;
|
||||
|
||||
// Set the client format from the EZAudioFile on the output
|
||||
[[EZOutput sharedOutput] setAudioStreamBasicDescription:self.audioFile.clientFormat];
|
||||
// Set the input format from the EZAudioFile on the output
|
||||
[self.output setInputFormat:[self.audioFile clientFormat]];
|
||||
|
||||
// Plot the whole waveform
|
||||
self.audioPlot.plotType = EZPlotTypeBuffer;
|
||||
@@ -93,29 +97,27 @@
|
||||
__weak typeof (self) weakSelf = self;
|
||||
[self.audioFile getWaveformDataWithCompletionBlock:^(float **waveformData,
|
||||
int length)
|
||||
{
|
||||
[weakSelf.audioPlot updateBuffer:waveformData[0]
|
||||
withBufferSize:length];
|
||||
}];
|
||||
{
|
||||
[weakSelf.audioPlot updateBuffer:waveformData[0]
|
||||
withBufferSize:length];
|
||||
}];
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
- (void)play:(id)sender
|
||||
{
|
||||
if (![[EZOutput sharedOutput] isPlaying])
|
||||
if (![self.output isPlaying])
|
||||
{
|
||||
if (self.eof)
|
||||
{
|
||||
[self.audioFile seekToFrame:0];
|
||||
}
|
||||
[EZOutput sharedOutput].outputDataSource = self;
|
||||
[[EZOutput sharedOutput] startPlayback];
|
||||
[self.output startPlayback];
|
||||
}
|
||||
else
|
||||
{
|
||||
[EZOutput sharedOutput].outputDataSource = nil;
|
||||
[[EZOutput sharedOutput] stopPlayback];
|
||||
[self.output stopPlayback];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,7 +165,7 @@
|
||||
{
|
||||
__weak typeof (self) weakSelf = self;
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if ([EZOutput sharedOutput].isPlaying)
|
||||
if ([self.output isPlaying])
|
||||
{
|
||||
if (weakSelf.audioPlot.plotType == EZPlotTypeBuffer &&
|
||||
weakSelf.audioPlot.shouldFill == YES &&
|
||||
@@ -196,29 +198,25 @@
|
||||
#pragma mark - EZOutputDataSource
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
- (void) output:(EZOutput *)output
|
||||
- (OSStatus) output:(EZOutput *)output
|
||||
shouldFillAudioBufferList:(AudioBufferList *)audioBufferList
|
||||
withNumberOfFrames:(UInt32)frames
|
||||
timestamp:(const AudioTimeStamp *)timestamp
|
||||
{
|
||||
if ( self.audioFile )
|
||||
if (self.audioFile)
|
||||
{
|
||||
UInt32 bufferSize;
|
||||
BOOL eof;
|
||||
[self.audioFile readFrames:frames
|
||||
audioBufferList:audioBufferList
|
||||
bufferSize:&bufferSize
|
||||
eof:&_eof];
|
||||
if ( _eof )
|
||||
eof:&eof];
|
||||
if (eof)
|
||||
{
|
||||
[self seekToFrame:0];
|
||||
[self.audioFile seekToFrame:0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
- (AudioStreamBasicDescription)outputHasAudioStreamBasicDescription:(EZOutput *)output
|
||||
{
|
||||
return self.audioFile.clientFormat;
|
||||
return noErr;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user