Compare commits

...

20 Commits

Author SHA1 Message Date
Syed Haris Ali c4fb3e27e7 moving these to new examples repo 2015-02-14 21:10:59 -08:00
Syed Haris Ali a6252b02dd adding utility classes 2015-02-14 21:08:35 -08:00
Syed Haris Ali 7f0bf3bb6c more cleanup 2015-02-14 19:23:48 -08:00
Syed Haris Ali 62b79ce6c2 got waveform data generating for interleaved and non-interleaved types 2015-02-14 19:17:50 -08:00
Syed Haris Ali 1415b5591e added copy 2015-02-14 19:01:42 -08:00
Syed Haris Ali ab892b9f74 added benchmark for speed test 2015-02-14 18:52:02 -08:00
Syed Haris Ali fde27c2db7 starting work on reading all data from audio file and then parsing data 2015-02-14 18:47:47 -08:00
Syed Haris Ali 1055e3b1dc cleaned up waveform getters and added synchronous fetching 2015-02-14 18:36:36 -08:00
Syed Haris Ali ceba0dd415 removed logging statement 2015-02-14 18:23:55 -08:00
Syed Haris Ali 6d6ae3e761 added property for total client frames in addition to total file frames 2015-02-14 18:02:30 -08:00
Syed Haris Ali 5261cb2961 fixed issue with total frames not properly recalculated for different sample rates 2015-02-14 16:33:40 -08:00
Syed Haris Ali 65491d453d added better way to obtain waveform data for all channels 2015-02-14 16:16:29 -08:00
Syed Haris Ali 4389a48875 made more progress, read is working and added mutex to prevent bogus buffer list err 2015-02-12 00:31:51 -08:00
Syed Haris Ali 3b4382986f trying to figure out why read is failing 2015-02-11 23:15:00 -08:00
Syed Haris Ali b327e5b140 added file format to initializer 2015-02-11 23:02:21 -08:00
Syed Haris Ali 73adf239ec added back metadata method 2015-02-11 23:02:21 -08:00
Syed Haris Ali c2c05b683b bit more cleanup in header 2015-02-11 23:02:21 -08:00
Syed Haris Ali 0bdade977d got simple initWithURL method back 2015-02-11 23:02:21 -08:00
Syed Haris Ali 3b0f32abaa added more robust file opening method 2015-02-11 23:02:21 -08:00
Syed Haris Ali 804cb1c3ef refactored process of creating EZAudioFile to allow read/write permissions on existing or new files 2015-02-11 23:02:21 -08:00
24 changed files with 1157 additions and 855 deletions
Vendored
BIN
View File
Binary file not shown.
-124
View File
@@ -1,124 +0,0 @@
//
// AEFloatConverter.h
// The Amazing Audio Engine
//
// Created by Michael Tyson on 25/10/2012.
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
#ifdef __cplusplus
extern "C" {
#endif
#import <Foundation/Foundation.h>
#import <AudioToolbox/AudioToolbox.h>
/*!
* Universal converter to float format
*
* Use this class to easily convert arbitrary audio formats to floating point
* for use with utilities like the Accelerate framework.
*/
@interface AEFloatConverter : NSObject
/*!
* Initialize
*
* @param sourceFormat The audio format to use
*/
- (id)initWithSourceFormat:(AudioStreamBasicDescription)sourceFormat;
/*!
* Convert audio to floating-point
*
* This C function, safe to use in a Core Audio realtime thread context, will take
* an audio buffer list of audio in the format you provided at initialisation, and
* convert it into a noninterleaved float array.
*
* @param converter Pointer to the converter object.
* @param sourceBuffer An audio buffer list containing the source audio.
* @param targetBuffers An array of floating-point arrays to store the converted float audio into.
* Note that you must provide the correct number of arrays, to match the number of channels.
* @param frames The number of frames to convert.
* @return YES on success; NO on failure
*/
BOOL AEFloatConverterToFloat(AEFloatConverter* converter, AudioBufferList *sourceBuffer, float * const * targetBuffers, UInt32 frames);
/*!
* Convert audio to floating-point, in a buffer list
*
* This C function, safe to use in a Core Audio realtime thread context, will take
* an audio buffer list of audio in the format you provided at initialisation, and
* convert it into a noninterleaved float format.
*
* @param converter Pointer to the converter object.
* @param sourceBuffer An audio buffer list containing the source audio.
* @param targetBuffer An audio buffer list to store the converted floating-point audio.
* @param frames The number of frames to convert.
* @return YES on success; NO on failure
*/
BOOL AEFloatConverterToFloatBufferList(AEFloatConverter* converter, AudioBufferList *sourceBuffer, AudioBufferList *targetBuffer, UInt32 frames);
/*!
* Convert audio from floating-point
*
* This C function, safe to use in a Core Audio realtime thread context, will take
* an audio buffer list of audio in the format you provided at initialisation, and
* convert it into a float array.
*
* @param converter Pointer to the converter object.
* @param sourceBuffers An array of floating-point arrays containing the floating-point audio to convert.
* Note that you must provide the correct number of arrays, to match the number of channels.
* @param targetBuffer An audio buffer list to store the converted audio into.
* @param frames The number of frames to convert.
* @return YES on success; NO on failure
*/
BOOL AEFloatConverterFromFloat(AEFloatConverter* converter, float * const * sourceBuffers, AudioBufferList *targetBuffer, UInt32 frames);
/*!
* Convert audio from floating-point, in a buffer list
*
* This C function, safe to use in a Core Audio realtime thread context, will take
* an audio buffer list of audio in the format you provided at initialisation, and
* convert it into a float array.
*
* @param converter Pointer to the converter object.
* @param sourceBuffer An audio buffer list containing the source audio.
* @param targetBuffer An audio buffer list to store the converted audio into.
* @param frames The number of frames to convert.
* @return YES on success; NO on failure
*/
BOOL AEFloatConverterFromFloatBufferList(AEFloatConverter* converter, AudioBufferList *sourceBuffer, AudioBufferList *targetBuffer, UInt32 frames);
/*!
* The AudioStreamBasicDescription representing the converted floating-point format
*/
@property (nonatomic, readonly) AudioStreamBasicDescription floatingPointAudioDescription;
/*!
* The source audio format set at initialization
*/
@property (nonatomic, readonly) AudioStreamBasicDescription sourceFormat;
@end
#ifdef __cplusplus
}
#endif
-211
View File
@@ -1,211 +0,0 @@
//
// AEFloatConverter.m
// The Amazing Audio Engine
//
// Created by Michael Tyson on 25/10/2012.
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
#import "AEFloatConverter.h"
#define checkResult(result,operation) (_checkResult((result),(operation),strrchr(__FILE__, '/')+1,__LINE__))
static inline BOOL _checkResult(OSStatus result, const char *operation, const char* file, int line) {
if ( result != noErr ) {
NSLog(@"%s:%d: %s result %d %08X %4.4s", file, line, operation, (int)result, (int)result, (char*)&result);
return NO;
}
return YES;
}
#define kNoMoreDataErr -2222
struct complexInputDataProc_t {
AudioBufferList *sourceBuffer;
};
@interface AEFloatConverter () {
AudioStreamBasicDescription _sourceAudioDescription;
AudioStreamBasicDescription _floatAudioDescription;
AudioConverterRef _toFloatConverter;
AudioConverterRef _fromFloatConverter;
AudioBufferList *_scratchFloatBufferList;
}
static OSStatus complexInputDataProc(AudioConverterRef inAudioConverter,
UInt32 *ioNumberDataPackets,
AudioBufferList *ioData,
AudioStreamPacketDescription **outDataPacketDescription,
void *inUserData);
@end
@implementation AEFloatConverter
@synthesize sourceFormat = _sourceAudioDescription;
-(id)initWithSourceFormat:(AudioStreamBasicDescription)sourceFormat {
if ( !(self = [super init]) ) return nil;
_floatAudioDescription.mFormatID = kAudioFormatLinearPCM;
_floatAudioDescription.mFormatFlags = kAudioFormatFlagIsFloat | kAudioFormatFlagIsPacked | kAudioFormatFlagIsNonInterleaved;
_floatAudioDescription.mChannelsPerFrame = sourceFormat.mChannelsPerFrame;
_floatAudioDescription.mBytesPerPacket = sizeof(float);
_floatAudioDescription.mFramesPerPacket = 1;
_floatAudioDescription.mBytesPerFrame = sizeof(float);
_floatAudioDescription.mBitsPerChannel = 8 * sizeof(float);
_floatAudioDescription.mSampleRate = sourceFormat.mSampleRate;
_sourceAudioDescription = sourceFormat;
if ( memcmp(&sourceFormat, &_floatAudioDescription, sizeof(AudioStreamBasicDescription)) != 0 ) {
checkResult(AudioConverterNew(&sourceFormat, &_floatAudioDescription, &_toFloatConverter), "AudioConverterNew");
checkResult(AudioConverterNew(&_floatAudioDescription, &sourceFormat, &_fromFloatConverter), "AudioConverterNew");
_scratchFloatBufferList = (AudioBufferList*)malloc(sizeof(AudioBufferList) + (_floatAudioDescription.mChannelsPerFrame-1)*sizeof(AudioBuffer));
_scratchFloatBufferList->mNumberBuffers = _floatAudioDescription.mChannelsPerFrame;
for ( int i=0; i<_scratchFloatBufferList->mNumberBuffers; i++ ) {
_scratchFloatBufferList->mBuffers[i].mNumberChannels = 1;
}
}
return self;
}
-(void)dealloc {
if ( _toFloatConverter ) AudioConverterDispose(_toFloatConverter);
if ( _fromFloatConverter ) AudioConverterDispose(_fromFloatConverter);
if ( _scratchFloatBufferList ) free(_scratchFloatBufferList);
// [super dealloc];
}
BOOL AEFloatConverterToFloat(AEFloatConverter* THIS, AudioBufferList *sourceBuffer, float * const * targetBuffers, UInt32 frames) {
if ( frames == 0 ) return YES;
if ( THIS->_toFloatConverter ) {
UInt32 priorDataByteSize = sourceBuffer->mBuffers[0].mDataByteSize;
for ( int i=0; i<sourceBuffer->mNumberBuffers; i++ ) {
sourceBuffer->mBuffers[i].mDataByteSize = frames * THIS->_sourceAudioDescription.mBytesPerFrame;
}
for ( int i=0; i<THIS->_scratchFloatBufferList->mNumberBuffers; i++ ) {
THIS->_scratchFloatBufferList->mBuffers[i].mData = targetBuffers[i];
THIS->_scratchFloatBufferList->mBuffers[i].mDataByteSize = frames * sizeof(float);
}
OSStatus result = AudioConverterFillComplexBuffer(THIS->_toFloatConverter,
complexInputDataProc,
&(struct complexInputDataProc_t) { .sourceBuffer = sourceBuffer },
&frames,
THIS->_scratchFloatBufferList,
NULL);
for ( int i=0; i<sourceBuffer->mNumberBuffers; i++ ) {
sourceBuffer->mBuffers[i].mDataByteSize = priorDataByteSize;
}
if ( !checkResult(result, "AudioConverterConvertComplexBuffer") ) {
return NO;
}
} else {
for ( int i=0; i<sourceBuffer->mNumberBuffers; i++ ) {
memcpy(targetBuffers[i], sourceBuffer->mBuffers[i].mData, frames * sizeof(float));
}
}
return YES;
}
BOOL AEFloatConverterToFloatBufferList(AEFloatConverter* converter, AudioBufferList *sourceBuffer, AudioBufferList *targetBuffer, UInt32 frames) {
assert(targetBuffer->mNumberBuffers == converter->_floatAudioDescription.mChannelsPerFrame);
float *targetBuffers[targetBuffer->mNumberBuffers];
for ( int i=0; i<targetBuffer->mNumberBuffers; i++ ) {
targetBuffers[i] = (float*)targetBuffer->mBuffers[i].mData;
}
return AEFloatConverterToFloat(converter, sourceBuffer, targetBuffers, frames);
}
BOOL AEFloatConverterFromFloat(AEFloatConverter* THIS, float * const * sourceBuffers, AudioBufferList *targetBuffer, UInt32 frames) {
if ( frames == 0 ) return YES;
if ( THIS->_fromFloatConverter ) {
for ( int i=0; i<THIS->_scratchFloatBufferList->mNumberBuffers; i++ ) {
THIS->_scratchFloatBufferList->mBuffers[i].mData = sourceBuffers[i];
THIS->_scratchFloatBufferList->mBuffers[i].mDataByteSize = frames * sizeof(float);
}
UInt32 priorDataByteSize = targetBuffer->mBuffers[0].mDataByteSize;
for ( int i=0; i<targetBuffer->mNumberBuffers; i++ ) {
targetBuffer->mBuffers[i].mDataByteSize = frames * THIS->_sourceAudioDescription.mBytesPerFrame;
}
OSStatus result = AudioConverterFillComplexBuffer(THIS->_fromFloatConverter,
complexInputDataProc,
&(struct complexInputDataProc_t) { .sourceBuffer = THIS->_scratchFloatBufferList },
&frames,
targetBuffer,
NULL);
for ( int i=0; i<targetBuffer->mNumberBuffers; i++ ) {
targetBuffer->mBuffers[i].mDataByteSize = priorDataByteSize;
}
if ( !checkResult(result, "AudioConverterConvertComplexBuffer") ) {
return NO;
}
} else {
for ( int i=0; i<targetBuffer->mNumberBuffers; i++ ) {
memcpy(targetBuffer->mBuffers[i].mData, sourceBuffers[i], frames * sizeof(float));
}
}
return YES;
}
BOOL AEFloatConverterFromFloatBufferList(AEFloatConverter* converter, AudioBufferList *sourceBuffer, AudioBufferList *targetBuffer, UInt32 frames) {
assert(sourceBuffer->mNumberBuffers == converter->_floatAudioDescription.mChannelsPerFrame);
float *sourceBuffers[sourceBuffer->mNumberBuffers];
for ( int i=0; i<sourceBuffer->mNumberBuffers; i++ ) {
sourceBuffers[i] = (float*)sourceBuffer->mBuffers[i].mData;
}
return AEFloatConverterFromFloat(converter, sourceBuffers, targetBuffer, frames);
}
static OSStatus complexInputDataProc(AudioConverterRef inAudioConverter,
UInt32 *ioNumberDataPackets,
AudioBufferList *ioData,
AudioStreamPacketDescription **outDataPacketDescription,
void *inUserData) {
struct complexInputDataProc_t *arg = (struct complexInputDataProc_t*)inUserData;
if ( !arg->sourceBuffer ) {
return kNoMoreDataErr;
}
memcpy(ioData, arg->sourceBuffer, sizeof(AudioBufferList) + (arg->sourceBuffer->mNumberBuffers-1)*sizeof(AudioBuffer));
arg->sourceBuffer = NULL;
return noErr;
}
-(AudioStreamBasicDescription)floatingPointAudioDescription {
return _floatAudioDescription;
}
@end
+32 -15
View File
@@ -25,24 +25,25 @@
#import <Foundation/Foundation.h>
#import <AudioToolbox/AudioToolbox.h>
#pragma mark - 3rd Party Utilties
#import "AEFloatConverter.h"
#import "TPCircularBuffer.h"
#pragma mark - Core Components
#import "EZAudioFile.h"
#import "EZMicrophone.h"
#import "EZOutput.h"
#import "EZRecorder.h"
#pragma mark - Extended Components
#import "EZAudioPlayer.h"
#pragma mark - Interface Components
#import "EZPlot.h"
#import "EZAudioPlot.h"
#import "EZAudioPlotGL.h"
#import "EZAudioPlotGLKViewController.h"
//#pragma mark - Core Components
//#import "EZAudioFile.h"
//#import "EZMicrophone.h"
//#import "EZOutput.h"
//#import "EZRecorder.h"
//
//#pragma mark - Extended Components
//#import "EZAudioPlayer.h"
//
//#pragma mark - Interface Components
//#import "EZPlot.h"
//#import "EZAudioPlot.h"
//#import "EZAudioPlotGL.h"
//#import "EZAudioPlotGLKViewController.h"
/**
EZAudio is a simple, intuitive framework for iOS and OSX. The goal of EZAudio was to provide a modular, cross-platform framework to simplify performing everyday audio operations like getting microphone input, creating audio waveforms, recording/playing audio files, etc. The visualization tools like the EZAudioPlot and EZAudioPlotGL were created to plug right into the framework's various components and provide highly optimized drawing routines that work in harmony with audio callback loops. All components retain the same namespace whether you're on an iOS device or a Mac computer so an EZAudioPlot understands it will subclass an UIView on an iOS device or an NSView on a Mac.
@@ -94,6 +95,22 @@
*/
+(AudioStreamBasicDescription)iLBCFormatWithSampleRate:(float)sampleRate;
/**
Checks an AudioStreamBasicDescription for an interleaved flag, meaning samples are
stored in one buffer one after another instead of two (or n channels) parallel buffers
@param asbd A valid AudioStreamBasicDescription
@return A BOOL indicating whether or not the AudioStreamBasicDescription is interleaved
*/
+ (BOOL) isInterleaved:(AudioStreamBasicDescription)asbd;
/**
Checks an AudioStreamBasicDescription to see if it is linear PCM, which is an
uncompressed, non-variable bit rate type format
@param asbd A valid AudioStreamBasicDescription
@return A BOOL indicating whether or not the AudioStreamBasicDescription is linear PCM
*/
+ (BOOL) isLinearPCM:(AudioStreamBasicDescription)asbd;
/**
@param channels The desired number of channels
+13 -3
View File
@@ -32,14 +32,14 @@
numberOfChannels:(UInt32)channels
interleaved:(BOOL)interleaved
{
AudioBufferList *audioBufferList = (AudioBufferList*)malloc(sizeof(AudioBufferList));
AudioBufferList *audioBufferList = (AudioBufferList*)malloc(sizeof(AudioBufferList) + sizeof(AudioBuffer)*(channels-1));
UInt32 outputBufferSize = 32 * frames; // 32 KB
audioBufferList->mNumberBuffers = interleaved ? 1 : channels;
for( int i = 0; i < audioBufferList->mNumberBuffers; i++ )
{
audioBufferList->mBuffers[i].mNumberChannels = channels;
audioBufferList->mBuffers[i].mDataByteSize = channels * outputBufferSize;
audioBufferList->mBuffers[i].mData = (float*)malloc(channels * sizeof(float) *outputBufferSize);
audioBufferList->mBuffers[i].mData = (float*)malloc(channels * sizeof(float) * outputBufferSize);
}
return audioBufferList;
}
@@ -100,6 +100,16 @@
return asbd;
}
+ (BOOL)isInterleaved:(AudioStreamBasicDescription)asbd
{
return !(asbd.mFormatFlags & kAudioFormatFlagIsNonInterleaved);
}
+ (BOOL)isLinearPCM:(AudioStreamBasicDescription)asbd
{
return asbd.mFormatID == kAudioFormatLinearPCM;
}
+(AudioStreamBasicDescription)M4AFormatWithNumberOfChannels:(UInt32)channels
sampleRate:(float)sampleRate
{
@@ -319,7 +329,7 @@
//
if( *scrollHistory == NULL ){
// Create the history buffer
*scrollHistory = (float*)calloc(kEZAudioPlotMaxHistoryBufferLength,floatByteSize);
*scrollHistory = (float*)calloc(1024,floatByteSize);
}
//
+20
View File
@@ -0,0 +1,20 @@
//
// EZAudioConverter.h
// EZAudioPlayFileExample
//
// Created by Syed Haris Ali on 2/14/15.
// Copyright (c) 2015 Syed Haris Ali. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <AudioToolbox/AudioToolbox.h>
@interface EZAudioConverter : NSObject
@property (nonatomic, assign, readonly) AudioStreamBasicDescription inputFormat;
@property (nonatomic, assign, readonly) AudioStreamBasicDescription outputFormat;
+ (instancetype) converterWithInputFormat:(AudioStreamBasicDescription)inputFormat
outputFormat:(AudioStreamBasicDescription)outputFormat;
@end
+38
View File
@@ -0,0 +1,38 @@
//
// EZAudioConverter.m
// EZAudioPlayFileExample
//
// Created by Syed Haris Ali on 2/14/15.
// Copyright (c) 2015 Syed Haris Ali. All rights reserved.
//
#import "EZAudioConverter.h"
typedef struct
{
AudioConverterRef converterRef;
AudioStreamBasicDescription inputFormat;
AudioStreamBasicDescription outputFormat;
} EZAudioConverterInfo;
@interface EZAudioConverter ()
@property (nonatomic, assign) EZAudioConverterInfo info;
@end
@implementation EZAudioConverter
+ (instancetype)converterWithInputFormat:(AudioStreamBasicDescription)inputFormat
outputFormat:(AudioStreamBasicDescription)outputFormat
{
id converter = [[self alloc] init];
EZAudioConverterInfo info;
memset(&info, 0, sizeof(info));
info.inputFormat = inputFormat;
info.outputFormat = outputFormat;
((EZAudioConverter *)converter).info = info;
return converter;
}
@end
+222 -70
View File
@@ -25,10 +25,26 @@
#import <Foundation/Foundation.h>
#import <AudioToolbox/AudioToolbox.h>
#import "EZAudioWaveformData.h"
//------------------------------------------------------------------------------
@class EZAudio;
@class EZAudioConverter;
@class EZAudioFile;
//------------------------------------------------------------------------------
typedef NS_ENUM(NSUInteger, EZAudioFilePermission)
{
EZAudioFilePermissionRead = kAudioFileReadPermission,
EZAudioFilePermissionWrite = kAudioFileWritePermission,
EZAudioFilePermissionReadWrite = kAudioFileReadWritePermission,
};
//------------------------------------------------------------------------------
#pragma mark - EZAudioFileDelegate
//------------------------------------------------------------------------------
/**
The EZAudioFileDelegate provides event callbacks for the EZAudioFile object. These type of events are triggered by reads and seeks on the file and gives feedback such as the audio data read as a float array for visualizations and the new seek position for UI updating.
*/
@@ -42,102 +58,192 @@
@param bufferSize The length of the buffers float arrays
@param numberOfChannels The number of channels. 2 for stereo, 1 for mono.
*/
-(void) audioFile:(EZAudioFile*)audioFile
readAudio:(float**)buffer
withBufferSize:(UInt32)bufferSize
withNumberOfChannels:(UInt32)numberOfChannels;
- (void) audioFile:(EZAudioFile*)audioFile
readAudio:(float**)buffer
withBufferSize:(UInt32)bufferSize
withNumberOfChannels:(UInt32)numberOfChannels;
//------------------------------------------------------------------------------
/**
Occurs when the audio file's internal seek position has been updated by the EZAudioFile functions `readFrames:audioBufferList:bufferSize:eof:` or `audioFile:updatedPosition:`.
@param audioFile The instance of the EZAudio in which the change occured
@param framePosition The new frame index as a 64-bit signed integer
*/
-(void)audioFile:(EZAudioFile*)audioFile
updatedPosition:(SInt64)framePosition;
- (void) audioFile:(EZAudioFile*)audioFile
updatedPosition:(SInt64)framePosition;
@end
//------------------------------------------------------------------------------
#pragma mark - EZAudioFile
//------------------------------------------------------------------------------
/**
The EZAudioFile provides a lightweight and intuitive way to asynchronously interact with audio files. These interactions included reading audio data, seeking within an audio file, getting information about the file, and pulling the waveform data for visualizing the contents of the audio file. The EZAudioFileDelegate provides event callbacks for when reads, seeks, and various updates happen within the audio file to allow the caller to interact with the action in meaningful ways. Common use cases here could be to read the audio file's data as AudioBufferList structures for output (see EZOutput) and visualizing the audio file's data as a float array using an audio plot (see EZAudioPlot).
*/
@interface EZAudioFile : NSObject
//------------------------------------------------------------------------------
#pragma mark - Blocks
//------------------------------------------------------------------------------
/**
A block used when returning back the waveform data. The waveform data itself will be an array of float values and the length indicates the total length of the float array.
@param waveformData An array of float values representing the amplitude data from the audio waveform
@param length The length of the waveform data's float array
*/
typedef void (^WaveformDataCompletionBlock)(float *waveformData, UInt32 length);
typedef void (^WaveformDataCompletionBlock)(EZAudioWaveformData *waveformData);
//------------------------------------------------------------------------------
#pragma mark - Properties
//------------------------------------------------------------------------------
/**
A EZAudioFileDelegate for the audio file that is used to return events such as new seek positions within the file and the read audio data as a float array.
*/
@property (nonatomic,assign) id<EZAudioFileDelegate> audioFileDelegate;
@property (nonatomic, weak) id<EZAudioFileDelegate> delegate;
//------------------------------------------------------------------------------
#pragma mark - Initialization
//------------------------------------------------------------------------------
/**
@name Initialization
*/
/**
The resolution of the waveform data. This value specifies how the recommendedDrawingFrameRate chooses itself. A low value like 128 will render a waveform containing 128 points representing a low resolution waveform while a high value like 4096 will render a high quality waveform. Higher resolutions provide more detail, but take more work to render in the audio waveform plots (EZAudioPlot or EZAudioPlotGL) while lower resolutions providel less detail, but work better for displaying many at a time (like in a UITableView)
Creates a new instance of the EZAudioFile using a file path URL. Read only.
@param url The file path reference of the audio file as an NSURL.
@return The newly created EZAudioFile instance.
*/
@property (nonatomic,assign) UInt32 waveformResolution;
- (instancetype)initWithURL:(NSURL*)url;
#pragma mark - Initializers
///-----------------------------------------------------------
/// @name Initializers
///-----------------------------------------------------------
//------------------------------------------------------------------------------
/**
Creates a new instance of the EZAudioFile using a file path URL.
@param url The file path reference of the audio file as an NSURL.
@param permission A constant describing what we intend on doing with the audio file (read, write, or both)
@param fileFormat An AudioStreamBasicDescription that will be used to create the audio file if it does not exist if the permission argument is set to EZAudioFilePermissionWrite or EZAudioFilePermissionReadWrite. Not used for EZAudioFilePermissionRead permission.
@return The newly created EZAudioFile instance.
*/
-(EZAudioFile*)initWithURL:(NSURL*)url;
- (instancetype)initWithURL:(NSURL*)url
permission:(EZAudioFilePermission)permission
fileFormat:(AudioStreamBasicDescription)fileFormat;
//------------------------------------------------------------------------------
/**
Creates a new instance of the EZAudioFile using a file path URL and allows specifying an EZAudioFileDelegate.
@param url The file path reference of the audio file as an NSURL.
@param delegate The audio file delegate that receives events specified by the EZAudioFileDelegate protocol
@param permission A constant describing what we intend on doing with the audio file (read, write, or both)
@param fileFormat An AudioStreamBasicDescription that will be used to create the audio file if it does not exist if the permission argument is set to EZAudioFilePermissionWrite or EZAudioFilePermissionReadWrite. Not used for EZAudioFilePermissionRead permission.
@return The newly created EZAudioFile instance.
*/
-(EZAudioFile*)initWithURL:(NSURL*)url
andDelegate:(id<EZAudioFileDelegate>)delegate;
- (instancetype)initWithURL:(NSURL*)url
delegate:(id<EZAudioFileDelegate>)delegate
permission:(EZAudioFilePermission)permission
fileFormat:(AudioStreamBasicDescription)fileFormat;
//------------------------------------------------------------------------------
/**
Class method that creates a new instance of the EZAudioFile using a file path URL and allows specifying an EZAudioFileDelegate, a read/write permission, a file format incase a new file is being written, and a client format for a format that will be used when read samples (different from file format).
@param url The file path reference of the audio file as an NSURL.
@param delegate The audio file delegate that receives events specified by the EZAudioFileDelegate protocol
@param permission A constant describing what we intend on doing with the audio file (read, write, or both)
@param fileFormat An AudioStreamBasicDescription that will be used to create the audio file if it does not exist if the permission argument is set to EZAudioFilePermissionWrite or EZAudioFilePermissionReadWrite. Not used for EZAudioFilePermissionRead permission.
@param clientFormat An AudioStreamBasicDescription that will be used as the client format on the audio file. For instance, the audio file might be in a 22.5 kHz sample rate format in its file format, but your app wants to read the samples at a sample rate of 44.1 kHz so it can iterate with other components (like a audio processing graph) without any weird playback effects. If this initializer is not used then a non-interleaved float format will be assumed.
@return The newly created EZAudioFile instance.
*/
- (instancetype)initWithURL:(NSURL*)url
delegate:(id<EZAudioFileDelegate>)delegate
permission:(EZAudioFilePermission)permission
fileFormat:(AudioStreamBasicDescription)fileFormat
clientFormat:(AudioStreamBasicDescription)clientFormat;
//------------------------------------------------------------------------------
#pragma mark - Class Initializers
///-----------------------------------------------------------
/// @name Class Initializers
///-----------------------------------------------------------
//------------------------------------------------------------------------------
/**
@name Class Initializers
*/
/**
Class method that creates a new instance of the EZAudioFile using a file path URL.
@param url The file path reference of the audio file as an NSURL.
@return The newly created EZAudioFile instance.
*/
+(EZAudioFile*)audioFileWithURL:(NSURL*)url;
+ (instancetype)audioFileWithURL:(NSURL*)url;
//------------------------------------------------------------------------------
/**
Class method that creates a new instance of the EZAudioFile using a file path URL.
@param url The file path reference of the audio file as an NSURL.
@param permission A constant describing what we intend on doing with the audio file (read, write, or both)
@param fileFormat An AudioStreamBasicDescription that will be used to create the audio file if it does not exist if the permission argument is set to EZAudioFilePermissionWrite or EZAudioFilePermissionReadWrite. Not used for EZAudioFilePermissionRead permission.
@return The newly created EZAudioFile instance.
*/
+ (instancetype)audioFileWithURL:(NSURL*)url
permission:(EZAudioFilePermission)permission
fileFormat:(AudioStreamBasicDescription)fileFormat;
//------------------------------------------------------------------------------
/**
Class method that creates a new instance of the EZAudioFile using a file path URL and allows specifying an EZAudioFileDelegate.
@param url The file path reference of the audio file as an NSURL.
@param delegate The audio file delegate that receives events specified by the EZAudioFileDelegate protocol
@param permission A constant describing what we intend on doing with the audio file (read, write, or both)
@param fileFormat An AudioStreamBasicDescription that will be used to create the audio file if it does not exist if the permission argument is set to EZAudioFilePermissionWrite or EZAudioFilePermissionReadWrite. Not used for EZAudioFilePermissionRead permission.
@return The newly created EZAudioFile instance.
*/
+(EZAudioFile*)audioFileWithURL:(NSURL*)url
andDelegate:(id<EZAudioFileDelegate>)delegate;
+ (instancetype) audioFileWithURL:(NSURL*)url
delegate:(id<EZAudioFileDelegate>)delegate
permission:(EZAudioFilePermission)permission
fileFormat:(AudioStreamBasicDescription)fileFormat;
//------------------------------------------------------------------------------
/**
Class method that creates a new instance of the EZAudioFile using a file path URL and allows specifying an EZAudioFileDelegate, a read/write permission, a file format incase a new file is being written, and a client format for a format that will be used when read samples (different from file format).
@param url The file path reference of the audio file as an NSURL.
@param delegate The audio file delegate that receives events specified by the EZAudioFileDelegate protocol
@param permission A constant describing what we intend on doing with the audio file (read, write, or both)
@param fileFormat An AudioStreamBasicDescription that will be used to create the audio file if it does not exist if the permission argument is set to EZAudioFilePermissionWrite or EZAudioFilePermissionReadWrite. Not used for EZAudioFilePermissionRead permission.
@param clientFormat An AudioStreamBasicDescription that will be used as the client format on the audio file. A client format is different from the file format in that it is the format of the other components interacting with this file. For instance, the file on disk could be a 22.5 kHz, float format, but we might have an audio processing graph that has a 44.1 kHz, signed integer format that we'd like to interact with. The client format lets us set that 44.1 kHz format on the audio file to properly read samples from it with any interpolation or format conversion that must take place. If not specified the default value is equal to the class method, 'defaultClientFormat'
@return The newly created EZAudioFile instance.
*/
+ (instancetype)audioFileWithURL:(NSURL*)url
delegate:(id<EZAudioFileDelegate>)delegate
permission:(EZAudioFilePermission)permission
fileFormat:(AudioStreamBasicDescription)fileFormat
clientFormat:(AudioStreamBasicDescription)clientFormat;;
//------------------------------------------------------------------------------
#pragma mark - Class Methods
///-----------------------------------------------------------
/// @name Class Methods
///-----------------------------------------------------------
//------------------------------------------------------------------------------
/**
@name Class Methods
*/
/**
A class method that subclasses can override to specify the default client format that will be used to read audio data from this file. A client format is different from the file format in that it is the format of the other components interacting with this file. For instance, the file on disk could be a 22.5 kHz, float format, but we might have an audio processing graph that has a 44.1 kHz, signed integer format that we'd like to interact with. The client format lets us set that 44.1 kHz format on the audio file to properly read samples from it with any interpolation or format conversion that must take place. Default is stereo, non-interleaved, 44.1 kHz.
@return An AudioStreamBasicDescription that serves as the audio file's client format.
*/
+ (AudioStreamBasicDescription)defaultClientFormat;
/**
Provides an array of the supported audio files types. Each audio file type is provided as a string, i.e. @"caf". Useful for filtering lists of files in an open panel to only the types allowed.
@return An array of NSString objects representing the represented file types.
*/
+(NSArray*)supportedAudioFileTypes;
+ (NSArray *)supportedAudioFileTypes;
//------------------------------------------------------------------------------
#pragma mark - Events
///-----------------------------------------------------------
/// @name Reading The Audio File
///-----------------------------------------------------------
//------------------------------------------------------------------------------
/**
@name Reading The Audio File
*/
/**
Reads a specified number of frames from the audio file. In addition, this will notify the EZAudioFileDelegate (if specified) of the read data as a float array with the audioFile:readAudio:withBufferSize:withNumberOfChannels: event and the new seek position within the file with the audioFile:updatedPosition: event.
@@ -147,95 +253,141 @@ typedef void (^WaveformDataCompletionBlock)(float *waveformData, UInt32 length);
@param eof A pointer to a BOOL in which to store whether the read operation reached the end of the audio file.
*/
-(void)readFrames:(UInt32)frames
audioBufferList:(AudioBufferList*)audioBufferList
bufferSize:(UInt32*)bufferSize
eof:(BOOL*)eof;
audioBufferList:(AudioBufferList *)audioBufferList
bufferSize:(UInt32 *)bufferSize
eof:(BOOL *)eof;
///-----------------------------------------------------------
/// @name Seeking Through The Audio File
///-----------------------------------------------------------
//------------------------------------------------------------------------------
#pragma mark - Seeking Through The Audio File
//------------------------------------------------------------------------------
/**
@name Seeking Through The Audio File
*/
/**
Seeks through an audio file to a specified frame. This will notify the EZAudioFileDelegate (if specified) with the audioFile:updatedPosition: function.
@param frame The new frame position to seek to as a SInt64.
*/
-(void)seekToFrame:(SInt64)frame;
- (void)seekToFrame:(SInt64)frame;
//------------------------------------------------------------------------------
#pragma mark - Getters
///-----------------------------------------------------------
/// @name Getting Information About The Audio File
///-----------------------------------------------------------
//------------------------------------------------------------------------------
/**
@name Getting Information About The Audio File
*/
/**
Provides the AudioStreamBasicDescription structure used within the app. The file's format will be converted to this format and then sent back as either a float array or a `AudioBufferList` pointer. Use this when communicating with other EZAudio components.
@return An AudioStreamBasicDescription structure describing the format of the audio file.
*/
-(AudioStreamBasicDescription)clientFormat;
- (AudioStreamBasicDescription)clientFormat;
//------------------------------------------------------------------------------
/**
Provides the AudioStreamBasicDescription structure containing the format of the file.
@return An AudioStreamBasicDescription structure describing the format of the audio file.
*/
-(AudioStreamBasicDescription)fileFormat;
- (AudioStreamBasicDescription)fileFormat;
//------------------------------------------------------------------------------
/**
Provides the frame index (a.k.a the seek positon) within the audio file as an integer. This can be helpful when seeking through the audio file.
@return The current frame index within the audio file as a SInt64.
*/
-(SInt64)frameIndex;
- (SInt64)frameIndex;
//------------------------------------------------------------------------------
/**
Provides a dictionary containing the metadata (ID3) tags that are included in the header for the audio file. Typically this contains stuff like artist, title, release year, etc.
@return An NSDictionary containing the metadata for the audio file.
*/
-(NSDictionary *)metadata;
- (NSDictionary *)metadata;
//------------------------------------------------------------------------------
/**
Provides the total duration of the audio file in seconds.
@return The total duration of the audio file as a Float32.
*/
-(Float32)totalDuration;
- (NSTimeInterval)totalDuration;
//------------------------------------------------------------------------------
/**
Provides the total frame count of the audio file.
@return The total number of frames in the audio file as a SInt64.
Provides the total frame count of the audio file in the client format.
@return The total number of frames in the audio file in the AudioStreamBasicDescription representing the client format as a SInt64.
*/
-(SInt64)totalFrames;
- (SInt64)totalClientFrames;
//------------------------------------------------------------------------------
/**
Provides the total frame count of the audio file in the file format.
@return The total number of frames in the audio file in the AudioStreamBasicDescription representing the file format as a SInt64.
*/
- (SInt64)totalFrames;
//------------------------------------------------------------------------------
/**
Provides the NSURL for the audio file.
@return An NSURL representing the path of the EZAudioFile instance.
*/
-(NSURL*)url;
- (NSURL*)url;
#pragma mark - Helpers
///-----------------------------------------------------------
/// @name Manipulating The Audio Data
///-----------------------------------------------------------
//------------------------------------------------------------------------------
#pragma mark - Setters
//------------------------------------------------------------------------------
/**
Tells the caller whether the EZAudioFile has cached waveform data that was loaded via the getWaveformDataWithCompletionBlock: function.
* @return A BOOL indicating whether there is cached waveform data
A client format is different from the file format in that it is the format of the other components interacting with this file. For instance, the file on disk could be a 22.5 kHz, float format, but we might have an audio processing graph that has a 44.1 kHz, signed integer format that we'd like to interact with. The client format lets us set that 44.1 kHz format on the audio file to properly read samples from it with any interpolation or format conversion that must take place. Default is stereo, non-interleaved, 44.1 kHz.
@param clientFormat An AudioStreamBasicDescription that should serve as the audio file's client format.
*/
-(BOOL)hasLoadedAudioData;
- (void)setClientFormat:(AudioStreamBasicDescription)clientFormat;
//------------------------------------------------------------------------------
#pragma mark - Helpers
//------------------------------------------------------------------------------
/**
Synchronously pulls the waveform amplitude data into a float array for the receiver. This returns a waveform with a default resolution of 1024, meaning there are 1024 data points to plot the waveform.
@param numberOfPoints A UInt32 representing the number of data points you need. The higher the number of points the more detailed the waveform will be.
@return A EZAudioWaveformData instance containing the audio data for all channels of the audio.
*/
- (EZAudioWaveformData *)getWaveformData;
//------------------------------------------------------------------------------
/**
Synchronously pulls the waveform amplitude data into a float array for the receiver.
@param numberOfPoints A UInt32 representing the number of data points you need. The higher the number of points the more detailed the waveform will be.
@return A EZAudioWaveformData instance containing the audio data for all channels of the audio.
*/
- (EZAudioWaveformData *)getWaveformDataWithNumberOfPoints:(UInt32)numberOfPoints;
//------------------------------------------------------------------------------
/**
Asynchronously pulls the waveform amplitude data into a float array for the receiver. This returns a waveform with a default resolution of 1024, meaning there are 1024 data points to plot the waveform.
@param completion A WaveformDataCompletionBlock that executes when the waveform data has been extracted. Provides a `EZAudioWaveformData` instance containing the waveform data for all audio channels.
*/
- (void)getWaveformDataWithCompletionBlock:(WaveformDataCompletionBlock)completion;
//------------------------------------------------------------------------------
/**
Asynchronously pulls the waveform amplitude data into a float array for the receiver.
@param waveformDataCompletionBlock A WaveformDataCompletionBlock that executes when the waveform data has been extracted. Provides the waveform data as a float array and the length of the array.
@param numberOfPoints A UInt32 representing the number of data points you need. The higher the number of points the more detailed the waveform will be.
@param completion A WaveformDataCompletionBlock that executes when the waveform data has been extracted. Provides a `EZAudioWaveformData` instance containing the waveform data for all audio channels.
*/
-(void)getWaveformDataWithCompletionBlock:(WaveformDataCompletionBlock)waveformDataCompletionBlock;
- (void)getWaveformDataWithNumberOfPoints:(UInt32)numberOfPoints
completion:(WaveformDataCompletionBlock)completion;
/**
Provides the minimum number of buffers that would be required with the constant frames read rate provided.
@param frameRate A constant frame rate to use when calculating the number of buffers needed as a UInt32.
@return The minimum number of buffers required for the constant frames read rate provided as a UInt32.
*/
-(UInt32)minBuffersWithFrameRate:(UInt32)frameRate;
/**
Provides a frame rate to use when drawing and averaging a bin of values to create each point in a graph. The ideal amount of end buffers seems to be between 1000-3000 so we determine a frame rate per audio file that can achieve a high degree of detail for the entire waveform.
@return A frame rate value as a UInt32 to use when reading frames in a file.
*/
-(UInt32)recommendedDrawingFrameRate;
//------------------------------------------------------------------------------
@end
+561 -304
View File
@@ -25,343 +25,600 @@
#import "EZAudioFile.h"
//------------------------------------------------------------------------------
#import "EZAudio.h"
#import "EZAudioConverter.h"
#import "EZAudioWaveformData.h"
#include <pthread.h>
#define kEZAudioFileWaveformDefaultResolution (1024)
//------------------------------------------------------------------------------
@interface EZAudioFile (){
// Reading from the audio file
ExtAudioFileRef _audioFile;
AudioStreamBasicDescription _clientFormat;
AudioStreamBasicDescription _fileFormat;
float **_floatBuffers;
AEFloatConverter *_floatConverter;
SInt64 _frameIndex;
CFURLRef _sourceURL;
Float32 _totalDuration;
SInt64 _totalFrames;
// Waveform Data
float *_waveformData;
UInt32 _waveformFrameRate;
UInt32 _waveformTotalBuffers;
}
// errors
static OSStatus EZAudioFileReadPermissionFileDoesNotExistCode = -88776;
// constants
static UInt32 EZAudioFileWaveformDefaultResolution = 1024;
static NSString *EZAudioFileWaveformDataQueueIdentifier = @"com.ezaudio.waveformQueue";
//------------------------------------------------------------------------------
typedef struct
{
AudioFileID audioFileID;
AudioStreamBasicDescription clientFormat;
Float32 duration;
ExtAudioFileRef extAudioFileRef;
AudioStreamBasicDescription fileFormat;
SInt64 frames;
EZAudioFilePermission permission;
CFURLRef sourceURL;
} EZAudioFileInfo;
//------------------------------------------------------------------------------
#pragma mark - EZAudioFile
//------------------------------------------------------------------------------
@interface EZAudioFile ()
@property (nonatomic) EZAudioFileInfo info;
@property (nonatomic) pthread_mutex_t lock;
@property (nonatomic) dispatch_queue_t waveformQueue;
@end
//------------------------------------------------------------------------------
@implementation EZAudioFile
@synthesize audioFileDelegate = _audioFileDelegate;
@synthesize waveformResolution = _waveformResolution;
#pragma mark - Initializers
-(EZAudioFile*)initWithURL:(NSURL*)url {
self = [super init];
if(self){
_sourceURL = (__bridge CFURLRef)url;
[self _configureAudioFile];
}
return self;
}
//------------------------------------------------------------------------------
#pragma mark - Initialization
//------------------------------------------------------------------------------
-(EZAudioFile *)initWithURL:(NSURL *)url andDelegate:(id<EZAudioFileDelegate>)delegate {
self = [self initWithURL:url];
if(self){
self.audioFileDelegate = delegate;
}
return self;
}
#pragma mark - Class Initializers
+(EZAudioFile*)audioFileWithURL:(NSURL*)url {
return [[EZAudioFile alloc] initWithURL:url];
}
+(EZAudioFile *)audioFileWithURL:(NSURL *)url andDelegate:(id<EZAudioFileDelegate>)delegate {
return [[EZAudioFile alloc] initWithURL:url andDelegate:delegate];
}
#pragma mark - Class Methods
+(NSArray *)supportedAudioFileTypes {
return @[ @"aac",
@"caf",
@"aif",
@"aiff",
@"aifc",
@"mp3",
@"mp4",
@"m4a",
@"snd",
@"au",
@"sd2",
@"wav" ];
}
#pragma mark - Private Configuation
-(void)_configureAudioFile {
// Source URL should not be nil
NSAssert(_sourceURL,@"Source URL was not specified correctly.");
// Try to open the file for reading
[EZAudio checkResult:ExtAudioFileOpenURL(_sourceURL,&_audioFile)
operation:"Failed to open audio file for reading"];
// Try pulling the stream description
UInt32 size = sizeof(_fileFormat);
[EZAudio checkResult:ExtAudioFileGetProperty(_audioFile,kExtAudioFileProperty_FileDataFormat, &size, &_fileFormat)
operation:"Failed to get audio stream basic description of input file"];
// Try pulling the total frame size
size = sizeof(_totalFrames);
[EZAudio checkResult:ExtAudioFileGetProperty(_audioFile,kExtAudioFileProperty_FileLengthFrames, &size, &_totalFrames)
operation:"Failed to get total frames of input file"];
_totalFrames = MAX(1, _totalFrames);
// Total duration
_totalDuration = _totalFrames / _fileFormat.mSampleRate;
// Set the client format on the stream
switch (_fileFormat.mChannelsPerFrame) {
case 1:
_clientFormat = [EZAudio monoFloatFormatWithSampleRate:_fileFormat.mSampleRate];
break;
case 2:
_clientFormat = [EZAudio stereoFloatInterleavedFormatWithSampleRate:_fileFormat.mSampleRate];
break;
default:
break;
}
[EZAudio checkResult:ExtAudioFileSetProperty(_audioFile,
kExtAudioFileProperty_ClientDataFormat,
sizeof (AudioStreamBasicDescription),
&_clientFormat)
operation:"Couldn't set client data format on input ext file"];
// Allocate the float buffers
_floatConverter = [[AEFloatConverter alloc] initWithSourceFormat:_clientFormat];
size_t sizeToAllocate = sizeof(float*) * _clientFormat.mChannelsPerFrame;
sizeToAllocate = MAX(8, sizeToAllocate);
_floatBuffers = (float**)malloc( sizeToAllocate );
UInt32 outputBufferSize = 32 * 1024; // 32 KB
for ( int i=0; i< _clientFormat.mChannelsPerFrame; i++ ) {
_floatBuffers[i] = (float*)malloc(outputBufferSize);
}
[EZAudio printASBD:_fileFormat];
// There's no waveform data yet
_waveformData = NULL;
// Set the default resolution for the waveform data
_waveformResolution = kEZAudioFileWaveformDefaultResolution;
}
#pragma mark - Events
-(void)readFrames:(UInt32)frames
audioBufferList:(AudioBufferList *)audioBufferList
bufferSize:(UInt32 *)bufferSize
eof:(BOOL *)eof {
[EZAudio checkResult:ExtAudioFileRead(_audioFile,
&frames,
audioBufferList)
operation:"Failed to read audio data from audio file"];
*bufferSize = audioBufferList->mBuffers[0].mDataByteSize/sizeof(float);
*eof = frames == 0;
_frameIndex += frames;
if( self.audioFileDelegate ){
if( [self.audioFileDelegate respondsToSelector:@selector(audioFile:updatedPosition:)] ){
[self.audioFileDelegate audioFile:self
updatedPosition:_frameIndex];
}
if( [self.audioFileDelegate respondsToSelector:@selector(audioFile:readAudio:withBufferSize:withNumberOfChannels:)] ){
AEFloatConverterToFloat(_floatConverter,audioBufferList,_floatBuffers,frames);
[self.audioFileDelegate audioFile:self
readAudio:_floatBuffers
withBufferSize:frames
withNumberOfChannels:_clientFormat.mChannelsPerFrame];
}
}
}
-(void)seekToFrame:(SInt64)frame {
[EZAudio checkResult:ExtAudioFileSeek(_audioFile,frame)
operation:"Failed to seek frame position within audio file"];
_frameIndex = frame;
if( self.audioFileDelegate ){
if( [self.audioFileDelegate respondsToSelector:@selector(audioFile:updatedPosition:)] ){
[self.audioFileDelegate audioFile:self updatedPosition:_frameIndex];
}
}
}
#pragma mark - Getters
-(BOOL)hasLoadedAudioData {
return _waveformData != NULL;
}
-(void)getWaveformDataWithCompletionBlock:(WaveformDataCompletionBlock)waveformDataCompletionBlock {
SInt64 currentFramePosition = _frameIndex;
if( _waveformData != NULL ){
waveformDataCompletionBlock( _waveformData, _waveformTotalBuffers );
return;
}
_waveformFrameRate = [self recommendedDrawingFrameRate];
_waveformTotalBuffers = [self minBuffersWithFrameRate:_waveformFrameRate];
_waveformData = (float*)malloc(sizeof(float)*_waveformTotalBuffers);
if( self.totalFrames == 0 ){
waveformDataCompletionBlock( _waveformData, _waveformTotalBuffers );
return;
}
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0ul), ^{
for( int i = 0; i < _waveformTotalBuffers; i++ ){
// Take a snapshot of each buffer through the audio file to form the waveform
AudioBufferList *bufferList = [EZAudio audioBufferListWithNumberOfFrames:_waveformFrameRate
numberOfChannels:_clientFormat.mChannelsPerFrame
interleaved:YES];
UInt32 bufferSize;
BOOL eof;
// Read in the specified number of frames
[EZAudio checkResult:ExtAudioFileRead(_audioFile,
&_waveformFrameRate,
bufferList)
operation:"Failed to read audio data from audio file"];
bufferSize = bufferList->mBuffers[0].mDataByteSize/sizeof(float);
bufferSize = MAX(1, bufferSize);
eof = _waveformFrameRate == 0;
_frameIndex += _waveformFrameRate;
// Calculate RMS of each buffer
float rms = [EZAudio RMS:bufferList->mBuffers[0].mData
length:bufferSize];
_waveformData[i] = rms;
// Since we malloc'ed, we should cleanup
[EZAudio freeBufferList:bufferList];
}
// Seek the audio file back to the beginning
[EZAudio checkResult:ExtAudioFileSeek(_audioFile,currentFramePosition)
operation:"Failed to seek frame position within audio file"];
_frameIndex = currentFramePosition;
// Once we're done send off the waveform data
dispatch_async(dispatch_get_main_queue(), ^{
waveformDataCompletionBlock( _waveformData, _waveformTotalBuffers );
});
});
}
-(AudioStreamBasicDescription)clientFormat {
return _clientFormat;
}
-(AudioStreamBasicDescription)fileFormat {
return _fileFormat;
}
-(SInt64)frameIndex {
return _frameIndex;
}
-(NSDictionary *)metadata
- (instancetype)init
{
AudioFileID audioFileID;
UInt32 propSize = sizeof(audioFileID);
self = [super init];
if (self)
{
memset(&_info, 0, sizeof(_info));
_info.permission = EZAudioFilePermissionRead;
pthread_mutex_init(&_lock, NULL);
_waveformQueue = dispatch_queue_create(EZAudioFileWaveformDataQueueIdentifier.UTF8String, DISPATCH_QUEUE_PRIORITY_DEFAULT);
}
return self;
}
//------------------------------------------------------------------------------
- (instancetype)initWithURL:(NSURL *)url
{
AudioStreamBasicDescription asbd;
return [self initWithURL:url
permission:EZAudioFilePermissionRead
fileFormat:asbd];
}
//------------------------------------------------------------------------------
- (instancetype)initWithURL:(NSURL*)url
permission:(EZAudioFilePermission)permission
fileFormat:(AudioStreamBasicDescription)fileFormat
{
return [self initWithURL:url
delegate:nil
permission:permission
fileFormat:fileFormat];
}
//------------------------------------------------------------------------------
- (instancetype)initWithURL:(NSURL*)url
delegate:(id<EZAudioFileDelegate>)delegate
permission:(EZAudioFilePermission)permission
fileFormat:(AudioStreamBasicDescription)fileFormat
{
return [self initWithURL:url
delegate:delegate
permission:permission
fileFormat:fileFormat
clientFormat:[self.class defaultClientFormat]];
}
//------------------------------------------------------------------------------
- (instancetype)initWithURL:(NSURL*)url
delegate:(id<EZAudioFileDelegate>)delegate
permission:(EZAudioFilePermission)permission
fileFormat:(AudioStreamBasicDescription)fileFormat
clientFormat:(AudioStreamBasicDescription)clientFormat
{
self = [self init];
if(self)
{
_info.clientFormat = clientFormat;
_info.fileFormat = fileFormat;
_info.permission = permission;
_info.sourceURL = (__bridge CFURLRef)url;
self.delegate = delegate;
[self setup];
}
return self;
}
//------------------------------------------------------------------------------
#pragma mark - Class Initializers
//------------------------------------------------------------------------------
+ (instancetype)audioFileWithURL:(NSURL*)url
{
return [[self alloc] initWithURL:url];
}
//------------------------------------------------------------------------------
+ (instancetype)audioFileWithURL:(NSURL*)url
permission:(EZAudioFilePermission)permission
fileFormat:(AudioStreamBasicDescription)fileFormat
{
return [[self alloc] initWithURL:url
permission:permission
fileFormat:fileFormat];
}
//------------------------------------------------------------------------------
+ (instancetype)audioFileWithURL:(NSURL*)url
delegate:(id<EZAudioFileDelegate>)delegate
permission:(EZAudioFilePermission)permission
fileFormat:(AudioStreamBasicDescription)fileFormat
{
return [[self alloc] initWithURL:url
delegate:delegate
permission:permission
fileFormat:fileFormat];
}
//------------------------------------------------------------------------------
+ (instancetype)audioFileWithURL:(NSURL*)url
delegate:(id<EZAudioFileDelegate>)delegate
permission:(EZAudioFilePermission)permission
fileFormat:(AudioStreamBasicDescription)fileFormat
clientFormat:(AudioStreamBasicDescription)clientFormat
{
return [[self alloc] initWithURL:url
delegate:delegate
permission:permission
fileFormat:fileFormat
clientFormat:clientFormat];
}
//------------------------------------------------------------------------------
#pragma mark - Class Methods
//------------------------------------------------------------------------------
+ (AudioStreamBasicDescription)defaultClientFormat
{
return [EZAudio stereoFloatInterleavedFormatWithSampleRate:44100];
}
//------------------------------------------------------------------------------
+ (NSArray *)supportedAudioFileTypes
{
return @[
@"aac",
@"caf",
@"aif",
@"aiff",
@"aifc",
@"mp3",
@"mp4",
@"m4a",
@"snd",
@"au",
@"sd2",
@"wav"
];
}
//------------------------------------------------------------------------------
#pragma mark - Setup
//------------------------------------------------------------------------------
- (void)setup
{
// we open the file differently depending on the permissions specified
[EZAudio checkResult:[self openAudioFile]
operation:"Failed to create/open audio file"];
[EZAudio checkResult:ExtAudioFileGetProperty(_audioFile,
kExtAudioFileProperty_AudioFile,
&propSize,
&audioFileID)
operation:"Failed to get audio file id"];
// set the client format
self.clientFormat = self.info.clientFormat;
}
//------------------------------------------------------------------------------
#pragma mark - Creating/Opening Audio File
//------------------------------------------------------------------------------
- (OSStatus)openAudioFile
{
// need a source url
NSAssert(_info.sourceURL, @"EZAudioFile cannot be created without a source url!");
// determine if the file actually exists
CFURLRef url = self.info.sourceURL;
NSURL *fileURL = (__bridge NSURL *)(url);
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:fileURL.path];
// create the file wrapper slightly differently depending what we are
// trying to do with it
OSStatus result = noErr;
EZAudioFilePermission permission = self.info.permission;
UInt32 propSize;
if (fileExists)
{
result = AudioFileOpenURL(url,
permission,
0,
&_info.audioFileID);
[EZAudio checkResult:result
operation:"failed to open audio file"];
}
else
{
// read permission is not applicable because the file does not exist
if (permission == EZAudioFilePermissionRead)
{
result = EZAudioFileReadPermissionFileDoesNotExistCode;
}
else
{
result = AudioFileCreateWithURL(url,
0,
&_info.fileFormat,
kAudioFileFlags_EraseFile,
&_info.audioFileID);
}
}
// get the ExtAudioFile wrapper
if (result == noErr)
{
[EZAudio checkResult:ExtAudioFileWrapAudioFileID(self.info.audioFileID,
false,
&_info.extAudioFileRef)
operation:"Failed to wrap audio file ID in ext audio file ref"];
}
// store the file format if we opened an existing file
if (fileExists)
{
propSize = sizeof(self.info.fileFormat);
[EZAudio checkResult:ExtAudioFileGetProperty(self.info.extAudioFileRef,
kExtAudioFileProperty_FileDataFormat,
&propSize,
&_info.fileFormat)
operation:"Failed to get file audio format on existing audio file"];
}
NSLog(@"file format......................");
[EZAudio printASBD:self.info.fileFormat];
NSLog(@"client format....................");
[EZAudio printASBD:self.info.clientFormat];
// done
return result;
}
//------------------------------------------------------------------------------
#pragma mark - Events
//------------------------------------------------------------------------------
- (void)readFrames:(UInt32)frames
audioBufferList:(AudioBufferList *)audioBufferList
bufferSize:(UInt32 *)bufferSize
eof:(BOOL *)eof
{
if (pthread_mutex_trylock(&_lock) == 0)
{
// perform read
[EZAudio checkResult:ExtAudioFileRead(self.info.extAudioFileRef,
&frames,
audioBufferList)
operation:"Failed to read audio data from file"];
*bufferSize = frames;
*eof = frames == 0;
pthread_mutex_unlock(&_lock);
// notify delegate
if ([self.delegate respondsToSelector:@selector(audioFile:updatedPosition:)])
{
[self.delegate audioFile:self
updatedPosition:self.frameIndex];
}
if ([self.delegate respondsToSelector:@selector(audioFile:readAudio:withBufferSize:withNumberOfChannels:)])
{
[self.delegate audioFile:self
readAudio:nil
withBufferSize:*bufferSize
withNumberOfChannels:self.info.clientFormat.mChannelsPerFrame];
}
}
}
//------------------------------------------------------------------------------
- (void)seekToFrame:(SInt64)frame
{
if (pthread_mutex_trylock(&_lock) == 0)
{
[EZAudio checkResult:ExtAudioFileSeek(self.info.extAudioFileRef,
frame)
operation:"Failed to seek frame position within audio file"];
pthread_mutex_unlock(&_lock);
// notify delegate
if ([self.delegate respondsToSelector:@selector(audioFile:updatedPosition:)])
{
[self.delegate audioFile:self
updatedPosition:self.frameIndex];
}
}
}
//------------------------------------------------------------------------------
#pragma mark - Getters
//------------------------------------------------------------------------------
- (EZAudioWaveformData *)getWaveformData
{
return [self getWaveformDataWithNumberOfPoints:EZAudioFileWaveformDefaultResolution];
}
//------------------------------------------------------------------------------
- (EZAudioWaveformData *)getWaveformDataWithNumberOfPoints:(UInt32)numberOfPoints
{
EZAudioWaveformData *waveformData;
if (pthread_mutex_trylock(&_lock) == 0)
{
// store current frame
SInt64 currentFrame = self.frameIndex;
UInt32 channels = self.clientFormat.mChannelsPerFrame;
BOOL interleaved = [EZAudio isInterleaved:self.clientFormat];
SInt64 totalFrames = self.totalClientFrames;
SInt64 framesPerBuffer = ((SInt64) totalFrames / numberOfPoints);
SInt64 framesPerChannel = framesPerBuffer / channels;
float **data = (float **)malloc( sizeof(float*) * channels );
for (int i = 0; i < channels; i++)
{
data[i] = (float *)malloc( sizeof(float) * numberOfPoints );
}
// seek to 0
[EZAudio checkResult:ExtAudioFileSeek(self.info.extAudioFileRef,
0)
operation:"Failed to seek frame position within audio file"];
// allocate an audio buffer list
AudioBufferList *audioBufferList = [EZAudio audioBufferListWithNumberOfFrames:(UInt32)totalFrames
numberOfChannels:self.info.clientFormat.mChannelsPerFrame
interleaved:interleaved];
UInt32 bufferSize = (UInt32)totalFrames;
[EZAudio checkResult:ExtAudioFileRead(self.info.extAudioFileRef,
&bufferSize,
audioBufferList)
operation:"Failed to read audio data from file waveform"];
// read through file and calculate rms at each point
SInt64 offset = 0;
for (SInt64 i = 0; i < numberOfPoints; i++)
{
float buffer[framesPerBuffer];
if (interleaved)
{
float *samples = (float *)audioBufferList->mBuffers[0].mData;
memcpy(buffer, &samples[offset], framesPerBuffer * sizeof(float));
for (int channel = 0; channel < channels; channel++)
{
float channelData[framesPerChannel];
for (int frame = 0; frame < framesPerChannel; frame++)
{
channelData[frame] = buffer[frame * channels + channel];
}
float rms = [EZAudio RMS:channelData length:(UInt32)framesPerChannel];
data[channel][i] = rms;
}
offset += channels * framesPerBuffer;
}
else
{
for (int channel = 0; channel < channels; channel++)
{
float *samples = (float *)audioBufferList->mBuffers[channel].mData;
memcpy(buffer, &samples[offset], framesPerBuffer * sizeof(float));
float rms = [EZAudio RMS:buffer length:(UInt32)framesPerBuffer];
data[channel][i] = rms;
}
offset += framesPerBuffer;
}
}
// clean up
[EZAudio freeBufferList:audioBufferList];
// seek back to previous position
[EZAudio checkResult:ExtAudioFileSeek(self.info.extAudioFileRef,
currentFrame)
operation:"Failed to seek frame position within audio file"];
pthread_mutex_unlock(&_lock);
waveformData = [EZAudioWaveformData dataWithNumberOfChannels:channels
buffers:(float **)data
bufferSize:numberOfPoints];
// cleanup
for (int i = 0; i < channels; i++)
{
free(data[i]);
}
free(data);
}
return waveformData;
}
//------------------------------------------------------------------------------
- (void)getWaveformDataWithCompletionBlock:(WaveformDataCompletionBlock)waveformDataCompletionBlock
{
[self getWaveformDataWithNumberOfPoints:EZAudioFileWaveformDefaultResolution
completion:waveformDataCompletionBlock];
}
//------------------------------------------------------------------------------
- (void)getWaveformDataWithNumberOfPoints:(UInt32)numberOfPoints
completion:(WaveformDataCompletionBlock)completion
{
if (!completion)
{
return;
}
// async get waveform data
dispatch_async(self.waveformQueue, ^{
EZAudioWaveformData *waveformData = [self getWaveformDataWithNumberOfPoints:numberOfPoints];
dispatch_async(dispatch_get_main_queue(), ^{
completion(waveformData);
});
});
}
//------------------------------------------------------------------------------
- (AudioStreamBasicDescription)clientFormat
{
return self.info.clientFormat;
}
//------------------------------------------------------------------------------
- (AudioStreamBasicDescription)fileFormat
{
return self.info.fileFormat;
}
//------------------------------------------------------------------------------
- (SInt64)frameIndex
{
SInt64 frameIndex;
[EZAudio checkResult:ExtAudioFileTell(self.info.extAudioFileRef, &frameIndex)
operation:"Failed to get frame index"];
return frameIndex;
}
//------------------------------------------------------------------------------
- (NSDictionary *)metadata
{
// get size of metadata property (dictionary)
UInt32 propSize = sizeof(_info.audioFileID);
CFDictionaryRef metadata;
UInt32 isWritable;
[EZAudio checkResult:AudioFileGetPropertyInfo(audioFileID,
UInt32 writable;
[EZAudio checkResult:AudioFileGetPropertyInfo(self.info.audioFileID,
kAudioFilePropertyInfoDictionary,
&propSize,
&isWritable)
&writable)
operation:"Failed to get the size of the metadata dictionary"];
[EZAudio checkResult:AudioFileGetProperty(audioFileID,
// pull metadata
[EZAudio checkResult:AudioFileGetProperty(self.info.audioFileID,
kAudioFilePropertyInfoDictionary,
&propSize,
&metadata)
operation:"Failed to get metadata dictionary"];
return (__bridge NSDictionary *)metadata;
// cast to NSDictionary
return (__bridge NSDictionary*)metadata;
}
-(Float32)totalDuration {
return _totalDuration;
//------------------------------------------------------------------------------
- (NSTimeInterval)totalDuration
{
SInt64 totalFrames = [self totalFrames];
return (NSTimeInterval) totalFrames / self.info.fileFormat.mSampleRate;
}
-(SInt64)totalFrames {
return _totalFrames;
}
//------------------------------------------------------------------------------
-(NSURL *)url {
return (__bridge NSURL*)_sourceURL;
}
#pragma mark - Setters
-(void)setWaveformResolution:(UInt32)waveformResolution {
if( _waveformResolution != waveformResolution ){
_waveformResolution = waveformResolution;
if( _waveformData ){
free(_waveformData);
_waveformData = NULL;
- (SInt64)totalClientFrames
{
SInt64 totalFrames = [self totalFrames];
// check sample rate of client vs file format
AudioStreamBasicDescription clientFormat = self.info.clientFormat;
AudioStreamBasicDescription fileFormat = self.info.fileFormat;
BOOL sameSampleRate = clientFormat.mSampleRate == fileFormat.mSampleRate;
if (!sameSampleRate)
{
NSTimeInterval duration = [self totalDuration];
totalFrames = duration * clientFormat.mSampleRate;
}
}
return totalFrames;
}
#pragma mark - Helpers
-(UInt32)minBuffersWithFrameRate:(UInt32)frameRate {
frameRate = frameRate > 0 ? frameRate : 1;
UInt32 val = (UInt32) _totalFrames / frameRate + 1;
return MAX(1, val);
//------------------------------------------------------------------------------
- (SInt64)totalFrames
{
SInt64 totalFrames;
UInt32 size = sizeof(SInt64);
[EZAudio checkResult:ExtAudioFileGetProperty(self.info.extAudioFileRef,
kExtAudioFileProperty_FileLengthFrames,
&size,
&totalFrames)
operation:"Failed to get total frames"];
return totalFrames;
}
-(UInt32)recommendedDrawingFrameRate {
UInt32 val = 1;
if(_waveformResolution > 0){
val = (UInt32) _totalFrames / _waveformResolution;
if(val > 1)
--val;
}
return MAX(1, val);
//------------------------------------------------------------------------------
- (NSURL*)url
{
return (__bridge NSURL*)self.info.sourceURL;
}
#pragma mark - Cleanup
-(void)dealloc {
if( _waveformData ){
free(_waveformData);
_waveformData = NULL;
}
// if( _floatBuffers ){
// free(_floatBuffers);
// _floatBuffers = NULL;
// }
_frameIndex = 0;
_waveformFrameRate = 0;
_waveformTotalBuffers = 0;
if( _audioFile ){
[EZAudio checkResult:ExtAudioFileDispose(_audioFile)
operation:"Failed to dispose of audio file"];
}
//------------------------------------------------------------------------------
#pragma mark - Setters
//------------------------------------------------------------------------------
- (void)setClientFormat:(AudioStreamBasicDescription)clientFormat
{
NSAssert([EZAudio isLinearPCM:clientFormat], @"Client format must be linear PCM");
// store the client format
_info.clientFormat = clientFormat;
// set the client format on the extended audio file ref
[EZAudio checkResult:ExtAudioFileSetProperty(self.info.extAudioFileRef,
kExtAudioFileProperty_ClientDataFormat,
sizeof(clientFormat),
&clientFormat)
operation:"Couldn't set client data format on file"];
}
//------------------------------------------------------------------------------
-(void)dealloc
{
pthread_mutex_destroy(&_lock);
[EZAudio checkResult:AudioFileClose(self.info.audioFileID) operation:"Failed to close audio file"];
[EZAudio checkResult:ExtAudioFileDispose(self.info.extAudioFileRef) operation:"Failed to dispose of ext audio file"];
}
//------------------------------------------------------------------------------
@end
+1
View File
@@ -26,6 +26,7 @@
#import "EZAudioPlotGL.h"
#import "EZAudio.h"
#import "EZAudioPlot.h"
#if TARGET_OS_IPHONE
#import "EZAudioPlotGLKViewController.h"
+35
View File
@@ -0,0 +1,35 @@
//
// EZAudioWaveformData.h
// EZAudioPlayFileExample
//
// Created by Syed Haris Ali on 2/14/15.
// Copyright (c) 2015 Syed Haris Ali. All rights reserved.
//
#import <Foundation/Foundation.h>
//------------------------------------------------------------------------------
#pragma mark - EZAudioWaveformData
//------------------------------------------------------------------------------
@interface EZAudioWaveformData : NSObject
//------------------------------------------------------------------------------
+ (instancetype) dataWithNumberOfChannels:(int)numberOfChannels
buffers:(float **)buffers
bufferSize:(UInt32)bufferSize;
//------------------------------------------------------------------------------
@property (nonatomic, assign, readonly) int numberOfChannels;
@property (nonatomic, assign, readonly) float **buffers;
@property (nonatomic, assign, readonly) UInt32 bufferSize;
//------------------------------------------------------------------------------
- (float *) bufferForChannel:(int)channel;
//------------------------------------------------------------------------------
@end
+74
View File
@@ -0,0 +1,74 @@
//
// EZAudioWaveformData.m
// EZAudioPlayFileExample
//
// Created by Syed Haris Ali on 2/14/15.
// Copyright (c) 2015 Syed Haris Ali. All rights reserved.
//
#import "EZAudioWaveformData.h"
//------------------------------------------------------------------------------
#pragma mark - EZAudioWaveformData
//------------------------------------------------------------------------------
@interface EZAudioWaveformData ()
@property (nonatomic, assign, readwrite) int numberOfChannels;
@property (nonatomic, assign, readwrite) float **buffers;
@property (nonatomic, assign, readwrite) UInt32 bufferSize;
@end
//------------------------------------------------------------------------------
@implementation EZAudioWaveformData
//------------------------------------------------------------------------------
- (void)dealloc
{
for (int i = 0; i < self.numberOfChannels; i++)
{
free(self.buffers[i]);
}
free(self.buffers);
}
//------------------------------------------------------------------------------
+ (instancetype)dataWithNumberOfChannels:(int)numberOfChannels
buffers:(float **)buffers
bufferSize:(UInt32)bufferSize
{
id waveformData = [[self alloc] init];
size_t size = sizeof(float *) * numberOfChannels;
float **buffersCopy = (float **)malloc(size);
for (int i = 0; i < numberOfChannels; i++)
{
size = sizeof(float) * bufferSize;
buffersCopy[i] = (float *)malloc(size);
memcpy(buffersCopy[i], buffers[i], size);
}
((EZAudioWaveformData *)waveformData).buffers = buffersCopy;
((EZAudioWaveformData *)waveformData).bufferSize = bufferSize;
((EZAudioWaveformData *)waveformData).numberOfChannels = numberOfChannels;
return waveformData;
}
//------------------------------------------------------------------------------
- (float *)bufferForChannel:(int)channel
{
float *buffer = NULL;
if (channel < self.numberOfChannels)
{
buffer = self.buffers[channel];
}
return buffer;
}
//------------------------------------------------------------------------------
@end
-1
View File
@@ -25,7 +25,6 @@
#import <Foundation/Foundation.h>
#import <AudioToolbox/AudioToolbox.h>
#import "AEFloatConverter.h"
#import "TargetConditionals.h"
@class EZAudio;
+12 -13
View File
@@ -51,7 +51,6 @@ static const UInt32 kEZAudioMicrophoneEnableFlag = 1;
BOOL _isFetching;
/// Stream Description
AEFloatConverter *converter;
AudioStreamBasicDescription streamFormat;
/// Audio Graph and Input/Output Units
@@ -100,10 +99,10 @@ static OSStatus inputCallback(void *inRefCon,
if( microphone.microphoneDelegate ){
// THIS IS NOT OCCURING ON THE MAIN THREAD
if( [microphone.microphoneDelegate respondsToSelector:@selector(microphone:hasAudioReceived:withBufferSize:withNumberOfChannels:)] ){
AEFloatConverterToFloat(microphone->converter,
microphone->microphoneInputBuffer,
microphone->floatBuffers,
inNumberFrames);
// AEFloatConverterToFloat(microphone->converter,
// microphone->microphoneInputBuffer,
// microphone->floatBuffers,
// inNumberFrames);
[microphone.microphoneDelegate microphone:microphone
hasAudioReceived:microphone->floatBuffers
withBufferSize:inNumberFrames
@@ -557,14 +556,14 @@ static OSStatus inputCallback(void *inRefCon,
#pragma mark - Float Converter Initialization
-(void)_configureFloatConverterWithFrameSize:(UInt32)bufferFrameSize {
UInt32 bufferSizeBytes = bufferFrameSize * streamFormat.mBytesPerFrame;
converter = [[AEFloatConverter alloc] initWithSourceFormat:streamFormat];
floatBuffers = (float**)malloc(sizeof(float*)*streamFormat.mChannelsPerFrame);
assert(floatBuffers);
for ( int i=0; i<streamFormat.mChannelsPerFrame; i++ ) {
floatBuffers[i] = (float*)malloc(bufferSizeBytes);
assert(floatBuffers[i]);
}
// UInt32 bufferSizeBytes = bufferFrameSize * streamFormat.mBytesPerFrame;
// converter = [[AEFloatConverter alloc] initWithSourceFormat:streamFormat];
// floatBuffers = (float**)malloc(sizeof(float*)*streamFormat.mChannelsPerFrame);
// assert(floatBuffers);
// for ( int i=0; i<streamFormat.mChannelsPerFrame; i++ ) {
// floatBuffers[i] = (float*)malloc(bufferSizeBytes);
// assert(floatBuffers[i]);
// }
}
#pragma mark - Input Callback Initialization
@@ -7,6 +7,9 @@
objects = {
/* Begin PBXBuildFile section */
668E4F821A905DAF00F4B814 /* EZAudioConverter.m in Sources */ = {isa = PBXBuildFile; fileRef = 668E4F811A905DAF00F4B814 /* EZAudioConverter.m */; };
668E4F851A905F8700F4B814 /* EZAudioWaveformData.m in Sources */ = {isa = PBXBuildFile; fileRef = 668E4F841A905F8700F4B814 /* EZAudioWaveformData.m */; };
668E4F881A90607500F4B814 /* EZMicrophone.m in Sources */ = {isa = PBXBuildFile; fileRef = 668E4F871A90607500F4B814 /* EZMicrophone.m */; };
94056EFB185BD83400EB94BA /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 94056EFA185BD83400EB94BA /* Cocoa.framework */; };
94056F05185BD83400EB94BA /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 94056F03185BD83400EB94BA /* InfoPlist.strings */; };
94056F07185BD83400EB94BA /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 94056F06185BD83400EB94BA /* main.m */; };
@@ -27,13 +30,11 @@
94056F66185BDB4700EB94BA /* AudioUnit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 94056F63185BDB4700EB94BA /* AudioUnit.framework */; };
94056F67185BDB4700EB94BA /* CoreAudio.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 94056F64185BDB4700EB94BA /* CoreAudio.framework */; };
9417A6D51865928C00D9D37B /* simple-drum-beat.wav in Resources */ = {isa = PBXBuildFile; fileRef = 9417A6D41865928C00D9D37B /* simple-drum-beat.wav */; };
9417A73E1867DD3400D9D37B /* AEFloatConverter.m in Sources */ = {isa = PBXBuildFile; fileRef = 9417A7261867DD3400D9D37B /* AEFloatConverter.m */; };
9417A73F1867DD3400D9D37B /* EZAudio.m in Sources */ = {isa = PBXBuildFile; fileRef = 9417A7281867DD3400D9D37B /* EZAudio.m */; };
9417A7401867DD3400D9D37B /* EZAudioFile.m in Sources */ = {isa = PBXBuildFile; fileRef = 9417A72A1867DD3400D9D37B /* EZAudioFile.m */; };
9417A7411867DD3400D9D37B /* EZAudioPlot.m in Sources */ = {isa = PBXBuildFile; fileRef = 9417A72C1867DD3400D9D37B /* EZAudioPlot.m */; };
9417A7421867DD3400D9D37B /* EZAudioPlotGL.m in Sources */ = {isa = PBXBuildFile; fileRef = 9417A72E1867DD3400D9D37B /* EZAudioPlotGL.m */; };
9417A7431867DD3400D9D37B /* EZAudioPlotGLKViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9417A7301867DD3400D9D37B /* EZAudioPlotGLKViewController.m */; };
9417A7441867DD3400D9D37B /* EZMicrophone.m in Sources */ = {isa = PBXBuildFile; fileRef = 9417A7321867DD3400D9D37B /* EZMicrophone.m */; };
9417A7451867DD3400D9D37B /* EZOutput.m in Sources */ = {isa = PBXBuildFile; fileRef = 9417A7341867DD3400D9D37B /* EZOutput.m */; };
9417A7461867DD3400D9D37B /* EZPlot.m in Sources */ = {isa = PBXBuildFile; fileRef = 9417A7361867DD3400D9D37B /* EZPlot.m */; };
9417A7471867DD3400D9D37B /* EZRecorder.m in Sources */ = {isa = PBXBuildFile; fileRef = 9417A7381867DD3400D9D37B /* EZRecorder.m */; };
@@ -53,6 +54,12 @@
/* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */
668E4F801A905DAF00F4B814 /* EZAudioConverter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EZAudioConverter.h; sourceTree = "<group>"; };
668E4F811A905DAF00F4B814 /* EZAudioConverter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EZAudioConverter.m; sourceTree = "<group>"; };
668E4F831A905F8700F4B814 /* EZAudioWaveformData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EZAudioWaveformData.h; sourceTree = "<group>"; };
668E4F841A905F8700F4B814 /* EZAudioWaveformData.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EZAudioWaveformData.m; sourceTree = "<group>"; };
668E4F861A90607500F4B814 /* EZMicrophone.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EZMicrophone.h; sourceTree = "<group>"; };
668E4F871A90607500F4B814 /* EZMicrophone.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EZMicrophone.m; sourceTree = "<group>"; };
94056EF7185BD83400EB94BA /* EZAudioPlayFileExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = EZAudioPlayFileExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
94056EFA185BD83400EB94BA /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
94056EFD185BD83400EB94BA /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; };
@@ -82,8 +89,6 @@
94056F63185BDB4700EB94BA /* AudioUnit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioUnit.framework; path = System/Library/Frameworks/AudioUnit.framework; sourceTree = SDKROOT; };
94056F64185BDB4700EB94BA /* CoreAudio.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreAudio.framework; path = System/Library/Frameworks/CoreAudio.framework; sourceTree = SDKROOT; };
9417A6D41865928C00D9D37B /* simple-drum-beat.wav */ = {isa = PBXFileReference; lastKnownFileType = audio.wav; name = "simple-drum-beat.wav"; path = "../../../simple-drum-beat.wav"; sourceTree = "<group>"; };
9417A7251867DD3400D9D37B /* AEFloatConverter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AEFloatConverter.h; sourceTree = "<group>"; };
9417A7261867DD3400D9D37B /* AEFloatConverter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AEFloatConverter.m; sourceTree = "<group>"; };
9417A7271867DD3400D9D37B /* EZAudio.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EZAudio.h; sourceTree = "<group>"; };
9417A7281867DD3400D9D37B /* EZAudio.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EZAudio.m; sourceTree = "<group>"; };
9417A7291867DD3400D9D37B /* EZAudioFile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EZAudioFile.h; sourceTree = "<group>"; };
@@ -94,8 +99,6 @@
9417A72E1867DD3400D9D37B /* EZAudioPlotGL.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EZAudioPlotGL.m; sourceTree = "<group>"; };
9417A72F1867DD3400D9D37B /* EZAudioPlotGLKViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EZAudioPlotGLKViewController.h; sourceTree = "<group>"; };
9417A7301867DD3400D9D37B /* EZAudioPlotGLKViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EZAudioPlotGLKViewController.m; sourceTree = "<group>"; };
9417A7311867DD3400D9D37B /* EZMicrophone.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EZMicrophone.h; sourceTree = "<group>"; };
9417A7321867DD3400D9D37B /* EZMicrophone.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EZMicrophone.m; sourceTree = "<group>"; };
9417A7331867DD3400D9D37B /* EZOutput.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EZOutput.h; sourceTree = "<group>"; };
9417A7341867DD3400D9D37B /* EZOutput.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EZOutput.m; sourceTree = "<group>"; };
9417A7351867DD3400D9D37B /* EZPlot.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EZPlot.h; sourceTree = "<group>"; };
@@ -230,10 +233,12 @@
9417A7241867DD3400D9D37B /* EZAudio */ = {
isa = PBXGroup;
children = (
9417A7251867DD3400D9D37B /* AEFloatConverter.h */,
9417A7261867DD3400D9D37B /* AEFloatConverter.m */,
9417A7271867DD3400D9D37B /* EZAudio.h */,
9417A7281867DD3400D9D37B /* EZAudio.m */,
668E4F801A905DAF00F4B814 /* EZAudioConverter.h */,
668E4F811A905DAF00F4B814 /* EZAudioConverter.m */,
668E4F831A905F8700F4B814 /* EZAudioWaveformData.h */,
668E4F841A905F8700F4B814 /* EZAudioWaveformData.m */,
9417A7291867DD3400D9D37B /* EZAudioFile.h */,
9417A72A1867DD3400D9D37B /* EZAudioFile.m */,
9417A72B1867DD3400D9D37B /* EZAudioPlot.h */,
@@ -242,8 +247,8 @@
9417A72E1867DD3400D9D37B /* EZAudioPlotGL.m */,
9417A72F1867DD3400D9D37B /* EZAudioPlotGLKViewController.h */,
9417A7301867DD3400D9D37B /* EZAudioPlotGLKViewController.m */,
9417A7311867DD3400D9D37B /* EZMicrophone.h */,
9417A7321867DD3400D9D37B /* EZMicrophone.m */,
668E4F861A90607500F4B814 /* EZMicrophone.h */,
668E4F871A90607500F4B814 /* EZMicrophone.m */,
9417A7331867DD3400D9D37B /* EZOutput.h */,
9417A7341867DD3400D9D37B /* EZOutput.m */,
9417A7351867DD3400D9D37B /* EZPlot.h */,
@@ -371,16 +376,17 @@
files = (
9417A7481867DD3400D9D37B /* TPCircularBuffer.c in Sources */,
9417A7451867DD3400D9D37B /* EZOutput.m in Sources */,
668E4F821A905DAF00F4B814 /* EZAudioConverter.m in Sources */,
9417A7431867DD3400D9D37B /* EZAudioPlotGLKViewController.m in Sources */,
94056F31185BD86D00EB94BA /* PlayFileViewController.m in Sources */,
9417A73E1867DD3400D9D37B /* AEFloatConverter.m in Sources */,
94056F0E185BD83400EB94BA /* AppDelegate.m in Sources */,
9417A7411867DD3400D9D37B /* EZAudioPlot.m in Sources */,
9417A7401867DD3400D9D37B /* EZAudioFile.m in Sources */,
668E4F881A90607500F4B814 /* EZMicrophone.m in Sources */,
668E4F851A905F8700F4B814 /* EZAudioWaveformData.m in Sources */,
9417A7421867DD3400D9D37B /* EZAudioPlotGL.m in Sources */,
94056F07185BD83400EB94BA /* main.m in Sources */,
9417A7461867DD3400D9D37B /* EZPlot.m in Sources */,
9417A7441867DD3400D9D37B /* EZMicrophone.m in Sources */,
9417A7471867DD3400D9D37B /* EZRecorder.m in Sources */,
9417A73F1867DD3400D9D37B /* EZAudio.m in Sources */,
);
@@ -27,6 +27,9 @@
// Import EZAudio header
#import "EZAudio.h"
#import "EZAudioFile.h"
#import "EZOutput.h"
#import "EZAudioPlot.h"
/**
Here's the default audio file included with the example
@@ -47,7 +50,8 @@
/**
The CoreGraphics based audio plot
*/
@property (nonatomic,weak) IBOutlet EZAudioPlotGL *audioPlot;
@property (nonatomic,weak) IBOutlet EZAudioPlot *audioPlotLeft;
@property (nonatomic,weak) IBOutlet EZAudioPlot *audioPlotRight;
#pragma mark - UI Extras
/**
@@ -32,7 +32,6 @@
@implementation PlayFileViewController
@synthesize audioFile;
@synthesize audioPlot;
@synthesize eof = _eof;
@synthesize framePositionSlider;
@@ -72,15 +71,20 @@
Customizing the audio plot's look
*/
// Background color
self.audioPlot.backgroundColor = [NSColor colorWithCalibratedRed: 0.175 green: 0.151 blue: 0.137 alpha: 1];
self.audioPlotLeft.backgroundColor = [NSColor colorWithCalibratedRed:0.1 green:0.3 blue:0.2 alpha:1.0];
self.audioPlotRight.backgroundColor = [NSColor colorWithCalibratedRed:0.1 green:0.3 blue:0.2 alpha:1.0];
// Waveform color
self.audioPlot.color = [NSColor colorWithCalibratedRed: 1.000 green: 1.000 blue: 1.000 alpha: 1];
self.audioPlotLeft.color = [NSColor colorWithCalibratedRed: 1.000 green: 1.000 blue: 1.000 alpha: 1];
self.audioPlotRight.color = [NSColor colorWithCalibratedRed: 1.000 green: 1.000 blue: 1.000 alpha: 1];
// Plot type
self.audioPlot.plotType = EZPlotTypeBuffer;
self.audioPlotLeft.plotType = EZPlotTypeBuffer;
self.audioPlotRight.plotType = EZPlotTypeBuffer;
// Fill
self.audioPlot.shouldFill = YES;
self.audioPlotLeft.shouldFill = YES;
self.audioPlotRight.shouldFill = YES;
// Mirror
self.audioPlot.shouldMirror = YES;
self.audioPlotLeft.shouldMirror = YES;
self.audioPlotRight.shouldMirror = YES;
/*
Try opening the sample file
@@ -119,6 +123,7 @@
openDlg.delegate = self;
if( [openDlg runModal] == NSOKButton ){
NSArray *selectedFiles = [openDlg URLs];
NSLog(@"selected files: %@", selectedFiles);
[self openFileWithFilePathURL:selectedFiles.firstObject];
}
}
@@ -128,10 +133,6 @@
if( self.eof ){
[self.audioFile seekToFrame:0];
}
if( self.audioPlot.plotType == EZPlotTypeBuffer &&
self.audioPlot.shouldFill == YES ){
self.audioPlot.plotType = EZPlotTypeRolling;
}
[EZOutput sharedOutput].outputDataSource = self;
[[EZOutput sharedOutput] startPlayback];
}
@@ -151,11 +152,11 @@
*/
-(void)drawBufferPlot {
// Change the plot type to the buffer plot
self.audioPlot.plotType = EZPlotTypeBuffer;
self.audioPlotLeft.plotType = EZPlotTypeBuffer;
// Don't fill
self.audioPlot.shouldFill = NO;
self.audioPlotLeft.shouldFill = NO;
// Don't mirror over the x-axis
self.audioPlot.shouldMirror = NO;
self.audioPlotLeft.shouldMirror = NO;
}
/*
@@ -163,19 +164,25 @@
*/
-(void)drawRollingPlot {
// Change the plot type to the rolling plot
self.audioPlot.plotType = EZPlotTypeRolling;
self.audioPlotLeft.plotType = EZPlotTypeRolling;
// Fill the waveform
self.audioPlot.shouldFill = YES;
self.audioPlotLeft.shouldFill = YES;
// Mirror over the x-axis
self.audioPlot.shouldMirror = YES;
self.audioPlotLeft.shouldMirror = YES;
}
-(void)openFileWithFilePathURL:(NSURL*)filePathURL {
// Stop playback
[[EZOutput sharedOutput] stopPlayback];
self.audioFile = [EZAudioFile audioFileWithURL:filePathURL andDelegate:self];
AudioStreamBasicDescription asbd;
self.audioFile = [EZAudioFile audioFileWithURL:filePathURL
delegate:self
permission:EZAudioFilePermissionRead
fileFormat:asbd];
[[EZOutput sharedOutput] setAudioStreamBasicDescription:self.audioFile.clientFormat];
self.eof = NO;
self.filePathLabel.stringValue = filePathURL.lastPathComponent;
self.framePositionSlider.minValue = 0.0f;
@@ -187,36 +194,47 @@
#pragma mark Mess Around With Audio Stream Basic Description Here!
self.sampleRateSlider.floatValue = self.audioFile.clientFormat.mSampleRate;
AudioStreamBasicDescription outputASBD = self.audioFile.clientFormat;
[[EZOutput sharedOutput] setAudioStreamBasicDescription:[EZAudio stereoFloatInterleavedFormatWithSampleRate:44100]];
// Plot the whole waveform
self.audioPlot.plotType = EZPlotTypeBuffer;
self.audioPlot.shouldFill = YES;
self.audioPlot.shouldMirror = YES;
[self.audioFile getWaveformDataWithCompletionBlock:^(float *waveformData, UInt32 length) {
self.audioPlot.shouldFill = YES;
self.audioPlot.shouldMirror = YES;
[self.audioPlot updateBuffer:waveformData withBufferSize:length];
self.audioPlotLeft.plotType = EZPlotTypeBuffer;
self.audioPlotLeft.shouldFill = YES;
self.audioPlotLeft.shouldMirror = YES;
self.audioPlotRight.plotType = EZPlotTypeBuffer;
self.audioPlotRight.shouldFill = YES;
self.audioPlotRight.shouldMirror = YES;
[self.audioFile getWaveformDataWithCompletionBlock:^(EZAudioWaveformData *data) {
self.audioPlotLeft.shouldFill = YES;
self.audioPlotLeft.shouldMirror = YES;
self.audioPlotRight.shouldFill = YES;
self.audioPlotRight.shouldMirror = YES;
if (data.numberOfChannels > 1)
{
[self.audioPlotLeft updateBuffer:[data bufferForChannel:0] withBufferSize:data.bufferSize];
[self.audioPlotRight updateBuffer:[data bufferForChannel:1] withBufferSize:data.bufferSize];
}
else
{
[self.audioPlotLeft updateBuffer:[data bufferForChannel:0] withBufferSize:data.bufferSize];
}
}];
}
#pragma mark - EZAudioFileDelegate
-(void)audioFile:(EZAudioFile *)audioFile readAudio:(float **)buffer withBufferSize:(UInt32)bufferSize withNumberOfChannels:(UInt32)numberOfChannels {
if( [EZOutput sharedOutput].isPlaying ){
dispatch_async(dispatch_get_main_queue(), ^{
if( self.audioPlot.plotType == EZPlotTypeBuffer &&
self.audioPlot.shouldFill == YES &&
self.audioPlot.shouldMirror == YES ){
self.audioPlot.shouldFill = NO;
self.audioPlot.shouldMirror = NO;
}
[self.audioPlot updateBuffer:buffer[0] withBufferSize:bufferSize];
});
}
-(void)audioFile:(EZAudioFile *)audioFile
readAudio:(float **)buffer
withBufferSize:(UInt32)bufferSize
withNumberOfChannels:(UInt32)numberOfChannels {
// if( [EZOutput sharedOutput].isPlaying ){
// dispatch_async(dispatch_get_main_queue(), ^{
// if( self.audioPlotLeft.plotType == EZPlotTypeBuffer &&
// self.audioPlotLeft.shouldFill == YES &&
// self.audioPlotLeft.shouldMirror == YES ){
// self.audioPlotLeft.shouldFill = NO;
// self.audioPlotLeft.shouldMirror = NO;
// }
// [self.audioPlotLeft updateBuffer:buffer[0] withBufferSize:bufferSize];
// });
// }
}
-(void)audioFile:(EZAudioFile *)audioFile
@@ -229,8 +247,8 @@
}
#pragma mark - EZOutputDataSource
-(void) output:(EZOutput *)output
shouldFillAudioBufferList:(AudioBufferList *)audioBufferList
-(void) output:(EZOutput*)output
shouldFillAudioBufferList:(AudioBufferList*)audioBufferList
withNumberOfFrames:(UInt32)frames
{
if( self.audioFile )
@@ -1,13 +1,14 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="6250" systemVersion="14A389" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="6254" systemVersion="14C109" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment version="1070" identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="6250"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="6254"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="PlayFileViewController">
<connections>
<outlet property="audioPlot" destination="Lz1-Gs-1lD" id="V5w-yH-ZVR"/>
<outlet property="audioPlotLeft" destination="aHI-vj-Ccv" id="Pwl-P4-MyY"/>
<outlet property="audioPlotRight" destination="Lz1-Gs-1lD" id="GKN-Pb-Ejy"/>
<outlet property="filePathLabel" destination="0eT-7c-7fJ" id="IGv-mA-5Hw"/>
<outlet property="framePositionSlider" destination="CFP-v0-TzQ" id="3oy-Xn-4JK"/>
<outlet property="playButton" destination="OQp-Lr-dlS" id="K5R-Qg-7DY"/>
@@ -19,18 +20,11 @@
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customView id="Xpo-HP-Ost">
<rect key="frame" x="0.0" y="0.0" width="480" height="272"/>
<rect key="frame" x="0.0" y="0.0" width="480" height="421"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<customView misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Lz1-Gs-1lD" customClass="EZAudioPlotGL">
<rect key="frame" x="0.0" y="0.0" width="480" height="148"/>
</customView>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="2Ma-jj-U3z">
<rect key="frame" x="14" y="224" width="125" height="32"/>
<constraints>
<constraint firstAttribute="height" constant="21" id="Lm5-0d-A72"/>
<constraint firstAttribute="width" constant="113" id="Tij-5V-y1Q"/>
</constraints>
<rect key="frame" x="14" y="373" width="125" height="32"/>
<buttonCell key="cell" type="push" title="Choose File..." bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="KLq-bf-Xkh">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
@@ -40,7 +34,7 @@
</connections>
</button>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="0eT-7c-7fJ">
<rect key="frame" x="141" y="235" width="38" height="17"/>
<rect key="frame" x="141" y="384" width="38" height="17"/>
<textFieldCell key="cell" lineBreakMode="truncatingMiddle" sendsActionOnEndEditing="YES" title="Label" id="vXQ-HF-vLX">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
@@ -48,11 +42,7 @@
</textFieldCell>
</textField>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="OQp-Lr-dlS">
<rect key="frame" x="14" y="191" width="125" height="32"/>
<constraints>
<constraint firstAttribute="height" constant="21" id="geC-A9-48j"/>
<constraint firstAttribute="width" constant="113" id="lc3-4H-QK6"/>
</constraints>
<rect key="frame" x="14" y="340" width="125" height="32"/>
<buttonCell key="cell" type="push" title="Play" alternateTitle="Pause" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="Z2A-7U-sb6">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
@@ -61,8 +51,11 @@
<action selector="play:" target="-2" id="y83-JF-y4e"/>
</connections>
</button>
<segmentedControl verticalHuggingPriority="750" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="bZW-tA-C61">
<rect key="frame" x="333" y="196" width="129" height="24"/>
<segmentedControl verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="bZW-tA-C61">
<rect key="frame" x="333" y="345" width="129" height="24"/>
<constraints>
<constraint firstAttribute="width" constant="125" id="3Yc-x7-gJk"/>
</constraints>
<segmentedCell key="cell" borderStyle="border" alignment="left" style="rounded" trackingMode="selectOne" id="8U1-ER-vPJ">
<font key="font" metaFont="system"/>
<segments>
@@ -74,39 +67,56 @@
<action selector="changePlotType:" target="-2" id="alU-Rf-22L"/>
</connections>
</segmentedControl>
<slider verticalHuggingPriority="750" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="CFP-v0-TzQ">
<rect key="frame" x="18" y="159" width="444" height="20"/>
<sliderCell key="cell" alignment="left" maxValue="100" doubleValue="9.3380614657210401" tickMarkPosition="above" sliderType="linear" id="gPc-pN-dmP"/>
<slider verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="CFP-v0-TzQ">
<rect key="frame" x="18" y="308" width="444" height="20"/>
<sliderCell key="cell" continuous="YES" alignment="left" maxValue="100" doubleValue="9.3380614657210401" tickMarkPosition="above" sliderType="linear" id="gPc-pN-dmP"/>
<connections>
<action selector="seekToFrame:" target="-2" id="iVY-so-6X2"/>
</connections>
</slider>
<slider verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="rRH-oS-VV3">
<rect key="frame" x="141" y="199" width="96" height="20"/>
<slider verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="rRH-oS-VV3">
<rect key="frame" x="141" y="348" width="96" height="20"/>
<constraints>
<constraint firstAttribute="width" constant="92" id="Ul6-1Z-zf6"/>
</constraints>
<sliderCell key="cell" state="on" alignment="left" minValue="8000" maxValue="88200" doubleValue="44100" tickMarkPosition="above" sliderType="linear" id="xbX-Ce-da5"/>
<connections>
<action selector="changeOutputSamplingFrequency:" target="-2" id="yWM-Ei-ztA"/>
</connections>
</slider>
<customView translatesAutoresizingMaskIntoConstraints="NO" id="aHI-vj-Ccv" customClass="EZAudioPlot">
<rect key="frame" x="0.0" y="148" width="480" height="148"/>
</customView>
<customView translatesAutoresizingMaskIntoConstraints="NO" id="Lz1-Gs-1lD" customClass="EZAudioPlot">
<rect key="frame" x="0.0" y="0.0" width="480" height="148"/>
</customView>
</subviews>
<constraints>
<constraint firstItem="CFP-v0-TzQ" firstAttribute="top" secondItem="OQp-Lr-dlS" secondAttribute="bottom" constant="20" id="6uf-rh-zEf"/>
<constraint firstItem="0eT-7c-7fJ" firstAttribute="leading" secondItem="2Ma-jj-U3z" secondAttribute="trailing" constant="10" id="AcA-Rv-Lwl"/>
<constraint firstItem="Lz1-Gs-1lD" firstAttribute="top" secondItem="CFP-v0-TzQ" secondAttribute="bottom" constant="13" id="JjU-ri-rxV"/>
<constraint firstItem="0eT-7c-7fJ" firstAttribute="top" secondItem="Xpo-HP-Ost" secondAttribute="top" constant="20" id="T86-Jj-i0N"/>
<constraint firstAttribute="bottom" secondItem="Lz1-Gs-1lD" secondAttribute="bottom" id="U2b-77-5uo"/>
<constraint firstAttribute="trailing" secondItem="bZW-tA-C61" secondAttribute="trailing" constant="20" id="UGO-OL-Dmk"/>
<constraint firstAttribute="trailing" secondItem="CFP-v0-TzQ" secondAttribute="trailing" constant="20" id="UpE-fD-Skp"/>
<constraint firstItem="2Ma-jj-U3z" firstAttribute="top" secondItem="Xpo-HP-Ost" secondAttribute="top" constant="20" id="a1a-7J-lzc"/>
<constraint firstItem="Lz1-Gs-1lD" firstAttribute="leading" secondItem="Xpo-HP-Ost" secondAttribute="leading" id="bZz-am-fqe"/>
<constraint firstItem="2Ma-jj-U3z" firstAttribute="leading" secondItem="Xpo-HP-Ost" secondAttribute="leading" constant="20" id="dc1-KX-H5W"/>
<constraint firstItem="OQp-Lr-dlS" firstAttribute="leading" secondItem="Xpo-HP-Ost" secondAttribute="leading" constant="20" id="g5e-2M-sHn"/>
<constraint firstAttribute="trailing" secondItem="Lz1-Gs-1lD" secondAttribute="trailing" id="jDC-Iz-9c4"/>
<constraint firstItem="bZW-tA-C61" firstAttribute="top" secondItem="0eT-7c-7fJ" secondAttribute="bottom" constant="16" id="ll5-1d-SaQ"/>
<constraint firstItem="CFP-v0-TzQ" firstAttribute="leading" secondItem="Xpo-HP-Ost" secondAttribute="leading" constant="20" id="qhq-Io-tdF"/>
<constraint firstItem="Lz1-Gs-1lD" firstAttribute="leading" secondItem="Xpo-HP-Ost" secondAttribute="leading" id="xtr-M9-Uot"/>
<constraint firstItem="OQp-Lr-dlS" firstAttribute="top" secondItem="2Ma-jj-U3z" secondAttribute="bottom" constant="12" id="yGn-40-QqT"/>
<constraint firstItem="CFP-v0-TzQ" firstAttribute="top" secondItem="OQp-Lr-dlS" secondAttribute="bottom" constant="21" id="2Xm-ZL-QU7"/>
<constraint firstItem="rRH-oS-VV3" firstAttribute="leading" secondItem="0eT-7c-7fJ" secondAttribute="leading" id="3CU-am-fxR"/>
<constraint firstItem="2Ma-jj-U3z" firstAttribute="leading" secondItem="Xpo-HP-Ost" secondAttribute="leading" constant="20" symbolic="YES" id="5ch-hJ-6Kp"/>
<constraint firstItem="CFP-v0-TzQ" firstAttribute="trailing" secondItem="bZW-tA-C61" secondAttribute="trailing" id="7rr-w2-gvA"/>
<constraint firstAttribute="trailing" secondItem="bZW-tA-C61" secondAttribute="trailing" constant="20" symbolic="YES" id="A17-rX-9Sa"/>
<constraint firstItem="OQp-Lr-dlS" firstAttribute="top" secondItem="2Ma-jj-U3z" secondAttribute="bottom" constant="12" symbolic="YES" id="Fpt-Cg-5Ur"/>
<constraint firstItem="OQp-Lr-dlS" firstAttribute="trailing" secondItem="2Ma-jj-U3z" secondAttribute="trailing" id="GoP-Jj-F0w"/>
<constraint firstItem="Lz1-Gs-1lD" firstAttribute="top" secondItem="aHI-vj-Ccv" secondAttribute="bottom" id="Izh-a4-03r"/>
<constraint firstItem="2Ma-jj-U3z" firstAttribute="top" secondItem="Xpo-HP-Ost" secondAttribute="top" constant="20" symbolic="YES" id="KHJ-an-Hqi"/>
<constraint firstItem="0eT-7c-7fJ" firstAttribute="top" secondItem="2Ma-jj-U3z" secondAttribute="top" id="NAh-en-Pw9"/>
<constraint firstItem="Lz1-Gs-1lD" firstAttribute="leading" secondItem="Xpo-HP-Ost" secondAttribute="leading" id="P2a-D3-NNl"/>
<constraint firstItem="0eT-7c-7fJ" firstAttribute="leading" secondItem="2Ma-jj-U3z" secondAttribute="trailing" constant="10" id="PBC-BN-wJn"/>
<constraint firstItem="aHI-vj-Ccv" firstAttribute="height" secondItem="Lz1-Gs-1lD" secondAttribute="height" id="RkJ-OA-oUM"/>
<constraint firstItem="OQp-Lr-dlS" firstAttribute="leading" secondItem="2Ma-jj-U3z" secondAttribute="leading" id="YaB-GO-JhC"/>
<constraint firstItem="Lz1-Gs-1lD" firstAttribute="trailing" secondItem="aHI-vj-Ccv" secondAttribute="trailing" id="Z3I-LF-Cja"/>
<constraint firstItem="CFP-v0-TzQ" firstAttribute="centerX" secondItem="aHI-vj-Ccv" secondAttribute="centerX" id="Zdn-mM-g9p"/>
<constraint firstItem="Lz1-Gs-1lD" firstAttribute="leading" secondItem="aHI-vj-Ccv" secondAttribute="leading" id="cTW-4H-R0G"/>
<constraint firstItem="bZW-tA-C61" firstAttribute="top" secondItem="OQp-Lr-dlS" secondAttribute="top" id="jls-iH-yCV"/>
<constraint firstItem="rRH-oS-VV3" firstAttribute="baseline" secondItem="OQp-Lr-dlS" secondAttribute="baseline" id="mHm-mA-sbt"/>
<constraint firstItem="Lz1-Gs-1lD" firstAttribute="top" secondItem="Xpo-HP-Ost" secondAttribute="top" constant="273" id="oy9-te-LMx"/>
<constraint firstAttribute="bottom" secondItem="Lz1-Gs-1lD" secondAttribute="bottom" id="sl1-b2-YvQ"/>
<constraint firstItem="OQp-Lr-dlS" firstAttribute="leading" secondItem="CFP-v0-TzQ" secondAttribute="leading" id="tLV-2q-F9W"/>
<constraint firstItem="aHI-vj-Ccv" firstAttribute="top" secondItem="CFP-v0-TzQ" secondAttribute="bottom" constant="14" id="z81-ib-E9q"/>
</constraints>
<point key="canvasLocation" x="241" y="331.5"/>
</customView>
</objects>
</document>
@@ -110,8 +110,9 @@
self.audioPlot.plotType = EZPlotTypeBuffer;
self.audioPlot.shouldFill = YES;
self.audioPlot.shouldMirror = YES;
[self.audioFile getWaveformDataWithCompletionBlock:^(float *waveformData, UInt32 length) {
[self.audioPlot updateBuffer:waveformData withBufferSize:length];
[self.audioFile getWaveformDataWithCompletionBlock:^(EZAudioWaveformData *waveformData) {
[self.audioPlot updateBuffer:[waveformData bufferForChannel:1]
withBufferSize:waveformData.bufferSize];
}];
}
@@ -10,29 +10,29 @@
<string>EZAudioExamplesiOS</string>
<key>IDESourceControlProjectOriginsDictionary</key>
<dict>
<key>F77EC8D9-F815-4829-9274-5DA08EA98D6B</key>
<key>9D6FF97A89F512CD81EAE1A971A1D2EB03E03F7C</key>
<string>https://github.com/syedhali/EZAudio.git</string>
</dict>
<key>IDESourceControlProjectPath</key>
<string>EZAudioExamples/iOS/EZAudioExamplesiOS.xcworkspace</string>
<key>IDESourceControlProjectRelativeInstallPathDictionary</key>
<dict>
<key>F77EC8D9-F815-4829-9274-5DA08EA98D6B</key>
<key>9D6FF97A89F512CD81EAE1A971A1D2EB03E03F7C</key>
<string>../../..</string>
</dict>
<key>IDESourceControlProjectURL</key>
<string>https://github.com/syedhali/EZAudio.git</string>
<key>IDESourceControlProjectVersion</key>
<integer>110</integer>
<integer>111</integer>
<key>IDESourceControlProjectWCCIdentifier</key>
<string>F77EC8D9-F815-4829-9274-5DA08EA98D6B</string>
<string>9D6FF97A89F512CD81EAE1A971A1D2EB03E03F7C</string>
<key>IDESourceControlProjectWCConfigurations</key>
<array>
<dict>
<key>IDESourceControlRepositoryExtensionIdentifierKey</key>
<string>public.vcs.git</string>
<key>IDESourceControlWCCIdentifierKey</key>
<string>F77EC8D9-F815-4829-9274-5DA08EA98D6B</string>
<string>9D6FF97A89F512CD81EAE1A971A1D2EB03E03F7C</string>
<key>IDESourceControlWCCName</key>
<string>EZAudio</string>
</dict>
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="5056" systemVersion="13E28" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="vXZ-lx-hvc">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6254" systemVersion="14C109" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="vXZ-lx-hvc">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3733"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6247"/>
</dependencies>
<scenes>
<!--Play File View Controller-->
@@ -18,11 +19,9 @@
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="uPM-eF-6ct" customClass="EZAudioPlotGL">
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<segmentedControl opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="plain" selectedSegmentIndex="0" translatesAutoresizingMaskIntoConstraints="NO" id="TsA-XB-MTe">
<rect key="frame" x="187" y="520" width="113" height="29"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<segments>
<segment title="Buffer"/>
<segment title="Rolling"/>
@@ -33,14 +32,12 @@
</segmentedControl>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Sh2-sS-uR6">
<rect key="frame" x="20" y="488" width="280" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="xKX-cQ-AvV">
<rect key="frame" x="20" y="519" width="30" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<state key="normal" title="Play">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
@@ -48,9 +45,8 @@
<action selector="play:" destination="vXZ-lx-hvc" eventType="touchUpInside" id="0vr-5R-dT3"/>
</connections>
</button>
<slider opaque="NO" contentMode="scaleToFill" misplaced="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" value="0.5" minValue="0.0" maxValue="1" continuous="NO" translatesAutoresizingMaskIntoConstraints="NO" id="tSM-7B-ujg">
<slider opaque="NO" contentMode="scaleToFill" misplaced="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" value="0.5" minValue="0.0" maxValue="1" translatesAutoresizingMaskIntoConstraints="NO" id="tSM-7B-ujg">
<rect key="frame" x="18" y="447" width="284" height="34"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<connections>
<action selector="seekToFrame:" destination="vXZ-lx-hvc" eventType="valueChanged" id="3A8-F6-h6C"/>
</connections>
@@ -133,7 +133,7 @@
[[EZOutput sharedOutput] stopPlayback];
self.audioFile = [EZAudioFile audioFileWithURL:filePathURL];
self.audioFile.audioFileDelegate = self;
self.audioFile.delegate = self;
self.eof = NO;
self.filePathLabel.text = filePathURL.lastPathComponent;
self.framePositionSlider.maximumValue = (float)self.audioFile.totalFrames;