sndfile.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017
  1. /*
  2. * This source code is public domain.
  3. *
  4. * Authors: Olivier Lapicque <[email protected]>,
  5. * Adam Goode <[email protected]> (endian and char fixes for PPC)
  6. */
  7. #if defined(HAVE_CONFIG_H) && !defined(CONFIG_H_INCLUDED)
  8. #include "config.h"
  9. #define CONFIG_H_INCLUDED 1
  10. #endif
  11. #ifndef MODPLUG_SNDFILE_H
  12. #define MODPLUG_SNDFILE_H
  13. #ifdef UNDER_CE
  14. int _strnicmp(const char *str1,const char *str2, int n);
  15. #endif
  16. #ifndef LPCBYTE
  17. typedef const BYTE * LPCBYTE;
  18. #endif
  19. #define MOD_AMIGAC2 0x1AB
  20. #define MAX_SAMPLE_LENGTH 16000000
  21. #define MAX_SAMPLE_RATE 192000
  22. #define MAX_ORDERS 256
  23. #define MAX_PATTERNS 240
  24. #define MAX_SAMPLES 240
  25. #define MAX_INSTRUMENTS MAX_SAMPLES
  26. #ifdef MODPLUG_FASTSOUNDLIB
  27. #define MAX_CHANNELS 80
  28. #else
  29. #define MAX_CHANNELS 128
  30. #endif
  31. #define MAX_BASECHANNELS 64
  32. #define MAX_ENVPOINTS 32
  33. #define MIN_PERIOD 0x0020
  34. #define MAX_PERIOD 0xFFFF
  35. #define MAX_PATTERNNAME 32
  36. #define MAX_CHANNELNAME 20
  37. #define MAX_INFONAME 80
  38. #define MAX_EQ_BANDS 6
  39. #define MAX_MIXPLUGINS 8
  40. #define MOD_TYPE_NONE 0x00
  41. #define MOD_TYPE_MOD 0x01
  42. #define MOD_TYPE_S3M 0x02
  43. #define MOD_TYPE_XM 0x04
  44. #define MOD_TYPE_MED 0x08
  45. #define MOD_TYPE_MTM 0x10
  46. #define MOD_TYPE_IT 0x20
  47. #define MOD_TYPE_669 0x40
  48. #define MOD_TYPE_ULT 0x80
  49. #define MOD_TYPE_STM 0x100
  50. #define MOD_TYPE_FAR 0x200
  51. #define MOD_TYPE_WAV 0x400
  52. #define MOD_TYPE_AMF 0x800
  53. #define MOD_TYPE_AMS 0x1000
  54. #define MOD_TYPE_DSM 0x2000
  55. #define MOD_TYPE_MDL 0x4000
  56. #define MOD_TYPE_OKT 0x8000
  57. #define MOD_TYPE_MID 0x10000
  58. #define MOD_TYPE_DMF 0x20000
  59. #define MOD_TYPE_PTM 0x40000
  60. #define MOD_TYPE_DBM 0x80000
  61. #define MOD_TYPE_MT2 0x100000
  62. #define MOD_TYPE_AMF0 0x200000
  63. #define MOD_TYPE_PSM 0x400000
  64. #define MOD_TYPE_J2B 0x800000
  65. #define MOD_TYPE_ABC 0x1000000
  66. #define MOD_TYPE_PAT 0x2000000
  67. #define MOD_TYPE_UMX 0x80000000 // Fake type
  68. #define MAX_MODTYPE 24
  69. // Channel flags:
  70. // Bits 0-7: Sample Flags
  71. #define CHN_16BIT 0x01
  72. #define CHN_LOOP 0x02
  73. #define CHN_PINGPONGLOOP 0x04
  74. #define CHN_SUSTAINLOOP 0x08
  75. #define CHN_PINGPONGSUSTAIN 0x10
  76. #define CHN_PANNING 0x20
  77. #define CHN_STEREO 0x40
  78. #define CHN_PINGPONGFLAG 0x80
  79. // Bits 8-31: Channel Flags
  80. #define CHN_MUTE 0x100
  81. #define CHN_KEYOFF 0x200
  82. #define CHN_NOTEFADE 0x400
  83. #define CHN_SURROUND 0x800
  84. #define CHN_NOIDO 0x1000
  85. #define CHN_HQSRC 0x2000
  86. #define CHN_FILTER 0x4000
  87. #define CHN_VOLUMERAMP 0x8000
  88. #define CHN_VIBRATO 0x10000
  89. #define CHN_TREMOLO 0x20000
  90. #define CHN_PANBRELLO 0x40000
  91. #define CHN_PORTAMENTO 0x80000
  92. #define CHN_GLISSANDO 0x100000
  93. #define CHN_VOLENV 0x200000
  94. #define CHN_PANENV 0x400000
  95. #define CHN_PITCHENV 0x800000
  96. #define CHN_FASTVOLRAMP 0x1000000
  97. #define CHN_EXTRALOUD 0x2000000
  98. #define CHN_REVERB 0x4000000
  99. #define CHN_NOREVERB 0x8000000
  100. #define ENV_VOLUME 0x0001
  101. #define ENV_VOLSUSTAIN 0x0002
  102. #define ENV_VOLLOOP 0x0004
  103. #define ENV_PANNING 0x0008
  104. #define ENV_PANSUSTAIN 0x0010
  105. #define ENV_PANLOOP 0x0020
  106. #define ENV_PITCH 0x0040
  107. #define ENV_PITCHSUSTAIN 0x0080
  108. #define ENV_PITCHLOOP 0x0100
  109. #define ENV_SETPANNING 0x0200
  110. #define ENV_FILTER 0x0400
  111. #define ENV_VOLCARRY 0x0800
  112. #define ENV_PANCARRY 0x1000
  113. #define ENV_PITCHCARRY 0x2000
  114. #define CMD_NONE 0
  115. #define CMD_ARPEGGIO 1
  116. #define CMD_PORTAMENTOUP 2
  117. #define CMD_PORTAMENTODOWN 3
  118. #define CMD_TONEPORTAMENTO 4
  119. #define CMD_VIBRATO 5
  120. #define CMD_TONEPORTAVOL 6
  121. #define CMD_VIBRATOVOL 7
  122. #define CMD_TREMOLO 8
  123. #define CMD_PANNING8 9
  124. #define CMD_OFFSET 10
  125. #define CMD_VOLUMESLIDE 11
  126. #define CMD_POSITIONJUMP 12
  127. #define CMD_VOLUME 13
  128. #define CMD_PATTERNBREAK 14
  129. #define CMD_RETRIG 15
  130. #define CMD_SPEED 16
  131. #define CMD_TEMPO 17
  132. #define CMD_TREMOR 18
  133. #define CMD_MODCMDEX 19
  134. #define CMD_S3MCMDEX 20
  135. #define CMD_CHANNELVOLUME 21
  136. #define CMD_CHANNELVOLSLIDE 22
  137. #define CMD_GLOBALVOLUME 23
  138. #define CMD_GLOBALVOLSLIDE 24
  139. #define CMD_KEYOFF 25
  140. #define CMD_FINEVIBRATO 26
  141. #define CMD_PANBRELLO 27
  142. #define CMD_XFINEPORTAUPDOWN 28
  143. #define CMD_PANNINGSLIDE 29
  144. #define CMD_SETENVPOSITION 30
  145. #define CMD_MIDI 31
  146. // Volume Column commands
  147. #define VOLCMD_VOLUME 1
  148. #define VOLCMD_PANNING 2
  149. #define VOLCMD_VOLSLIDEUP 3
  150. #define VOLCMD_VOLSLIDEDOWN 4
  151. #define VOLCMD_FINEVOLUP 5
  152. #define VOLCMD_FINEVOLDOWN 6
  153. #define VOLCMD_VIBRATOSPEED 7
  154. #define VOLCMD_VIBRATO 8
  155. #define VOLCMD_PANSLIDELEFT 9
  156. #define VOLCMD_PANSLIDERIGHT 10
  157. #define VOLCMD_TONEPORTAMENTO 11
  158. #define VOLCMD_PORTAUP 12
  159. #define VOLCMD_PORTADOWN 13
  160. #define RSF_16BIT 0x04
  161. #define RSF_STEREO 0x08
  162. #define RS_PCM8S 0 // 8-bit signed
  163. #define RS_PCM8U 1 // 8-bit unsigned
  164. #define RS_PCM8D 2 // 8-bit delta values
  165. #define RS_ADPCM4 3 // 4-bit ADPCM-packed
  166. #define RS_PCM16D 4 // 16-bit delta values
  167. #define RS_PCM16S 5 // 16-bit signed
  168. #define RS_PCM16U 6 // 16-bit unsigned
  169. #define RS_PCM16M 7 // 16-bit motorola order
  170. #define RS_STPCM8S (RS_PCM8S|RSF_STEREO) // stereo 8-bit signed
  171. #define RS_STPCM8U (RS_PCM8U|RSF_STEREO) // stereo 8-bit unsigned
  172. #define RS_STPCM8D (RS_PCM8D|RSF_STEREO) // stereo 8-bit delta values
  173. #define RS_STPCM16S (RS_PCM16S|RSF_STEREO) // stereo 16-bit signed
  174. #define RS_STPCM16U (RS_PCM16U|RSF_STEREO) // stereo 16-bit unsigned
  175. #define RS_STPCM16D (RS_PCM16D|RSF_STEREO) // stereo 16-bit delta values
  176. #define RS_STPCM16M (RS_PCM16M|RSF_STEREO) // stereo 16-bit signed big endian
  177. // IT 2.14 compressed samples
  178. #define RS_IT2148 0x10
  179. #define RS_IT21416 0x14
  180. #define RS_IT2158 0x12
  181. #define RS_IT21516 0x16
  182. // AMS Packed Samples
  183. #define RS_AMS8 0x11
  184. #define RS_AMS16 0x15
  185. // DMF Huffman compression
  186. #define RS_DMF8 0x13
  187. #define RS_DMF16 0x17
  188. // MDL Huffman compression
  189. #define RS_MDL8 0x20
  190. #define RS_MDL16 0x24
  191. #define RS_PTM8DTO16 0x25
  192. // Stereo Interleaved Samples
  193. #define RS_STIPCM8S (RS_PCM8S|0x40|RSF_STEREO) // stereo 8-bit signed
  194. #define RS_STIPCM8U (RS_PCM8U|0x40|RSF_STEREO) // stereo 8-bit unsigned
  195. #define RS_STIPCM16S (RS_PCM16S|0x40|RSF_STEREO) // stereo 16-bit signed
  196. #define RS_STIPCM16U (RS_PCM16U|0x40|RSF_STEREO) // stereo 16-bit unsigned
  197. #define RS_STIPCM16M (RS_PCM16M|0x40|RSF_STEREO) // stereo 16-bit signed big endian
  198. // 24-bit signed
  199. #define RS_PCM24S (RS_PCM16S|0x80) // mono 24-bit signed
  200. #define RS_STIPCM24S (RS_PCM16S|0x80|RSF_STEREO) // stereo 24-bit signed
  201. #define RS_PCM32S (RS_PCM16S|0xC0) // mono 24-bit signed
  202. #define RS_STIPCM32S (RS_PCM16S|0xC0|RSF_STEREO) // stereo 24-bit signed
  203. // NNA types
  204. #define NNA_NOTECUT 0
  205. #define NNA_CONTINUE 1
  206. #define NNA_NOTEOFF 2
  207. #define NNA_NOTEFADE 3
  208. // DCT types
  209. #define DCT_NONE 0
  210. #define DCT_NOTE 1
  211. #define DCT_SAMPLE 2
  212. #define DCT_INSTRUMENT 3
  213. // DNA types
  214. #define DNA_NOTECUT 0
  215. #define DNA_NOTEOFF 1
  216. #define DNA_NOTEFADE 2
  217. // Mixer Hardware-Dependent features
  218. #define SYSMIX_ENABLEMMX 0x01
  219. #define SYSMIX_WINDOWSNT 0x02
  220. #define SYSMIX_SLOWCPU 0x04
  221. #define SYSMIX_FASTCPU 0x08
  222. // Module flags
  223. #define SONG_EMBEDMIDICFG 0x0001
  224. #define SONG_FASTVOLSLIDES 0x0002
  225. #define SONG_ITOLDEFFECTS 0x0004
  226. #define SONG_ITCOMPATMODE 0x0008
  227. #define SONG_LINEARSLIDES 0x0010
  228. #define SONG_PATTERNLOOP 0x0020
  229. #define SONG_STEP 0x0040
  230. #define SONG_PAUSED 0x0080
  231. #define SONG_FADINGSONG 0x0100
  232. #define SONG_ENDREACHED 0x0200
  233. #define SONG_GLOBALFADE 0x0400
  234. #define SONG_CPUVERYHIGH 0x0800
  235. #define SONG_FIRSTTICK 0x1000
  236. #define SONG_MPTFILTERMODE 0x2000
  237. #define SONG_SURROUNDPAN 0x4000
  238. #define SONG_EXFILTERRANGE 0x8000
  239. #define SONG_AMIGALIMITS 0x10000
  240. // Global Options (Renderer)
  241. #define SNDMIX_REVERSESTEREO 0x0001
  242. #define SNDMIX_NOISEREDUCTION 0x0002
  243. #define SNDMIX_AGC 0x0004
  244. #define SNDMIX_NORESAMPLING 0x0008
  245. #define SNDMIX_HQRESAMPLER 0x0010
  246. #define SNDMIX_MEGABASS 0x0020
  247. #define SNDMIX_SURROUND 0x0040
  248. #define SNDMIX_REVERB 0x0080
  249. #define SNDMIX_EQ 0x0100
  250. #define SNDMIX_SOFTPANNING 0x0200
  251. #define SNDMIX_ULTRAHQSRCMODE 0x0400
  252. // Misc Flags (can safely be turned on or off)
  253. #define SNDMIX_DIRECTTODISK 0x10000
  254. #define SNDMIX_ENABLEMMX 0x20000
  255. #define SNDMIX_NOBACKWARDJUMPS 0x40000
  256. #define SNDMIX_MAXDEFAULTPAN 0x80000 // Used by the MOD loader
  257. // Reverb Types (GM2 Presets)
  258. enum {
  259. REVERBTYPE_SMALLROOM,
  260. REVERBTYPE_MEDIUMROOM,
  261. REVERBTYPE_LARGEROOM,
  262. REVERBTYPE_SMALLHALL,
  263. REVERBTYPE_MEDIUMHALL,
  264. REVERBTYPE_LARGEHALL,
  265. NUM_REVERBTYPES
  266. };
  267. enum {
  268. SRCMODE_NEAREST,
  269. SRCMODE_LINEAR,
  270. SRCMODE_SPLINE,
  271. SRCMODE_POLYPHASE,
  272. NUM_SRC_MODES
  273. };
  274. // Sample Struct
  275. typedef struct _MODINSTRUMENT
  276. {
  277. UINT nLength,nLoopStart,nLoopEnd;
  278. UINT nSustainStart, nSustainEnd;
  279. signed char *pSample;
  280. UINT nC4Speed;
  281. WORD nPan;
  282. WORD nVolume;
  283. WORD nGlobalVol;
  284. WORD uFlags;
  285. signed char RelativeTone;
  286. signed char nFineTune;
  287. BYTE nVibType;
  288. BYTE nVibSweep;
  289. BYTE nVibDepth;
  290. BYTE nVibRate;
  291. CHAR name[22];
  292. } MODINSTRUMENT;
  293. // Instrument Struct
  294. typedef struct _INSTRUMENTHEADER
  295. {
  296. UINT nFadeOut;
  297. DWORD dwFlags;
  298. WORD nGlobalVol;
  299. WORD nPan;
  300. WORD VolPoints[MAX_ENVPOINTS];
  301. WORD PanPoints[MAX_ENVPOINTS];
  302. WORD PitchPoints[MAX_ENVPOINTS];
  303. BYTE VolEnv[MAX_ENVPOINTS];
  304. BYTE PanEnv[MAX_ENVPOINTS];
  305. BYTE PitchEnv[MAX_ENVPOINTS];
  306. BYTE Keyboard[128];
  307. BYTE NoteMap[128];
  308. BYTE nVolEnv;
  309. BYTE nPanEnv;
  310. BYTE nPitchEnv;
  311. BYTE nVolLoopStart;
  312. BYTE nVolLoopEnd;
  313. BYTE nVolSustainBegin;
  314. BYTE nVolSustainEnd;
  315. BYTE nPanLoopStart;
  316. BYTE nPanLoopEnd;
  317. BYTE nPanSustainBegin;
  318. BYTE nPanSustainEnd;
  319. BYTE nPitchLoopStart;
  320. BYTE nPitchLoopEnd;
  321. BYTE nPitchSustainBegin;
  322. BYTE nPitchSustainEnd;
  323. BYTE nNNA;
  324. BYTE nDCT;
  325. BYTE nDNA;
  326. BYTE nPanSwing;
  327. BYTE nVolSwing;
  328. BYTE nIFC;
  329. BYTE nIFR;
  330. WORD wMidiBank;
  331. BYTE nMidiProgram;
  332. BYTE nMidiChannel;
  333. BYTE nMidiDrumKey;
  334. signed char nPPS;
  335. unsigned char nPPC;
  336. CHAR name[32];
  337. CHAR filename[12];
  338. } INSTRUMENTHEADER;
  339. // Channel Struct
  340. typedef struct _MODCHANNEL
  341. {
  342. // First 32-bytes: Most used mixing information: don't change it
  343. signed char * pCurrentSample;
  344. DWORD nPos;
  345. DWORD nPosLo; // actually 16-bit
  346. LONG nInc; // 16.16
  347. LONG nRightVol;
  348. LONG nLeftVol;
  349. LONG nRightRamp;
  350. LONG nLeftRamp;
  351. // 2nd cache line
  352. DWORD nLength;
  353. DWORD dwFlags;
  354. DWORD nLoopStart;
  355. DWORD nLoopEnd;
  356. LONG nRampRightVol;
  357. LONG nRampLeftVol;
  358. LONG nFilter_Y1, nFilter_Y2, nFilter_Y3, nFilter_Y4;
  359. LONG nFilter_A0, nFilter_B0, nFilter_B1;
  360. LONG nROfs, nLOfs;
  361. LONG nRampLength;
  362. // Information not used in the mixer
  363. signed char * pSample;
  364. LONG nNewRightVol, nNewLeftVol;
  365. LONG nRealVolume, nRealPan;
  366. LONG nVolume, nPan, nFadeOutVol;
  367. LONG nPeriod, nC4Speed, nPortamentoDest;
  368. INSTRUMENTHEADER *pHeader;
  369. MODINSTRUMENT *pInstrument;
  370. DWORD nVolEnvPosition, nPanEnvPosition, nPitchEnvPosition;
  371. DWORD nMasterChn, nVUMeter;
  372. LONG nGlobalVol, nInsVol;
  373. LONG nFineTune, nTranspose;
  374. LONG nPortamentoSlide, nAutoVibDepth;
  375. UINT nAutoVibPos, nVibratoPos, nTremoloPos, nPanbrelloPos;
  376. // 16-bit members
  377. signed short nVolSwing, nPanSwing;
  378. // 8-bit members
  379. BYTE nNote, nNNA;
  380. BYTE nNewNote, nNewIns, nCommand, nArpeggio;
  381. BYTE nOldVolumeSlide, nOldFineVolUpDown;
  382. BYTE nOldPortaUpDown, nOldFinePortaUpDown;
  383. BYTE nOldPanSlide, nOldChnVolSlide;
  384. BYTE nVibratoType, nVibratoSpeed, nVibratoDepth;
  385. BYTE nTremoloType, nTremoloSpeed, nTremoloDepth;
  386. BYTE nPanbrelloType, nPanbrelloSpeed, nPanbrelloDepth;
  387. BYTE nOldCmdEx, nOldVolParam, nOldTempo;
  388. BYTE nOldOffset, nOldHiOffset;
  389. BYTE nCutOff, nResonance;
  390. BYTE nRetrigCount, nRetrigParam;
  391. BYTE nTremorCount, nTremorParam;
  392. BYTE nPatternLoop, nPatternLoopCount;
  393. BYTE nRowNote, nRowInstr;
  394. BYTE nRowVolCmd, nRowVolume;
  395. BYTE nRowCommand, nRowParam;
  396. BYTE nLeftVU, nRightVU;
  397. BYTE nActiveMacro, nPadding;
  398. } MODCHANNEL;
  399. typedef struct _MODCHANNELSETTINGS
  400. {
  401. UINT nPan;
  402. UINT nVolume;
  403. DWORD dwFlags;
  404. UINT nMixPlugin;
  405. char szName[MAX_CHANNELNAME]; // changed from CHAR
  406. } MODCHANNELSETTINGS;
  407. typedef struct _MODCOMMAND
  408. {
  409. BYTE note;
  410. BYTE instr;
  411. BYTE volcmd;
  412. BYTE command;
  413. BYTE vol;
  414. BYTE param;
  415. } MODCOMMAND, *LPMODCOMMAND;
  416. ////////////////////////////////////////////////////////////////////
  417. // Mix Plugins
  418. #define MIXPLUG_MIXREADY 0x01 // Set when cleared
  419. class MODPLUG_EXPORT IMixPlugin
  420. {
  421. public:
  422. virtual ~IMixPlugin();
  423. virtual int AddRef() = 0;
  424. virtual int Release() = 0;
  425. virtual void SaveAllParameters() = 0;
  426. virtual void RestoreAllParameters() = 0;
  427. virtual void Process(float *pOutL, float *pOutR, unsigned long nSamples) = 0;
  428. virtual void Init(unsigned long nFreq, int bReset) = 0;
  429. virtual void MidiSend(DWORD dwMidiCode) = 0;
  430. virtual void MidiCommand(UINT nMidiCh, UINT nMidiProg, UINT note, UINT vol) = 0;
  431. };
  432. #define MIXPLUG_INPUTF_MASTEREFFECT 0x01 // Apply to master mix
  433. #define MIXPLUG_INPUTF_BYPASS 0x02 // Bypass effect
  434. #define MIXPLUG_INPUTF_WETMIX 0x04 // Wet Mix (dry added)
  435. typedef struct _SNDMIXPLUGINSTATE
  436. {
  437. DWORD dwFlags; // MIXPLUG_XXXX
  438. LONG nVolDecayL, nVolDecayR; // Buffer click removal
  439. int *pMixBuffer; // Stereo effect send buffer
  440. float *pOutBufferL; // Temp storage for int -> float conversion
  441. float *pOutBufferR;
  442. } SNDMIXPLUGINSTATE, *PSNDMIXPLUGINSTATE;
  443. typedef struct _SNDMIXPLUGININFO
  444. {
  445. DWORD dwPluginId1;
  446. DWORD dwPluginId2;
  447. DWORD dwInputRouting; // MIXPLUG_INPUTF_XXXX
  448. DWORD dwOutputRouting; // 0=mix 0x80+=fx
  449. DWORD dwReserved[4]; // Reserved for routing info
  450. CHAR szName[32];
  451. CHAR szLibraryName[64]; // original DLL name
  452. } SNDMIXPLUGININFO, *PSNDMIXPLUGININFO; // Size should be 128
  453. typedef struct _SNDMIXPLUGIN
  454. {
  455. IMixPlugin *pMixPlugin;
  456. PSNDMIXPLUGINSTATE pMixState;
  457. ULONG nPluginDataSize;
  458. PVOID pPluginData;
  459. SNDMIXPLUGININFO Info;
  460. } SNDMIXPLUGIN, *PSNDMIXPLUGIN;
  461. typedef BOOL (*PMIXPLUGINCREATEPROC)(PSNDMIXPLUGIN);
  462. ////////////////////////////////////////////////////////////////////
  463. enum {
  464. MIDIOUT_START=0,
  465. MIDIOUT_STOP,
  466. MIDIOUT_TICK,
  467. MIDIOUT_NOTEON,
  468. MIDIOUT_NOTEOFF,
  469. MIDIOUT_VOLUME,
  470. MIDIOUT_PAN,
  471. MIDIOUT_BANKSEL,
  472. MIDIOUT_PROGRAM,
  473. };
  474. typedef struct MODMIDICFG
  475. {
  476. char szMidiGlb[9*32]; // changed from CHAR
  477. char szMidiSFXExt[16*32]; // changed from CHAR
  478. char szMidiZXXExt[128*32]; // changed from CHAR
  479. } MODMIDICFG, *LPMODMIDICFG;
  480. #define NOTE_MAX 120 //Defines maximum notevalue as well as maximum number of notes.
  481. typedef VOID (* LPSNDMIXHOOKPROC)(int *, unsigned long, unsigned long); // buffer, samples, channels
  482. //==============
  483. class MODPLUG_EXPORT CSoundFile
  484. //==============
  485. {
  486. public: // Static Members
  487. static UINT m_nXBassDepth, m_nXBassRange;
  488. static UINT m_nReverbDepth, m_nReverbDelay, gnReverbType;
  489. static UINT m_nProLogicDepth, m_nProLogicDelay;
  490. static UINT m_nStereoSeparation;
  491. static UINT m_nMaxMixChannels;
  492. static LONG m_nStreamVolume;
  493. static DWORD gdwSysInfo, gdwSoundSetup, gdwMixingFreq, gnBitsPerSample, gnChannels;
  494. static UINT gnAGC, gnVolumeRampSamples, gnVUMeter, gnCPUUsage;
  495. static LPSNDMIXHOOKPROC gpSndMixHook;
  496. static PMIXPLUGINCREATEPROC gpMixPluginCreateProc;
  497. public: // for Editing
  498. MODCHANNEL Chn[MAX_CHANNELS]; // Channels
  499. UINT ChnMix[MAX_CHANNELS]; // Channels to be mixed
  500. MODINSTRUMENT Ins[MAX_SAMPLES]; // Instruments
  501. INSTRUMENTHEADER *Headers[MAX_INSTRUMENTS]; // Instrument Headers
  502. MODCHANNELSETTINGS ChnSettings[MAX_BASECHANNELS]; // Channels settings
  503. MODCOMMAND *Patterns[MAX_PATTERNS]; // Patterns
  504. WORD PatternSize[MAX_PATTERNS]; // Patterns Lengths
  505. BYTE Order[MAX_ORDERS]; // Pattern Orders
  506. MODMIDICFG m_MidiCfg; // Midi macro config table
  507. SNDMIXPLUGIN m_MixPlugins[MAX_MIXPLUGINS]; // Mix plugins
  508. UINT m_nDefaultSpeed, m_nDefaultTempo, m_nDefaultGlobalVolume;
  509. DWORD m_dwSongFlags; // Song flags SONG_XXXX
  510. UINT m_nChannels, m_nMixChannels, m_nMixStat, m_nBufferCount;
  511. UINT m_nType, m_nSamples, m_nInstruments;
  512. UINT m_nTickCount, m_nTotalCount, m_nPatternDelay, m_nFrameDelay;
  513. UINT m_nMusicSpeed, m_nMusicTempo;
  514. UINT m_nNextRow, m_nRow;
  515. UINT m_nPattern,m_nCurrentPattern,m_nNextPattern,m_nRestartPos;
  516. UINT m_nMasterVolume, m_nGlobalVolume, m_nSongPreAmp;
  517. UINT m_nFreqFactor, m_nTempoFactor, m_nOldGlbVolSlide;
  518. LONG m_nMinPeriod, m_nMaxPeriod, m_nRepeatCount, m_nInitialRepeatCount;
  519. DWORD m_nGlobalFadeSamples, m_nGlobalFadeMaxSamples;
  520. UINT m_nMaxOrderPosition;
  521. UINT m_nPatternNames;
  522. LPSTR m_lpszSongComments, m_lpszPatternNames;
  523. char m_szNames[MAX_INSTRUMENTS][32]; // changed from CHAR
  524. CHAR CompressionTable[16];
  525. public:
  526. CSoundFile();
  527. ~CSoundFile();
  528. public:
  529. BOOL Create(LPCBYTE lpStream, DWORD dwMemLength=0);
  530. BOOL Destroy();
  531. UINT GetType() const { return m_nType; }
  532. UINT GetNumChannels() const;
  533. UINT GetLogicalChannels() const { return m_nChannels; }
  534. BOOL SetMasterVolume(UINT vol, BOOL bAdjustAGC=FALSE);
  535. UINT GetMasterVolume() const { return m_nMasterVolume; }
  536. UINT GetNumPatterns() const;
  537. UINT GetNumInstruments() const;
  538. UINT GetNumSamples() const { return m_nSamples; }
  539. UINT GetCurrentPos() const;
  540. UINT GetCurrentPattern() const { return m_nPattern; }
  541. UINT GetCurrentOrder() const { return m_nCurrentPattern; }
  542. UINT GetSongComments(LPSTR s, UINT cbsize, UINT linesize=32);
  543. UINT GetRawSongComments(LPSTR s, UINT cbsize, UINT linesize=32);
  544. UINT GetMaxPosition() const;
  545. void SetCurrentPos(UINT nPos);
  546. void SetCurrentOrder(UINT nOrder);
  547. void GetTitle(LPSTR s) const { lstrcpyn(s,m_szNames[0],32); }
  548. LPCSTR GetTitle() const { return m_szNames[0]; }
  549. UINT GetSampleName(UINT nSample,LPSTR s=NULL) const;
  550. UINT GetInstrumentName(UINT nInstr,LPSTR s=NULL) const;
  551. UINT GetMusicSpeed() const { return m_nMusicSpeed; }
  552. UINT GetMusicTempo() const { return m_nMusicTempo; }
  553. DWORD GetLength(BOOL bAdjust, BOOL bTotal=FALSE);
  554. DWORD GetSongTime() { return GetLength(FALSE, TRUE); }
  555. void SetRepeatCount(int n) { m_nRepeatCount = n; m_nInitialRepeatCount = n; }
  556. int GetRepeatCount() const { return m_nRepeatCount; }
  557. BOOL IsPaused() const { return (m_dwSongFlags & SONG_PAUSED) ? TRUE : FALSE; }
  558. void LoopPattern(int nPat, int nRow=0);
  559. void CheckCPUUsage(UINT nCPU);
  560. BOOL SetPatternName(UINT nPat, LPCSTR lpszName);
  561. BOOL GetPatternName(UINT nPat, LPSTR lpszName, UINT cbSize=MAX_PATTERNNAME) const;
  562. // Module Loaders
  563. BOOL ReadXM(LPCBYTE lpStream, DWORD dwMemLength);
  564. BOOL ReadS3M(LPCBYTE lpStream, DWORD dwMemLength);
  565. BOOL ReadMod(LPCBYTE lpStream, DWORD dwMemLength);
  566. BOOL ReadMed(LPCBYTE lpStream, DWORD dwMemLength);
  567. BOOL ReadMTM(LPCBYTE lpStream, DWORD dwMemLength);
  568. BOOL ReadSTM(LPCBYTE lpStream, DWORD dwMemLength);
  569. BOOL ReadIT(LPCBYTE lpStream, DWORD dwMemLength);
  570. BOOL Read669(LPCBYTE lpStream, DWORD dwMemLength);
  571. BOOL ReadUlt(LPCBYTE lpStream, DWORD dwMemLength);
  572. BOOL ReadWav(LPCBYTE lpStream, DWORD dwMemLength);
  573. BOOL ReadDSM(LPCBYTE lpStream, DWORD dwMemLength);
  574. BOOL ReadFAR(LPCBYTE lpStream, DWORD dwMemLength);
  575. BOOL ReadAMS(LPCBYTE lpStream, DWORD dwMemLength);
  576. BOOL ReadAMS2(LPCBYTE lpStream, DWORD dwMemLength);
  577. BOOL ReadMDL(LPCBYTE lpStream, DWORD dwMemLength);
  578. BOOL ReadOKT(LPCBYTE lpStream, DWORD dwMemLength);
  579. BOOL ReadDMF(LPCBYTE lpStream, DWORD dwMemLength);
  580. BOOL ReadPTM(LPCBYTE lpStream, DWORD dwMemLength);
  581. BOOL ReadDBM(LPCBYTE lpStream, DWORD dwMemLength);
  582. BOOL ReadAMF(LPCBYTE lpStream, DWORD dwMemLength);
  583. BOOL ReadMT2(LPCBYTE lpStream, DWORD dwMemLength);
  584. BOOL ReadPSM(LPCBYTE lpStream, DWORD dwMemLength);
  585. BOOL ReadJ2B(LPCBYTE lpStream, DWORD dwMemLength);
  586. BOOL ReadUMX(LPCBYTE lpStream, DWORD dwMemLength);
  587. BOOL ReadABC(LPCBYTE lpStream, DWORD dwMemLength);
  588. BOOL TestABC(LPCBYTE lpStream, DWORD dwMemLength);
  589. BOOL ReadMID(LPCBYTE lpStream, DWORD dwMemLength);
  590. BOOL TestMID(LPCBYTE lpStream, DWORD dwMemLength);
  591. BOOL ReadPAT(LPCBYTE lpStream, DWORD dwMemLength);
  592. BOOL TestPAT(LPCBYTE lpStream, DWORD dwMemLength);
  593. // Save Functions
  594. #ifndef MODPLUG_NO_FILESAVE
  595. UINT WriteSample(FILE *f, MODINSTRUMENT *pins, UINT nFlags, UINT nMaxLen=0);
  596. BOOL SaveXM(LPCSTR lpszFileName, UINT nPacking=0);
  597. BOOL SaveS3M(LPCSTR lpszFileName, UINT nPacking=0);
  598. BOOL SaveMod(LPCSTR lpszFileName, UINT nPacking=0);
  599. BOOL SaveIT(LPCSTR lpszFileName, UINT nPacking=0);
  600. #endif // MODPLUG_NO_FILESAVE
  601. // MOD Convert function
  602. UINT GetBestSaveFormat() const;
  603. UINT GetSaveFormats() const;
  604. void ConvertModCommand(MODCOMMAND *) const;
  605. void S3MConvert(MODCOMMAND *m, BOOL bIT) const;
  606. void S3MSaveConvert(UINT *pcmd, UINT *pprm, BOOL bIT) const;
  607. WORD ModSaveCommand(const MODCOMMAND *m, BOOL bXM) const;
  608. public:
  609. // Real-time sound functions
  610. VOID ResetChannels();
  611. UINT Read(LPVOID lpBuffer, UINT cbBuffer);
  612. UINT CreateStereoMix(int count);
  613. BOOL FadeSong(UINT msec);
  614. BOOL GlobalFadeSong(UINT msec);
  615. UINT GetTotalTickCount() const { return m_nTotalCount; }
  616. VOID ResetTotalTickCount() { m_nTotalCount = 0; }
  617. public:
  618. // Mixer Config
  619. static BOOL InitPlayer(BOOL bReset=FALSE);
  620. static BOOL SetMixConfig(UINT nStereoSeparation, UINT nMaxMixChannels);
  621. static BOOL SetWaveConfig(UINT nRate,UINT nBits,UINT nChannels,BOOL bMMX=FALSE);
  622. static BOOL SetResamplingMode(UINT nMode); // SRCMODE_XXXX
  623. static BOOL IsStereo() { return (gnChannels > 1) ? TRUE : FALSE; }
  624. static DWORD GetSampleRate() { return gdwMixingFreq; }
  625. static DWORD GetBitsPerSample() { return gnBitsPerSample; }
  626. static DWORD InitSysInfo();
  627. static DWORD GetSysInfo() { return gdwSysInfo; }
  628. // AGC
  629. static BOOL GetAGC() { return (gdwSoundSetup & SNDMIX_AGC) ? TRUE : FALSE; }
  630. static void SetAGC(BOOL b);
  631. static void ResetAGC();
  632. static void ProcessAGC(int count);
  633. //GCCFIX -- added these functions back in!
  634. static BOOL SetWaveConfigEx(BOOL bSurround,BOOL bNoOverSampling,BOOL bReverb,BOOL hqido,BOOL bMegaBass,BOOL bNR,BOOL bEQ);
  635. // DSP Effects
  636. static void InitializeDSP(BOOL bReset);
  637. static void ProcessStereoDSP(int count);
  638. static void ProcessMonoDSP(int count);
  639. // [Reverb level 0(quiet)-100(loud)], [delay in ms, usually 40-200ms]
  640. static BOOL SetReverbParameters(UINT nDepth, UINT nDelay);
  641. // [XBass level 0(quiet)-100(loud)], [cutoff in Hz 10-100]
  642. static BOOL SetXBassParameters(UINT nDepth, UINT nRange);
  643. // [Surround level 0(quiet)-100(heavy)] [delay in ms, usually 5-40ms]
  644. static BOOL SetSurroundParameters(UINT nDepth, UINT nDelay);
  645. public:
  646. BOOL ReadNote();
  647. BOOL ProcessRow();
  648. BOOL ProcessEffects();
  649. UINT GetNNAChannel(UINT nChn) const;
  650. void CheckNNA(UINT nChn, UINT instr, int note, BOOL bForceCut);
  651. void NoteChange(UINT nChn, int note, BOOL bPorta=FALSE, BOOL bResetEnv=TRUE);
  652. void InstrumentChange(MODCHANNEL *pChn, UINT instr, BOOL bPorta=FALSE,BOOL bUpdVol=TRUE,BOOL bResetEnv=TRUE);
  653. // Channel Effects
  654. void PortamentoUp(MODCHANNEL *pChn, UINT param);
  655. void PortamentoDown(MODCHANNEL *pChn, UINT param);
  656. void FinePortamentoUp(MODCHANNEL *pChn, UINT param);
  657. void FinePortamentoDown(MODCHANNEL *pChn, UINT param);
  658. void ExtraFinePortamentoUp(MODCHANNEL *pChn, UINT param);
  659. void ExtraFinePortamentoDown(MODCHANNEL *pChn, UINT param);
  660. void TonePortamento(MODCHANNEL *pChn, UINT param);
  661. void Vibrato(MODCHANNEL *pChn, UINT param);
  662. void FineVibrato(MODCHANNEL *pChn, UINT param);
  663. void VolumeSlide(MODCHANNEL *pChn, UINT param);
  664. void PanningSlide(MODCHANNEL *pChn, UINT param);
  665. void ChannelVolSlide(MODCHANNEL *pChn, UINT param);
  666. void FineVolumeUp(MODCHANNEL *pChn, UINT param);
  667. void FineVolumeDown(MODCHANNEL *pChn, UINT param);
  668. void Tremolo(MODCHANNEL *pChn, UINT param);
  669. void Panbrello(MODCHANNEL *pChn, UINT param);
  670. void RetrigNote(UINT nChn, UINT param);
  671. void NoteCut(UINT nChn, UINT nTick);
  672. void KeyOff(UINT nChn);
  673. int PatternLoop(MODCHANNEL *, UINT param);
  674. void ExtendedMODCommands(UINT nChn, UINT param);
  675. void ExtendedS3MCommands(UINT nChn, UINT param);
  676. void ExtendedChannelEffect(MODCHANNEL *, UINT param);
  677. void ProcessMidiMacro(UINT nChn, LPCSTR pszMidiMacro, UINT param=0);
  678. void SetupChannelFilter(MODCHANNEL *pChn, BOOL bReset, int flt_modifier=256) const;
  679. // Low-Level effect processing
  680. void DoFreqSlide(MODCHANNEL *pChn, LONG nFreqSlide);
  681. // Global Effects
  682. void SetTempo(UINT param);
  683. void SetSpeed(UINT param);
  684. void GlobalVolSlide(UINT param);
  685. DWORD IsSongFinished(UINT nOrder, UINT nRow) const;
  686. BOOL IsValidBackwardJump(UINT nStartOrder, UINT nStartRow, UINT nJumpOrder, UINT nJumpRow) const;
  687. // Read/Write sample functions
  688. signed char GetDeltaValue(signed char prev, UINT n) const { return (signed char)(prev + CompressionTable[n & 0x0F]); }
  689. UINT PackSample(int &sample, int next);
  690. BOOL CanPackSample(LPSTR pSample, UINT nLen, UINT nPacking, BYTE *result=NULL);
  691. UINT ReadSample(MODINSTRUMENT *pIns, UINT nFlags, LPCSTR pMemFile, DWORD dwMemLength);
  692. BOOL DestroySample(UINT nSample);
  693. BOOL DestroyInstrument(UINT nInstr);
  694. BOOL IsSampleUsed(UINT nSample);
  695. BOOL IsInstrumentUsed(UINT nInstr);
  696. BOOL RemoveInstrumentSamples(UINT nInstr);
  697. UINT DetectUnusedSamples(BOOL *);
  698. BOOL RemoveSelectedSamples(BOOL *);
  699. void AdjustSampleLoop(MODINSTRUMENT *pIns);
  700. // I/O from another sound file
  701. BOOL ReadInstrumentFromSong(UINT nInstr, CSoundFile *, UINT nSrcInstrument);
  702. BOOL ReadSampleFromSong(UINT nSample, CSoundFile *, UINT nSrcSample);
  703. // Period/Note functions
  704. UINT GetNoteFromPeriod(UINT period) const;
  705. UINT GetPeriodFromNote(UINT note, int nFineTune, UINT nC4Speed) const;
  706. UINT GetFreqFromPeriod(UINT period, UINT nC4Speed, int nPeriodFrac=0) const;
  707. // Misc functions
  708. MODINSTRUMENT *GetSample(UINT n) { return Ins+n; }
  709. void ResetMidiCfg();
  710. UINT MapMidiInstrument(DWORD dwProgram, UINT nChannel, UINT nNote);
  711. BOOL ITInstrToMPT(const void *p, INSTRUMENTHEADER *penv, UINT trkvers);
  712. UINT SaveMixPlugins(FILE *f=NULL, BOOL bUpdate=TRUE);
  713. UINT LoadMixPlugins(const void *pData, UINT nLen);
  714. #ifndef NO_FILTER
  715. DWORD CutOffToFrequency(UINT nCutOff, int flt_modifier=256) const; // [0-255] => [1-10KHz]
  716. #endif
  717. // Static helper functions
  718. public:
  719. static DWORD TransposeToFrequency(int transp, int ftune=0);
  720. static int FrequencyToTranspose(DWORD freq);
  721. static void FrequencyToTranspose(MODINSTRUMENT *psmp);
  722. // System-Dependant functions
  723. public:
  724. static MODCOMMAND *AllocatePattern(UINT rows, UINT nchns);
  725. static signed char* AllocateSample(UINT nbytes);
  726. static void FreePattern(LPVOID pat);
  727. static void FreeSample(LPVOID p);
  728. static UINT Normalize24BitBuffer(LPBYTE pbuffer, UINT cbsizebytes, DWORD lmax24, DWORD dwByteInc);
  729. };
  730. // inline DWORD BigEndian(DWORD x) { return ((x & 0xFF) << 24) | ((x & 0xFF00) << 8) | ((x & 0xFF0000) >> 8) | ((x & 0xFF000000) >> 24); }
  731. // inline WORD BigEndianW(WORD x) { return (WORD)(((x >> 8) & 0xFF) | ((x << 8) & 0xFF00)); }
  732. //////////////////////////////////////////////////////////
  733. // WAVE format information
  734. #pragma pack(1)
  735. // Standard IFF chunks IDs
  736. #define IFFID_FORM 0x4d524f46
  737. #define IFFID_RIFF 0x46464952
  738. #define IFFID_WAVE 0x45564157
  739. #define IFFID_LIST 0x5453494C
  740. #define IFFID_INFO 0x4F464E49
  741. // IFF Info fields
  742. #define IFFID_ICOP 0x504F4349
  743. #define IFFID_IART 0x54524149
  744. #define IFFID_IPRD 0x44525049
  745. #define IFFID_INAM 0x4D414E49
  746. #define IFFID_ICMT 0x544D4349
  747. #define IFFID_IENG 0x474E4549
  748. #define IFFID_ISFT 0x54465349
  749. #define IFFID_ISBJ 0x4A425349
  750. #define IFFID_IGNR 0x524E4749
  751. #define IFFID_ICRD 0x44524349
  752. // Wave IFF chunks IDs
  753. #define IFFID_wave 0x65766177
  754. #define IFFID_fmt 0x20746D66
  755. #define IFFID_wsmp 0x706D7377
  756. #define IFFID_pcm 0x206d6370
  757. #define IFFID_data 0x61746164
  758. #define IFFID_smpl 0x6C706D73
  759. #define IFFID_xtra 0x61727478
  760. typedef struct WAVEFILEHEADER
  761. {
  762. DWORD id_RIFF; // "RIFF"
  763. DWORD filesize; // file length-8
  764. DWORD id_WAVE;
  765. } WAVEFILEHEADER;
  766. typedef struct WAVEFORMATHEADER
  767. {
  768. DWORD id_fmt; // "fmt "
  769. DWORD hdrlen; // 16
  770. WORD format; // 1
  771. WORD channels; // 1:mono, 2:stereo
  772. DWORD freqHz; // sampling freq
  773. DWORD bytessec; // bytes/sec=freqHz*samplesize
  774. WORD samplesize; // sizeof(sample)
  775. WORD bitspersample; // bits per sample (8/16)
  776. } WAVEFORMATHEADER;
  777. typedef struct WAVEDATAHEADER
  778. {
  779. DWORD id_data; // "data"
  780. DWORD length; // length of data
  781. } WAVEDATAHEADER;
  782. typedef struct WAVESMPLHEADER
  783. {
  784. // SMPL
  785. DWORD smpl_id; // "smpl" -> 0x6C706D73
  786. DWORD smpl_len; // length of smpl: 3Ch (54h with sustain loop)
  787. DWORD dwManufacturer;
  788. DWORD dwProduct;
  789. DWORD dwSamplePeriod; // 1000000000/freqHz
  790. DWORD dwBaseNote; // 3Ch = C-4 -> 60 + RelativeTone
  791. DWORD dwPitchFraction;
  792. DWORD dwSMPTEFormat;
  793. DWORD dwSMPTEOffset;
  794. DWORD dwSampleLoops; // number of loops
  795. DWORD cbSamplerData;
  796. } WAVESMPLHEADER;
  797. typedef struct SAMPLELOOPSTRUCT
  798. {
  799. DWORD dwIdentifier;
  800. DWORD dwLoopType; // 0=normal, 1=bidi
  801. DWORD dwLoopStart;
  802. DWORD dwLoopEnd; // Byte offset ?
  803. DWORD dwFraction;
  804. DWORD dwPlayCount; // Loop Count, 0=infinite
  805. } SAMPLELOOPSTRUCT;
  806. typedef struct WAVESAMPLERINFO
  807. {
  808. WAVESMPLHEADER wsiHdr;
  809. SAMPLELOOPSTRUCT wsiLoops[2];
  810. } WAVESAMPLERINFO;
  811. typedef struct WAVELISTHEADER
  812. {
  813. DWORD list_id; // "LIST" -> 0x5453494C
  814. DWORD list_len;
  815. DWORD info; // "INFO"
  816. } WAVELISTHEADER;
  817. typedef struct WAVEEXTRAHEADER
  818. {
  819. DWORD xtra_id; // "xtra" -> 0x61727478
  820. DWORD xtra_len;
  821. DWORD dwFlags;
  822. WORD wPan;
  823. WORD wVolume;
  824. WORD wGlobalVol;
  825. WORD wReserved;
  826. BYTE nVibType;
  827. BYTE nVibSweep;
  828. BYTE nVibDepth;
  829. BYTE nVibRate;
  830. } WAVEEXTRAHEADER;
  831. #pragma pack()
  832. ///////////////////////////////////////////////////////////
  833. // Low-level Mixing functions
  834. #define MIXBUFFERSIZE 512
  835. #define MIXING_ATTENUATION 4
  836. #define MIXING_CLIPMIN (-0x08000000)
  837. #define MIXING_CLIPMAX (0x07FFFFFF)
  838. #define VOLUMERAMPPRECISION 12
  839. #define FADESONGDELAY 100
  840. #define EQ_BUFFERSIZE (MIXBUFFERSIZE)
  841. #define AGC_PRECISION 9
  842. #define AGC_UNITY (1 << AGC_PRECISION)
  843. // Calling conventions
  844. #ifdef MSC_VER
  845. #define MPPASMCALL __cdecl
  846. #define MPPFASTCALL __fastcall
  847. #else
  848. #define MPPASMCALL
  849. #define MPPFASTCALL
  850. #endif
  851. #define MOD2XMFineTune(k) ((int)( (signed char)((k)<<4) ))
  852. #define XM2MODFineTune(k) ((int)( (k>>4)&0x0f ))
  853. int _muldiv(long a, long b, long c);
  854. int _muldivr(long a, long b, long c);
  855. // Byte swapping functions from the GNU C Library and libsdl
  856. /* Swap bytes in 16 bit value. */
  857. #ifdef __GNUC__
  858. # define bswap_16(x) \
  859. (__extension__ \
  860. ({ unsigned short int __bsx = (x); \
  861. ((((__bsx) >> 8) & 0xff) | (((__bsx) & 0xff) << 8)); }))
  862. #else
  863. static __inline unsigned short int
  864. bswap_16 (unsigned short int __bsx)
  865. {
  866. return ((((__bsx) >> 8) & 0xff) | (((__bsx) & 0xff) << 8));
  867. }
  868. #endif
  869. /* Swap bytes in 32 bit value. */
  870. #ifdef __GNUC__
  871. # define bswap_32(x) \
  872. (__extension__ \
  873. ({ unsigned int __bsx = (x); \
  874. ((((__bsx) & 0xff000000) >> 24) | (((__bsx) & 0x00ff0000) >> 8) | \
  875. (((__bsx) & 0x0000ff00) << 8) | (((__bsx) & 0x000000ff) << 24)); }))
  876. #else
  877. static __inline unsigned int
  878. bswap_32 (unsigned int __bsx)
  879. {
  880. return ((((__bsx) & 0xff000000) >> 24) | (((__bsx) & 0x00ff0000) >> 8) |
  881. (((__bsx) & 0x0000ff00) << 8) | (((__bsx) & 0x000000ff) << 24));
  882. }
  883. #endif
  884. #if (defined ARM) && (defined _WIN32_WCE)
  885. static __inline unsigned short int
  886. ARM_get16(const void *data)
  887. {
  888. unsigned short int s;
  889. memcpy(&s,data,sizeof(s));
  890. return s;
  891. }
  892. static __inline unsigned int
  893. ARM_get32(const void *data)
  894. {
  895. unsigned int s;
  896. memcpy(&s,data,sizeof(s));
  897. return s;
  898. }
  899. #define bswapLE16(X) ARM_get16(&X)
  900. #define bswapLE32(X) ARM_get32(&X)
  901. #define bswapBE16(X) bswap_16(ARM_get16(&X))
  902. #define bswapBE32(X) bswap_32(ARM_get32(&X))
  903. // From libsdl
  904. #elif defined(WORDS_BIGENDIAN) && WORDS_BIGENDIAN
  905. #define bswapLE16(X) bswap_16(X)
  906. #define bswapLE32(X) bswap_32(X)
  907. #define bswapBE16(X) (X)
  908. #define bswapBE32(X) (X)
  909. #else
  910. #define bswapLE16(X) (X)
  911. #define bswapLE32(X) (X)
  912. #define bswapBE16(X) bswap_16(X)
  913. #define bswapBE32(X) bswap_32(X)
  914. #endif
  915. #endif