Forum > Audio and Video

YM Player

(1/1)

Gigatron:
Hi,
I am working on the st Sound ym player; ym mean a module format from Arnaud Carré alias Leonard Oxygen
http://leonard.oxg.free.fr/

Here is the beta stage on this nice player; the compiler option is set to OS to Win32 and CPU I386;
The library YM2149SSND.dll is for 32bit not for X64 .. not working when compiling for X64 on visual studio ;

I certainly made mistakes in the code, but it's a beta version and the modules works :)
ftp modland ym database : https://modland.com/pub/modules/YM/

All units and module (tcb.ym) and library are here :)

main unit :

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit Unit1; {$mode objfpc}{$H+}//{$PACKRECORDS C} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, windows,  mmsystem, ym_player ; const  REPLAY_RATE = 44100;  Channels = 1;  ym_File = 'tcb.ym';  REPLAY_DEPTH  = 16;  REPLAY_SAMPLELEN = REPLAY_DEPTH div 8;  SampleRate = 44100; // number of samples per second  BufSize = 65536*2 ; //   multiple of 2  BufferCount = 4;  type TYM_MusicInfo = record    pSongName: PAnsiChar;    pSongAuthor: PAnsiChar;    pSongComment: PAnsiChar;    pSongType: PAnsiChar;    pSongPlayer: PAnsiChar;    musicTimeInSec: Integer;    musicTimeInMs: Integer;  end;   { TForm1 }   TForm1 = class(TForm)    Timer1: TTimer;    procedure FormCreate(Sender: TObject);     procedure Timer1Timer(Sender: TObject);  private     buffers: array[0..BufferCount-1] of array[0..BufSize-1] of SmallInt;     waveHeaders: array[0..BufferCount-1] of TWaveHdr;     currentBuffer: Integer;  publicend; var  Form1: TForm1;  waveOut: HWAVEOUT;  waveHeader: TWaveHdr;  ym_pmus: PYM_Music ;  ym_mus : string;  ok_flag : boolean = true; implementation {$R *.lfm} /// audio init et le reste !!procedure HandleError(const Str: PAnsiChar);begin  if Str <> nil then  begin    ShowMessage('Error: Wrong Format ? '+ Str);    Halt(1);  end;end; procedure FillBuffer(bufferIndex: Integer);begin     YM_ComputePCM(ym_pmus, @Form1.buffers[bufferIndex][0], BufSize  );     if Form1.buffers[bufferIndex][0] = 0 then  begin    ShowMessage('Attention : le buffer est vide');  end;  Form1.waveHeaders[bufferIndex].dwFlags := Form1.waveHeaders[bufferIndex].dwFlags and (not WHDR_DONE); end; function WaveOutCallback(hwo: HWAVEOUT; uMsg: UINT; dwInstance, dwParam1, dwParam2: DWORD_PTR): DWORD; stdcall;begin  if uMsg = WOM_DONE then  begin     FillBuffer(Form1.currentBuffer);    waveOutWrite(waveOut, @Form1.waveHeaders[Form1.currentBuffer], SizeOf(TWaveHdr));    Form1.currentBuffer := (Form1.currentBuffer + 1) mod BufferCount;  end;   Result := 0;end; procedure InitAudio;var  wFormat: TWaveFormatEx;  i: Integer;begin  SetThreadPriority(GetCurrentThread, THREAD_PRIORITY_LOWEST);   with wFormat do  begin    wFormatTag := WAVE_FORMAT_PCM; // 1   nChannels := 1; // Mono   nSamplesPerSec := REPLAY_RATE; // 44100   wBitsPerSample := REPLAY_DEPTH; // 16 bits   nBlockAlign := nChannels * (wBitsPerSample div 8); // Taille echantillon   nAvgBytesPerSec := nSamplesPerSec * nBlockAlign;   cbSize := 0;  end;   if waveOutOpen(@waveOut, WAVE_MAPPER, @wFormat, QWORD(@WaveOutCallback), 0, CALLBACK_FUNCTION) <> MMSYSERR_NOERROR then   ShowMessage('Error: Audio initialization failed');   // buffers  for i := 0 to BufferCount - 1 do  begin    ZeroMemory(@Form1.waveHeaders[i], SizeOf(TWaveHdr));     with Form1.waveHeaders[i] do    begin      lpData := @Form1.buffers[i][0];      dwBufferLength := BufSize * SizeOf(SmallInt);      dwFlags := 0 ;    end;     waveOutPrepareHeader(waveOut, @Form1.waveHeaders[i], SizeOf(TWaveHdr));  end;    Form1.currentBuffer := 0;end; { TForm1 } procedure TForm1.FormCreate(Sender: TObject);  begin    ym_mus :='tcb.ym';    InitAudio;    ym_pmus := YM_Init;    if ym_pmus = nil then    ShowMessage('YM_Init failed');    YM_LoadFile(ym_pmus, Pchar(ym_mus));    if not YM_LoadFile(ym_pmus, Pchar(ym_mus)) then   begin     ShowMessage('YM file not Loaded');     HandleError(YM_GetLastError(ym_pmus));     Exit;   end;    FillBuffer(0);   waveOutWrite(waveOut, @waveHeaders[0], SizeOf(TWaveHdr));   YM_Play(ym_pmus);   // on va dans l'espace :))  end;// noting yet for the timer !!procedure TForm1.Timer1Timer(Sender: TObject);begin end; end.  
ym_player unit

 
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---// Based on c source from Arnaud CarrĂ© alias Leonard Oxygene stsoundLibrary 1.43// Credits : To do ..........// Pascal adaptation by Gigatronunit ym_player; {$mode objfpc}{$H+} interface type  PYM_Music = Pointer;    const  YM  = 1;  SND = 0;     type    PYMMusicInfo = record      pSongName: PChar;      pSongAuthor: PChar;      pSongComment: PChar;      pSongType: PChar;      pSongPlayer: PChar;      musicTimeInSec: Integer;      musicTimeInMs: Integer;    end;    const    YMFALSE = 0;    YMTRUE = not YMFALSE; function YM_Init: PYM_Music; cdecl; external 'YM2149SSND.dll';procedure YM_Destroy(pMusic: PYM_Music); cdecl; external 'YM2149SSND.dll';function YM_LoadFile(pMusic: PYM_Music; mus: PAnsiChar): Boolean; cdecl; external 'YM2149SSND.dll';function YM_LoadFromMemory(pMusic: PYM_Music; pBlock: Pointer; size: Integer): Boolean; cdecl; external 'YM2149SSND.dll';procedure YM_Play(pMusic: PYM_Music); cdecl; external 'YM2149SSND.dll';function YM_ComputePCM(pMusic: PYM_Music; pBuffer: Pointer; nbSample: Integer): Boolean; cdecl; external 'YM2149SSND.dll';procedure YM_Information(pMusic: PYM_Music; Info: PYMMusicInfo); cdecl; external 'YM2149SSND.dll'; procedure YM_LowpassFilter(pMusic: PYM_Music; bActive: Boolean); cdecl; external 'YM2149SSND.dll';procedure YM_SetLoopMode(pMusic: PYM_Music; bLoop: Boolean); cdecl; external 'YM2149SSND.dll';function  YM_GetLastError(pMusic: PYM_Music): PAnsiChar; cdecl; external 'YM2149SSND.dll';function  YM_GetRegister(pMusic: PYM_Music; reg: Integer): Integer; cdecl; external 'YM2149SSND.dll';procedure YM_Pause(pMusic: PYM_Music); cdecl; external 'YM2149SSND.dll';procedure YM_Stop(pMusic: PYM_Music); cdecl; external 'YM2149SSND.dll';function  YM_IsOver(pMusic: PYM_Music): Boolean; cdecl; external 'YM2149SSND.dll';procedure YM_Restart(pMusic: PYM_Music); cdecl; external 'YM2149SSND.dll';function  YM_IsSeekable(pMusic: PYM_Music): Boolean; cdecl; external 'YM2149SSND.dll';function  YM_GetPosition(pMusic: PYM_Music): LongInt; cdecl; external 'YM2149SSND.dll';procedure YM_MusicSeek(pMusic: PYM_Music; timeInMs: LongInt); cdecl; external 'YM2149SSND.dll';  implementation end.  

 

TRon:
🐧 For the intuxicated folks 🐧

Navigation

[0] Message Index

Go to full version