diff --git a/EZAudio/Core-Components/EZRecorder.h b/EZAudio/Core-Components/EZRecorder.h index 9ffc6ec..30c8d64 100644 --- a/EZAudio/Core-Components/EZRecorder.h +++ b/EZAudio/Core-Components/EZRecorder.h @@ -25,8 +25,8 @@ /** Creates a new instance of an EZRecorder using a destination file path URL and the source format of the incoming audio. - @param url An NSURL specifying the file path location of where the audio file should be written to. - @param sourceFormat The AudioStreamBasicDescription for the incoming audio that will be written to the file. + @param url An NSURL specifying the file path location of where the audio file should be written to. + @param sourceFormat The AudioStreamBasicDescription for the incoming audio that will be written to the file. @return The newly created EZRecorder instance. */ -(EZRecorder*)initWithDestinationURL:(NSURL*)url @@ -40,8 +40,8 @@ /** Class method to create a new instance of an EZRecorder using a destination file path URL and the source format of the incoming audio. - @param url An NSURL specifying the file path location of where the audio file should be written to. - @param sourceFormat The AudioStreamBasicDescription for the incoming audio that will be written to the file. + @param url An NSURL specifying the file path location of where the audio file should be written to. + @param sourceFormat The AudioStreamBasicDescription for the incoming audio that will be written to the file. @return The newly created EZRecorder instance. */ +(EZRecorder*)recorderWithDestinationURL:(NSURL*)url diff --git a/EZAudio/Core-Components/EZRecorder.m b/EZAudio/Core-Components/EZRecorder.m index 5a9a2f0..628b7af 100644 --- a/EZAudio/Core-Components/EZRecorder.m +++ b/EZAudio/Core-Components/EZRecorder.m @@ -51,7 +51,7 @@ typedef struct { +(AudioStreamBasicDescription)defaultDestinationFormat { AudioStreamBasicDescription destinationFormat; destinationFormat.mFormatID = kAudioFormatLinearPCM; - destinationFormat.mChannelsPerFrame = 2; + destinationFormat.mChannelsPerFrame = 1; destinationFormat.mBitsPerChannel = 16; destinationFormat.mBytesPerPacket = destinationFormat.mBytesPerFrame = 2 * destinationFormat.mChannelsPerFrame; destinationFormat.mFramesPerPacket = 1; @@ -69,12 +69,12 @@ typedef struct { // Create the extended audio file [EZAudio checkResult:ExtAudioFileCreateWithURL(_destinationFileURL, - kAudioFileCAFType, - &_destinationFormat, - NULL, - kAudioFileFlags_EraseFile, - &_destinationFile) - operation:"Failed to create ExtendedAudioFile reference"]; + kAudioFileCAFType, + &_destinationFormat, + NULL, + kAudioFileFlags_EraseFile, + &_destinationFile) + operation:"Failed to create ExtendedAudioFile reference"]; // Set the client format _clientFormat = _destinationFormat; @@ -83,7 +83,6 @@ typedef struct { numberOfChannels:_destinationFormat.mChannelsPerFrame interleaved:YES]; } - UInt32 propertySize = sizeof(_clientFormat); [EZAudio checkResult:ExtAudioFileSetProperty(_destinationFile, kExtAudioFileProperty_ClientDataFormat, @@ -96,7 +95,7 @@ typedef struct { operation:"Failed to initialize with ExtAudioFileWriteAsync"]; // Setup the audio converter - [EZAudio checkResult:AudioConverterNew(&_sourceFormat, &_destinationFormat, &_audioConverter) + [EZAudio checkResult:AudioConverterNew(&_sourceFormat, &_clientFormat, &_audioConverter) operation:"Failed to create new audio converter"]; } @@ -107,7 +106,7 @@ typedef struct { // Setup output buffers UInt32 outputBufferSize = 32 * 1024; // 32 KB - AudioBufferList *convertedData = (AudioBufferList*)malloc(sizeof(AudioBufferList)); + AudioBufferList *convertedData = [EZAudio audioBufferList]; convertedData->mNumberBuffers = 1; convertedData->mBuffers[0].mNumberChannels = _clientFormat.mChannelsPerFrame; convertedData->mBuffers[0].mDataByteSize = outputBufferSize; diff --git a/EZAudioExamples/OSX/EZAudioPlayFileExample/EZAudioPlayFileExample.xcodeproj/project.pbxproj b/EZAudioExamples/OSX/EZAudioPlayFileExample/EZAudioPlayFileExample.xcodeproj/project.pbxproj index 0f2072f..dfd721d 100644 --- a/EZAudioExamples/OSX/EZAudioPlayFileExample/EZAudioPlayFileExample.xcodeproj/project.pbxproj +++ b/EZAudioExamples/OSX/EZAudioPlayFileExample/EZAudioPlayFileExample.xcodeproj/project.pbxproj @@ -183,9 +183,9 @@ 94056F0C185BD83400EB94BA /* AppDelegate.h */, 94056F0D185BD83400EB94BA /* AppDelegate.m */, 94056F2E185BD86D00EB94BA /* PlayFileViewController.h */, + 94056F2F185BD86D00EB94BA /* PlayFileViewController.m */, 94056F30185BD86D00EB94BA /* PlayFileViewController.xib */, 94056F0F185BD83400EB94BA /* MainMenu.xib */, - 94056F2F185BD86D00EB94BA /* PlayFileViewController.m */, 94056F12185BD83400EB94BA /* Images.xcassets */, 94056F01185BD83400EB94BA /* Supporting Files */, ); diff --git a/EZAudioExamples/OSX/EZAudioPlayFileExample/EZAudioPlayFileExample/PlayFileViewController.h b/EZAudioExamples/OSX/EZAudioPlayFileExample/EZAudioPlayFileExample/PlayFileViewController.h index 75c83a9..68ee31e 100644 --- a/EZAudioExamples/OSX/EZAudioPlayFileExample/EZAudioPlayFileExample/PlayFileViewController.h +++ b/EZAudioExamples/OSX/EZAudioPlayFileExample/EZAudioPlayFileExample/PlayFileViewController.h @@ -30,7 +30,7 @@ /** The CoreGraphics based audio plot */ -@property (nonatomic,weak) IBOutlet EZAudioPlot *audioPlot; +@property (nonatomic,weak) IBOutlet EZAudioPlotGL *audioPlot; #pragma mark - UI Extras /** @@ -38,6 +38,11 @@ */ @property (nonatomic,weak) IBOutlet NSTextField *filePathLabel; +/** + A slider to indicate the current frame position in the audio file + */ +@property (nonatomic,weak) IBOutlet NSSlider *framePositionSlider; + /** A BOOL indicating whether or not we've reached the end of the file */ @@ -59,4 +64,9 @@ */ -(IBAction)play:(id)sender; +/** + Seeks to a specific frame in the audio file. + */ +-(IBAction)seekToFrame:(id)sender; + @end diff --git a/EZAudioExamples/OSX/EZAudioPlayFileExample/EZAudioPlayFileExample/PlayFileViewController.m b/EZAudioExamples/OSX/EZAudioPlayFileExample/EZAudioPlayFileExample/PlayFileViewController.m index 74b7368..070f6a3 100644 --- a/EZAudioExamples/OSX/EZAudioPlayFileExample/EZAudioPlayFileExample/PlayFileViewController.m +++ b/EZAudioExamples/OSX/EZAudioPlayFileExample/EZAudioPlayFileExample/PlayFileViewController.m @@ -16,6 +16,7 @@ @synthesize audioFile; @synthesize audioPlot; @synthesize eof = _eof; +@synthesize framePositionSlider; #pragma mark - Initialization -(id)init { @@ -110,6 +111,10 @@ } } +-(void)seekToFrame:(id)sender { + [self.audioFile seekToFrame:(SInt64)[(NSSlider*)sender doubleValue]]; +} + #pragma mark - Action Extensions /* Give the visualization of the current buffer (this is almost exactly the openFrameworks audio input example) @@ -140,17 +145,15 @@ // Stop playback [[EZOutput sharedOutput] stopPlayback]; - self.audioFile = [EZAudioFile audioFileWithURL:filePathURL]; - self.audioFile.audioFileDelegate = self; - self.eof = NO; - self.filePathLabel.stringValue = filePathURL.lastPathComponent; + self.audioFile = [EZAudioFile audioFileWithURL:filePathURL andDelegate:self]; + self.eof = NO; + self.filePathLabel.stringValue = filePathURL.lastPathComponent; + self.framePositionSlider.minValue = 0.0f; + self.framePositionSlider.maxValue = (double)self.audioFile.totalFrames; // Plot the whole waveform - // Plot type self.audioPlot.plotType = EZPlotTypeBuffer; - // Fill self.audioPlot.shouldFill = YES; - // Mirror self.audioPlot.shouldMirror = YES; [self.audioFile getWaveformDataWithCompletionBlock:^(float *waveformData, UInt32 length) { [self.audioPlot updateBuffer:waveformData withBufferSize:length]; @@ -173,6 +176,15 @@ } } +-(void)audioFile:(EZAudioFile *)audioFile + updatedPosition:(SInt64)framePosition { + dispatch_async(dispatch_get_main_queue(), ^{ + if( ![self.framePositionSlider.cell isHighlighted] ){ + self.framePositionSlider.floatValue = (float)framePosition; + } + }); +} + #pragma mark - EZOutputDataSource -(AudioBufferList *)output:(EZOutput *)output needsBufferListWithFrames:(UInt32)frames @@ -204,7 +216,6 @@ [self.audioFile seekToFrame:0]; return nil; } - return bufferList; } return nil; diff --git a/EZAudioExamples/OSX/EZAudioPlayFileExample/EZAudioPlayFileExample/PlayFileViewController.xib b/EZAudioExamples/OSX/EZAudioPlayFileExample/EZAudioPlayFileExample/PlayFileViewController.xib index bf64ad5..fea861f 100644 --- a/EZAudioExamples/OSX/EZAudioPlayFileExample/EZAudioPlayFileExample/PlayFileViewController.xib +++ b/EZAudioExamples/OSX/EZAudioPlayFileExample/EZAudioPlayFileExample/PlayFileViewController.xib @@ -9,6 +9,7 @@ + @@ -18,8 +19,8 @@ - - + +