modplug.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. #elif defined(MODPLUG_BUILD) && defined(SYM_VISIBILITY)
  20. # define MODPLUG_EXPORT __attribute__((visibility("default")))
  21. #else
  22. #define MODPLUG_EXPORT
  23. #endif
  24. struct _ModPlugFile;
  25. typedef struct _ModPlugFile ModPlugFile;
  26. struct _ModPlugNote {
  27. unsigned char Note;
  28. unsigned char Instrument;
  29. unsigned char VolumeEffect;
  30. unsigned char Effect;
  31. unsigned char Volume;
  32. unsigned char Parameter;
  33. };
  34. typedef struct _ModPlugNote ModPlugNote;
  35. typedef void (*ModPlugMixerProc)(int*, unsigned long, unsigned long);
  36. /* Load a mod file. [data] should point to a block of memory containing the complete
  37. * file, and [size] should be the size of that block.
  38. * Return the loaded mod file on success, or NULL on failure. */
  39. MODPLUG_EXPORT ModPlugFile* ModPlug_Load(const void* data, int size);
  40. /* Unload a mod file. */
  41. MODPLUG_EXPORT void ModPlug_Unload(ModPlugFile* file);
  42. /* Read sample data into the buffer. Returns the number of bytes read. If the end
  43. * of the mod has been reached, zero is returned. */
  44. MODPLUG_EXPORT int ModPlug_Read(ModPlugFile* file, void* buffer, int size);
  45. /* Get the name of the mod. The returned buffer is stored within the ModPlugFile
  46. * structure and will remain valid until you unload the file. */
  47. MODPLUG_EXPORT const char* ModPlug_GetName(ModPlugFile* file);
  48. /* Get the length of the mod, in milliseconds. Note that this result is not always
  49. * accurate, especially in the case of mods with loops. */
  50. MODPLUG_EXPORT int ModPlug_GetLength(ModPlugFile* file);
  51. /* Seek to a particular position in the song. Note that seeking and MODs don't mix very
  52. * well. Some mods will be missing instruments for a short time after a seek, as ModPlug
  53. * does not scan the sequence backwards to find out which instruments were supposed to be
  54. * playing at that time. (Doing so would be difficult and not very reliable.) Also,
  55. * note that seeking is not very exact in some mods -- especially those for which
  56. * ModPlug_GetLength() does not report the full length. */
  57. MODPLUG_EXPORT void ModPlug_Seek(ModPlugFile* file, int millisecond);
  58. enum _ModPlug_Flags
  59. {
  60. MODPLUG_ENABLE_OVERSAMPLING = 1 << 0, /* Enable oversampling (*highly* recommended) */
  61. MODPLUG_ENABLE_NOISE_REDUCTION = 1 << 1, /* Enable noise reduction */
  62. MODPLUG_ENABLE_REVERB = 1 << 2, /* Enable reverb */
  63. MODPLUG_ENABLE_MEGABASS = 1 << 3, /* Enable megabass */
  64. MODPLUG_ENABLE_SURROUND = 1 << 4 /* Enable surround sound. */
  65. };
  66. enum _ModPlug_ResamplingMode
  67. {
  68. MODPLUG_RESAMPLE_NEAREST = 0, /* No interpolation (very fast, extremely bad sound quality) */
  69. MODPLUG_RESAMPLE_LINEAR = 1, /* Linear interpolation (fast, good quality) */
  70. MODPLUG_RESAMPLE_SPLINE = 2, /* Cubic spline interpolation (high quality) */
  71. MODPLUG_RESAMPLE_FIR = 3 /* 8-tap fir filter (extremely high quality) */
  72. };
  73. typedef struct _ModPlug_Settings
  74. {
  75. int mFlags; /* One or more of the MODPLUG_ENABLE_* flags above, bitwise-OR'ed */
  76. /* Note that ModPlug always decodes sound at 44100kHz, 32 bit, stereo and then
  77. * down-mixes to the settings you choose. */
  78. int mChannels; /* Number of channels - 1 for mono or 2 for stereo */
  79. int mBits; /* Bits per sample - 8, 16, or 32 */
  80. int mFrequency; /* Sampling rate - 11025, 22050, or 44100 */
  81. int mResamplingMode; /* One of MODPLUG_RESAMPLE_*, above */
  82. int mStereoSeparation; /* Stereo separation, 1 - 256 */
  83. int mMaxMixChannels; /* Maximum number of mixing channels (polyphony), 32 - 256 */
  84. int mReverbDepth; /* Reverb level 0(quiet)-100(loud) */
  85. int mReverbDelay; /* Reverb delay in ms, usually 40-200ms */
  86. int mBassAmount; /* XBass level 0(quiet)-100(loud) */
  87. int mBassRange; /* XBass cutoff in Hz 10-100 */
  88. int mSurroundDepth; /* Surround level 0(quiet)-100(heavy) */
  89. int mSurroundDelay; /* Surround delay in ms, usually 5-40ms */
  90. int mLoopCount; /* Number of times to loop. Zero prevents looping.
  91. * -1 loops forever. */
  92. } ModPlug_Settings;
  93. /* Get and set the mod decoder settings. All options, except for channels, bits-per-sample,
  94. * sampling rate, and loop count, will take effect immediately. Those options which don't
  95. * take effect immediately will take effect the next time you load a mod. */
  96. MODPLUG_EXPORT void ModPlug_GetSettings(ModPlug_Settings* settings);
  97. MODPLUG_EXPORT void ModPlug_SetSettings(const ModPlug_Settings* settings);
  98. /* New ModPlug API Functions */
  99. /* NOTE: Master Volume (1-512) */
  100. MODPLUG_EXPORT unsigned int ModPlug_GetMasterVolume(ModPlugFile* file) ;
  101. MODPLUG_EXPORT void ModPlug_SetMasterVolume(ModPlugFile* file,unsigned int cvol) ;
  102. MODPLUG_EXPORT int ModPlug_GetCurrentSpeed(ModPlugFile* file);
  103. MODPLUG_EXPORT int ModPlug_GetCurrentTempo(ModPlugFile* file);
  104. MODPLUG_EXPORT int ModPlug_GetCurrentOrder(ModPlugFile* file);
  105. MODPLUG_EXPORT int ModPlug_GetCurrentPattern(ModPlugFile* file);
  106. MODPLUG_EXPORT int ModPlug_GetCurrentRow(ModPlugFile* file);
  107. MODPLUG_EXPORT int ModPlug_GetPlayingChannels(ModPlugFile* file);
  108. MODPLUG_EXPORT void ModPlug_SeekOrder(ModPlugFile* file,int order);
  109. MODPLUG_EXPORT int ModPlug_GetModuleType(ModPlugFile* file);
  110. MODPLUG_EXPORT char* ModPlug_GetMessage(ModPlugFile* file);
  111. #define MODPLUG_NO_FILESAVE /* experimental yet. must match stdafx.h. */
  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