EZRecorder

@interface EZRecorder : NSObject

The EZRecorder provides a flexible way to create an audio file and append raw audio data to it. The EZRecorder will convert the incoming audio on the fly to the destination format so no conversion is needed between this and any other component. Right now the only supported output format is ‘caf’. Each output file should have its own EZRecorder instance (think 1 EZRecorder = 1 audio file).

  • An EZRecorderDelegate to listen for the write and close events.

    Declaration

    Objective-C

    @property (readwrite, nonatomic) id<EZRecorderDelegate> delegate;

    Swift

    weak var delegate: EZRecorderDelegate! { get set }
  • Creates an instance of the EZRecorder with a file path URL to write out the file to, a client format describing the in-application common format (see clientFormat for more info), and a file type (see EZRecorderFileType) that will automatically create an internal fileFormat and audio file type hint. - parameter: url An NSURL representing the file path the output file should be written - parameter: clientFormat An AudioStreamBasicDescription describing the in-applciation common format (always linear PCM) - parameter: fileType A constant described by the EZRecorderFileType that corresponds to the type of destination file that should be written. For instance, an AAC file written using an ’.m4a’ extension would correspond to EZRecorderFileTypeM4A. See EZRecorderFileType for all the constants and mapping combinations. - returns: A newly created EZRecorder instance.

    Declaration

    Objective-C

    - (instancetype)initWithURL:(NSURL *)url
                   clientFormat:(AudioStreamBasicDescription)clientFormat
                       fileType:(EZRecorderFileType)fileType;

    Swift

    init!(url: URL!, clientFormat: AudioStreamBasicDescription, fileType: EZRecorderFileType)

    Parameters

    url

    An NSURL representing the file path the output file should be written

    clientFormat

    An AudioStreamBasicDescription describing the in-applciation common format (always linear PCM)

    fileType

    A constant described by the EZRecorderFileType that corresponds to the type of destination file that should be written. For instance, an AAC file written using an ’.m4a’ extension would correspond to EZRecorderFileTypeM4A. See EZRecorderFileType for all the constants and mapping combinations.

    Return Value

    A newly created EZRecorder instance.

  • Creates an instance of the EZRecorder with a file path URL to write out the file to, a client format describing the in-application common format (see clientFormat for more info), and a file type (see EZRecorderFileType) that will automatically create an internal fileFormat and audio file type hint, as well as a delegate to respond to the recorder’s write and close events. - parameter: url An NSURL representing the file path the output file should be written - parameter: clientFormat An AudioStreamBasicDescription describing the in-applciation common format (always linear PCM) - parameter: fileType A constant described by the EZRecorderFileType that corresponds to the type of destination file that should be written. For instance, an AAC file written using an ’.m4a’ extension would correspond to EZRecorderFileTypeM4A. See EZRecorderFileType for all the constants and mapping combinations. - parameter: delegate An EZRecorderDelegate to listen for the recorder’s write and close events. - returns: A newly created EZRecorder instance.

    Declaration

    Objective-C

    - (instancetype)initWithURL:(NSURL *)url
                   clientFormat:(AudioStreamBasicDescription)clientFormat
                       fileType:(EZRecorderFileType)fileType
                       delegate:(id<EZRecorderDelegate>)delegate;

    Swift

    init!(url: URL!, clientFormat: AudioStreamBasicDescription, fileType: EZRecorderFileType, delegate: EZRecorderDelegate!)

    Parameters

    url

    An NSURL representing the file path the output file should be written

    clientFormat

    An AudioStreamBasicDescription describing the in-applciation common format (always linear PCM)

    fileType

    A constant described by the EZRecorderFileType that corresponds to the type of destination file that should be written. For instance, an AAC file written using an ’.m4a’ extension would correspond to EZRecorderFileTypeM4A. See EZRecorderFileType for all the constants and mapping combinations.

    delegate

    An EZRecorderDelegate to listen for the recorder’s write and close events.

    Return Value

    A newly created EZRecorder instance.

  • Creates an instance of the EZRecorder with a file path URL to write out the file to, a client format describing the in-application common format (see clientFormat for more info), a file format describing the destination format on disk (see fileFormat for more info), and an audio file type (an AudioFileTypeID for Core Audio, not a EZRecorderFileType). - parameter: url An NSURL representing the file path the output file should be written - parameter: clientFormat An AudioStreamBasicDescription describing the in-applciation common format (always linear PCM) - parameter: fileFormat An AudioStreamBasicDescription describing the format of the audio being written to disk (MP3, AAC, WAV, etc) - parameter: audioFileTypeID An AudioFileTypeID that matches your fileFormat (i.e. kAudioFileM4AType for an M4A format) - returns: A newly created EZRecorder instance.

    Declaration

    Objective-C

    - (instancetype)initWithURL:(NSURL *)url
                   clientFormat:(AudioStreamBasicDescription)clientFormat
                     fileFormat:(AudioStreamBasicDescription)fileFormat
                audioFileTypeID:(AudioFileTypeID)audioFileTypeID;

    Swift

    init!(url: URL!, clientFormat: AudioStreamBasicDescription, fileFormat: AudioStreamBasicDescription, audioFileTypeID: AudioFileTypeID)

    Parameters

    url

    An NSURL representing the file path the output file should be written

    clientFormat

    An AudioStreamBasicDescription describing the in-applciation common format (always linear PCM)

    fileFormat

    An AudioStreamBasicDescription describing the format of the audio being written to disk (MP3, AAC, WAV, etc)

    audioFileTypeID

    An AudioFileTypeID that matches your fileFormat (i.e. kAudioFileM4AType for an M4A format)

    Return Value

    A newly created EZRecorder instance.

  • Creates an instance of the EZRecorder with a file path URL to write out the file to, a client format describing the in-application common format (see clientFormat for more info), a file format describing the destination format on disk (see fileFormat for more info), an audio file type (an AudioFileTypeID for Core Audio, not a EZRecorderFileType), and delegate to respond to the recorder’s write and close events. - parameter: url An NSURL representing the file path the output file should be written - parameter: clientFormat An AudioStreamBasicDescription describing the in-applciation common format (always linear PCM) - parameter: fileFormat An AudioStreamBasicDescription describing the format of the audio being written to disk (MP3, AAC, WAV, etc) - parameter: audioFileTypeID An AudioFileTypeID that matches your fileFormat (i.e. kAudioFileM4AType for an M4A format) - parameter: delegate An EZRecorderDelegate to listen for the recorder’s write and close events. - returns: A newly created EZRecorder instance.

    Declaration

    Objective-C

    - (instancetype)initWithURL:(NSURL *)url
                   clientFormat:(AudioStreamBasicDescription)clientFormat
                     fileFormat:(AudioStreamBasicDescription)fileFormat
                audioFileTypeID:(AudioFileTypeID)audioFileTypeID
                       delegate:(id<EZRecorderDelegate>)delegate;

    Swift

    init!(url: URL!, clientFormat: AudioStreamBasicDescription, fileFormat: AudioStreamBasicDescription, audioFileTypeID: AudioFileTypeID, delegate: EZRecorderDelegate!)

    Parameters

    url

    An NSURL representing the file path the output file should be written

    clientFormat

    An AudioStreamBasicDescription describing the in-applciation common format (always linear PCM)

    fileFormat

    An AudioStreamBasicDescription describing the format of the audio being written to disk (MP3, AAC, WAV, etc)

    audioFileTypeID

    An AudioFileTypeID that matches your fileFormat (i.e. kAudioFileM4AType for an M4A format)

    delegate

    An EZRecorderDelegate to listen for the recorder’s write and close events.

    Return Value

    A newly created EZRecorder instance.

  • Creates a new instance of an EZRecorder using a destination file path URL and the source format of the incoming audio. - parameter: url An NSURL specifying the file path location of where the audio file should be written to. - parameter: sourceFormat The AudioStreamBasicDescription for the incoming audio that will be written to the file. - parameter: destinationFileType A constant described by the EZRecorderFileType that corresponds to the type of destination file that should be written. For instance, an AAC file written using an ’.m4a’ extension would correspond to EZRecorderFileTypeM4A. See EZRecorderFileType for all the constants and mapping combinations. @deprecated This property is deprecated starting in version 0.8.0. - note: Please use initWithURL:clientFormat:fileType: initializer instead. - returns: The newly created EZRecorder instance.

    Declaration

    Objective-C

    - (instancetype)initWithDestinationURL:(NSURL *)url
                              sourceFormat:(AudioStreamBasicDescription)sourceFormat
                       destinationFileType:(EZRecorderFileType)destinationFileType;

    Swift

    init!(destinationURL url: URL!, sourceFormat: AudioStreamBasicDescription, destinationFileType: EZRecorderFileType)

    Parameters

    url

    An NSURL specifying the file path location of where the audio file should be written to.

    sourceFormat

    The AudioStreamBasicDescription for the incoming audio that will be written to the file.

    destinationFileType

    A constant described by the EZRecorderFileType that corresponds to the type of destination file that should be written. For instance, an AAC file written using an ’.m4a’ extension would correspond to EZRecorderFileTypeM4A. See EZRecorderFileType for all the constants and mapping combinations.

    Return Value

    The newly created EZRecorder instance.

  • Class method to create an instance of the EZRecorder with a file path URL to write out the file to, a client format describing the in-application common format (see clientFormat for more info), and a file type (see EZRecorderFileType) that will automatically create an internal fileFormat and audio file type hint. - parameter: url An NSURL representing the file path the output file should be written - parameter: clientFormat An AudioStreamBasicDescription describing the in-applciation common format (always linear PCM) - parameter: fileType A constant described by the EZRecorderFileType that corresponds to the type of destination file that should be written. For instance, an AAC file written using an ’.m4a’ extension would correspond to EZRecorderFileTypeM4A. See EZRecorderFileType for all the constants and mapping combinations. - returns: A newly created EZRecorder instance.

    Declaration

    Objective-C

    + (instancetype)recorderWithURL:(NSURL *)url
                       clientFormat:(AudioStreamBasicDescription)clientFormat
                           fileType:(EZRecorderFileType)fileType;

    Parameters

    url

    An NSURL representing the file path the output file should be written

    clientFormat

    An AudioStreamBasicDescription describing the in-applciation common format (always linear PCM)

    fileType

    A constant described by the EZRecorderFileType that corresponds to the type of destination file that should be written. For instance, an AAC file written using an ’.m4a’ extension would correspond to EZRecorderFileTypeM4A. See EZRecorderFileType for all the constants and mapping combinations.

    Return Value

    A newly created EZRecorder instance.

  • Class method to create an instance of the EZRecorder with a file path URL to write out the file to, a client format describing the in-application common format (see clientFormat for more info), and a file type (see EZRecorderFileType) that will automatically create an internal fileFormat and audio file type hint, as well as a delegate to respond to the recorder’s write and close events. - parameter: url An NSURL representing the file path the output file should be written - parameter: clientFormat An AudioStreamBasicDescription describing the in-applciation common format (always linear PCM) - parameter: fileType A constant described by the EZRecorderFileType that corresponds to the type of destination file that should be written. For instance, an AAC file written using an ’.m4a’ extension would correspond to EZRecorderFileTypeM4A. See EZRecorderFileType for all the constants and mapping combinations. - parameter: delegate An EZRecorderDelegate to listen for the recorder’s write and close events. - returns: A newly created EZRecorder instance.

    Declaration

    Objective-C

    + (instancetype)recorderWithURL:(NSURL *)url
                       clientFormat:(AudioStreamBasicDescription)clientFormat
                           fileType:(EZRecorderFileType)fileType
                           delegate:(id<EZRecorderDelegate>)delegate;

    Parameters

    url

    An NSURL representing the file path the output file should be written

    clientFormat

    An AudioStreamBasicDescription describing the in-applciation common format (always linear PCM)

    fileType

    A constant described by the EZRecorderFileType that corresponds to the type of destination file that should be written. For instance, an AAC file written using an ’.m4a’ extension would correspond to EZRecorderFileTypeM4A. See EZRecorderFileType for all the constants and mapping combinations.

    delegate

    An EZRecorderDelegate to listen for the recorder’s write and close events.

    Return Value

    A newly created EZRecorder instance.

  • Class method to create an instance of the EZRecorder with a file path URL to write out the file to, a client format describing the in-application common format (see clientFormat for more info), a file format describing the destination format on disk (see fileFormat for more info), and an audio file type (an AudioFileTypeID for Core Audio, not a EZRecorderFileType). - parameter: url An NSURL representing the file path the output file should be written - parameter: clientFormat An AudioStreamBasicDescription describing the in-applciation common format (always linear PCM) - parameter: fileFormat An AudioStreamBasicDescription describing the format of the audio being written to disk (MP3, AAC, WAV, etc) - parameter: audioFileTypeID An AudioFileTypeID that matches your fileFormat (i.e. kAudioFileM4AType for an M4A format) - returns: A newly created EZRecorder instance.

    Declaration

    Objective-C

    + (instancetype)recorderWithURL:(NSURL *)url
                       clientFormat:(AudioStreamBasicDescription)clientFormat
                         fileFormat:(AudioStreamBasicDescription)fileFormat
                    audioFileTypeID:(AudioFileTypeID)audioFileTypeID;

    Parameters

    url

    An NSURL representing the file path the output file should be written

    clientFormat

    An AudioStreamBasicDescription describing the in-applciation common format (always linear PCM)

    fileFormat

    An AudioStreamBasicDescription describing the format of the audio being written to disk (MP3, AAC, WAV, etc)

    audioFileTypeID

    An AudioFileTypeID that matches your fileFormat (i.e. kAudioFileM4AType for an M4A format)

    Return Value

    A newly created EZRecorder instance.

  • Class method to create an instance of the EZRecorder with a file path URL to write out the file to, a client format describing the in-application common format (see clientFormat for more info), a file format describing the destination format on disk (see fileFormat for more info), an audio file type (an AudioFileTypeID for Core Audio, not a EZRecorderFileType), and delegate to respond to the recorder’s write and close events. - parameter: url An NSURL representing the file path the output file should be written - parameter: clientFormat An AudioStreamBasicDescription describing the in-applciation common format (always linear PCM) - parameter: fileFormat An AudioStreamBasicDescription describing the format of the audio being written to disk (MP3, AAC, WAV, etc) - parameter: audioFileTypeID An AudioFileTypeID that matches your fileFormat (i.e. kAudioFileM4AType for an M4A format) - parameter: delegate An EZRecorderDelegate to listen for the recorder’s write and close events. - returns: A newly created EZRecorder instance.

    Declaration

    Objective-C

    + (instancetype)recorderWithURL:(NSURL *)url
                       clientFormat:(AudioStreamBasicDescription)clientFormat
                         fileFormat:(AudioStreamBasicDescription)fileFormat
                    audioFileTypeID:(AudioFileTypeID)audioFileTypeID
                           delegate:(id<EZRecorderDelegate>)delegate;

    Parameters

    url

    An NSURL representing the file path the output file should be written

    clientFormat

    An AudioStreamBasicDescription describing the in-applciation common format (always linear PCM)

    fileFormat

    An AudioStreamBasicDescription describing the format of the audio being written to disk (MP3, AAC, WAV, etc)

    audioFileTypeID

    An AudioFileTypeID that matches your fileFormat (i.e. kAudioFileM4AType for an M4A format)

    delegate

    An EZRecorderDelegate to listen for the recorder’s write and close events.

    Return Value

    A newly created EZRecorder instance.

  • Class method to create a new instance of an EZRecorder using a destination file path URL and the source format of the incoming audio. - parameter: url An NSURL specifying the file path location of where the audio file should be written to. - parameter: sourceFormat The AudioStreamBasicDescription for the incoming audio that will be written to the file (also called the clientFormat). - parameter: destinationFileType A constant described by the EZRecorderFileType that corresponds to the type of destination file that should be written. For instance, an AAC file written using an ’.m4a’ extension would correspond to EZRecorderFileTypeM4A. See EZRecorderFileType for all the constants and mapping combinations. - returns: The newly created EZRecorder instance.

    Declaration

    Objective-C

    + (instancetype)
    recorderWithDestinationURL:(NSURL *)url
                  sourceFormat:(AudioStreamBasicDescription)sourceFormat
           destinationFileType:(EZRecorderFileType)destinationFileType;

    Parameters

    url

    An NSURL specifying the file path location of where the audio file should be written to.

    sourceFormat

    The AudioStreamBasicDescription for the incoming audio that will be written to the file (also called the clientFormat).

    destinationFileType

    A constant described by the EZRecorderFileType that corresponds to the type of destination file that should be written. For instance, an AAC file written using an ’.m4a’ extension would correspond to EZRecorderFileTypeM4A. See EZRecorderFileType for all the constants and mapping combinations.

    Return Value

    The newly created EZRecorder instance.

  • Provides the common AudioStreamBasicDescription that will be used for in-app interaction. The recorder’s format will be converted from this format to the fileFormat. 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 recorder to properly write samples from the graph out to the file in the desired destination format. - warning: This must be a linear PCM format! - returns: An AudioStreamBasicDescription structure describing the format of the audio file.

    Declaration

    Objective-C

    @property (assign, readwrite, atomic) AudioStreamBasicDescription clientFormat;

    Swift

    var clientFormat: AudioStreamBasicDescription { get set }

    Return Value

    An AudioStreamBasicDescription structure describing the format of the audio file.

  • Provides the current write offset in the audio file as an NSTimeInterval (i.e. in seconds). When setting this it will determine the correct frame offset and perform a seekToFrame to the new time offset. - warning: Make sure the new current time offset is less than the duration or you will receive an invalid seek assertion.

    Declaration

    Objective-C

    @property (readonly, atomic) NSTimeInterval currentTime;

    Swift

    var currentTime: TimeInterval { get }
  • Provides the duration of the audio file in seconds.

    Declaration

    Objective-C

    @property (readonly, atomic) NSTimeInterval duration;

    Swift

    var duration: TimeInterval { get }
  • Provides the AudioStreamBasicDescription structure containing the format of the recorder’s audio file. - returns: An AudioStreamBasicDescription structure describing the format of the audio file.

    Declaration

    Objective-C

    @property (readonly, atomic) AudioStreamBasicDescription fileFormat;

    Swift

    var fileFormat: AudioStreamBasicDescription { get }

    Return Value

    An AudioStreamBasicDescription structure describing the format of the audio file.

  • Provides the current time as an NSString with the time format MM:SS.

    Declaration

    Objective-C

    @property (readonly, atomic) NSString *formattedCurrentTime;

    Swift

    var formattedCurrentTime: String! { get }
  • Provides the duration as an NSString with the time format MM:SS.

    Declaration

    Objective-C

    @property (readonly, atomic) NSString *formattedDuration;

    Swift

    var formattedDuration: String! { get }
  • Provides the frame index (a.k.a the write positon) within the audio file as SInt64. This can be helpful when seeking through the audio file. - returns: The current frame index within the audio file as a SInt64.

    Declaration

    Objective-C

    @property (readonly, atomic) SInt64 frameIndex;

    Swift

    var frameIndex: Int64 { get }

    Return Value

    The current frame index within the audio file as a SInt64.

  • Provides the total frame count of the recorder’s audio file in the file format. - returns: The total number of frames in the recorder in the AudioStreamBasicDescription representing the file format as a SInt64.

    Declaration

    Objective-C

    @property (readonly, atomic) SInt64 totalFrames;

    Swift

    var totalFrames: Int64 { get }

    Return Value

    The total number of frames in the recorder in the AudioStreamBasicDescription representing the file format as a SInt64.

  • Provides the file path that’s currently being used by the recorder. - returns: The NSURL representing the file path of the recorder path being used for recording.

    Declaration

    Objective-C

    - (NSURL *)url;

    Swift

    func url() -> URL!

    Return Value

    The NSURL representing the file path of the recorder path being used for recording.

  • Appends audio data to the tail of the output file from an AudioBufferList. - parameter: bufferList The AudioBufferList holding the audio data to append - parameter: bufferSize The size of each of the buffers in the buffer list.

    Declaration

    Objective-C

    - (void)appendDataFromBufferList:(AudioBufferList *)bufferList
                      withBufferSize:(UInt32)bufferSize;

    Swift

    func appendData(from bufferList: UnsafeMutablePointer

    Parameters

    bufferList

    The AudioBufferList holding the audio data to append

    bufferSize

    The size of each of the buffers in the buffer list.

  • Finishes writes to the recorder’s audio file and closes it.

    Declaration

    Objective-C

    - (void)closeAudioFile;

    Swift

    func closeAudioFile()