From e61016c071c07d917f69c3b667454286a456f4b3 Mon Sep 17 00:00:00 2001 From: fredvs Date: Sat, 30 Nov 2024 22:32:56 +0100 Subject: [PATCH] Thanks to GuvaCode, added length and seek for xmp files (mod, xm, ...), --- examples/uos.pas | 14 +++++++++----- examples/uos_libxmp.pas | 5 +++++ src/uos.pas | 14 +++++++++----- src/uos_libxmp.pas | 5 +++++ 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/examples/uos.pas b/examples/uos.pas index 20c817a..649411c 100644 --- a/examples/uos.pas +++ b/examples/uos.pas @@ -82,7 +82,7 @@ interface Classes, DynLibs, ctypes, Math, sysutils; const - uos_version : cint32 = 2241012; + uos_version : cint32 = 2241130; {$IF DEFINED (bs2b)} BS2B_HIGH_CLEVEL = (CInt32 (700)) or ( (CInt32 (30)) shl 16); @@ -8410,6 +8410,7 @@ function Tuos_Player.AddFromFile (Filename: PChar; OutputIndex: cint32; {$IF DEFINED (xmp)} mi: xmp_module_info; + fi: xmp_frame_info; {$endif} {$IF DEFINED (mpg123)} @@ -8559,7 +8560,7 @@ function Tuos_Player.AddFromFile (Filename: PChar; OutputIndex: cint32; {$endif} xmp_start_player (StreamIn[x].Data.HandleSt, 44100, 0); xmp_get_module_info (StreamIn[x].Data.HandleSt, mi); - // xmp_get_frame_info (StreamIn[x].Data.HandleSt , fi); + xmp_get_frame_info (StreamIn[x].Data.HandleSt , fi); StreamIn[x].Data.LibOpen := 5; StreamIn[x].Data.filename := FileName; @@ -8602,9 +8603,9 @@ function Tuos_Player.AddFromFile (Filename: PChar; OutputIndex: cint32; StreamIn[x].Data.track := ''; StreamIn[x].Data.genre := ''; StreamIn[x].Data.album := ''; - - StreamIn[x].Data.Length := 0; - + + StreamIn[x].Data.Length := round(fi.total_time * StreamIn[x].Data.samplerate / 1000); + err := 0; {$IF DEFINED (uos_debug) and DEFINED (unix)} WriteLn ('XMP_open END OK'); @@ -9423,6 +9424,9 @@ procedure Tuos_Player.DoSeek ( x : integer); {$IF DEFINED (opus)} 4 : op_pcm_seek (StreamIn[x].Data.HandleOP, StreamIn[x].Data.Poseek); {$endif} + {$IF DEFINED (xmp)} + 5 : xmp_seek_time(StreamIn[x].Data.HandleSt,round(StreamIn[x].Data.Poseek / (StreamIn[x].Data.samplerate / 1000))); + {$endif} end; end; diff --git a/examples/uos_libxmp.pas b/examples/uos_libxmp.pas index 9754bab..a91b167 100644 --- a/examples/uos_libxmp.pas +++ b/examples/uos_libxmp.pas @@ -317,6 +317,8 @@ xmp_callbacks = record xmp_restart_module: procedure(ctx: xmp_context); cdecl; xmp_channel_vol: function(ctx: xmp_context; channel: Integer; volume: Integer): Integer; cdecl; xmp_set_player: function(ctx: xmp_context; param: Integer; value: Integer): Integer; cdecl; + xmp_set_position: function(ctx: xmp_context; pos: Integer): Integer; cdecl; + xmp_seek_time: function(ctx: xmp_context; time: Integer): Integer; cdecl; // Not used yet... //function xmp_test_module_from_memory(const data: Pointer; size: LongInt; info: xmp_test_info): Integer; cdecl; external 'xmp'; @@ -397,6 +399,9 @@ function xmp_IsLoaded: boolean; Pointer(xmp_restart_module):=DynLibs.GetProcedureAddress(xmp_Handle,PChar('xmp_restart_module')); Pointer(xmp_channel_vol):=DynLibs.GetProcedureAddress(xmp_Handle,PChar('xmp_channel_vol')); Pointer(xmp_set_player):=DynLibs.GetProcedureAddress(xmp_Handle,PChar('xmp_set_player')); +Pointer(xmp_set_position):=DynLibs.GetProcedureAddress(xmp_Handle,PChar('xmp_set_position')); +Pointer(xmp_seek_time):=DynLibs.GetProcedureAddress(xmp_Handle,PChar('xmp_seek_time')); + end; Result := xmp_IsLoaded; ReferenceCounter:=1; diff --git a/src/uos.pas b/src/uos.pas index 20c817a..649411c 100644 --- a/src/uos.pas +++ b/src/uos.pas @@ -82,7 +82,7 @@ interface Classes, DynLibs, ctypes, Math, sysutils; const - uos_version : cint32 = 2241012; + uos_version : cint32 = 2241130; {$IF DEFINED (bs2b)} BS2B_HIGH_CLEVEL = (CInt32 (700)) or ( (CInt32 (30)) shl 16); @@ -8410,6 +8410,7 @@ function Tuos_Player.AddFromFile (Filename: PChar; OutputIndex: cint32; {$IF DEFINED (xmp)} mi: xmp_module_info; + fi: xmp_frame_info; {$endif} {$IF DEFINED (mpg123)} @@ -8559,7 +8560,7 @@ function Tuos_Player.AddFromFile (Filename: PChar; OutputIndex: cint32; {$endif} xmp_start_player (StreamIn[x].Data.HandleSt, 44100, 0); xmp_get_module_info (StreamIn[x].Data.HandleSt, mi); - // xmp_get_frame_info (StreamIn[x].Data.HandleSt , fi); + xmp_get_frame_info (StreamIn[x].Data.HandleSt , fi); StreamIn[x].Data.LibOpen := 5; StreamIn[x].Data.filename := FileName; @@ -8602,9 +8603,9 @@ function Tuos_Player.AddFromFile (Filename: PChar; OutputIndex: cint32; StreamIn[x].Data.track := ''; StreamIn[x].Data.genre := ''; StreamIn[x].Data.album := ''; - - StreamIn[x].Data.Length := 0; - + + StreamIn[x].Data.Length := round(fi.total_time * StreamIn[x].Data.samplerate / 1000); + err := 0; {$IF DEFINED (uos_debug) and DEFINED (unix)} WriteLn ('XMP_open END OK'); @@ -9423,6 +9424,9 @@ procedure Tuos_Player.DoSeek ( x : integer); {$IF DEFINED (opus)} 4 : op_pcm_seek (StreamIn[x].Data.HandleOP, StreamIn[x].Data.Poseek); {$endif} + {$IF DEFINED (xmp)} + 5 : xmp_seek_time(StreamIn[x].Data.HandleSt,round(StreamIn[x].Data.Poseek / (StreamIn[x].Data.samplerate / 1000))); + {$endif} end; end; diff --git a/src/uos_libxmp.pas b/src/uos_libxmp.pas index 9754bab..a91b167 100644 --- a/src/uos_libxmp.pas +++ b/src/uos_libxmp.pas @@ -317,6 +317,8 @@ xmp_callbacks = record xmp_restart_module: procedure(ctx: xmp_context); cdecl; xmp_channel_vol: function(ctx: xmp_context; channel: Integer; volume: Integer): Integer; cdecl; xmp_set_player: function(ctx: xmp_context; param: Integer; value: Integer): Integer; cdecl; + xmp_set_position: function(ctx: xmp_context; pos: Integer): Integer; cdecl; + xmp_seek_time: function(ctx: xmp_context; time: Integer): Integer; cdecl; // Not used yet... //function xmp_test_module_from_memory(const data: Pointer; size: LongInt; info: xmp_test_info): Integer; cdecl; external 'xmp'; @@ -397,6 +399,9 @@ function xmp_IsLoaded: boolean; Pointer(xmp_restart_module):=DynLibs.GetProcedureAddress(xmp_Handle,PChar('xmp_restart_module')); Pointer(xmp_channel_vol):=DynLibs.GetProcedureAddress(xmp_Handle,PChar('xmp_channel_vol')); Pointer(xmp_set_player):=DynLibs.GetProcedureAddress(xmp_Handle,PChar('xmp_set_player')); +Pointer(xmp_set_position):=DynLibs.GetProcedureAddress(xmp_Handle,PChar('xmp_set_position')); +Pointer(xmp_seek_time):=DynLibs.GetProcedureAddress(xmp_Handle,PChar('xmp_seek_time')); + end; Result := xmp_IsLoaded; ReferenceCounter:=1;