fmod_codec.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /* ======================================================================================== */
  2. /* FMOD Core API - Codec development header file. */
  3. /* Copyright (c), Firelight Technologies Pty, Ltd. 2004-2024. */
  4. /* */
  5. /* Use this header if you are wanting to develop your own file format plugin to use with */
  6. /* FMOD's codec system. With this header you can make your own fileformat plugin that FMOD */
  7. /* can register and use. See the documentation and examples on how to make a working */
  8. /* plugin. */
  9. /* */
  10. /* For more detail visit: */
  11. /* https://fmod.com/docs/2.03/api/core-api.html */
  12. /* ======================================================================================== */
  13. #ifndef _FMOD_CODEC_H
  14. #define _FMOD_CODEC_H
  15. /*
  16. Codec types
  17. */
  18. typedef struct FMOD_CODEC_STATE FMOD_CODEC_STATE;
  19. typedef struct FMOD_CODEC_WAVEFORMAT FMOD_CODEC_WAVEFORMAT;
  20. /*
  21. Codec constants
  22. */
  23. #define FMOD_CODEC_PLUGIN_VERSION 1
  24. typedef int FMOD_CODEC_SEEK_METHOD;
  25. #define FMOD_CODEC_SEEK_METHOD_SET 0
  26. #define FMOD_CODEC_SEEK_METHOD_CURRENT 1
  27. #define FMOD_CODEC_SEEK_METHOD_END 2
  28. /*
  29. Codec callbacks
  30. */
  31. typedef FMOD_RESULT (F_CALL *FMOD_CODEC_OPEN_CALLBACK) (FMOD_CODEC_STATE *codec_state, FMOD_MODE usermode, FMOD_CREATESOUNDEXINFO *userexinfo);
  32. typedef FMOD_RESULT (F_CALL *FMOD_CODEC_CLOSE_CALLBACK) (FMOD_CODEC_STATE *codec_state);
  33. typedef FMOD_RESULT (F_CALL *FMOD_CODEC_READ_CALLBACK) (FMOD_CODEC_STATE *codec_state, void *buffer, unsigned int samples_in, unsigned int *samples_out);
  34. typedef FMOD_RESULT (F_CALL *FMOD_CODEC_GETLENGTH_CALLBACK) (FMOD_CODEC_STATE *codec_state, unsigned int *length, FMOD_TIMEUNIT lengthtype);
  35. typedef FMOD_RESULT (F_CALL *FMOD_CODEC_SETPOSITION_CALLBACK) (FMOD_CODEC_STATE *codec_state, int subsound, unsigned int position, FMOD_TIMEUNIT postype);
  36. typedef FMOD_RESULT (F_CALL *FMOD_CODEC_GETPOSITION_CALLBACK) (FMOD_CODEC_STATE *codec_state, unsigned int *position, FMOD_TIMEUNIT postype);
  37. typedef FMOD_RESULT (F_CALL *FMOD_CODEC_SOUNDCREATE_CALLBACK) (FMOD_CODEC_STATE *codec_state, int subsound, FMOD_SOUND *sound);
  38. typedef FMOD_RESULT (F_CALL *FMOD_CODEC_GETWAVEFORMAT_CALLBACK)(FMOD_CODEC_STATE *codec_state, int index, FMOD_CODEC_WAVEFORMAT *waveformat);
  39. /*
  40. Codec functions
  41. */
  42. typedef FMOD_RESULT (F_CALL *FMOD_CODEC_METADATA_FUNC) (FMOD_CODEC_STATE *codec_state, FMOD_TAGTYPE tagtype, char *name, void *data, unsigned int datalen, FMOD_TAGDATATYPE datatype, int unique);
  43. typedef void * (F_CALL *FMOD_CODEC_ALLOC_FUNC) (unsigned int size, unsigned int align, const char *file, int line);
  44. typedef void (F_CALL *FMOD_CODEC_FREE_FUNC) (void *ptr, const char *file, int line);
  45. typedef void (F_CALL *FMOD_CODEC_LOG_FUNC) (FMOD_DEBUG_FLAGS level, const char *file, int line, const char *function, const char *string, ...);
  46. typedef FMOD_RESULT (F_CALL *FMOD_CODEC_FILE_READ_FUNC) (FMOD_CODEC_STATE *codec_state, void *buffer, unsigned int sizebytes, unsigned int *bytesread);
  47. typedef FMOD_RESULT (F_CALL *FMOD_CODEC_FILE_SEEK_FUNC) (FMOD_CODEC_STATE *codec_state, unsigned int pos, FMOD_CODEC_SEEK_METHOD method);
  48. typedef FMOD_RESULT (F_CALL *FMOD_CODEC_FILE_TELL_FUNC) (FMOD_CODEC_STATE *codec_state, unsigned int *pos);
  49. typedef FMOD_RESULT (F_CALL *FMOD_CODEC_FILE_SIZE_FUNC) (FMOD_CODEC_STATE *codec_state, unsigned int *size);
  50. /*
  51. Codec structures
  52. */
  53. typedef struct FMOD_CODEC_DESCRIPTION
  54. {
  55. unsigned int apiversion;
  56. const char *name;
  57. unsigned int version;
  58. int defaultasstream;
  59. FMOD_TIMEUNIT timeunits;
  60. FMOD_CODEC_OPEN_CALLBACK open;
  61. FMOD_CODEC_CLOSE_CALLBACK close;
  62. FMOD_CODEC_READ_CALLBACK read;
  63. FMOD_CODEC_GETLENGTH_CALLBACK getlength;
  64. FMOD_CODEC_SETPOSITION_CALLBACK setposition;
  65. FMOD_CODEC_GETPOSITION_CALLBACK getposition;
  66. FMOD_CODEC_SOUNDCREATE_CALLBACK soundcreate;
  67. FMOD_CODEC_GETWAVEFORMAT_CALLBACK getwaveformat;
  68. } FMOD_CODEC_DESCRIPTION;
  69. struct FMOD_CODEC_WAVEFORMAT
  70. {
  71. const char* name;
  72. FMOD_SOUND_FORMAT format;
  73. int channels;
  74. int frequency;
  75. unsigned int lengthbytes;
  76. unsigned int lengthpcm;
  77. unsigned int pcmblocksize;
  78. int loopstart;
  79. int loopend;
  80. FMOD_MODE mode;
  81. FMOD_CHANNELMASK channelmask;
  82. FMOD_CHANNELORDER channelorder;
  83. float peakvolume;
  84. };
  85. typedef struct FMOD_CODEC_STATE_FUNCTIONS
  86. {
  87. FMOD_CODEC_METADATA_FUNC metadata;
  88. FMOD_CODEC_ALLOC_FUNC alloc;
  89. FMOD_CODEC_FREE_FUNC free;
  90. FMOD_CODEC_LOG_FUNC log;
  91. FMOD_CODEC_FILE_READ_FUNC read;
  92. FMOD_CODEC_FILE_SEEK_FUNC seek;
  93. FMOD_CODEC_FILE_TELL_FUNC tell;
  94. FMOD_CODEC_FILE_SIZE_FUNC size;
  95. } FMOD_CODEC_STATE_FUNCTIONS;
  96. struct FMOD_CODEC_STATE
  97. {
  98. void *plugindata;
  99. FMOD_CODEC_WAVEFORMAT *waveformat;
  100. FMOD_CODEC_STATE_FUNCTIONS *functions;
  101. int numsubsounds;
  102. };
  103. /*
  104. Codec macros
  105. */
  106. #define FMOD_CODEC_METADATA(_state, _tagtype, _name, _data, _datalen, _datatype, _unique) \
  107. (_state)->functions->metadata(_state, _tagtype, _name, _data, _datalen, _datatype, _unique)
  108. #define FMOD_CODEC_ALLOC(_state, _size, _align) \
  109. (_state)->functions->alloc(_size, _align, __FILE__, __LINE__)
  110. #define FMOD_CODEC_FREE(_state, _ptr) \
  111. (_state)->functions->free(_ptr, __FILE__, __LINE__)
  112. #define FMOD_CODEC_LOG(_state, _level, _location, _format, ...) \
  113. (_state)->functions->log(_level, __FILE__, __LINE__, _location, _format, ##__VA_ARGS__)
  114. #define FMOD_CODEC_FILE_READ(_state, _buffer, _sizebytes, _bytesread) \
  115. (_state)->functions->read(_state, _buffer, _sizebytes, _bytesread)
  116. #define FMOD_CODEC_FILE_SEEK(_state, _pos, _method) \
  117. (_state)->functions->seek(_state, _pos, _method)
  118. #define FMOD_CODEC_FILE_TELL(_state, _pos) \
  119. (_state)->functions->tell(_state, _pos)
  120. #define FMOD_CODEC_FILE_SIZE(_state, _size) \
  121. (_state)->functions->size(_state, _size)
  122. #endif