DEADSOFTWARE

implement SDL1.2 system driver
[d2df-sdl.git] / src / engine / e_soundfile_wav.pas
index b5b838d4ba224da50e1301ec8db02cfedea0a6e2..ba7bcdf67057a5d65f6e057b6ab4c755838f3b01 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;
 
   TWAVLoaderFactory = class (TSoundLoaderFactory)
+  public
     function MatchHeader(Data: Pointer; Len: LongWord): Boolean; override;
     function MatchExtension(FName: string): Boolean; override;
     function GetLoader(): TSoundLoader; override;
@@ -44,7 +44,13 @@ type
 
 implementation
 
-uses sdl2, utils, e_log;
+uses
+  {$IFDEF USE_SDL}
+    SDL,
+  {$ELSE}
+    SDL2,
+  {$ENDIF}
+  utils, e_log;
 
 (* TWAVLoaderFactory *)
 
@@ -73,7 +79,6 @@ begin
 end;
 
 (* TWAVLoader *)
-
 function TWAVLoader.Load(Data: Pointer; Len: LongWord; SStreaming: Boolean): Boolean;
 var
   Spec: TSDL_AudioSpec;
@@ -85,14 +90,22 @@ begin
 
   RW := SDL_RWFromConstMem(Data, Len);
 
+{$IFDEF USE_SDL2}
   if SDL_LoadWAV_RW(RW, 0, @Spec, @TmpBuf, @TmpLen) = nil then
+{$ELSE}
+  if SDL_LoadWAV_RW(RW, 0, @Spec, PUInt8(@TmpBuf), @TmpLen) = nil then
+{$ENDIF}
   begin
     e_LogWriteln('Could not load WAV: ' + SDL_GetError());
   end
   else
   begin
     FFormat.SampleRate := Spec.freq;
-    FFormat.SampleBits := SDL_AUDIO_BITSIZE(Spec.format);
+    {$IFDEF USE_SDL2}
+      FFormat.SampleBits := SDL_AUDIO_BITSIZE(Spec.format);
+    {$ELSE}
+      FFormat.SampleBits := Spec.format and $FF;
+    {$ENDIF}
     FFormat.Channels := Spec.channels;
     FStreaming := False; // never stream wavs
     FDataLen := TmpLen;
@@ -120,14 +133,22 @@ begin
     exit;
   end;
 
+{$IFDEF USE_SDL2}
   if SDL_LoadWAV_RW(RW, 0, @Spec, @TmpBuf, @TmpLen) = nil then
+{$ELSE}
+  if SDL_LoadWAV_RW(RW, 0, @Spec, PUInt8(@TmpBuf), @TmpLen) = nil then
+{$ENDIF}
   begin
     e_LogWritefln('Could not load WAV file `%s`: %s', [FName, SDL_GetError()]);
   end
   else
   begin
     FFormat.SampleRate := Spec.freq;
-    FFormat.SampleBits := SDL_AUDIO_BITSIZE(Spec.format);
+    {$IFDEF USE_SDL2}
+      FFormat.SampleBits := SDL_AUDIO_BITSIZE(Spec.format);
+    {$ELSE}
+      FFormat.SampleBits := Spec.format and $FF;
+    {$ENDIF}
     FFormat.Channels := Spec.channels;
     FStreaming := False; // never stream wavs
     FDataLen := TmpLen;