Browse Source

* freaking commit error, commited modplug.pas again

git-svn-id: trunk@4696 -
ivost 19 years ago
parent
commit
cfc2f77ef1
3 changed files with 174 additions and 6 deletions
  1. 1 0
      .gitattributes
  2. 133 0
      packages/extra/modplug/modplug.pas
  3. 40 6
      packages/extra/openal/examples/madopenal.pas

+ 1 - 0
.gitattributes

@@ -2956,6 +2956,7 @@ packages/extra/md4/Makefile.fpc svneol=native#text/plain
 packages/extra/md4/md4.pas svneol=native#text/plain
 packages/extra/md4/md4.pas svneol=native#text/plain
 packages/extra/modplug/Makefile svneol=native#text/plain
 packages/extra/modplug/Makefile svneol=native#text/plain
 packages/extra/modplug/Makefile.fpc svneol=native#text/plain
 packages/extra/modplug/Makefile.fpc svneol=native#text/plain
+packages/extra/modplug/modplug.pas svneol=native#text/plain
 packages/extra/ncurses/Makefile svneol=native#text/plain
 packages/extra/ncurses/Makefile svneol=native#text/plain
 packages/extra/ncurses/Makefile.fpc svneol=native#text/plain
 packages/extra/ncurses/Makefile.fpc svneol=native#text/plain
 packages/extra/ncurses/db_demo.pp svneol=native#text/plain
 packages/extra/ncurses/db_demo.pp svneol=native#text/plain

+ 133 - 0
packages/extra/modplug/modplug.pas

@@ -0,0 +1,133 @@
+{
+  Translation of the libmodplug headers for FreePascal
+  Copyright (C) 2006 by Ivo Steinmann
+}
+
+(*
+ * This source code is public domain.
+ *
+ * Authors: Kenton Varda <[email protected]> (C interface wrapper)
+ *)
+
+unit modplug;
+
+{$mode objfpc}
+{$MINENUMSIZE 4}
+
+interface
+
+uses
+  ctypes;
+
+{$IFDEF WINDOWS}
+  {$DEFINE DYNLINK}
+{$ENDIF}
+
+//{$DEFINE DYNLINK}
+
+{$IFDEF DYNLINK}
+const
+{$IF Defined(WINDOWS)}
+  modpluglib = 'libmodplug.dll';
+{$ELSEIF Defined(UNIX)}
+  modpluglib = 'libmodplug.so';
+{$ELSE}
+  {$MESSAGE ERROR 'DYNLINK not supported'}
+{$IFEND}
+{$ELSE}
+  //{$LINKLIB stdc++}
+  {$LINKLIB modplug}
+{$ENDIF}
+
+
+type
+  PModPlugFile = ^ModPlugFile;
+  ModPlugFile = record
+  end;
+
+(* Load a mod file.  [data] should point to a block of memory containing the complete
+ * file, and [size] should be the size of that block.
+ * Return the loaded mod file on success, or NULL on failure. *)
+function ModPlug_Load(data: pointer; size: cint): PModPlugFile; cdecl; external {$IFDEF DYNLINK}modpluglib{$ENDIF};
+
+(* Unload a mod file. *)
+procedure ModPlug_Unload(_file: PModPlugFile); cdecl; external {$IFDEF DYNLINK}modpluglib{$ENDIF};
+
+(* Read sample data into the buffer.  Returns the number of bytes read.  If the end
+ * of the mod has been reached, zero is returned. *)
+function ModPlug_Read(_file: PModPlugFile; buffer: pointer; size: cint): cint; cdecl; external {$IFDEF DYNLINK}modpluglib{$ENDIF};
+
+(* Get the name of the mod.  The returned buffer is stored within the ModPlugFile
+ * structure and will remain valid until you unload the file. *)
+function ModPlug_GetName(_file: PModPlugFile): pcchar; cdecl; external {$IFDEF DYNLINK}modpluglib{$ENDIF};
+
+(* Get the length of the mod, in milliseconds.  Note that this result is not always
+ * accurate, especially in the case of mods with loops. *)
+function ModPlug_GetLength(_file: PModPlugFile): cint; cdecl; external {$IFDEF DYNLINK}modpluglib{$ENDIF};
+
+(* Seek to a particular position in the song.  Note that seeking and MODs don't mix very
+ * well.  Some mods will be missing instruments for a short time after a seek, as ModPlug
+ * does not scan the sequence backwards to find out which instruments were supposed to be
+ * playing at that time.  (Doing so would be difficult and not very reliable.)  Also,
+ * note that seeking is not very exact in some mods -- especially those for which
+ * ModPlug_GetLength() does not report the full length. *)
+procedure ModPlug_Seek(_file: PModPlugFile; millisecond: cint); cdecl; external {$IFDEF DYNLINK}modpluglib{$ENDIF};
+
+
+const
+// _ModPlug_Flags
+  MODPLUG_ENABLE_OVERSAMPLING     = 1 shl 0;  (* Enable oversampling (highly recommended) *)
+  MODPLUG_ENABLE_NOISE_REDUCTION  = 1 shl 1;  (* Enable noise reduction *)
+  MODPLUG_ENABLE_REVERB           = 1 shl 2;  (* Enable reverb *)
+  MODPLUG_ENABLE_MEGABASS         = 1 shl 3;  (* Enable megabass *)
+  MODPLUG_ENABLE_SURROUND         = 1 shl 4;  (* Enable surround sound. *)
+
+// _ModPlug_ResamplingMode
+  MODPLUG_RESAMPLE_NEAREST = 0;  (* No interpolation (very fast, extremely bad sound quality) *)
+  MODPLUG_RESAMPLE_LINEAR  = 1;  (* Linear interpolation (fast, good quality) *)
+  MODPLUG_RESAMPLE_SPLINE  = 2;  (* Cubic spline interpolation (high quality) *)
+  MODPLUG_RESAMPLE_FIR     = 3;  (* 8-tap fir filter (extremely high quality) *)
+
+type
+  PModPlug_Settings = ^ModPlug_Settings;
+  ModPlug_Settings = record
+    mFlags          : cint;  (* One or more of the MODPLUG_ENABLE_* flags above, bitwise-OR'ed *)
+
+    (* Note that ModPlug always decodes sound at 44100kHz, 32 bit, stereo and then
+     * down-mixes to the settings you choose. *)
+    mChannels       : cint;  (* Number of channels - 1 for mono or 2 for stereo *)
+    mBits           : cint;  (* Bits per sample - 8, 16, or 32 *)
+    mFrequency      : cint;  (* Sampling rate - 11025, 22050, or 44100 *)
+    mResamplingMode : cint;  (* One of MODPLUG_RESAMPLE_*, above *)
+
+    mReverbDepth    : cint;  (* Reverb level 0(quiet)-100(loud)      *)
+    mReverbDelay    : cint;  (* Reverb delay in ms, usually 40-200ms *)
+    mBassAmount     : cint;  (* XBass level 0(quiet)-100(loud)       *)
+    mBassRange      : cint;  (* XBass cutoff in Hz 10-100            *)
+    mSurroundDepth  : cint;  (* Surround level 0(quiet)-100(heavy)   *)
+    mSurroundDelay  : cint;  (* Surround delay in ms, usually 5-40ms *)
+    mLoopCount      : cint;  (* Number of times to loop.  Zero prevents looping. -1 loops forever. *)
+  end;
+
+(* Get and set the mod decoder settings.  All options, except for channels, bits-per-sample,
+ * sampling rate, and loop count, will take effect immediately.  Those options which don't
+ * take effect immediately will take effect the next time you load a mod. *)
+procedure ModPlug_GetSettings(settings: PModPlug_Settings); cdecl; external {$IFDEF DYNLINK}modpluglib{$ENDIF};
+procedure ModPlug_SetSettings(const settings: PModPlug_Settings); cdecl; external {$IFDEF DYNLINK}modpluglib{$ENDIF};
+
+
+// libc functions
+function _new(s: cuint): pointer; cdecl;
+procedure _delete(p: pointer); cdecl;
+
+implementation
+
+function _new(s: cuint): pointer; cdecl;
+begin
+end;
+
+procedure _delete(p: pointer); cdecl;
+begin
+end;
+
+end.

+ 40 - 6
packages/extra/openal/examples/madopenal.pas

@@ -79,19 +79,19 @@ end;
 
 
 // oggvorbis
 // oggvorbis
 var
 var
-  ogg_vorbis    : OggVorbis_File;
+  ogg_file      : OggVorbis_File;
   ogg_callbacks : ov_callbacks;
   ogg_callbacks : ov_callbacks;
 
 
 {procedure ogg_reset;
 {procedure ogg_reset;
 begin
 begin
-  ov_pcm_seek(ogg_vorbis, 0);
+  ov_pcm_seek(ogg_file, 0);
 end;}
 end;}
 
 
 function ogg_read(const Buffer: Pointer; const Count: Longword): Longword;
 function ogg_read(const Buffer: Pointer; const Count: Longword): Longword;
 var
 var
   Res: clong;
   Res: clong;
 begin
 begin
-  Res := ov_read_ext(ogg_vorbis, Buffer, Count, false, 2, true);
+  Res := ov_read_ext(ogg_file, Buffer, Count, false, 2, true);
   if Res < 0 then
   if Res < 0 then
     Result := 0 else
     Result := 0 else
     Result := Res;
     Result := Res;
@@ -128,6 +128,21 @@ begin
 end;
 end;
 
 
 
 
+// modplug
+var
+  mod_file: PModPlugFile;
+
+function mod_read(const Buffer: Pointer; const Count: Longword): Longword;
+var
+  Res: cint;
+begin
+  Res := ModPlug_Read(mod_file, Buffer, Count);
+  if Res < 0 then
+    Result := 0 else
+    Result := Res;
+end;
+
+
 // openal
 // openal
 const
 const
   al_format  : array[1..2] of ALenum = (AL_FORMAT_MONO16, AL_FORMAT_STEREO16);
   al_format  : array[1..2] of ALenum = (AL_FORMAT_MONO16, AL_FORMAT_STEREO16);
@@ -203,6 +218,7 @@ end;
 var
 var
   Filename: String;
   Filename: String;
   ov: pvorbis_info;
   ov: pvorbis_info;
+  tmp: pointer;
 begin
 begin
 // define codec
 // define codec
  { WriteLn('Define codec');
  { WriteLn('Define codec');
@@ -239,9 +255,9 @@ begin
         ogg_callbacks.close := @source_close_func;
         ogg_callbacks.close := @source_close_func;
         ogg_callbacks.tell  := @source_tell_func;
         ogg_callbacks.tell  := @source_tell_func;
 
 
-        if ov_open_callbacks(source, ogg_vorbis, nil, 0, ogg_callbacks) >= 0 then
+        if ov_open_callbacks(source, ogg_file, nil, 0, ogg_callbacks) >= 0 then
         begin
         begin
-          ov := ov_info(ogg_vorbis, -1);
+          ov := ov_info(ogg_file, -1);
           codec_read := @ogg_read;
           codec_read := @ogg_read;
           codec_rate := ov^.rate;
           codec_rate := ov^.rate;
           codec_chan := ov^.channels;
           codec_chan := ov^.channels;
@@ -266,6 +282,19 @@ begin
         codec_chan := 2;
         codec_chan := 2;
         codec_bs   := 2*codec_chan;
         codec_bs   := 2*codec_chan;
       end;
       end;
+
+    5: // modplug
+      begin
+        GetMem(tmp, source.Size);
+        source.Read(tmp^, source.Size);
+        mod_file := ModPlug_Load(tmp, source.Size);
+        FreeMem(tmp);
+
+        codec_read := @mod_read;
+        codec_rate := 44100;//48000;
+        codec_chan := 2;
+        codec_bs   := 2*codec_chan;
+      end;
   end;
   end;
 
 
   if not Assigned(codec_read) then
   if not Assigned(codec_read) then
@@ -316,7 +345,7 @@ begin
 
 
     2: // oggvorbis
     2: // oggvorbis
       begin
       begin
-        ov_clear(ogg_vorbis);
+        ov_clear(ogg_file);
       end;
       end;
 
 
     3: // a52
     3: // a52
@@ -328,6 +357,11 @@ begin
       begin
       begin
         dts_decoder_free(dts_decoder);
         dts_decoder_free(dts_decoder);
       end;
       end;
+
+    5: // modplug
+      begin
+        ModPlug_Unload(mod_file);
+      end;
   end;
   end;