sndfile.h 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028
  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;
  488. static UINT m_nXBassRange;
  489. static UINT m_nReverbDepth;
  490. static UINT m_nReverbDelay;
  491. static UINT gnReverbType;
  492. static UINT m_nProLogicDepth;
  493. static UINT m_nProLogicDelay;
  494. static UINT m_nStereoSeparation;
  495. static UINT m_nMaxMixChannels;
  496. static LONG m_nStreamVolume;
  497. static DWORD gdwSysInfo;
  498. static DWORD gdwSoundSetup;
  499. static DWORD gdwMixingFreq;
  500. static DWORD gnBitsPerSample;
  501. static DWORD gnChannels;
  502. static UINT gnAGC;
  503. static UINT gnVolumeRampSamples;
  504. static UINT gnVUMeter;
  505. static UINT gnCPUUsage;
  506. static LPSNDMIXHOOKPROC gpSndMixHook;
  507. static PMIXPLUGINCREATEPROC gpMixPluginCreateProc;
  508. public: // for Editing
  509. MODCHANNEL Chn[MAX_CHANNELS]; // Channels
  510. UINT ChnMix[MAX_CHANNELS]; // Channels to be mixed
  511. MODINSTRUMENT Ins[MAX_SAMPLES]; // Instruments
  512. INSTRUMENTHEADER *Headers[MAX_INSTRUMENTS]; // Instrument Headers
  513. MODCHANNELSETTINGS ChnSettings[MAX_BASECHANNELS]; // Channels settings
  514. MODCOMMAND *Patterns[MAX_PATTERNS]; // Patterns
  515. WORD PatternSize[MAX_PATTERNS]; // Patterns Lengths
  516. BYTE Order[MAX_ORDERS]; // Pattern Orders
  517. MODMIDICFG m_MidiCfg; // Midi macro config table
  518. SNDMIXPLUGIN m_MixPlugins[MAX_MIXPLUGINS]; // Mix plugins
  519. UINT m_nDefaultSpeed, m_nDefaultTempo, m_nDefaultGlobalVolume;
  520. DWORD m_dwSongFlags; // Song flags SONG_XXXX
  521. UINT m_nChannels, m_nMixChannels, m_nMixStat, m_nBufferCount;
  522. UINT m_nType, m_nSamples, m_nInstruments;
  523. UINT m_nTickCount, m_nTotalCount, m_nPatternDelay, m_nFrameDelay;
  524. UINT m_nMusicSpeed, m_nMusicTempo;
  525. UINT m_nNextRow, m_nRow, m_nNextStartRow;
  526. UINT m_nPattern,m_nCurrentPattern,m_nNextPattern,m_nRestartPos;
  527. UINT m_nMasterVolume, m_nGlobalVolume, m_nSongPreAmp;
  528. UINT m_nFreqFactor, m_nTempoFactor, m_nOldGlbVolSlide;
  529. LONG m_nMinPeriod, m_nMaxPeriod, m_nRepeatCount, m_nInitialRepeatCount;
  530. DWORD m_nGlobalFadeSamples, m_nGlobalFadeMaxSamples;
  531. UINT m_nMaxOrderPosition;
  532. UINT m_nPatternNames;
  533. LPSTR m_lpszSongComments, m_lpszPatternNames;
  534. char m_szNames[MAX_INSTRUMENTS][32]; // changed from CHAR
  535. CHAR CompressionTable[16];
  536. public:
  537. CSoundFile();
  538. ~CSoundFile();
  539. public:
  540. BOOL Create(LPCBYTE lpStream, DWORD dwMemLength=0);
  541. BOOL Destroy();
  542. UINT GetType() const { return m_nType; }
  543. UINT GetNumChannels() const;
  544. UINT GetLogicalChannels() const { return m_nChannels; }
  545. BOOL SetMasterVolume(UINT vol, BOOL bAdjustAGC=FALSE);
  546. UINT GetMasterVolume() const { return m_nMasterVolume; }
  547. UINT GetNumPatterns() const;
  548. UINT GetNumInstruments() const;
  549. UINT GetNumSamples() const { return m_nSamples; }
  550. UINT GetCurrentPos() const;
  551. UINT GetCurrentPattern() const { return m_nPattern; }
  552. UINT GetCurrentOrder() const { return m_nCurrentPattern; }
  553. UINT GetSongComments(LPSTR s, UINT cbsize, UINT linesize=32);
  554. UINT GetRawSongComments(LPSTR s, UINT cbsize, UINT linesize=32);
  555. UINT GetMaxPosition() const;
  556. void SetCurrentPos(UINT nPos);
  557. void SetCurrentOrder(UINT nOrder);
  558. void GetTitle(LPSTR s) const { lstrcpyn(s,m_szNames[0],32); }
  559. LPCSTR GetTitle() const { return m_szNames[0]; }
  560. UINT GetSampleName(UINT nSample,LPSTR s=NULL) const;
  561. UINT GetInstrumentName(UINT nInstr,LPSTR s=NULL) const;
  562. UINT GetMusicSpeed() const { return m_nMusicSpeed; }
  563. UINT GetMusicTempo() const { return m_nMusicTempo; }
  564. DWORD GetLength(BOOL bAdjust, BOOL bTotal=FALSE);
  565. DWORD GetSongTime() { return GetLength(FALSE, TRUE); }
  566. void SetRepeatCount(int n) { m_nRepeatCount = n; m_nInitialRepeatCount = n; }
  567. int GetRepeatCount() const { return m_nRepeatCount; }
  568. BOOL IsPaused() const { return (m_dwSongFlags & SONG_PAUSED) ? TRUE : FALSE; }
  569. void LoopPattern(int nPat, int nRow=0);
  570. void CheckCPUUsage(UINT nCPU);
  571. BOOL SetPatternName(UINT nPat, LPCSTR lpszName);
  572. BOOL GetPatternName(UINT nPat, LPSTR lpszName, UINT cbSize=MAX_PATTERNNAME) const;
  573. // Module Loaders
  574. BOOL ReadXM(LPCBYTE lpStream, DWORD dwMemLength);
  575. BOOL ReadS3M(LPCBYTE lpStream, DWORD dwMemLength);
  576. BOOL ReadMod(LPCBYTE lpStream, DWORD dwMemLength);
  577. BOOL ReadMed(LPCBYTE lpStream, DWORD dwMemLength);
  578. BOOL ReadMTM(LPCBYTE lpStream, DWORD dwMemLength);
  579. BOOL ReadSTM(LPCBYTE lpStream, DWORD dwMemLength);
  580. BOOL ReadIT(LPCBYTE lpStream, DWORD dwMemLength);
  581. BOOL Read669(LPCBYTE lpStream, DWORD dwMemLength);
  582. BOOL ReadUlt(LPCBYTE lpStream, DWORD dwMemLength);
  583. BOOL ReadWav(LPCBYTE lpStream, DWORD dwMemLength);
  584. BOOL ReadDSM(LPCBYTE lpStream, DWORD dwMemLength);
  585. BOOL ReadFAR(LPCBYTE lpStream, DWORD dwMemLength);
  586. BOOL ReadAMS(LPCBYTE lpStream, DWORD dwMemLength);
  587. BOOL ReadAMS2(LPCBYTE lpStream, DWORD dwMemLength);
  588. BOOL ReadMDL(LPCBYTE lpStream, DWORD dwMemLength);
  589. BOOL ReadOKT(LPCBYTE lpStream, DWORD dwMemLength);
  590. BOOL ReadDMF(LPCBYTE lpStream, DWORD dwMemLength);
  591. BOOL ReadPTM(LPCBYTE lpStream, DWORD dwMemLength);
  592. BOOL ReadDBM(LPCBYTE lpStream, DWORD dwMemLength);
  593. BOOL ReadAMF(LPCBYTE lpStream, DWORD dwMemLength);
  594. BOOL ReadMT2(LPCBYTE lpStream, DWORD dwMemLength);
  595. BOOL ReadPSM(LPCBYTE lpStream, DWORD dwMemLength);
  596. BOOL ReadJ2B(LPCBYTE lpStream, DWORD dwMemLength);
  597. BOOL ReadUMX(LPCBYTE lpStream, DWORD dwMemLength);
  598. BOOL ReadABC(LPCBYTE lpStream, DWORD dwMemLength);
  599. BOOL TestABC(LPCBYTE lpStream, DWORD dwMemLength);
  600. BOOL ReadMID(LPCBYTE lpStream, DWORD dwMemLength);
  601. BOOL TestMID(LPCBYTE lpStream, DWORD dwMemLength);
  602. BOOL ReadPAT(LPCBYTE lpStream, DWORD dwMemLength);
  603. BOOL TestPAT(LPCBYTE lpStream, DWORD dwMemLength);
  604. // Save Functions
  605. #ifndef MODPLUG_NO_FILESAVE
  606. UINT WriteSample(FILE *f, MODINSTRUMENT *pins, UINT nFlags, UINT nMaxLen=0);
  607. BOOL SaveXM(LPCSTR lpszFileName, UINT nPacking=0);
  608. BOOL SaveS3M(LPCSTR lpszFileName, UINT nPacking=0);
  609. BOOL SaveMod(LPCSTR lpszFileName, UINT nPacking=0);
  610. BOOL SaveIT(LPCSTR lpszFileName, UINT nPacking=0);
  611. #endif // MODPLUG_NO_FILESAVE
  612. // MOD Convert function
  613. UINT GetBestSaveFormat() const;
  614. UINT GetSaveFormats() const;
  615. void ConvertModCommand(MODCOMMAND *) const;
  616. void S3MConvert(MODCOMMAND *m, BOOL bIT) const;
  617. void S3MSaveConvert(UINT *pcmd, UINT *pprm, BOOL bIT) const;
  618. WORD ModSaveCommand(const MODCOMMAND *m, BOOL bXM) const;
  619. public:
  620. // Real-time sound functions
  621. VOID ResetChannels();
  622. UINT Read(LPVOID lpBuffer, UINT cbBuffer);
  623. UINT CreateStereoMix(int count);
  624. BOOL FadeSong(UINT msec);
  625. BOOL GlobalFadeSong(UINT msec);
  626. UINT GetTotalTickCount() const { return m_nTotalCount; }
  627. VOID ResetTotalTickCount() { m_nTotalCount = 0; }
  628. public:
  629. // Mixer Config
  630. static BOOL InitPlayer(BOOL bReset=FALSE);
  631. static BOOL SetMixConfig(UINT nStereoSeparation, UINT nMaxMixChannels);
  632. static BOOL SetWaveConfig(UINT nRate,UINT nBits,UINT nChannels,BOOL bMMX=FALSE);
  633. static BOOL SetResamplingMode(UINT nMode); // SRCMODE_XXXX
  634. static BOOL IsStereo() { return (gnChannels > 1) ? TRUE : FALSE; }
  635. static DWORD GetSampleRate() { return gdwMixingFreq; }
  636. static DWORD GetBitsPerSample() { return gnBitsPerSample; }
  637. static DWORD InitSysInfo();
  638. static DWORD GetSysInfo() { return gdwSysInfo; }
  639. // AGC
  640. static BOOL GetAGC() { return (gdwSoundSetup & SNDMIX_AGC) ? TRUE : FALSE; }
  641. static void SetAGC(BOOL b);
  642. static void ResetAGC();
  643. static void ProcessAGC(int count);
  644. //GCCFIX -- added these functions back in!
  645. static BOOL SetWaveConfigEx(BOOL bSurround,BOOL bNoOverSampling,BOOL bReverb,BOOL hqido,BOOL bMegaBass,BOOL bNR,BOOL bEQ);
  646. // DSP Effects
  647. static void InitializeDSP(BOOL bReset);
  648. static void ProcessStereoDSP(int count);
  649. static void ProcessMonoDSP(int count);
  650. // [Reverb level 0(quiet)-100(loud)], [delay in ms, usually 40-200ms]
  651. static BOOL SetReverbParameters(UINT nDepth, UINT nDelay);
  652. // [XBass level 0(quiet)-100(loud)], [cutoff in Hz 10-100]
  653. static BOOL SetXBassParameters(UINT nDepth, UINT nRange);
  654. // [Surround level 0(quiet)-100(heavy)] [delay in ms, usually 5-40ms]
  655. static BOOL SetSurroundParameters(UINT nDepth, UINT nDelay);
  656. public:
  657. BOOL ReadNote();
  658. BOOL ProcessRow();
  659. BOOL ProcessEffects();
  660. UINT GetNNAChannel(UINT nChn) const;
  661. void CheckNNA(UINT nChn, UINT instr, int note, BOOL bForceCut);
  662. void NoteChange(UINT nChn, int note, BOOL bPorta=FALSE, BOOL bResetEnv=TRUE);
  663. void InstrumentChange(MODCHANNEL *pChn, UINT instr, BOOL bPorta=FALSE,BOOL bUpdVol=TRUE,BOOL bResetEnv=TRUE);
  664. // Channel Effects
  665. void PortamentoUp(MODCHANNEL *pChn, UINT param);
  666. void PortamentoDown(MODCHANNEL *pChn, UINT param);
  667. void FinePortamentoUp(MODCHANNEL *pChn, UINT param);
  668. void FinePortamentoDown(MODCHANNEL *pChn, UINT param);
  669. void ExtraFinePortamentoUp(MODCHANNEL *pChn, UINT param);
  670. void ExtraFinePortamentoDown(MODCHANNEL *pChn, UINT param);
  671. void TonePortamento(MODCHANNEL *pChn, UINT param);
  672. void Vibrato(MODCHANNEL *pChn, UINT param);
  673. void FineVibrato(MODCHANNEL *pChn, UINT param);
  674. void VolumeSlide(MODCHANNEL *pChn, UINT param);
  675. void PanningSlide(MODCHANNEL *pChn, UINT param);
  676. void ChannelVolSlide(MODCHANNEL *pChn, UINT param);
  677. void FineVolumeUp(MODCHANNEL *pChn, UINT param);
  678. void FineVolumeDown(MODCHANNEL *pChn, UINT param);
  679. void Tremolo(MODCHANNEL *pChn, UINT param);
  680. void Panbrello(MODCHANNEL *pChn, UINT param);
  681. void RetrigNote(UINT nChn, UINT param);
  682. void NoteCut(UINT nChn, UINT nTick);
  683. void KeyOff(UINT nChn);
  684. int PatternLoop(MODCHANNEL *, UINT param);
  685. void ExtendedMODCommands(UINT nChn, UINT param);
  686. void ExtendedS3MCommands(UINT nChn, UINT param);
  687. void ExtendedChannelEffect(MODCHANNEL *, UINT param);
  688. void ProcessMidiMacro(UINT nChn, LPCSTR pszMidiMacro, UINT param=0);
  689. void SetupChannelFilter(MODCHANNEL *pChn, BOOL bReset, int flt_modifier=256) const;
  690. // Low-Level effect processing
  691. void DoFreqSlide(MODCHANNEL *pChn, LONG nFreqSlide);
  692. // Global Effects
  693. void SetTempo(UINT param);
  694. void SetSpeed(UINT param);
  695. void GlobalVolSlide(UINT param);
  696. DWORD IsSongFinished(UINT nOrder, UINT nRow) const;
  697. BOOL IsValidBackwardJump(UINT nStartOrder, UINT nStartRow, UINT nJumpOrder, UINT nJumpRow) const;
  698. // Read/Write sample functions
  699. signed char GetDeltaValue(signed char prev, UINT n) const { return (signed char)(prev + CompressionTable[n & 0x0F]); }
  700. UINT PackSample(int &sample, int next);
  701. BOOL CanPackSample(LPSTR pSample, UINT nLen, UINT nPacking, BYTE *result=NULL);
  702. UINT ReadSample(MODINSTRUMENT *pIns, UINT nFlags, LPCSTR pMemFile, DWORD dwMemLength);
  703. BOOL DestroySample(UINT nSample);
  704. BOOL DestroyInstrument(UINT nInstr);
  705. BOOL IsSampleUsed(UINT nSample);
  706. BOOL IsInstrumentUsed(UINT nInstr);
  707. BOOL RemoveInstrumentSamples(UINT nInstr);
  708. UINT DetectUnusedSamples(BOOL *);
  709. BOOL RemoveSelectedSamples(BOOL *);
  710. void AdjustSampleLoop(MODINSTRUMENT *pIns);
  711. // I/O from another sound file
  712. BOOL ReadInstrumentFromSong(UINT nInstr, CSoundFile *, UINT nSrcInstrument);
  713. BOOL ReadSampleFromSong(UINT nSample, CSoundFile *, UINT nSrcSample);
  714. // Period/Note functions
  715. UINT GetNoteFromPeriod(UINT period) const;
  716. UINT GetPeriodFromNote(UINT note, int nFineTune, UINT nC4Speed) const;
  717. UINT GetFreqFromPeriod(UINT period, UINT nC4Speed, int nPeriodFrac=0) const;
  718. // Misc functions
  719. MODINSTRUMENT *GetSample(UINT n) { return Ins+n; }
  720. void ResetMidiCfg();
  721. UINT MapMidiInstrument(DWORD dwProgram, UINT nChannel, UINT nNote);
  722. BOOL ITInstrToMPT(const void *p, INSTRUMENTHEADER *penv, UINT trkvers);
  723. UINT SaveMixPlugins(FILE *f=NULL, BOOL bUpdate=TRUE);
  724. UINT LoadMixPlugins(const void *pData, UINT nLen);
  725. #ifndef NO_FILTER
  726. DWORD CutOffToFrequency(UINT nCutOff, int flt_modifier=256) const; // [0-255] => [1-10KHz]
  727. #endif
  728. // Static helper functions
  729. public:
  730. static DWORD TransposeToFrequency(int transp, int ftune=0);
  731. static int FrequencyToTranspose(DWORD freq);
  732. static void FrequencyToTranspose(MODINSTRUMENT *psmp);
  733. // System-Dependant functions
  734. public:
  735. static MODCOMMAND *AllocatePattern(UINT rows, UINT nchns);
  736. static signed char* AllocateSample(UINT nbytes);
  737. static void FreePattern(LPVOID pat);
  738. static void FreeSample(LPVOID p);
  739. static UINT Normalize24BitBuffer(LPBYTE pbuffer, UINT cbsizebytes, DWORD lmax24, DWORD dwByteInc);
  740. };
  741. // inline DWORD BigEndian(DWORD x) { return ((x & 0xFF) << 24) | ((x & 0xFF00) << 8) | ((x & 0xFF0000) >> 8) | ((x & 0xFF000000) >> 24); }
  742. // inline WORD BigEndianW(WORD x) { return (WORD)(((x >> 8) & 0xFF) | ((x << 8) & 0xFF00)); }
  743. //////////////////////////////////////////////////////////
  744. // WAVE format information
  745. #pragma pack(1)
  746. // Standard IFF chunks IDs
  747. #define IFFID_FORM 0x4d524f46
  748. #define IFFID_RIFF 0x46464952
  749. #define IFFID_WAVE 0x45564157
  750. #define IFFID_LIST 0x5453494C
  751. #define IFFID_INFO 0x4F464E49
  752. // IFF Info fields
  753. #define IFFID_ICOP 0x504F4349
  754. #define IFFID_IART 0x54524149
  755. #define IFFID_IPRD 0x44525049
  756. #define IFFID_INAM 0x4D414E49
  757. #define IFFID_ICMT 0x544D4349
  758. #define IFFID_IENG 0x474E4549
  759. #define IFFID_ISFT 0x54465349
  760. #define IFFID_ISBJ 0x4A425349
  761. #define IFFID_IGNR 0x524E4749
  762. #define IFFID_ICRD 0x44524349
  763. // Wave IFF chunks IDs
  764. #define IFFID_wave 0x65766177
  765. #define IFFID_fmt 0x20746D66
  766. #define IFFID_wsmp 0x706D7377
  767. #define IFFID_pcm 0x206d6370
  768. #define IFFID_data 0x61746164
  769. #define IFFID_smpl 0x6C706D73
  770. #define IFFID_xtra 0x61727478
  771. typedef struct WAVEFILEHEADER
  772. {
  773. DWORD id_RIFF; // "RIFF"
  774. DWORD filesize; // file length-8
  775. DWORD id_WAVE;
  776. } WAVEFILEHEADER;
  777. typedef struct WAVEFORMATHEADER
  778. {
  779. DWORD id_fmt; // "fmt "
  780. DWORD hdrlen; // 16
  781. WORD format; // 1
  782. WORD channels; // 1:mono, 2:stereo
  783. DWORD freqHz; // sampling freq
  784. DWORD bytessec; // bytes/sec=freqHz*samplesize
  785. WORD samplesize; // sizeof(sample)
  786. WORD bitspersample; // bits per sample (8/16)
  787. } WAVEFORMATHEADER;
  788. typedef struct WAVEDATAHEADER
  789. {
  790. DWORD id_data; // "data"
  791. DWORD length; // length of data
  792. } WAVEDATAHEADER;
  793. typedef struct WAVESMPLHEADER
  794. {
  795. // SMPL
  796. DWORD smpl_id; // "smpl" -> 0x6C706D73
  797. DWORD smpl_len; // length of smpl: 3Ch (54h with sustain loop)
  798. DWORD dwManufacturer;
  799. DWORD dwProduct;
  800. DWORD dwSamplePeriod; // 1000000000/freqHz
  801. DWORD dwBaseNote; // 3Ch = C-4 -> 60 + RelativeTone
  802. DWORD dwPitchFraction;
  803. DWORD dwSMPTEFormat;
  804. DWORD dwSMPTEOffset;
  805. DWORD dwSampleLoops; // number of loops
  806. DWORD cbSamplerData;
  807. } WAVESMPLHEADER;
  808. typedef struct SAMPLELOOPSTRUCT
  809. {
  810. DWORD dwIdentifier;
  811. DWORD dwLoopType; // 0=normal, 1=bidi
  812. DWORD dwLoopStart;
  813. DWORD dwLoopEnd; // Byte offset ?
  814. DWORD dwFraction;
  815. DWORD dwPlayCount; // Loop Count, 0=infinite
  816. } SAMPLELOOPSTRUCT;
  817. typedef struct WAVESAMPLERINFO
  818. {
  819. WAVESMPLHEADER wsiHdr;
  820. SAMPLELOOPSTRUCT wsiLoops[2];
  821. } WAVESAMPLERINFO;
  822. typedef struct WAVELISTHEADER
  823. {
  824. DWORD list_id; // "LIST" -> 0x5453494C
  825. DWORD list_len;
  826. DWORD info; // "INFO"
  827. } WAVELISTHEADER;
  828. typedef struct WAVEEXTRAHEADER
  829. {
  830. DWORD xtra_id; // "xtra" -> 0x61727478
  831. DWORD xtra_len;
  832. DWORD dwFlags;
  833. WORD wPan;
  834. WORD wVolume;
  835. WORD wGlobalVol;
  836. WORD wReserved;
  837. BYTE nVibType;
  838. BYTE nVibSweep;
  839. BYTE nVibDepth;
  840. BYTE nVibRate;
  841. } WAVEEXTRAHEADER;
  842. #pragma pack()
  843. ///////////////////////////////////////////////////////////
  844. // Low-level Mixing functions
  845. #define MIXBUFFERSIZE 512
  846. #define MIXING_ATTENUATION 4
  847. #define MIXING_CLIPMIN (-0x08000000)
  848. #define MIXING_CLIPMAX (0x07FFFFFF)
  849. #define VOLUMERAMPPRECISION 12
  850. #define FADESONGDELAY 100
  851. #define EQ_BUFFERSIZE (MIXBUFFERSIZE)
  852. #define AGC_PRECISION 9
  853. #define AGC_UNITY (1 << AGC_PRECISION)
  854. // Calling conventions
  855. #ifdef MSC_VER
  856. #define MPPASMCALL __cdecl
  857. #define MPPFASTCALL __fastcall
  858. #else
  859. #define MPPASMCALL
  860. #define MPPFASTCALL
  861. #endif
  862. #define MOD2XMFineTune(k) ((int)( (signed char)((k)<<4) ))
  863. #define XM2MODFineTune(k) ((int)( (k>>4)&0x0f ))
  864. int _muldiv(long a, long b, long c);
  865. int _muldivr(long a, long b, long c);
  866. // Byte swapping functions from the GNU C Library and libsdl
  867. /* Swap bytes in 16 bit value. */
  868. #ifdef __GNUC__
  869. # define bswap_16(x) \
  870. (__extension__ \
  871. ({ unsigned short int __bsx = (x); \
  872. ((((__bsx) >> 8) & 0xff) | (((__bsx) & 0xff) << 8)); }))
  873. #else
  874. static __inline unsigned short int
  875. bswap_16 (unsigned short int __bsx)
  876. {
  877. return ((((__bsx) >> 8) & 0xff) | (((__bsx) & 0xff) << 8));
  878. }
  879. #endif
  880. /* Swap bytes in 32 bit value. */
  881. #ifdef __GNUC__
  882. # define bswap_32(x) \
  883. (__extension__ \
  884. ({ unsigned int __bsx = (x); \
  885. ((((__bsx) & 0xff000000) >> 24) | (((__bsx) & 0x00ff0000) >> 8) | \
  886. (((__bsx) & 0x0000ff00) << 8) | (((__bsx) & 0x000000ff) << 24)); }))
  887. #else
  888. static __inline unsigned int
  889. bswap_32 (unsigned int __bsx)
  890. {
  891. return ((((__bsx) & 0xff000000) >> 24) | (((__bsx) & 0x00ff0000) >> 8) |
  892. (((__bsx) & 0x0000ff00) << 8) | (((__bsx) & 0x000000ff) << 24));
  893. }
  894. #endif
  895. #if (defined ARM) && (defined _WIN32_WCE)
  896. static __inline unsigned short int
  897. ARM_get16(const void *data)
  898. {
  899. unsigned short int s;
  900. memcpy(&s,data,sizeof(s));
  901. return s;
  902. }
  903. static __inline unsigned int
  904. ARM_get32(const void *data)
  905. {
  906. unsigned int s;
  907. memcpy(&s,data,sizeof(s));
  908. return s;
  909. }
  910. #define bswapLE16(X) ARM_get16(&X)
  911. #define bswapLE32(X) ARM_get32(&X)
  912. #define bswapBE16(X) bswap_16(ARM_get16(&X))
  913. #define bswapBE32(X) bswap_32(ARM_get32(&X))
  914. // From libsdl
  915. #elif defined(WORDS_BIGENDIAN) && WORDS_BIGENDIAN
  916. #define bswapLE16(X) bswap_16(X)
  917. #define bswapLE32(X) bswap_32(X)
  918. #define bswapBE16(X) (X)
  919. #define bswapBE32(X) (X)
  920. #else
  921. #define bswapLE16(X) (X)
  922. #define bswapLE32(X) (X)
  923. #define bswapBE16(X) bswap_16(X)
  924. #define bswapBE32(X) bswap_32(X)
  925. #endif
  926. #endif