Skip to content

Commit

Permalink
Thanks to GuvaCode, added length and seek for xmp files (mod, xm, ...),
Browse files Browse the repository at this point in the history
  • Loading branch information
fredvs committed Nov 30, 2024
1 parent f656b56 commit e61016c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
14 changes: 9 additions & 5 deletions examples/uos.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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;

Expand Down
5 changes: 5 additions & 0 deletions examples/uos_libxmp.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down
14 changes: 9 additions & 5 deletions src/uos.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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;

Expand Down
5 changes: 5 additions & 0 deletions src/uos_libxmp.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit e61016c

Please sign in to comment.