Updated examples to use updated EZOutputDataSource method output:shouldFillAudioBufferList:withNumberOfFrames: instead of the old method. Much cleaner and much more stable

This commit is contained in:
Syed Haris Ali
2014-02-10 23:11:39 -08:00
parent 01352aed7d
commit f482234fae
2 changed files with 23 additions and 81 deletions
@@ -13,8 +13,6 @@
UInt32 _waveformDrawingIndex;
UInt32 _waveformFrameRate;
UInt32 _waveformTotalBuffers;
AudioBufferList *_fileBufferList;
}
@end
@@ -68,11 +66,6 @@
Try opening the sample file
*/
[self openFileWithFilePathURL:[NSURL fileURLWithPath:kAudioFileDefault]];
/**
Initialize the AudioBufferList that will hold the file's data (we're essentially streaming only chunks of the file at a time to keep a low memory footprint.
*/
_fileBufferList = [EZAudio audioBufferList];
}
@@ -186,46 +179,24 @@ withNumberOfChannels:(UInt32)numberOfChannels {
}
#pragma mark - EZOutputDataSource
-(AudioBufferList *)output:(EZOutput *)output
needsBufferListWithFrames:(UInt32)frames
withBufferSize:(UInt32 *)bufferSize {
if( self.audioFile ){
// Reached the end of the file
if( self.eof ){
// Here's what you do to loop the file
[self.audioFile seekToFrame:0];
self.eof = NO;
_fileBufferList = [EZAudio audioBufferList];
return nil;
}
// Allocate a buffer list to hold the file's data
BOOL eof;
-(void)output:(EZOutput *)output shouldFillAudioBufferList:(AudioBufferList *)audioBufferList withNumberOfFrames:(UInt32)frames
{
if( self.audioFile )
{
UInt32 bufferSize;
[self.audioFile readFrames:frames
audioBufferList:_fileBufferList
bufferSize:bufferSize
eof:&eof];
self.eof = eof;
// Reached the end of the file on the last read
if( eof ){
[EZAudio freeBufferList:_fileBufferList];
return nil;
audioBufferList:audioBufferList
bufferSize:&bufferSize
eof:&_eof];
if( _eof )
{
[self seekToFrame:0];
}
return _fileBufferList;
}
return nil;
}
-(AudioStreamBasicDescription)outputHasAudioStreamBasicDescription:(EZOutput *)output {
return self.audioFile.clientFormat;
}
-(void)dealloc {
[EZAudio freeBufferList:_fileBufferList];
}
@end