Retrieves a CoreAudio codec encoder's ExtAudioFileRef object.

void *BASS_Encode_GetCARef(
    HENCODE handle


handleThe encoder.

Return value

If successful, then the encoder's ExtAudioFileRef object is returned, otherwise NULL is returned. Use BASS_ErrorGetCode to get the error code.

Error codes

BASS_ERROR_HANDLEhandle is not valid.
BASS_ERROR_NOTAVAILThe encoder is not using a CoreAudio codec.


This function allows those that are familiar with the Extended Audio File Services interface to configure a CoreAudio codec. Configuration changes need to be made before any data is encoded, so the encoder should be created in a paused state (BASS_ENCODE_PAUSE) to ensure that.


This function is only available on OSX and iOS.


Tell the codec the expected duration.
#include <AudioToolbox/ExtendedAudioFile.h>
encoder=BASS_Encode_StartCAFile(channel, 'mp4f', 'aac ', 0, 128000, "output.mp4"); // start the encoder
ExtAudioFileRef eaf=BASS_Encode_GetCARef(encoder); // get the encoder's ExtAudioFileRef
AudioFileID afid;
UInt32 s=sizeof(afid);
if (!ExtAudioFileGetProperty(eaf, kExtAudioFileProperty_AudioFile, &s, &afid)) { // get associated AudioFileID
	Float64 duration=expected_duration_in_seconds;
	AudioFileSetProperty(afid, kAudioFilePropertyReserveDuration, sizeof(duration), &duration); // set expected duration
BASS_Encode_SetPaused(encoder, FALSE); // start encoding

See also

BASS_Encode_StartCA, BASS_Encode_StartCAFile