gcmodplay.pp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. unit gcmodplay;
  2. {$mode objfpc}
  3. {$J+}
  4. {$INLINE ON}
  5. {$MACRO ON}
  6. {$ASSERTIONS ON}
  7. interface
  8. uses
  9. ctypes, gctypes;
  10. const
  11. MAX_VOICES = 32;
  12. type
  13. _modinstr = record
  14. name_ : array [0..22] of cint8; (* 000..021 *)
  15. length : cuint32; (* 022..023 *)
  16. finetune : cuint8; (* 024 *)
  17. volume : cuint8; (* 025 *)
  18. loop_start : cuint32; (* 026..027 *)
  19. loop_end : cuint32; (* 028..029 *)
  20. loop_length : cuint32;
  21. looped : cbool;
  22. data : pcint8;
  23. end;
  24. MOD_INSTR = _modinstr;
  25. Pcbool = ^cbool;
  26. _mod = record
  27. loaded : cbool;
  28. name_ : array [0..20] of cint8;
  29. instrument : array [0..30] of MOD_INSTR;
  30. num_patterns : cint32;
  31. song_length : cuint8;
  32. ciaa : cuint8;
  33. song : array [0..127] of cuint8;
  34. id : array [0..3] of cint8;
  35. patterndata : pcuint8;
  36. num_instr : cint32;
  37. num_voices : cint32; (* Number of voices in the MOD *)
  38. num_channels : cint32; (* Number of channels to actually mix (num_channels-num_voices = number of sfx channels) *)
  39. mixingbuf : pcuint8;
  40. mixingbuflen : cint32;
  41. shiftval : cint32; (* Number of bits to lshift every mixed 16bit word by *)
  42. (* Player variables *)
  43. channel_active : array [0..MAX_VOICES-1] of cbool;
  44. patterndelay : cint32;
  45. speed : cint32;
  46. bpm : cint32;
  47. songpos : cint32; (* In the song *)
  48. patternline : cint32; (* In the pattern *)
  49. patternline_jumpto : cint32; (* For the E6 effect *)
  50. patternline_jumpcount : cint32; (* For the E6 effect *)
  51. speedcounter : cint32;
  52. freq : cint32;
  53. bits : cint32;
  54. channels : cint32; (* 1 = mono, 2 = stereo *)
  55. playpos : array [0..MAX_VOICES-1] of cuint32; (* Playing position for each channel *)
  56. instnum : array [0..MAX_VOICES-1] of cuint8; (* Current instrument *)
  57. chanfreq : array [0..MAX_VOICES-1] of cuint16; (* Current frequency *)
  58. channote : array [0..MAX_VOICES-1] of cuint16; (* Last note triggered *)
  59. volume : array [0..MAX_VOICES-1] of cuint8; (* Current volume *)
  60. effect : array [0..MAX_VOICES-1] of cuint8; (* Current effect *)
  61. effectop : array [0..MAX_VOICES-1] of cuint8; (* Current effect operand *)
  62. last_effect : array [0..MAX_VOICES-1] of cuint8;
  63. (* Effects handling *)
  64. portamento_to : array [0..MAX_VOICES-1] of cuint16;
  65. porta_speed : array [0..MAX_VOICES-1] of cuint8;
  66. retrigger_counter : array [0..MAX_VOICES-1] of cuint8;
  67. arp_counter : cuint8;
  68. sintabpos : array [0..MAX_VOICES-1] of cuint8;
  69. vib_freq : array [0..MAX_VOICES-1] of cuint8;
  70. vib_depth : array [0..MAX_VOICES-1] of cuint8;
  71. vib_basefreq : array [0..MAX_VOICES-1] of cuint16;
  72. trem_basevol : array [0..MAX_VOICES-1] of cuint8;
  73. trem_freq : array [0..MAX_VOICES-1] of cuint8;
  74. trem_depth : array [0..MAX_VOICES-1] of cuint8;
  75. glissando : array [0..MAX_VOICES-1] of cbool;
  76. trem_wave : array [0..MAX_VOICES-1] of cuint8;
  77. vib_wave : array [0..MAX_VOICES-1] of cuint8;
  78. nextinstr : array [0..MAX_VOICES-1] of cuint8;
  79. nextnote : array [0..MAX_VOICES-1] of cuint16;
  80. samplespertick : cuint32;
  81. samplescounter : cuint32;
  82. modraw : pcuint8;
  83. bpmtab : pcuint32;
  84. inctab : pcuint32;
  85. notebeats : cuint32;
  86. callback : procedure(par0: pointer); cdecl;
  87. musicvolume : cuint8;
  88. sfxvolume : cuint8;
  89. set_ : cbool;
  90. notify : Pcbool;
  91. end;
  92. TMOD = _mod;
  93. PMOD = ^_mod;
  94. union_word = record
  95. case Integer of
  96. 0:(abyte: record
  97. high: cuint8;
  98. low : cuint8;
  99. end;
  100. );
  101. 1:(aword : cuint16;);
  102. end;
  103. union_dword = record
  104. case Integer of
  105. 0:(aword: record
  106. high: cuint16;
  107. low: cuint16;
  108. end;
  109. );
  110. 1:(adword : cuint32;);
  111. end;
  112. TCallback = procedure(par0: pointer; par1: pcuint8; par2: cuint32); cdecl;
  113. _modsndbuf = record
  114. freq : cuint32;
  115. fmt : cuint16;
  116. chans : cuint32;
  117. samples : f32;
  118. usr_data : pointer;
  119. callback : TCallback;
  120. end;
  121. MODSNDBUF = _modsndbuf;
  122. PMODSNDBUF = ^_modsndbuf;
  123. _modplay = record
  124. mod_ : TMOD;
  125. playing : cbool;
  126. paused : cbool;
  127. bits : cbool;
  128. stereo : cbool;
  129. manual_polling : cbool;
  130. playfreq : cuint32;
  131. numSFXChans : cuint32;
  132. soundBuf : MODSNDBUF;
  133. end;
  134. TMODPlay = _modplay;
  135. PMODPlay = ^_modplay;
  136. var
  137. semitonetab : array [0..4095] of cuint8; cvar; external;
  138. freqtab: array [0..0] of cuint16; cvar; external;
  139. procedure MODPlay_Init(mod_: PMODPlay); cdecl; external;
  140. function MODPlay_SetFrequency(mod_: PMODPlay; freq: cuint32): cint32; cdecl; external;
  141. procedure MODPlay_SetStereo(mod_: PMODPlay; stereo: cbool); cdecl; external;
  142. function MODPlay_SetMOD(mod_: PMODPlay; mem: pointer): cint32; cdecl; external;
  143. procedure MODPlay_Unload(mod_: PMODPlay); cdecl; external;
  144. function MODPlay_AllocSFXChannels(mod_: PMODPlay; sfxchans: cuint32): cint32; cdecl; external;
  145. function MODPlay_Start(mod_: PMODPlay): cint32; cdecl; external;
  146. function MODPlay_Stop(mod_: PMODPlay): cint32; cdecl; external;
  147. function MODPlay_TriggerNote(mod_: PMODPlay; chan: cuint32; inst: cuint8; freq: cuint16; vol: cuint8): cint32; cdecl; external;
  148. function MODPlay_Pause(mod_: PMODPlay; par1: cbool): cint32; cdecl; external;
  149. procedure MODPlay_SetVolume(mod_: PMODPlay; musicvolume, sfxvolume: cint32); cdecl; external;
  150. function MOD_SetMOD(par0: PMOD; par1: pcuint8): cint32; cdecl; external;
  151. function MOD_Load(par0: PMOD; par1: pcchar): cint32; cdecl; external;
  152. procedure MOD_Free(par0: PMOD); cdecl; external;
  153. procedure MOD_Start(par0: PMOD); cdecl; external;
  154. function MOD_Player(par0: PMOD): cuint32; cdecl; external;
  155. function MOD_TriggerNote(par0: PMOD; par1: cint32; par2: cuint8;
  156. par3: cuint16; par4: cuint8): cint32; cdecl; external;
  157. function MOD_AllocSFXChannels(par0: PMOD; par1: cint32): cint32; cdecl; external;
  158. function getNote(par0: PMOD; par1, par2: cint32): cuint16; cdecl; external;
  159. function getInstr(par0: PMOD; par1, par2: cint32): cuint8; cdecl; external;
  160. function getEffect(par0: PMOD; par1, par2: cint32): cuint8; cdecl; external;
  161. function getEffectOp(par0: PMOD; par1, par2: cint32): cuint8; cdecl; external;
  162. function mix_mono_16bit(mod_: PMOD; buf: pcint16; numSamples: cint): cint; cdecl; external;
  163. function mix_stereo_16bit(mod_: PMOD; buf: pcint16; numSamples: cint): cint; cdecl; external;
  164. implementation
  165. initialization
  166. {$linklib aesnd}
  167. {$linklib modplay}
  168. end.