From 1091a54dd9996ee2bc7620dfed900d64d066af88 Mon Sep 17 00:00:00 2001 From: fgsfds Date: Sun, 1 Sep 2019 03:01:27 +0300 Subject: [PATCH] Sound: OpenAL: Streams can now be non-looping; XMP tweaks --- src/engine/e_sound_al.inc | 2 ++ src/engine/e_soundfile.pas | 2 ++ src/engine/e_soundfile_xmp.pas | 16 +++++++++++----- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/engine/e_sound_al.inc b/src/engine/e_sound_al.inc index dfe5919..312b701 100644 --- a/src/engine/e_sound_al.inc +++ b/src/engine/e_sound_al.inc @@ -329,6 +329,7 @@ begin end else begin + Loader.Looping := e_SoundsArray[find_id].Loops; e_SoundsArray[find_id].alBuffer := 0; e_SoundsArray[find_id].Loader := Loader; end; @@ -402,6 +403,7 @@ begin end else begin + Loader.Looping := e_SoundsArray[find_id].Loops; e_SoundsArray[find_id].alBuffer := 0; e_SoundsArray[find_id].Loader := Loader; end; diff --git a/src/engine/e_soundfile.pas b/src/engine/e_soundfile.pas index 919715c..6cae52c 100644 --- a/src/engine/e_soundfile.pas +++ b/src/engine/e_soundfile.pas @@ -34,6 +34,7 @@ type protected FFormat: TSoundFormat; FStreaming: Boolean; + FLooping: Boolean; public function Load(Data: Pointer; Len: LongWord; SStreaming: Boolean): Boolean; virtual; abstract; overload; @@ -48,6 +49,7 @@ type property Format: TSoundFormat read FFormat; property Streaming: Boolean read FStreaming; + property Looping: Boolean read FLooping write FLooping; end; TSoundLoaderFactory = class diff --git a/src/engine/e_soundfile_xmp.pas b/src/engine/e_soundfile_xmp.pas index aaf1df1..33c902f 100644 --- a/src/engine/e_soundfile_xmp.pas +++ b/src/engine/e_soundfile_xmp.pas @@ -100,10 +100,10 @@ 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; + FFormat.SampleRate := 48000; FFormat.SampleBits := 16; FFormat.Channels := 2; @@ -136,10 +136,10 @@ 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; + FFormat.SampleRate := 48000; FFormat.SampleBits := 16; FFormat.Channels := 2; @@ -165,10 +165,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; -- 2.29.2