Recent

Author Topic: Join wav files  (Read 48449 times)

Fred vS

  • Hero Member
  • *****
  • Posts: 3724
    • StrumPract is the musicians best friend
Re: Join wav files
« Reply #45 on: February 06, 2014, 11:39:50 pm »
« Last Edit: February 06, 2014, 11:42:28 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

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: Join wav files
« Reply #46 on: February 07, 2014, 05:40:25 am »
The solution is here :
http://forum.lazarus.freepascal.org/index.php/topic,23479.msg140408.html#msg140408
Back to "mute buffer" approach. Won't the following code work?
Code: [Select]
   Player1 := TUOS_Player.Create(True, self);
   Player1.AddIntoDevOut;
   for i:=1 to length(edit1.text) do begin
     Player1.AddFromFile(application.Location+'\morse audio\'+edit1.text[i]+'_MP3.mp3');
     Player1.AddFromFile(application.Location+'\morse audio\mute2seconds.wav'');
   end;
   Player1.Play;
end;
where mute2seconds.wav is just a file with 2 seconds of silence?

KMagic

  • Full Member
  • ***
  • Posts: 100
Re: Join wav files
« Reply #47 on: February 07, 2014, 06:20:36 am »
The solution is here :
http://forum.lazarus.freepascal.org/index.php/topic,23479.msg140408.html#msg140408
Back to "mute buffer" approach. Won't the following code work?
Code: [Select]
   Player1 := TUOS_Player.Create(True, self);
   Player1.AddIntoDevOut;
   for i:=1 to length(edit1.text) do begin
     Player1.AddFromFile(application.Location+'\morse audio\'+edit1.text[i]+'_MP3.mp3');
     Player1.AddFromFile(application.Location+'\morse audio\mute2seconds.wav'');
   end;
   Player1.Play;
end;
where mute2seconds.wav is just a file with 2 seconds of silence?

This code does not seem to work.I don't know why.

KMagic

  • Full Member
  • ***
  • Posts: 100
Re: Join wav files
« Reply #48 on: February 07, 2014, 01:20:44 pm »
is there any way to get the duration of a mp3 file?

KMagic

  • Full Member
  • ***
  • Posts: 100
Re: Join wav files
« Reply #49 on: February 07, 2014, 01:40:01 pm »
I found this line in the simple player example of UOS. Is it for the duration of the mp3?

Fred vS

  • Hero Member
  • *****
  • Posts: 3724
    • StrumPract is the musicians best friend
Re: Join wav files
« Reply #50 on: February 07, 2014, 04:16:16 pm »
Code: [Select]
Player1 := TUOS_Player.Create(True, self);
   Player1.AddIntoDevOut;
   for i:=1 to length(edit1.text) do begin
     Player1.AddFromFile(application.Location+'\morse audio\'+edit1.text[i]+'_MP3.mp3');
     Player1.AddFromFile(application.Location+'\morse audio\mute2seconds.wav'');
   end;
   Player1.Play;
Quote
This code does not seem to work.I don't know why.

Of course, it could not work.
Player1.AddFromFile => add a audio file into the input of the player.

So, with

Code: [Select]
for i:=1 to length(edit1.text) do begin
     Player1.AddFromFile(application.Location+'\morse audio\'+edit1.text[i]+'_MP3.mp3');
     Player1.AddFromFile(application.Location+'\morse audio\mute2seconds.wav'');
   end;

You will add many input into the same player... If it works, it will play all that files together...

You MUST use the "EndProc" feature of uos => EndProc is the procedure launched when the thread arrived on 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 #51 on: February 07, 2014, 05:18:36 pm »
I don't really get it. Where should I put it? Should I put player1.endProc:=@closeplayer1?

Fred vS

  • Hero Member
  • *****
  • Posts: 3724
    • StrumPract is the musicians best friend
Re: Join wav files
« Reply #52 on: February 07, 2014, 09:25:58 pm »
Quote
Hello KMagic.

The solution is here :
http://forum.lazarus.freepascal.org/index.php/topic,23479.msg140408.html#msg140408

Thanks

=>

Code: [Select]
..

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('MyWav.wav');
  Player1.EndProc := @ClosePlayer1;
  Player1.Play;
 end;     

procedure TForm1.ClosePlayer1;
var
Player2 :  TUOS_Player ;
begin
sleep(2000);
  Player2 := TUOS_Player.Create(True, self);
  Player2.AddIntoDevOut;   //// add a Output with default parameters
  Player2.AddFromFile('MyWav2.wav');
  Player2.EndProc := @ClosePlayer2;
  Player2.Play;
 end;     

procedure TForm1.ClosePlayer2;
var
Player3 :  TUOS_Player ;
begin
sleep(2000);
  Player3 := TUOS_Player.Create(True, self);
  Player3.AddIntoDevOut;   //// add a Output with default parameters
  Player3.AddFromFile('MyWav2.wav');
  Player3.EndProc := @ClosePlayer3;
  Player3.Play;
 end;     

etc...

Please, read carefully that code...
It will , when you click on the button, create a new player, assign a Input (here a audio-file), assign a output (here out device of your sound card) and, the important thing:
assign a procedure to execute when the thread (the player) has terminated.
When all  that is done it will play the player (player1.play).

That end-procedure (EndProc), closeplayer1, will first, wait 2 seconds, then , like for player1, also create a new player2, assign in-output and assign also a EndProc (closeplayer2),
When all that is done it  will play the player2 (player2.play).

That end-procedure (EndProc), closeplayer2, will first, wait 2 seconds, then , like for player2, also create a new player3, assign in-output and assign also a EndProc (closeplayer3),
When all that is done it  will play the player3(player3.play).

That end-procedure (EndProc), closeplayer3, will first, wait 2 seconds, then , like for player3, also create a new player4, assign in-output and assign also a EndProc (closeplayer4),
When all that is done it  will play the player4 (player4.play).

.... => how many times you have song to play...


When you get it, feel free to invent a loop procedure to do that...
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 #53 on: February 08, 2014, 12:51:56 pm »
I understood what you mean.
Why is there '@' in this line Player1.EndProc := @ClosePlayer1;? I haven't seen this before.

Fred vS

  • Hero Member
  • *****
  • Posts: 3724
    • StrumPract is the musicians best friend
Re: Join wav files
« Reply #54 on: February 09, 2014, 02:48:11 pm »
Quote
I understood what you mean.
Why is there '@' in this line Player1.EndProc := @ClosePlayer1;? I haven't seen this before.

@ is  an "address of" operator. It means "point to procedure ClosePlayer1".

See here some "windy" discussion about that :

http://forum.lazarus.freepascal.org/index.php/topic,18928.0.html?PHPSESSID=e01a2bcbfd427d57004841e50cb6079d
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

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: Join wav files
« Reply #55 on: February 17, 2014, 06:04:32 pm »
an awesome example of doing the same task without external files.
http://www.leapsecond.com/tools/morsewav.c
in C though :)

 

TinyPortal © 2005-2018