Recent

Author Topic: LAZ-ACS and MP3  (Read 4962 times)

clemmi

  • Jr. Member
  • **
  • Posts: 54
LAZ-ACS and MP3
« on: October 17, 2015, 12:04:31 am »
Does anyone have a working simple sample code to play short mp3 audio files?
I downloaded the LAZ-ASC package but can't find how to program it. Or some other package if better.
Thanks.

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1290
Re: LAZ-ACS and MP3
« Reply #1 on: October 17, 2015, 09:18:19 am »
hello,
you can try uos

example to play a mp3 file in a console app win32 :
Code: Pascal  [Select][+][-]
  1. program consoleplaymp3;
  2. {$mode objfpc}{$H+}
  3.    {$DEFINE UseCThreads}
  4. uses
  5.   Classes,
  6.   SysUtils,
  7.   CustApp,
  8.   uos_flat,
  9.   ctypes { you can add units after this };
  10.  
  11. type
  12.  
  13.   { TUOSConsole }
  14.  
  15.   TuosConsole = class(TCustomApplication)
  16.   private
  17.     procedure ConsolePlaymp3;
  18.   protected
  19.     procedure doRun; override;
  20.   public
  21.     procedure Consoleclose;
  22.     constructor Create(TheOwner: TComponent); override;
  23.   end;
  24.  
  25.  
  26. var
  27.   res: integer;
  28.   ordir, opath, sndfilename, PA_FileName, SF_FileName, MP3_FileName: string;
  29.   PlayerIndex1: cardinal;
  30.   In1Index : integer;
  31.  
  32.   { TuosConsole }
  33.  
  34.   procedure TuosConsole.ConsolePlayMP3;
  35.   begin
  36.     ordir := IncludeTrailingBackslash(ExtractFilePath(ParamStr(0)));
  37.     PA_FileName := ordir + 'lib\Windows\32bit\LibPortaudio-32.dll';
  38.     SF_FileName := ordir + 'lib\Windows\32bit\LibSndFile-32.dll';
  39.     MP3_FileName :=  ordir + 'lib\Windows\32bit\LibMpg123-32.dll';
  40.     sndfilename := ordir + 'sound\Speed.mp3';
  41.     PlayerIndex1 := 0;
  42.     // Load the libraries
  43.     // function uos_LoadLib(PortAudioFileName: Pchar; SndFileFileName: Pchar; Mpg123FileName: Pchar; SoundTouchFileName: Pchar) : integer;
  44.    res := uos_LoadLib(Pchar(PA_FileName), Pchar(SF_FileName),Pchar(MP3_FileName), nil) ;
  45.     writeln('Result of loading (if 0 => ok ) : ' + IntToStr(res));
  46.    if res = 0 then begin
  47.    uos_CreatePlayer(PlayerIndex1); //// Create the player
  48.    In1Index := uos_AddFromFile(PlayerIndex1,(pchar(sndfilename)));
  49.    uos_AddIntoDevOut(PlayerIndex1, -1, -1, uos_InputGetSampleRate(PlayerIndex1, In1Index), -1, -1, -1);
  50.     uos_Play(PlayerIndex1);
  51.    end;
  52.  
  53. end;
  54.  
  55.   procedure TuosConsole.doRun;
  56.   begin
  57.     ConsolePlayMP3;
  58.     writeln('Press a key to exit...');
  59.       readln;
  60.       uos_unloadLib();
  61.       Terminate;
  62.     end;
  63.  
  64.   procedure TuosConsole.ConsoleClose;
  65.   begin
  66.     Terminate;
  67.   end;
  68.  
  69.   constructor TuosConsole.Create(TheOwner: TComponent);
  70.   begin
  71.     inherited Create(TheOwner);
  72.     StopOnException := True;
  73.   end;
  74.  
  75. var
  76.   Application: TUOSConsole;
  77. begin
  78.   Application := TUOSConsole.Create(nil);
  79.   Application.Title := 'Console Player';
  80.     Application.Run;
  81.   Application.Free;
  82. end.

Friendly, J.P
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

serbod

  • Full Member
  • ***
  • Posts: 146
Re: LAZ-ACS and MP3
« Reply #2 on: October 17, 2015, 12:31:28 pm »
Simple console audio player example for ACS 3.0

https://github.com/serbod/acs/blob/master/demos/AcsConsolePlayer/consp.lpr

Code: Pascal  [Select][+][-]
  1. program consp;
  2.  
  3. { ACS Console audio player }
  4. {$mode objfpc}{$H+}
  5.  
  6. uses
  7.   {$IFDEF UNIX}{$IFDEF UseCThreads}
  8.   cthreads,
  9.   {$ENDIF}{$ENDIF}
  10.   Classes, SysUtils, CustApp,
  11.   acs_file, acs_audio, // audio in/out, file in/out
  12.   acs_allformats, // all files formats
  13.   acs_stdaudio; // standard audio driver
  14.  
  15. type
  16.  
  17.   { TAcsApplication }
  18.  
  19.   TAcsApplication = class(TCustomApplication)
  20.   private
  21.     AudioOut: TAcsAudioOut;
  22.     FileIn: TAcsFileIn;
  23.   protected
  24.     procedure DoRun; override;
  25.   public
  26.     constructor Create(TheOwner: TComponent); override;
  27.     destructor Destroy; override;
  28.   end;
  29.  
  30. { TAcsApplication }
  31.  
  32. procedure TAcsApplication.DoRun;
  33. begin
  34.   // parse parameters
  35.   if (ParamCount < 1) or HasOption('h','help') then
  36.   begin
  37.     WriteLn('Usage: ', ExtractFileName(ExeName),' <audio_file_name>');
  38.     Terminate;
  39.     Exit;
  40.   end;
  41.  
  42.   { add your program here }
  43.   FileIn.FileName := Params[1];
  44.   AudioOut.Run();
  45.   while AudioOut.Active do
  46.   begin
  47.     Sleep(10);
  48.   end;
  49.  
  50.   // stop program loop
  51.   Terminate;
  52. end;
  53.  
  54. constructor TAcsApplication.Create(TheOwner: TComponent);
  55. begin
  56.   inherited Create(TheOwner);
  57.   StopOnException:=True;
  58.   // create simple processing chain FileIn -> AudioOut
  59.   FileIn := TAcsFileIn.Create(nil);
  60.   AudioOut := TAcsAudioOut.Create(nil);
  61.   AudioOut.Input := FileIn;
  62. end;
  63.  
  64. destructor TAcsApplication.Destroy;
  65. begin
  66.   FreeAndNil(AudioOut);
  67.   FreeAndNil(FileIn);
  68.   inherited Destroy;
  69. end;
  70.  
  71. var
  72.   Application: TAcsApplication;
  73. begin
  74.   Application:=TAcsApplication.Create(nil);
  75.   Application.Title:='ACS Example';
  76.   Application.Run;
  77.   Application.Free;
  78. end.
  79.  

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1290
Re: LAZ-ACS and MP3
« Reply #3 on: October 18, 2015, 02:13:56 am »
hello,
very good job serbod, your package is easy to install and we need only few lines of code to play an audio file.
there is a small bug  ( my config Lazarus 1.4.4 windows 7 32 bits) :
When i put a non visual component of your package  (ie : TacsAudioOut ) on a form, while resizing the form, your component disappears. When i stop resize, the component is visible. Same thing when i move another component in the form. Your component "flicks".

EDIT :
oops  :-X  not a bug, same thing with the other "non visual" components (ie : TTimer) ,

Friendly, J.P
« Last Edit: October 18, 2015, 02:37:03 am by Jurassic Pork »
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

 

TinyPortal © 2005-2018