/' ==================================================================================================== '/
/' FMOD Ex - codec development header file. Copyright (c), Firelight Technologies Pty, Ltd. 2004-2011.  '/
/'                                                                                                      '/
/' Use this header if you are wanting to develop your own file format plugin to use with                '/
/' FMOD's codec system.  With this header you can make your own fileformat plugin that FMOD             '/
/' can register and use.  See the documentation and examples on how to make a working plugin.           '/
/'                                                                                                      '/
/' ==================================================================================================== '/

#ifndef _FMOD_CODEC_BI
#define _FMOD_CODEC_BI

type as FMOD_CODEC_STATE_ FMOD_CODEC_STATE
type as FMOD_CODEC_WAVEFORMAT_ FMOD_CODEC_WAVEFORMAT

/'
    Codec callbacks
'/ 
type FMOD_CODEC_OPENCALLBACK as function(byval codec_state as FMOD_CODEC_STATE ptr, byval usermode as FMOD_MODE, _
byval userexinfo as FMOD_CREATESOUNDEXINFO ptr) as FMOD_RESULT
type FMOD_CODEC_CLOSECALLBACK as function(byval codec_state as FMOD_CODEC_STATE ptr) as FMOD_RESULT
type FMOD_CODEC_READCALLBACK as function(byval codec_state as FMOD_CODEC_STATE ptr, byval buffer as any ptr, byval sizebytes as uinteger, _
byval bytesread as uinteger ptr) as FMOD_RESULT
type FMOD_CODEC_GETLENGTHCALLBACK as function(byval codec_state as FMOD_CODEC_STATE ptr, byval length as uinteger ptr, _
byval lengthtype as FMOD_TIMEUNIT) as FMOD_RESULT
type FMOD_CODEC_SETPOSITIONCALLBACK as function(byval codec_state as FMOD_CODEC_STATE ptr, byval subsound as integer, byval position as uinteger, _
byval postype as FMOD_TIMEUNIT) as FMOD_RESULT
type FMOD_CODEC_GETPOSITIONCALLBACK as function(byval codec_state as FMOD_CODEC_STATE ptr, byval position as uinteger, byval postype as FMOD_TIMEUNIT) as FMOD_RESULT
type FMOD_CODEC_SOUNDCREATECALLBACK as function(byval codec_state as FMOD_CODEC_STATE ptr, byval subsound as integer, byval sound as FMOD_SOUND ptr) as FMOD_RESULT
type  FMOD_CODEC_METADATACALLBACK as function(byval codec_state as FMOD_CODEC_STATE ptr, byval tagtype as FMOD_TAGTYPE, _
byval name_ as zstring ptr, byval data_ as any ptr, byval datalen as uinteger, byval datatype as FMOD_TAGDATATYPE, byval unique as integer) as FMOD_RESULT
type FMOD_CODEC_GETWAVEFORMAT as function(byval codec_state as FMOD_CODEC_STATE ptr, byval index as integer, byval waveformat as FMOD_CODEC_WAVEFORMAT ptr) as FMOD_RESULT


/'
[STRUCTURE] 
[
    [DESCRIPTION]
    When creating a codec, declare one of these and provide the relevant callbacks and name for FMOD to use when it opens and reads a file.

    [REMARKS]
    Members marked with [in] mean the variable can be written to.  The user can set the value.
    Members marked with [out] mean the variable is modified by FMOD and is for reading purposes only.  Do not change this value.

    [PLATFORMS]
    Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android

    [SEE_ALSO]
    FMOD_CODEC_STATE
]
'/
type FMOD_CODEC_DESCRIPTION
    as const zstring ptr name            /' [in] Name of the codec. '/
    as uinteger version         /' [in] Plugin writer's version number. '/
    as integer defaultasstream /' [in] Tells FMOD to open the file as a stream when calling Fmod_system_createSound, and not a static sample.  Should normally be 0 (FALSE), because generally the user wants to decode the file into memory when using Fmod_system_createSound.   Mainly used for formats that decode for a very long time, or could use large amounts of memory when decoded.  Usually sequenced formats such as mod/s3m/xm/it/midi fall into this category.   It is mainly to stop users that don't know what they're doing from getting FMOD_ERR_MEMORY returned from createSound when they should have in fact called Fmod_system_createStream or used FMOD_CREATESTREAM in Fmod_system_createSound. '/
    as FMOD_TIMEUNIT timeunits       /' [in] When setposition codec is called, only these time formats will be passed to the codec. Use bitwise OR to accumulate different types. '/
    as FMOD_CODEC_OPENCALLBACK open            /' [in] Open callback for the codec for when FMOD tries to open a sound using this codec. '/
    as FMOD_CODEC_CLOSECALLBACK close           /' [in] Close callback for the codec for when FMOD tries to close a sound using this codec.  '/
    as FMOD_CODEC_READCALLBACK read            /' [in] Read callback for the codec for when FMOD tries to read some data from the file to the destination format (specified in the open callback). '/
    as FMOD_CODEC_GETLENGTHCALLBACK getlength       /' [in] Callback to return the length of the song in whatever format required when Fmod_sound_getLength is called. '/
    as FMOD_CODEC_SETPOSITIONCALLBACK setposition     /' [in] Seek callback for the codec for when FMOD tries to seek within the file with Channel::setPosition. '/
    as FMOD_CODEC_GETPOSITIONCALLBACK getposition     /' [in] Tell callback for the codec for when FMOD tries to get the current position within the with Channel::getPosition. '/
    as FMOD_CODEC_SOUNDCREATECALLBACK soundcreate     /' [in] Sound creation callback for the codec when FMOD finishes creating the sound.  (So the codec can set more parameters for the related created sound, ie loop points/mode or 3D attributes etc). '/
    as FMOD_CODEC_GETWAVEFORMAT getwaveformat   /' [in] Callback to tell FMOD about the waveformat of a particular subsound.  This is to save memory, rather than saving 1000 FMOD_CODEC_WAVEFORMAT structures in the codec, the codec might have a more optimal way of storing this information. '/
end type


/'
[STRUCTURE] 
[
    [DESCRIPTION]
    Set these values marked 'in' to tell fmod what sort of sound to create.
    The format, channels and frequency tell FMOD what sort of hardware buffer to create when you initialize your code.  So if you wrote an MP3 codec that decoded to stereo 16bit integer PCM, you would specify FMOD_SOUND_FORMAT_PCM16, and channels would be equal to 2.
    Members marked as 'out' are set by fmod.  Do not modify these.  Simply specify 0 for these values when declaring the structure, FMOD will fill in the values for you after creation with the correct function pointers.

    [REMARKS]
    Members marked with [in] mean the variable can be written to.  The user can set the value.
    Members marked with [out] mean the variable is modified by FMOD and is for reading purposes only.  Do not change this value.
    
    An FMOD file might be from disk, memory or network, however the file may be opened by the user.
    
    'numsubsounds' should be 0 if the file is a normal single sound stream or sound.  Examples of this would be .WAV, .WMA, .MP3, .AIFF.
    'numsubsounds' should be 1+ if the file is a container format, and does not contain wav data itself.  Examples of these types would be CDDA (multiple CD tracks), FSB (contains multiple sounds), MIDI/MOD/S3M/XM/IT (contain instruments).
    The arrays of format, channel, frequency, length and blockalign should point to 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 of each attribute, the same as if the number of subsounds was 1.  If subsounds was 100 for example, each pointer should point to an array of 100 of each attribute.
    When a sound has 1 or more subsounds, you must play the individual sounds specified by first obtaining the subsound with Fmod_sound_getSubSound.
    
    [PLATFORMS]
    Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android

    [SEE_ALSO]
    FMOD_SOUND_FORMAT
    FMOD_FILE_READCALLBACK      
    FMOD_FILE_SEEKCALLBACK      
    FMOD_CODEC_METADATACALLBACK
    Fmod_sound_getSubSound
    Fmod_sound_getNumSubSounds
]
'/
type FMOD_CODEC_WAVEFORMAT_
    as zstring * 256 name      /' [in] Name of sound.'/
    as FMOD_SOUND_FORMAT format        /' [in] Format for (decompressed) codec output, ie FMOD_SOUND_FORMAT_PCM8, FMOD_SOUND_FORMAT_PCM16.'/
    as integer channels      /' [in] Number of channels used by codec, ie mono = 1, stereo = 2. '/
    as integer frequency     /' [in] Default frequency in hz of the codec, ie 44100. '/
    as uinteger lengthbytes   /' [in] Length in bytes of the source data. '/
    as uinteger lengthpcm     /' [in] Length in decompressed, PCM samples of the file, ie length in seconds * frequency.  Used for Fmod_sound_getLength and for memory allocation of static decompressed sample data. '/
    as integer                blockalign    /' [in] Blockalign in decompressed, PCM samples of the optimal decode chunk size for this format.  The codec read callback will be called in multiples of this value. '/
    as integer loopstart     /' [in] Loopstart in decompressed, PCM samples of file. '/
    as integer loopend       /' [in] Loopend in decompressed, PCM samples of file. '/
    as FMOD_MODE mode          /' [in] Mode to determine whether the sound should by default load as looping, non looping, 2d or 3d. '/
    as uinteger channelmask   /' [in] Microsoft speaker channel mask, as defined for WAVEFORMATEXTENSIBLE and is found in ksmedia.h.  Leave at 0 to play in natural speaker order. '/
end type


/'
[STRUCTURE] 
[
    [DESCRIPTION]
    Codec plugin structure that is passed into each callback.
    
    Set these numsubsounds and waveformat members when called in FMOD_CODEC_OPENCALLBACK to tell fmod what sort of sound to create.
    
    The format, channels and frequency tell FMOD what sort of hardware buffer to create when you initialize your code.  So if you wrote an MP3 codec that decoded to stereo 16bit integer PCM, you would specify FMOD_SOUND_FORMAT_PCM16, and channels would be equal to 2.

    [REMARKS]
    Members marked with [in] mean the variable can be written to.  The user can set the value.
    Members marked with [out] mean the variable is modified by FMOD and is for reading purposes only.  Do not change this value.
    
    An FMOD file might be from disk, memory or internet, however the file may be opened by the user.
    
    'numsubsounds' should be 0 if the file is a normal single sound stream or sound.  Examples of this would be .WAV, .WMA, .MP3, .AIFF.
    'numsubsounds' should be 1+ if the file is a container format, and does not contain wav data itself.  Examples of these types would be CDDA (multiple CD tracks), FSB (contains multiple sounds), DLS (contain instruments).
    The arrays of format, channel, frequency, length and blockalign should point to 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 of each attribute, the same as if the number of subsounds was 1.  If subsounds was 100 for example, each pointer should point to an array of 100 of each attribute.
    When a sound has 1 or more subsounds, you must play the individual sounds specified by first obtaining the subsound with Fmod_sound_getSubSound.
    
    [PLATFORMS]
    Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android

    [SEE_ALSO]
    FMOD_SOUND_FORMAT
    FMOD_FILE_READCALLBACK      
    FMOD_FILE_SEEKCALLBACK      
    FMOD_CODEC_METADATACALLBACK
    Fmod_sound_getSubSound
    Fmod_sound_getNumSubSounds
]
'/
type FMOD_CODEC_STATE_
    as integer numsubsounds  /' [in] Number of 'subsounds' in this sound.  Anything other than 0 makes it a 'container' format (ie CDDA/DLS/FSB etc which contain 1 or more su bsounds).  For most normal, single sound codec such as WAV/AIFF/MP3, this should be 0 as they are not a container for subsounds, they are the sound by itself. '/
    as FMOD_CODEC_WAVEFORMAT ptr waveformat    /' [in] Pointer to an array of format structures containing information about each sample.  Can be 0 or NULL if FMOD_CODEC_GETWAVEFORMAT callback is preferred.  The number of entries here must equal the number of subsounds defined in the subsound parameter. If numsubsounds = 0 then there should be 1 instance of this structure. '/
    as any ptr plugindata    /' [in] Plugin writer created data the codec author wants to attach to this object. '/
                                               
    as any ptr filehandle    /' [out] This will return an internal FMOD file handle to use with the callbacks provided.  '/
    as uinteger filesize      /' [out] This will contain the size of the file in bytes. '/
    as FMOD_FILE_READCALLBACK fileread      /' [out] This will return a callable FMOD file function to use from codec. '/
    as FMOD_FILE_SEEKCALLBACK fileseek      /' [out] This will return a callable FMOD file function to use from codec.  '/
    as FMOD_CODEC_METADATACALLBACK metadata      /' [out] This will return a callable FMOD metadata function to use from codec.  '/
end type

#endif


