Recent

Author Topic: Sidmon Player Library  (Read 468 times)

Gigatron

  • Sr. Member
  • ****
  • Posts: 369
  • Amiga Rulez !!
    • Gigatron Shader Network Demo
Sidmon Player Library
« on: January 25, 2026, 01:15:42 am »
It's Late here :) and i am tired.

Let's add more than near 180 modules to our modules players ;

This time is Sidmon Amiga player ; Based on FLOD 4.1 by :
2012/04/30
   Christian Corti
   Neoart Costa Rica

   E-Mail: flod@neoartcr.com

C conversion by RoFlor ; Sources are exctracted and compiled with Mingw64;

Sidmon player by Michael Kleps (Unknown/DOC in 1990

Sidmon 1 & 2 ; https://ftp.modland.com/pub/modules/SidMon%201/
                       https://ftp.modland.com/pub/modules/SidMon%202/

This version is not working well V0.9 Beta ; after song finished crash occured ... (must see what's wrong) i think buffer is empty so nothing to play..
So don't run compiled Executable...  Stop the program from Lazarus Editor;

Regards

Main Unit;
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls,
  9.   sidmon_lib, mmsystem, windows;
  10.  
  11. const
  12.   Channels      = 2;
  13.   BitsPerSample = 16;
  14.   SampleRate    = 44100;              // Nombre d'échantillons par seconde
  15.   BufSize       = 8192-1024-1024;    // To do .. Alien Buffer !!!
  16.   BufferCount   = 4;
  17.  
  18. type
  19.   { TForm1 }
  20.  
  21.   TForm1 = class(TForm)
  22.     Label1: TLabel;
  23.  
  24.     procedure FormCreate(Sender: TObject);
  25.     procedure FormDestroy(Sender: TObject);
  26.     procedure FormShow(Sender: TObject);
  27.  
  28.   private
  29.     buffers: array[0..BufferCount-1] of array[0..BufSize-1] of  Byte;
  30.     waveHeaders: array[0..BufferCount-1] of TWaveHdr;
  31.     currentBuffer: Integer;
  32.     currentSong: Integer;
  33.     maxSongs: Integer;
  34.   public
  35.   end;
  36.  
  37. var
  38.   Form1: TForm1;
  39.   waveOut: HWAVEOUT;
  40.   FDecoder: Pointer; // sidmon decoder !
  41.   ok_flag: Boolean = false;
  42.  
  43. implementation
  44.  
  45. {$R *.lfm}
  46.  
  47. procedure FillBuffer(bufferIndex: Integer);
  48. begin
  49.   if ok_flag and (FDecoder <> nil) then
  50.   begin
  51.  
  52.     sidmon_decoder_fillBuffer(FDecoder, @Form1.Buffers[bufferIndex][0], BufSize);
  53.  
  54.   end;
  55. end;
  56.  
  57. function WaveOutCallback(hwo: HWAVEOUT; uMsg: UINT; dwInstance, dwParam1, dwParam2: DWORD_PTR): DWORD; stdcall;
  58. begin
  59.   if uMsg = WOM_DONE then
  60.   begin
  61.     FillBuffer(Form1.currentBuffer);
  62.     waveOutWrite(waveOut, @Form1.waveHeaders[Form1.currentBuffer], SizeOf(TWaveHdr));
  63.     Form1.currentBuffer := (Form1.currentBuffer + 1) mod BufferCount;
  64.   end;
  65.   Result := 0;
  66. end;
  67.  
  68. procedure InitAudio;
  69. var
  70.   wFormat: TWaveFormatEx;
  71.   i: Integer;
  72. begin
  73.  // SetThreadPriority(GetCurrentThread, THREAD_PRIORITY_HIGHEST);  // if needed
  74.  
  75.   with wFormat do
  76.   begin
  77.    wFormatTag := 1; // PcM
  78.    nChannels := 2; // stereo 2
  79.    nSamplesPerSec := 44100; // 44100
  80.    wBitsPerSample := 16; // 16 bits
  81.    nBlockAlign := nChannels * (wBitsPerSample div 8); // Taille echantillon
  82.    nAvgBytesPerSec := nSamplesPerSec * nBlockAlign;
  83.    cbSize := 0;
  84.   end;
  85.  
  86.   if waveOutOpen(@waveOut, WAVE_MAPPER, @wFormat, QWORD(@WaveOutCallback), 0, CALLBACK_FUNCTION) <> MMSYSERR_NOERROR then
  87.    ShowMessage('Error: Audio initialization failed');
  88.  
  89.   // buffers
  90.   for i := 0 to BufferCount - 1 do
  91.   begin
  92.     ZeroMemory(@Form1.waveHeaders[i], SizeOf(TWaveHdr));
  93.      with Form1.waveHeaders[i] do
  94.     begin
  95.       lpData := @Form1.buffers[i][0];
  96.       dwBufferLength := BufSize *   SizeOf(Byte);
  97.       dwFlags := 0 ;
  98.     end;
  99.      waveOutPrepareHeader(waveOut, @Form1.waveHeaders[i], SizeOf(TWaveHdr));
  100.   end;
  101.      Form1.currentBuffer := 0;
  102.     for i := 0 to BufferCount - 1 do
  103.      begin
  104.      FillBuffer(i);
  105.      waveOutWrite(waveOut, @Form1.waveHeaders[i], SizeOf(TWaveHdr));
  106.     end;
  107. end;
  108.  
  109. procedure TForm1.FormCreate(Sender: TObject);
  110. var
  111.   Buffer: TBytes;
  112.   FileName: string;
  113.   formatName: integer;
  114. begin
  115.  
  116.   ok_flag := False;
  117.   waveOut := 0;
  118.   currentSong := 0;
  119.   maxSongs := 1;
  120.  
  121.    FDecoder := sidmon_decoder_new;
  122.  
  123.    FileName := 'fusion.sid2';
  124.  
  125.  
  126.     // Chargement du fichier
  127.     with TMemoryStream.Create do
  128.     try
  129.       LoadFromFile(FileName);
  130.       SetLength(Buffer, Size);
  131.       Position := 0;
  132.       ReadBuffer(Buffer[0], Size);
  133.     finally
  134.       Free;
  135.     end;
  136.  
  137.      formatName := sidmon_decoder_detect(FDecoder, @Buffer[0], Length(Buffer));
  138.     if formatName = 0 then
  139.     begin
  140.       ShowMessage('Format SidMon non reconnu');
  141.       Exit;
  142.     end;
  143.  
  144.     // Initialiser le décodeur
  145.     if not sidmon_decoder_init(FDecoder, @Buffer[0], Length(Buffer)) then
  146.     begin
  147.       ShowMessage('Erreur d''initialisation');
  148.       Exit;
  149.     end;
  150. end;
  151.  
  152. procedure TForm1.FormShow(Sender: TObject);
  153. var s_duration : integer;
  154. begin
  155.      InitAudio;
  156.      ok_flag := true;
  157.  
  158.      Label1.Caption:= 'Default Duration :' +IntToStr(sidmon_decoder_getDuration(Fdecoder) div 1000) + ' sec ' ;
  159. end;
  160.  
  161. procedure TForm1.FormDestroy(Sender: TObject);
  162. begin
  163.   ok_flag := False;
  164.  
  165.   if waveOut <> 0 then
  166.   begin
  167.     waveOutReset(waveOut);
  168.     waveOutClose(waveOut);
  169.   end;
  170.  
  171.   if FDecoder <> nil then
  172.     sidmon_decoder_delete(FDecoder);
  173. end;
  174.  
  175. end.
  176.  

Sidmon_lib;
Code: Pascal  [Select][+][-]
  1. unit sidmon_lib;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. const
  8.   SIDMON_DLL = 'SidMon.dll';
  9.  
  10. type
  11.   SmonDecoder = Pointer;
  12.  
  13. // ============================================================================
  14. // Fonctions de la DLL SidMon
  15.  
  16. function  sidmon_decoder_new: SmonDecoder; cdecl; external SIDMON_DLL;
  17. procedure sidmon_decoder_delete(decoder: SmonDecoder); cdecl; external SIDMON_DLL;
  18.  
  19. //   format (retourne 0=inconnu, 1=SidMon1, 2=SidMon2)
  20. function  sidmon_decoder_detect(decoder: SmonDecoder; buffer: Pointer; bufferLen: Cardinal): Integer; cdecl; external SIDMON_DLL;
  21.  
  22. // Init decoder
  23. function  sidmon_decoder_init(decoder: SmonDecoder; buffer: Pointer; bufferLen: Cardinal): Boolean; cdecl; external SIDMON_DLL;
  24.  
  25. // fill buff
  26. function  sidmon_decoder_fillBuffer(decoder: SmonDecoder; buffer: Pointer; bufferSize: Cardinal): Cardinal; cdecl; external SIDMON_DLL;
  27.  
  28. // Infos
  29. function  sidmon_decoder_getSongs(decoder: SmonDecoder): Integer; cdecl; external SIDMON_DLL;
  30. function  sidmon_decoder_getDuration(decoder: SmonDecoder): Cardinal; cdecl; external SIDMON_DLL;
  31. function  sidmon_decoder_getFormat(decoder: SmonDecoder): Integer; cdecl; external SIDMON_DLL;
  32.  
  33. implementation
  34.  
  35. end.  

« Last Edit: January 25, 2026, 09:19:19 pm by Gigatron »
Coding faster than Light !

Gigatron

  • Sr. Member
  • ****
  • Posts: 369
  • Amiga Rulez !!
    • Gigatron Shader Network Demo
Re: Sidmon Player Library
« Reply #1 on: January 26, 2026, 03:25:03 pm »
Hi

This is an improved version of SidmonPlayer Library;

Don't know if it's 100% working or perfect accurate rendering ; Added some
options like Song Loop & Pause & Resume.

Demo song from Mel'o'dee ; https://www.youtube.com/watch?v=vyQT2pupGaQ

Have fun ; the next player are Delta music 2
 D.Whittaker



« Last Edit: January 26, 2026, 04:52:46 pm by Gigatron »
Coding faster than Light !

Gigatron

  • Sr. Member
  • ****
  • Posts: 369
  • Amiga Rulez !!
    • Gigatron Shader Network Demo
Re: Sidmon Player Library
« Reply #2 on: February 07, 2026, 02:56:58 pm »
Hi

Sidmon Player .dll was reduced to 88 kb and improved again.
This is the latest version worked like a charm :)

Have Fun

Gigatron
Coding faster than Light !

 

TinyPortal © 2005-2018