diff --git a/EZAudioExamples/OSX/EZAudioPlayFileExample/EZAudioPlayFileExample/PlayFileViewController.m b/EZAudioExamples/OSX/EZAudioPlayFileExample/EZAudioPlayFileExample/PlayFileViewController.m index f103e32..ad99f5f 100644 --- a/EZAudioExamples/OSX/EZAudioPlayFileExample/EZAudioPlayFileExample/PlayFileViewController.m +++ b/EZAudioExamples/OSX/EZAudioPlayFileExample/EZAudioPlayFileExample/PlayFileViewController.m @@ -25,9 +25,7 @@ #import "PlayFileViewController.h" -@interface PlayFileViewController (){ - AudioBufferList *_fileBufferList; -} +@interface PlayFileViewController () @property (nonatomic,weak) IBOutlet NSSegmentedControl *plotSegmentControl; @property (nonatomic,weak) IBOutlet NSButton *playButton; @end @@ -88,11 +86,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]; } @@ -222,38 +215,20 @@ } #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; } #pragma mark - NSOpenSavePanelDelegate @@ -278,8 +253,4 @@ return NO; } --(void)dealloc { - [EZAudio freeBufferList:_fileBufferList]; -} - @end diff --git a/EZAudioExamples/iOS/EZAudioPlayFileExample/EZAudioPlayFileExample/PlayFileViewController.m b/EZAudioExamples/iOS/EZAudioPlayFileExample/EZAudioPlayFileExample/PlayFileViewController.m index 3b56206..c63fbe8 100644 --- a/EZAudioExamples/iOS/EZAudioPlayFileExample/EZAudioPlayFileExample/PlayFileViewController.m +++ b/EZAudioExamples/iOS/EZAudioPlayFileExample/EZAudioPlayFileExample/PlayFileViewController.m @@ -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