Recent

Author Topic: Join wav files  (Read 48464 times)

KMagic

  • Full Member
  • ***
  • Posts: 100
Re: Join wav files
« Reply #30 on: February 04, 2014, 02:14:31 pm »
I got a simple program using UOS like this:
Code: [Select]
unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,UOS;

type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.Button1Click(Sender: TObject);
var player1:TUOS_player;
begin

  Player1 := TUOS_Player.Create(True, self);
  Player1.AddIntoDevOut;   //// add a Output with default parameters
  Player1.AddFromFile('test.wav');
  Player1.EndProc := @Close;
  Player1.Play;

end;

end.

Why does this error occur after I click button1?

KMagic

  • Full Member
  • ***
  • Posts: 100
Re: Join wav files
« Reply #31 on: February 04, 2014, 02:17:27 pm »
Error:

Fred vS

  • Hero Member
  • *****
  • Posts: 3726
    • StrumPract is the musicians best friend
Re: Join wav files
« Reply #32 on: February 04, 2014, 02:18:03 pm »
Quote
Why does this error occur after I click button1?

Hum, you dont have load any libraries...

Please, take a look at "Simple Player" or "Multi Player example".

Many thanks,
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Fred vS

  • Hero Member
  • *****
  • Posts: 3726
    • StrumPract is the musicians best friend
Re: Join wav files
« Reply #33 on: February 04, 2014, 02:24:43 pm »
@ KMagic.

Ok, we will do it from the beginning...

1) Go on site :
https://github.com/fredvs/uos/

Click on button Download ZIP (on middle-right side).
When you get the file, unzip It.

2) Go on /uos/examples and choose "SimplePlayer.lpi", compile it and run it...

3) After that , look inside the code to understand how it works...

Hope it helps...
« Last Edit: February 04, 2014, 02:26:52 pm by Fred vS »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

KMagic

  • Full Member
  • ***
  • Posts: 100
Re: Join wav files
« Reply #34 on: February 04, 2014, 02:26:16 pm »
I will take a look at them. Thank you very much.

KMagic

  • Full Member
  • ***
  • Posts: 100
Re: Join wav files
« Reply #35 on: February 04, 2014, 07:41:50 pm »
I have read the example and written a simple program which can play a wav sound. Why is there an error?

https://www.mediafire.com/?f7kkt99m2qy7eu4

Fred vS

  • Hero Member
  • *****
  • Posts: 3726
    • StrumPract is the musicians best friend
Re: Join wav files
« Reply #36 on: February 04, 2014, 08:40:19 pm »
@ KMagic

Code: [Select]
unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,UOS;

type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1;
   Init: TUOS_Init;

implementation

{$R *.lfm}

{ TForm1 }


procedure TForm1.Button1Click(Sender: TObject);
var player1:TUOS_player;
begin
   Player1 := TUOS_Player.Create(True, self);
   Player1.AddIntoDevOut;
  Player1.AddFromFile('test.wav');
   Player1.Play;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
    application.ProcessMessages;
    Init := TUOS_Init.Create;
  Init.PA_FileName :=Application.location+'lib\LibPortaudio-32.dll' ;
   Init.SF_FileName := Application.location+'lib\LibSndFile-32.dll';
  Init.MP_FileName := Application.location+'lib\LibMpg123-32.dll';
    Init.Flag := LoadAll;
   Init.LoadLib;
end;

end.
« Last Edit: February 04, 2014, 08:44:37 pm by Fred vS »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

KMagic

  • Full Member
  • ***
  • Posts: 100
Re: Join wav files
« Reply #37 on: February 05, 2014, 03:49:37 am »
why nothing happens when I click button1?

Fred vS

  • Hero Member
  • *****
  • Posts: 3726
    • StrumPract is the musicians best friend
Re: Join wav files
« Reply #38 on: February 05, 2014, 01:01:01 pm »
Quote
why nothing happens when I click button1?

Here it is working...

Have you copy test.wav in same directory of your program ?

Have you try the examples in uos/example, are them all working ?
« Last Edit: February 05, 2014, 01:03:25 pm by Fred vS »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

KMagic

  • Full Member
  • ***
  • Posts: 100
Re: Join wav files
« Reply #39 on: February 05, 2014, 03:36:15 pm »
Yes. Test.wav is in same directory of my program.
  The example of UOS works very well. I don't know why nothing happens when I click button1 in my program.

KMagic

  • Full Member
  • ***
  • Posts: 100
Re: Join wav files
« Reply #40 on: February 05, 2014, 03:44:38 pm »
This is where I put my wav file.

Fred vS

  • Hero Member
  • *****
  • Posts: 3726
    • StrumPract is the musicians best friend
Re: Join wav files
« Reply #41 on: February 05, 2014, 09:50:21 pm »
Hello KMagic

In your code you do :

Code: [Select]
Player1.AddFromFile('test.wav');
So, because you do not give any information where is test.wav, the program (project1.exe) will try to find test.wav in his own directory (G:\Khanh\Study\Pascal\exercise\simple) .

But in the picture you give, i do not see test.wav in G:\Khanh\Study\Pascal\exercise\simple.

You have to copy G:\KHanh\Study\Pascal\exercise\simple\sound\test.wav into G:\KHanh\Study\Pascal\exercise\simple.

Or use that :

Code: [Select]
Player1.AddFromFile('G:\Khanh\Study\Pascal\exercise\simple\sound\test.wav');
« Last Edit: February 05, 2014, 10:17:24 pm by Fred vS »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

KMagic

  • Full Member
  • ***
  • Posts: 100
Re: Join wav files
« Reply #42 on: February 06, 2014, 10:36:22 am »
It works now. Thank you very much.

Fred vS

  • Hero Member
  • *****
  • Posts: 3726
    • StrumPract is the musicians best friend
Re: Join wav files
« Reply #43 on: February 06, 2014, 02:34:24 pm »
Quote
It works now. Thank you very much.

Haaa, im very happy  ;D

PS : Do not forget to call unLoadLib() when you close your application, otherwise you will have a memory leak (memory not  freed).
 
Code: [Select]
procedure TForm1.FormDestroy(Sender: TObject);
begin
   init.UnloadLib(); /// for release dynamic loaded libraries
   init.free;  /// for freed the init class created;
end;
   

PS2 : The same for Player1, but it will be easier to free it if you do not declare it inside the procedure but in main program, like that :

Code: [Select]
...
var
  Form1: TForm1;
   Init: TUOS_Init;
   player1:TUOS_player; /// delcare it there
...
implementation
...
procedure TForm1.FormDestroy(Sender: TObject);
begin
   player1.free;  /// free player1
   init.UnloadLib(); /// for release dynamic loaded libraries
   init.free;  /// for freed the init class created;
end;
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

KMagic

  • Full Member
  • ***
  • Posts: 100
Re: Join wav files
« Reply #44 on: February 06, 2014, 03:42:31 pm »
1) Basically, my simple program works well. However, when I come to write an multiple wav files player using sleep() as I said in the first post. When the first file is played, the second file is played immediately after that. Let's me show you what I mean:
Code: [Select]
procedure ...
begin

procedure TForm1.Button1Click(Sender: TObject);
var
   i:longint;

begin
  sleep(400);

  for i:=1 to length(edit1.text) do begin
    Player1 := TUOS_Player.Create(True, self);
   Player1.AddIntoDevOut;
  Player1.AddFromFile(application.Location+'\morse audio\'+edit1.text[i]+'_MP3.mp3');
   Player1.Play;
        end;

end;

 
note: I have the files named from a.mp3 to z.mp3.
 When player1.play is executed, then program immediately go to sleep(400). How can I make the program pause until player1 is played completely. I think we should put another sleep(x) after player1.play (x:duration of player1). Therefore, the problem is how to get x?
2) Why do I encounter this problem when I edit my program as you just said. This window appear after I close my app (nothing happens before I close my app)
« Last Edit: February 06, 2014, 03:44:39 pm by KMagic »

 

TinyPortal © 2005-2018