modplug.pas 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. {
  2. Translation of the libmodplug headers for FreePascal
  3. Copyright (C) 2006 by Ivo Steinmann
  4. }
  5. (*
  6. * This source code is public domain.
  7. *
  8. * Authors: Kenton Varda <[email protected]> (C interface wrapper)
  9. *)
  10. {$IFNDEF FPC_DOTTEDUNITS}
  11. unit modplug;
  12. {$ENDIF FPC_DOTTEDUNITS}
  13. {$mode objfpc}
  14. {$MINENUMSIZE 4}
  15. interface
  16. {$IFDEF FPC_DOTTEDUNITS}
  17. uses
  18. System.CTypes;
  19. {$ELSE FPC_DOTTEDUNITS}
  20. uses
  21. ctypes;
  22. {$ENDIF FPC_DOTTEDUNITS}
  23. {$IFDEF WINDOWS}
  24. {$DEFINE DYNLINK}
  25. {$ENDIF}
  26. //{$DEFINE DYNLINK}
  27. {$IFDEF DYNLINK}
  28. const
  29. {$IF Defined(WINDOWS)}
  30. modpluglib = 'libmodplug.dll';
  31. {$ELSEIF Defined(UNIX)}
  32. modpluglib = 'libmodplug.so';
  33. {$ELSE}
  34. {$MESSAGE ERROR 'DYNLINK not supported'}
  35. {$IFEND}
  36. {$ELSE}
  37. //{$LINKLIB stdc++}
  38. {$LINKLIB modplug}
  39. {$ENDIF}
  40. type
  41. PModPlugFile = ^ModPlugFile;
  42. ModPlugFile = record
  43. end;
  44. (* Load a mod file. [data] should point to a block of memory containing the complete
  45. * file, and [size] should be the size of that block.
  46. * Return the loaded mod file on success, or NULL on failure. *)
  47. function ModPlug_Load(data: pointer; size: cint): PModPlugFile; cdecl; external {$IFDEF DYNLINK}modpluglib{$ENDIF};
  48. (* Unload a mod file. *)
  49. procedure ModPlug_Unload(_file: PModPlugFile); cdecl; external {$IFDEF DYNLINK}modpluglib{$ENDIF};
  50. (* Read sample data into the buffer. Returns the number of bytes read. If the end
  51. * of the mod has been reached, zero is returned. *)
  52. function ModPlug_Read(_file: PModPlugFile; buffer: pointer; size: cint): cint; cdecl; external {$IFDEF DYNLINK}modpluglib{$ENDIF};
  53. (* Get the name of the mod. The returned buffer is stored within the ModPlugFile
  54. * structure and will remain valid until you unload the file. *)
  55. function ModPlug_GetName(_file: PModPlugFile): pcchar; cdecl; external {$IFDEF DYNLINK}modpluglib{$ENDIF};
  56. (* Get the length of the mod, in milliseconds. Note that this result is not always
  57. * accurate, especially in the case of mods with loops. *)
  58. function ModPlug_GetLength(_file: PModPlugFile): cint; cdecl; external {$IFDEF DYNLINK}modpluglib{$ENDIF};
  59. (* Seek to a particular position in the song. Note that seeking and MODs don't mix very
  60. * well. Some mods will be missing instruments for a short time after a seek, as ModPlug
  61. * does not scan the sequence backwards to find out which instruments were supposed to be
  62. * playing at that time. (Doing so would be difficult and not very reliable.) Also,
  63. * note that seeking is not very exact in some mods -- especially those for which
  64. * ModPlug_GetLength() does not report the full length. *)
  65. procedure ModPlug_Seek(_file: PModPlugFile; millisecond: cint); cdecl; external {$IFDEF DYNLINK}modpluglib{$ENDIF};
  66. const
  67. // _ModPlug_Flags
  68. MODPLUG_ENABLE_OVERSAMPLING = 1 shl 0; (* Enable oversampling (highly recommended) *)
  69. MODPLUG_ENABLE_NOISE_REDUCTION = 1 shl 1; (* Enable noise reduction *)
  70. MODPLUG_ENABLE_REVERB = 1 shl 2; (* Enable reverb *)
  71. MODPLUG_ENABLE_MEGABASS = 1 shl 3; (* Enable megabass *)
  72. MODPLUG_ENABLE_SURROUND = 1 shl 4; (* Enable surround sound. *)
  73. // _ModPlug_ResamplingMode
  74. MODPLUG_RESAMPLE_NEAREST = 0; (* No interpolation (very fast, extremely bad sound quality) *)
  75. MODPLUG_RESAMPLE_LINEAR = 1; (* Linear interpolation (fast, good quality) *)
  76. MODPLUG_RESAMPLE_SPLINE = 2; (* Cubic spline interpolation (high quality) *)
  77. MODPLUG_RESAMPLE_FIR = 3; (* 8-tap fir filter (extremely high quality) *)
  78. type
  79. PModPlug_Settings = ^ModPlug_Settings;
  80. ModPlug_Settings = record
  81. mFlags : cint; (* One or more of the MODPLUG_ENABLE_* flags above, bitwise-OR'ed *)
  82. (* Note that ModPlug always decodes sound at 44100kHz, 32 bit, stereo and then
  83. * down-mixes to the settings you choose. *)
  84. mChannels : cint; (* Number of channels - 1 for mono or 2 for stereo *)
  85. mBits : cint; (* Bits per sample - 8, 16, or 32 *)
  86. mFrequency : cint; (* Sampling rate - 11025, 22050, or 44100 *)
  87. mResamplingMode : cint; (* One of MODPLUG_RESAMPLE_*, above *)
  88. mReverbDepth : cint; (* Reverb level 0(quiet)-100(loud) *)
  89. mReverbDelay : cint; (* Reverb delay in ms, usually 40-200ms *)
  90. mBassAmount : cint; (* XBass level 0(quiet)-100(loud) *)
  91. mBassRange : cint; (* XBass cutoff in Hz 10-100 *)
  92. mSurroundDepth : cint; (* Surround level 0(quiet)-100(heavy) *)
  93. mSurroundDelay : cint; (* Surround delay in ms, usually 5-40ms *)
  94. mLoopCount : cint; (* Number of times to loop. Zero prevents looping. -1 loops forever. *)
  95. end;
  96. (* Get and set the mod decoder settings. All options, except for channels, bits-per-sample,
  97. * sampling rate, and loop count, will take effect immediately. Those options which don't
  98. * take effect immediately will take effect the next time you load a mod. *)
  99. procedure ModPlug_GetSettings(settings: PModPlug_Settings); cdecl; external {$IFDEF DYNLINK}modpluglib{$ENDIF};
  100. procedure ModPlug_SetSettings(const settings: PModPlug_Settings); cdecl; external {$IFDEF DYNLINK}modpluglib{$ENDIF};
  101. implementation
  102. function cppNew(s: cint): pointer; cdecl; public; alias : '_Znaj'; alias : '_Znwj';
  103. begin
  104. GetMem(Result, s);
  105. end;
  106. procedure cppDelete(p: pointer); cdecl; public; alias : '_ZdlPv'; alias : '_ZdaPv';
  107. begin
  108. FreeMem(p);
  109. end;
  110. end.