modplug.pas 5.0 KB

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