Recent

Author Topic: UOS Wave Demo not working. [SOLVED]  (Read 2256 times)

Josh

  • Hero Member
  • *****
  • Posts: 1344
UOS Wave Demo not working. [SOLVED]
« on: July 24, 2024, 09:42:11 am »
Hi

Using
Lazarus 3.5 (rev lazarus_3_4-39-g27df05ce8a) FPC 3.2.3 i386-win32-win32/win64.
edt: and Lazarus 3.5 (rev lazarus_3_4-68-g3a2e12409f) FPC 3.2.3 x86_64-win64-win32/win64.

Playing around with UOs, I can play audio from memory stream working great.
Was wanting to add waveform so i opened a few examples and a prob.

i open waveform, as this is the goto example, but this does not work.
waveform is blank,if you click play, it plays but then nothing else works, ie stop does not work, cant choose a new file.
it is though it has not acknowledged the audio has finished.

Any thoughts
« Last Edit: July 25, 2024, 04:45:46 pm by Josh »
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

Thaddy

  • Hero Member
  • *****
  • Posts: 16187
  • Censorship about opinions does not belong here.
Re: UOS Wave Demo not working.
« Reply #1 on: July 24, 2024, 09:50:45 am »
Thoughts are we need more info? I use UOS and Fred v.s. is a forum member.
But your info is a be sparse, to say the least.
If I smell bad code it usually is bad code and that includes my own code.

Josh

  • Hero Member
  • *****
  • Posts: 1344
Re: UOS Wave Demo not working.
« Reply #2 on: July 24, 2024, 10:03:04 am »
Hi Thaddy

If you try the wavedemo in examples it should make sense.
It is possible issue with the fixes branch.

ran, clicked play, na na na nana, controls no longer work

edt: dll's are dated Jan 6 2023
« Last Edit: July 24, 2024, 11:10:33 am by Josh »
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

Thaddy

  • Hero Member
  • *****
  • Posts: 16187
  • Censorship about opinions does not belong here.
Re: UOS Wave Demo not working.
« Reply #3 on: July 24, 2024, 10:49:11 am »
I do not have your version available, so I suggest you ping Fred? he is very active.
If I smell bad code it usually is bad code and that includes my own code.

Fred vS

  • Hero Member
  • *****
  • Posts: 3413
    • StrumPract is the musicians best friend
Re: UOS Wave Demo not working.
« Reply #4 on: July 24, 2024, 02:37:20 pm »
Hello Josh.

Did you use the last commit of uos?
https://github.com/fredvs/uos/

Here it works but I did not try yet with Lazarus 3.5.
Also I dont have a Windows machine at the moment...

Did you click on the "Design Wave Form" button?
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: 3413
    • StrumPract is the musicians best friend
Re: UOS Wave Demo not working.
« Reply #5 on: July 24, 2024, 03:14:24 pm »
Re-hello Josh.

Ok, I found a Windows 11 machine.
But not yet with Lazarus 3.5. ( only Lazarus 2.2.4 ).

And there it works. (see screenshot).

Maybe it is related with Lazarus 3.5. (but I cannot install it on that Widows 11 machine at the moment).
« Last Edit: July 24, 2024, 03:25:40 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

Josh

  • Hero Member
  • *****
  • Posts: 1344
Re: UOS Wave Demo not working.
« Reply #6 on: July 24, 2024, 04:55:47 pm »
Hi @Fred vS,

I used the version that came from OPM, done a complete clean all/delete  rebuild of lazarus.

Tonight if I get time, I will  install a fresh lazarus and fpc (fixes branch) x64.
and no other 3rd party components.
then install UOS from OPM and test. (state of fixes on OPM)
then install UOS from your repo and test (state of fixes on repo)

Its entirely possible, that my fixes install (upgraded many times with updates of 3rd party packages including uos via OPM) has got a little messed. I have had that happen before.

Will report back.....
TBC..
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

Fred vS

  • Hero Member
  • *****
  • Posts: 3413
    • StrumPract is the musicians best friend
Re: UOS Wave Demo not working.
« Reply #7 on: July 24, 2024, 05:52:02 pm »
Hello Josh.

In the screenshot you gave, the uos is version 2220425 (version 2 dated 2022/04/25).
So it looks like OPM has an older version of uos.
The current version (with many fixes) is 2240422 (version 2 dated 2024/04/22).

It would be great if OPM could give the latest uos commits (and that you use it too  ;) )
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

Josh

  • Hero Member
  • *****
  • Posts: 1344
Re: UOS Wave Demo not working.
« Reply #8 on: July 25, 2024, 04:43:30 pm »
Hi Fred vS,

I have tested UOS with fresh installs of  latest fixes of  x86  and x86-64.

Both OPM and repo versions of waveform player are working.
So conclusion my fixes install was somehow 'screwed'.

odd how opm version of 2022 has 2023 dlls.

Questions.
I have generated audio in a TMemoryStream, and I can Play it without issue.
(I think this may be the issue, playing from tmemorystream, rather than a file, and no I do not want to save the generated audio to file).
I cannot do the following.
1. Get positon of the playing Stream using uos_InputPositionTime, it returns 0.
2. If I try to ceate waveform data, it sort of works but it plays the complete audio first before the endproc waveform generator is run.
3. If I pause with uos_Pause(PlayerIndex1) then later call uos_PlayNoFree(PlayerIndex1) to resume play, it starts from the beginning.

I have only just starting playing with UOs, soo suspect its me... ;)
« Last Edit: July 25, 2024, 06:37:09 pm by Josh »
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

Fred vS

  • Hero Member
  • *****
  • Posts: 3413
    • StrumPract is the musicians best friend
Re: UOS Wave Demo not working.
« Reply #9 on: July 25, 2024, 07:01:26 pm »
Hi Fred vS,

I have tested UOS with fresh installs of  latest fixes of  x86  and x86-64.

Both OPM and repo versions of waveform player are working.

Nice that it works! (But better to use last uos commits  ;) )

Questions.
I have generated audio in a TMemoryStream, and I can Play it without issue.
(I think this may be the issue, playing from tmemorystream, rather than a file, and no I do not want to save the generated audio to file).
I cannot do the following.
1. Get positon of the playing Stream using uos_InputPositionTime, it returns 0.
2. If I try to ceate waveform data, it sort of works but it plays the complete audio first before the endproc waveform generator is run.
3. If I pause with uos_Pause(PlayerIndex1) then later call uos_PlayNoFree(PlayerIndex1) to resume play, it starts from the beginning.

I have only just starting playing with UOs, soo suspect its me... ;)

Hum, difficult to give a diagnosis without seeing the patient.

For 1.  Did you enable seek-position before play with:
Code: Pascal  [Select][+][-]
  1.  uos_InputSetPositionEnable(PlayerIndex1, InputIndex1, 1);
    You may take a look at SimplePlayer demo.

For 2. Hum, sorry but I dont understand it. I fear I will need to see your code.
 [EDIT] If you want to play the audio and have the waveform at the same time, usually I use 2 players, one to get the wavedata and the other  play the audio.  And then do uos_play(playerwavedata) followed with uos(playaudio).
Of course it will be a short delay to render the waveform depending on the size of the audio-file-memorystream-etc...
But because each player is a independent thread, one will not borrow the other.

For 3. For resume, please use uos_RePlay:
   
Code: Pascal  [Select][+][-]
  1. uos_RePlay(PlayerIndex1);
   You may also take a look at SimplePlayer demo.
« Last Edit: July 26, 2024, 12:55:52 am 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

Josh

  • Hero Member
  • *****
  • Posts: 1344
Re: UOS Wave Demo not working. [SOLVED]
« Reply #10 on: July 26, 2024, 12:40:14 pm »
Hi Fred vS,

I must be doing something wrong, as I cant get any wavedata, using debug I have put values in commented code below.


Code: Pascal  [Select][+][-]
  1. procedure TForm1.CalcWaveData;
  2. var
  3.   wavecounter,auddatapoint: integer;
  4.   audioleveldata: array of cfloat;
  5. begin
  6.   audioleveldata := uos_InputGetLevelArray(PlayerIndex2, InputIndex1);  
  7.   // <- this is nil after , should it not be an array of single values
  8.   wavecounter:=0;
  9.   auddatapoint:=0;
  10.   SetLength(Aud,(length(audioleveldata) div 2)+100);
  11.   while wavecounter < length(audioleveldata) do
  12.   begin
  13.     Aud[auddatapoint].Left:=audioleveldata[wavecounter];
  14.     Aud[auddatapoint].Right:=audioleveldata[wavecounter+1];
  15.     aud[auddatapoint].HasEvent:=random(1000)<3;
  16.     inc(wavecounter,2);
  17.     inc(auddatapoint);
  18.   end;
  19.   setlength(Aud,auddatapoint);
  20. end;                  
  21.  
  22.  
  23. // calculate wave data
  24.   PlayerIndex2 := 0;
  25.   if uos_CreatePlayer(PlayerIndex2) then
  26.   begin
  27.     InputIndex1 := uos_AddFromMemoryStream(PlayerIndex2,wav_stream,-1,-1,0,-1);
  28.         // <- wav_stream is a valid stream as it plays size 33534860
  29.     chan := uos_InputGetChannels(PlayerIndex2, InputIndex1);
  30.         // <- return 2
  31.     filelength := uos_InputLength(PlayerIndex2, InputIndex1);
  32.         // < size 8383704
  33.     uos_InputSetPositionEnable(PlayerIndex2, InputIndex1, 0);
  34.         // tried with and without above no difference
  35.     uos_InputSetLevelArrayEnable(PlayerIndex2, InputIndex1, 0);
  36.     samplerate:=uos_inputgetSampleRate(PlayerIndex2,InputIndex1);
  37.         // <- return48000
  38.     DecodeTime(uos_InputLengthTime(PlayerIndex2, InputIndex1), ho, mi, se, ms);
  39.         // calculate frames as need 100 levels per second
  40.         // ho=0   mi=2   se=54   ms=667
  41.     framewanted:=round(filelength/(mi*6000)+(se*100)+(ms div 10));  
  42.         // <-6165
  43.     uos_InputSetFrameCount(PlayerIndex2, InputIndex1,framewanted);
  44.     uos_EndProc(PlayerIndex2, @CalcWaveData);
  45.     uos_Play(PlayerIndex2);
  46.        
« Last Edit: July 26, 2024, 01:21:42 pm by Josh »
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

Fred vS

  • Hero Member
  • *****
  • Posts: 3413
    • StrumPract is the musicians best friend
Re: UOS Wave Demo not working. [SOLVED]
« Reply #11 on: July 26, 2024, 02:34:19 pm »
Hello Josh.

I cannot test your code at the moment (because I dont have my laptop here).

But, at first check, this code is not ok:

Code: Pascal  [Select][+][-]
  1. uos_InputSetPositionEnable(PlayerIndex2, InputIndex1, 0); // not needed for data calculation but with last parameter = 0 ---> no calculation
  2. uos_InputSetLevelArrayEnable(PlayerIndex2, InputIndex1, 0); // with last parameter = 0 ---> no calculation

Should be (please take a look at WaveForm demo):
 
Code: Pascal  [Select][+][-]
  1. uos_InputSetLevelArrayEnable(PlayerIndex2, InputIndex1, 2); // with last parameter = 2 ---> calculation after each loop
 

[EDIT] If you want to use 2 different independent players, please use different index for each one. If you use same index for Player2, it will erase previous Player1.
For example:
Code: Pascal  [Select][+][-]
  1.  PlayerIndex1 := 0;
  2.  PlayerIndex2 := 1;

I will try your code this week-end.

Fre;D
« Last Edit: July 26, 2024, 03:43:32 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

Fred vS

  • Hero Member
  • *****
  • Posts: 3413
    • StrumPract is the musicians best friend
Re: UOS Wave Demo not working. [SOLVED]
« Reply #12 on: July 26, 2024, 07:03:23 pm »
Re-hello Josh.

Here updated code from WaveForm project using a TMemorySteam.

Replace the procedure Button3Click() with this:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button3Click(Sender: TObject);
  2. var
  3.   filelength, framewanted: integer;
  4.   thememorystream1: Tmemorystream;  // The memorystream that we will use
  5.   begin
  6.    Edit4.Text := application.Location  + directoryseparator  + 'sound'  + directoryseparator + 'test.flac';    // use libsndfile
  7.  
  8.   form1.Height   := 456;
  9.   form1.Position := poScreenCenter;
  10.   if fileexists(Edit4.Text) then
  11.   begin
  12.     if Assigned(waveformBMP) then
  13.       waveformBMP.Free;
  14.     waveformBMP        := TBitmap.Create;
  15.     PaintBox2.Parent.DoubleBuffered := True;
  16.     waveformBMP.Height := PaintBox2.Height;
  17.     waveformBMP.Width  := PaintBox2.Width;
  18.     waveformBMP.Canvas.AntialiasingMode := amOn;
  19.     waveformBMP.Canvas.Pen.Width := 1;
  20.     waveformBMP.Canvas.brush.Color := clgray;
  21.     waveformBMP.Canvas.FillRect(0, 0, PaintBox2.Width, PaintBox2.Height);
  22.     PaintBox2.Refresh;
  23.  
  24.     PlayerIndex1 := 0;
  25.  
  26.      //   Create a memory stream from a audio file wav, ogg, flac, mp3, opus.
  27.     thememorystream1          := TMemoryStream.Create;
  28.     thememorystream1.LoadFromFile(PChar(Edit4.Text));
  29.     thememorystream1.Position := 0;
  30.  
  31.     // Create the player.
  32.     uos_CreatePlayer(PlayerIndex1);
  33.     // PlayerIndex : from 0 to what your computer can do !
  34.     // If PlayerIndex exists already, it will be overwritten...
  35.  
  36.      In1Index := uos_AddFromMemoryStream(PlayerIndex1, thememorystream1, 0, -1, 2, 1024 * 8);
  37.       // Add a input from memory stream with custom parameters
  38.       // MemoryStream : Memory stream of encoded audio.
  39.       // TypeAudio : default : -1 --> 0 (0: flac, ogg, wav; 1: mp3; 2:opus)
  40.       // OutputIndex : Output index of used output
  41.               // -1: all output, -2: no output, other a existing OutputIndex
  42.                // (if multi-output then OutName = name of each output separeted by ';')
  43.       // SampleFormat : default : -1 (2:Int16) (0: Float32, 1:Int32, 2:Int16)
  44.       // FramesCount : default : -1 (4096)
  45.       //  Result :  Input Index in array  -1 = error
  46.  
  47.     chan := uos_InputGetChannels(PlayerIndex1, In1Index);
  48.     // Get the number of channels.
  49.  
  50.    // no output because only decode the steam for wave form
  51.  
  52.    // get the length of the audio file
  53.     filelength := uos_InputLength(PlayerIndex1, In1Index);
  54.  
  55.     ///// set calculation of level/volume into array (useful for wave form procedure)
  56.     uos_InputSetLevelArrayEnable(PlayerIndex1, In1Index, 2);
  57.     ///////// set level calculation (default is 0)
  58.     // 0 => no calcul
  59.     // 1 => calcul before all DSP procedures.
  60.     // 2 => calcul after all DSP procedures.
  61.  
  62.     //// determine how much frame will be designed
  63.     framewanted := filelength div paintbox2.Width;
  64.     uos_InputSetFrameCount(PlayerIndex1, In1Index, framewanted);
  65.  
  66.     ///// Assign the procedure of object to execute at end of stream
  67.     uos_EndProc(PlayerIndex1, @DrawWaveForm);
  68.  
  69.     uos_Play(PlayerIndex1);  /////// everything is ready, here we are, lets do it...
  70.  
  71.   end
  72.   else
  73.     MessageDlg(edit4.Text + ' do not exist...', mtWarning, [mbYes], 0);
  74.  
  75. end;
  76.  

Compile it and click on "Design Wave Form".

Fre;D
« Last Edit: July 26, 2024, 07:56:41 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

 

TinyPortal © 2005-2018