modplug.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*
  2. * This source code is public domain.
  3. *
  4. * Authors: Kenton Varda <[email protected]> (C interface wrapper)
  5. */
  6. #ifndef MODPLUG_MODPLUG_H
  7. #define MODPLUG_MODPLUG_H
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. #if defined(_WIN32) || defined(__CYGWIN__)
  12. # if defined(MODPLUG_BUILD) && defined(DLL_EXPORT) /* building libmodplug as a dll for windows */
  13. # define MODPLUG_EXPORT __declspec(dllexport)
  14. # elif defined(MODPLUG_BUILD) || defined(MODPLUG_STATIC) /* building or using static libmodplug for windows */
  15. # define MODPLUG_EXPORT
  16. # else
  17. # define MODPLUG_EXPORT __declspec(dllimport) /* using libmodplug dll for windows */
  18. # endif
  19. /* FIXME: USE VISIBILITY ATTRIBUTES HERE */
  20. #elif defined(MODPLUG_BUILD)
  21. #define MODPLUG_EXPORT
  22. #else
  23. #define MODPLUG_EXPORT
  24. #endif
  25. struct _ModPlugFile;
  26. typedef struct _ModPlugFile ModPlugFile;
  27. struct _ModPlugNote {
  28. unsigned char Note;
  29. unsigned char Instrument;
  30. unsigned char VolumeEffect;
  31. unsigned char Effect;
  32. unsigned char Volume;
  33. unsigned char Parameter;
  34. };
  35. typedef struct _ModPlugNote ModPlugNote;
  36. typedef void (*ModPlugMixerProc)(int*, unsigned long, unsigned long);
  37. /* Load a mod file. [data] should point to a block of memory containing the complete
  38. * file, and [size] should be the size of that block.
  39. * Return the loaded mod file on success, or NULL on failure. */
  40. MODPLUG_EXPORT ModPlugFile* ModPlug_Load(const void* data, int size);
  41. /* Unload a mod file. */
  42. MODPLUG_EXPORT void ModPlug_Unload(ModPlugFile* file);
  43. /* Read sample data into the buffer. Returns the number of bytes read. If the end
  44. * of the mod has been reached, zero is returned. */
  45. MODPLUG_EXPORT int ModPlug_Read(ModPlugFile* file, void* buffer, int size);
  46. /* Get the name of the mod. The returned buffer is stored within the ModPlugFile
  47. * structure and will remain valid until you unload the file. */
  48. MODPLUG_EXPORT const char* ModPlug_GetName(ModPlugFile* file);
  49. /* Get the length of the mod, in milliseconds. Note that this result is not always
  50. * accurate, especially in the case of mods with loops. */
  51. MODPLUG_EXPORT int ModPlug_GetLength(ModPlugFile* file);
  52. /* Seek to a particular position in the song. Note that seeking and MODs don't mix very
  53. * well. Some mods will be missing instruments for a short time after a seek, as ModPlug
  54. * does not scan the sequence backwards to find out which instruments were supposed to be
  55. * playing at that time. (Doing so would be difficult and not very reliable.) Also,
  56. * note that seeking is not very exact in some mods -- especially those for which
  57. * ModPlug_GetLength() does not report the full length. */
  58. MODPLUG_EXPORT void ModPlug_Seek(ModPlugFile* file, int millisecond);
  59. enum _ModPlug_Flags
  60. {
  61. MODPLUG_ENABLE_OVERSAMPLING = 1 << 0, /* Enable oversampling (*highly* recommended) */
  62. MODPLUG_ENABLE_NOISE_REDUCTION = 1 << 1, /* Enable noise reduction */
  63. MODPLUG_ENABLE_REVERB = 1 << 2, /* Enable reverb */
  64. MODPLUG_ENABLE_MEGABASS = 1 << 3, /* Enable megabass */
  65. MODPLUG_ENABLE_SURROUND = 1 << 4 /* Enable surround sound. */
  66. };
  67. enum _ModPlug_ResamplingMode
  68. {
  69. MODPLUG_RESAMPLE_NEAREST = 0, /* No interpolation (very fast, extremely bad sound quality) */
  70. MODPLUG_RESAMPLE_LINEAR = 1, /* Linear interpolation (fast, good quality) */
  71. MODPLUG_RESAMPLE_SPLINE = 2, /* Cubic spline interpolation (high quality) */
  72. MODPLUG_RESAMPLE_FIR = 3 /* 8-tap fir filter (extremely high quality) */
  73. };
  74. typedef struct _ModPlug_Settings
  75. {
  76. int mFlags; /* One or more of the MODPLUG_ENABLE_* flags above, bitwise-OR'ed */
  77. /* Note that ModPlug always decodes sound at 44100kHz, 32 bit, stereo and then
  78. * down-mixes to the settings you choose. */
  79. int mChannels; /* Number of channels - 1 for mono or 2 for stereo */
  80. int mBits; /* Bits per sample - 8, 16, or 32 */
  81. int mFrequency; /* Sampling rate - 11025, 22050, or 44100 */
  82. int mResamplingMode; /* One of MODPLUG_RESAMPLE_*, above */
  83. int mStereoSeparation; /* Stereo separation, 1 - 256 */
  84. int mMaxMixChannels; /* Maximum number of mixing channels (polyphony), 32 - 256 */
  85. int mReverbDepth; /* Reverb level 0(quiet)-100(loud) */
  86. int mReverbDelay; /* Reverb delay in ms, usually 40-200ms */
  87. int mBassAmount; /* XBass level 0(quiet)-100(loud) */
  88. int mBassRange; /* XBass cutoff in Hz 10-100 */
  89. int mSurroundDepth; /* Surround level 0(quiet)-100(heavy) */
  90. int mSurroundDelay; /* Surround delay in ms, usually 5-40ms */
  91. int mLoopCount; /* Number of times to loop. Zero prevents looping.
  92. -1 loops forever. */
  93. } ModPlug_Settings;
  94. /* Get and set the mod decoder settings. All options, except for channels, bits-per-sample,
  95. * sampling rate, and loop count, will take effect immediately. Those options which don't
  96. * take effect immediately will take effect the next time you load a mod. */
  97. MODPLUG_EXPORT void ModPlug_GetSettings(ModPlug_Settings* settings);
  98. MODPLUG_EXPORT void ModPlug_SetSettings(const ModPlug_Settings* settings);
  99. /* New ModPlug API Functions */
  100. /* NOTE: Master Volume (1-512) */
  101. MODPLUG_EXPORT unsigned int ModPlug_GetMasterVolume(ModPlugFile* file) ;
  102. MODPLUG_EXPORT void ModPlug_SetMasterVolume(ModPlugFile* file,unsigned int cvol) ;
  103. MODPLUG_EXPORT int ModPlug_GetCurrentSpeed(ModPlugFile* file);
  104. MODPLUG_EXPORT int ModPlug_GetCurrentTempo(ModPlugFile* file);
  105. MODPLUG_EXPORT int ModPlug_GetCurrentOrder(ModPlugFile* file);
  106. MODPLUG_EXPORT int ModPlug_GetCurrentPattern(ModPlugFile* file);
  107. MODPLUG_EXPORT int ModPlug_GetCurrentRow(ModPlugFile* file);
  108. MODPLUG_EXPORT int ModPlug_GetPlayingChannels(ModPlugFile* file);
  109. MODPLUG_EXPORT void ModPlug_SeekOrder(ModPlugFile* file,int order);
  110. MODPLUG_EXPORT int ModPlug_GetModuleType(ModPlugFile* file);
  111. MODPLUG_EXPORT char* ModPlug_GetMessage(ModPlugFile* file);
  112. #ifndef MODPLUG_NO_FILESAVE
  113. /*
  114. * EXPERIMENTAL Export Functions
  115. */
  116. /*Export to a Scream Tracker 3 S3M module. EXPERIMENTAL (only works on Little-Endian platforms)*/
  117. MODPLUG_EXPORT char ModPlug_ExportS3M(ModPlugFile* file, const char* filepath);
  118. /*Export to a Extended Module (XM). EXPERIMENTAL (only works on Little-Endian platforms)*/
  119. MODPLUG_EXPORT char ModPlug_ExportXM(ModPlugFile* file, const char* filepath);
  120. /*Export to a Amiga MOD file. EXPERIMENTAL.*/
  121. MODPLUG_EXPORT char ModPlug_ExportMOD(ModPlugFile* file, const char* filepath);
  122. /*Export to a Impulse Tracker IT file. Should work OK in Little-Endian & Big-Endian platforms :-) */
  123. MODPLUG_EXPORT char ModPlug_ExportIT(ModPlugFile* file, const char* filepath);
  124. #endif // MODPLUG_NO_FILESAVE
  125. MODPLUG_EXPORT unsigned int ModPlug_NumInstruments(ModPlugFile* file);
  126. MODPLUG_EXPORT unsigned int ModPlug_NumSamples(ModPlugFile* file);
  127. MODPLUG_EXPORT unsigned int ModPlug_NumPatterns(ModPlugFile* file);
  128. MODPLUG_EXPORT unsigned int ModPlug_NumChannels(ModPlugFile* file);
  129. MODPLUG_EXPORT unsigned int ModPlug_SampleName(ModPlugFile* file, unsigned int qual, char* buff);
  130. MODPLUG_EXPORT unsigned int ModPlug_InstrumentName(ModPlugFile* file, unsigned int qual, char* buff);
  131. /*
  132. * Retrieve pattern note-data
  133. */
  134. MODPLUG_EXPORT ModPlugNote* ModPlug_GetPattern(ModPlugFile* file, int pattern, unsigned int* numrows);
  135. /*
  136. * =================
  137. * Mixer callback
  138. * =================
  139. *
  140. * Use this callback if you want to 'modify' the mixed data of LibModPlug.
  141. *
  142. * void proc(int* buffer,unsigned long channels,unsigned long nsamples) ;
  143. *
  144. * 'buffer': A buffer of mixed samples
  145. * 'channels': N. of channels in the buffer
  146. * 'nsamples': N. of samples in the buffeer (without taking care of n.channels)
  147. *
  148. * (Samples are signed 32-bit integers)
  149. */
  150. MODPLUG_EXPORT void ModPlug_InitMixerCallback(ModPlugFile* file,ModPlugMixerProc proc) ;
  151. MODPLUG_EXPORT void ModPlug_UnloadMixerCallback(ModPlugFile* file) ;
  152. #ifdef __cplusplus
  153. } /* extern "C" */
  154. #endif
  155. #endif