DEADSOFTWARE

changed license to GPLv3 only; sorry, no trust to FSF anymore
[d2df-sdl.git] / src / engine / e_soundfile_xmp.pas
index aaf1df194d3b1904f25ff6993d6e5beab46d503f..b4c406ce139d3ade999c6697c5b0aa4c55ceba27 100644 (file)
@@ -2,8 +2,7 @@
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
+ * the Free Software Foundation, version 3 of the License ONLY.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -37,6 +36,7 @@ type
   end;
 
   TXMPLoaderFactory = class (TSoundLoaderFactory)
+  public
     function MatchHeader(Data: Pointer; Len: LongWord): Boolean; override;
     function MatchExtension(FName: string): Boolean; override;
     function GetLoader(): TSoundLoader; override;
@@ -88,6 +88,7 @@ end;
 function TXMPLoader.Load(Data: Pointer; Len: LongWord; SStreaming: Boolean): Boolean;
 var
   Err: LongInt;
+  Interp: LongInt;
 begin
   Result := False;
 
@@ -100,10 +101,14 @@ begin
     if Err <> 0 then
       raise Exception.Create('xmp_load_module_from_memory failed');
 
-    if xmp_start_player(FXMP, e_SoundFormat.SampleRate, 0) <> 0 then
+    if xmp_start_player(FXMP, 48000, 0) <> 0 then
       raise Exception.Create('xmp_start_player failed');
 
-    FFormat.SampleRate := e_SoundFormat.SampleRate;
+    if e_MusicLerp then Interp := XMP_INTERP_LINEAR
+    else Interp := XMP_INTERP_NEAREST;
+    xmp_set_player(FXMP, XMP_PLAYER_INTERP, Interp);
+
+    FFormat.SampleRate := 48000;
     FFormat.SampleBits := 16;
     FFormat.Channels := 2;
 
@@ -124,6 +129,7 @@ end;
 function TXMPLoader.Load(FName: string; SStreaming: Boolean): Boolean;
 var
   Err: LongInt;
+  Interp: LongInt;
 begin
   Result := False;
 
@@ -136,10 +142,14 @@ begin
     if Err <> 0 then
       raise Exception.Create('xmp_load_module failed');
 
-    if xmp_start_player(FXMP, e_SoundFormat.SampleRate, 0) <> 0 then
+    if xmp_start_player(FXMP, 48000, 0) <> 0 then
       raise Exception.Create('xmp_start_player failed');
 
-    FFormat.SampleRate := e_SoundFormat.SampleRate;
+    if e_MusicLerp then Interp := XMP_INTERP_LINEAR
+    else Interp := XMP_INTERP_NEAREST;
+    xmp_set_player(FXMP, XMP_PLAYER_INTERP, Interp);
+
+    FFormat.SampleRate := 48000;
     FFormat.SampleBits := 16;
     FFormat.Channels := 2;
 
@@ -165,10 +175,16 @@ begin
 end;
 
 function TXMPLoader.FillBuffer(Buf: Pointer; Len: LongWord): LongWord;
+var
+  LoopN: LongInt;
 begin
   Result := 0;
   if FXMP = nil then Exit;
-  if xmp_play_buffer(FXMP, Buf, Len, 0) = 0 then
+  if FLooping then
+    LoopN := 0
+  else
+    LoopN := 1;
+  if xmp_play_buffer(FXMP, Buf, Len, LoopN) = 0 then
     Result := Len;
 end;