FMOD API User Manual 2.00
An interface that manages Codec plugins
Structures:
Callbacks:
State function:
Codec close callback.
This callback is called to shut down and release memory for the codec instance.
FMOD_RESULT F_CALLBACK FMOD_CODEC_CLOSE_CALLBACK(
FMOD_CODEC_STATE *codec_state
);
Invoked by:
See Also: FMOD_CODEC_DESCRIPTION, FMOD_CODEC_OPEN_CALLBACK, FMOD_CODEC_SOUNDCREATE_CALLBACK
Codec description.
This description structure allows the plugin writer to define all functionality required for a user defined codec.
typedef struct FMOD_CODEC_DESCRIPTION {
const char *name;
unsigned int version;
int defaultasstream;
FMOD_TIMEUNIT timeunits;
FMOD_CODEC_OPEN_CALLBACK open;
FMOD_CODEC_CLOSE_CALLBACK close;
FMOD_CODEC_READ_CALLBACK read;
FMOD_CODEC_GETLENGTH_CALLBACK getlength;
FMOD_CODEC_SETPOSITION_CALLBACK setposition;
FMOD_CODEC_GETPOSITION_CALLBACK getposition;
FMOD_CODEC_SOUNDCREATE_CALLBACK soundcreate;
FMOD_CODEC_GETWAVEFORMAT_CALLBACK getwaveformat;
} FMOD_CODEC_DESCRIPTION;
See Also: FMOD_CODEC_STATE, FMOD_CODEC_WAVEFORMAT
Codec get length callback.
This callback is called to retrieve the length of the audio file of this codec type.
FMOD_RESULT F_CALLBACK FMOD_CODEC_GETLENGTH_CALLBACK(
FMOD_CODEC_STATE *codec_state,
unsigned int *length,
FMOD_TIMEUNIT lengthtype
);
lengthtype.length. (FMOD_TIMEUNIT)Invoked by:
See Also: FMOD_CODEC_DESCRIPTION
Codec get position callback.
This callback is called to retrieve the current read position of the audio file of this codec type.
FMOD_RESULT F_CALLBACK FMOD_CODEC_GETPOSITION_CALLBACK(
FMOD_CODEC_STATE *codec_state,
unsigned int *position,
FMOD_TIMEUNIT postype
);
postype.position. This will be one of the timeunits supplied by the codec author in the FMOD_CODEC_DESCRIPTION structure. (FMOD_TIMEUNIT)Invoked by:
See Also: FMOD_CODEC_DESCRIPTION
Codec get wave format callback.
This callback is called to allow FMOD to retrieve the format of the file the codec instance represents.
FMOD_RESULT F_CALLBACK FMOD_CODEC_GETWAVEFORMAT_CALLBACK(
FMOD_CODEC_STATE *codec_state,
int index,
FMOD_CODEC_WAVEFORMAT *waveformat
);
Useful to reduce memory usage by limiting the number of FMOD_CODEC_WAVEFORMAT structures.
Codec metadata function.
This function is to be called when a codec's metadata is updated.
FMOD_RESULT F_CALLBACK FMOD_CODEC_METADATA_FUNC(
FMOD_CODEC_STATE *codec_state,
FMOD_TAGTYPE tagtype,
char *name,
void *data,
unsigned int datalen,
FMOD_TAGDATATYPE datatype,
int unique
);
Data length of the tag data in bytes.
Codec metadata can be retrieved by the user with Sound::getTag
Codec metadata can be added during creation, or during playback. A common case for play time metadata is internet based streams.
See Also: FMOD_CODEC_DESCRIPTION
Codec open callback.
This callback is called to initialize a codec instance using the codec's file handle to verify if the file is of the type of the codec, and to do any file reading required for initialization of the codec.
FMOD_RESULT F_CALLBACK FMOD_CODEC_OPEN_CALLBACK(
FMOD_CODEC_STATE *codec_state,
FMOD_MODE usermode,
FMOD_CREATESOUNDEXINFO *userexinfo
);
Invoked by:
Implementation detail:
This callback is where the file format check is done, memory is allocated, and the codec is initialized.
The usermode and userexinfo parameters tell the codec what was passed in by the user. Generally these can be ignored, as the file format usually determines the format and frequency of the sound. If you have a flexible format codec (ie you don't mind what output format your codec writes to), you might want to use the parameter that was passed in by the user to specify the output sound format / frequency.
Read and seek within the file using the fileread and fileseek members of the FMOD_CODEC_STATE structure that is passed in.
Note!: Do not use your own filesystem.
The reasons for this are:
Important! FMOD will ping all codecs trying to find the right one for the file the user has passed in. Make sure the first line of your codec open is a FAST format check. Ie it reads an identifying string, checks it and returns an error FMOD_ERR_FORMAT if it is not found.
See Also: FMOD_CODEC_DESCRIPTION, FMOD_CODEC_CLOSE_CALLBACK, FMOD_CODEC_SOUNDCREATE_CALLBACK
Codec read callback.
This callback is called to read PCM data from the codec instance.
FMOD_RESULT F_CALLBACK FMOD_CODEC_READ_CALLBACK(
FMOD_CODEC_STATE *codec_state,
void *buffer,
unsigned int samples_in,
unsigned int *samples_out
);
Target PCM data buffer. Note that the format of this data is the format described in FMOD_CODEC_WAVEFORMAT.
Number of PCM samples to decode
Number of PCM samples decoded
This callback is issued when FMOD tries to read some data from the file to the destination format (the format specified in the FMOD_CODEC_OPEN_CALLBACK).
Implementation detail:
If you cannot read number of samples requested, simply return FMOD_OK and give samples_out the number of samples you decoded.
Read and seek within the file using the fileread and fileseek members of the FMOD_CODEC_STATE structure that is passed in.
Note!: Do not use your own filesystem.
The reasons for this are:
See Also: FMOD_CODEC_DESCRIPTION
Codec set position callback.
This callback is called to set the audible position of a codec instance.
FMOD_RESULT F_CALLBACK FMOD_CODEC_SETPOSITION_CALLBACK(
FMOD_CODEC_STATE *codec_state,
int subsound,
unsigned int position,
FMOD_TIMEUNIT postype
);
postype.position. This will be one of the timeunits supplied by the codec author in the FMOD_CODEC_DESCRIPTION structure. (FMOD_TIMEUNIT)Invoked by:
Implementation detail:
Read and seek within the file using the fileread and fileseek members of the FMOD_CODEC_STATE structure that is passed in.
Note!: Do not use your own filesystem.
The reasons for this are:
See Also: Channel::getPosition, FMOD_CODEC_READ_CALLBACK, FMOD_CODEC_GETLENGTH_CALLBACK, FMOD_CODEC_GETPOSITION_CALLBACK
Codec sound create callback.
This callback is called after a Sound is created.
FMOD_RESULT F_CALLBACK FMOD_CODEC_SOUNDCREATE_CALLBACK(
FMOD_CODEC_STATE *codec_state,
int subsound,
FMOD_SOUND *sound
);
Invoked by:
Useful so the codec can set more parameters for the related created sound.
See Also: System::createSound, System::createStream
Codec state structure that is passed into each callback.
typedef struct FMOD_CODEC_STATE {
int numsubsounds;
FMOD_CODEC_WAVEFORMAT *waveformat;
void *plugindata;
void *filehandle;
unsigned int filesize;
FMOD_FILE_READ_CALLBACK fileread;
FMOD_FILE_SEEK_CALLBACK fileseek;
FMOD_CODEC_METADATA_FUNC metadata;
int waveformatversion;
} FMOD_CODEC_STATE;
'numsubsounds' should be 1+ if the file is a container format, and does not contain wav data itself. Examples of these types would be FSB (contains multiple sounds), DLS (contain instruments).
The waveformat value should point to an arrays of information based on how many subsounds are in the format. If the number of subsounds is 0 then it should point to 1 waveformat, the same as if the number of subsounds was 1. If subsounds was 100 for example, there should be a pointer to an array of 100 waveformat structures.
When a sound has 1 or more subsounds, the caller must play the individual sounds specified by first obtaining the subsound with Sound::getSubSound.
Codec wave format.
This structure defines the attributes of a sound, and determines the format of the Sound object when it is created with System::createSound or System::createStream
typedef struct FMOD_CODEC_WAVEFORMAT {
const char* name;
FMOD_SOUND_FORMAT format;
int channels;
int frequency;
unsigned int lengthbytes;
unsigned int lengthpcm;
unsigned int pcmblocksize;
int loopstart;
int loopend;
FMOD_MODE mode;
FMOD_CHANNELMASK channelmask;
FMOD_CHANNELORDER channelorder;
float peakvolume;
} FMOD_CODEC_WAVEFORMAT;
Default frequency of the codec.
Length of the source data. Used for FMOD_TIMEUNIT_RAWBYTES.
Length of the file. Used for Sound::getLength and for memory allocation of static decompressed sample data.
Loop start position.
Loop end position.
Default sound loading mode. (FMOD_MODE)
The format, channels, frequency and lengthpcm tell FMOD what sort of sound buffer to create when you initialize your code.
If you wrote an MP3 codec that decoded to stereo 16bit integer PCM for a 44khz sound, you would specify FMOD_SOUND_FORMAT_PCM16, and channels would be equal to 2, and frequency would be 44100.
1.07 Note. 'blockalign' member which was in bytes has been removed. 'pcmblocksize' is now the replacement, and is measured in PCM samples only, not bytes. This is purely to support buffering
internal to FMOD for codecs that are not sample accurate.
Note: When registering a codec, format, channels, frequency and lengthpcm must be supplied, otherwise there will be an error.
This structure is optional if FMOD_CODEC_GETWAVEFORMAT_CALLBACK is specified.
An array of these structures may be needed if FMOD_CODEC_STATE::numsubsounds is larger than 1.
See Also: FMOD_CODEC_STATE, FMOD_CODEC_DESCRIPTION
Codec Wave format version number.
Use this for binary compatibility of the FMOD_CODEC_WAVEFORMAT structure and for future expansion.
#define FMOD_CODEC_WAVEFORMAT_VERSION 3
FMOD_CODEC_WAVEFORMAT_VERSION
:
Should be set into FMOD_CODEC_STATE in the FMOD_CODEC_OPEN_CALLBACK.
The version here represents the version of the FMOD_CODEC_WAVEFORMAT structure, which has evolved over time in FMOD. The FMOD_CODEC_STATE contains the waveformat member with the structure in question.
See Also: FMOD_CODEC_DESCRIPTION