Forum > Audio and Video

UOS Wave Demo not working. [SOLVED]

<< < (3/3)

Josh:
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  [+][-]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";}};} ---procedure TForm1.CalcWaveData;var  wavecounter,auddatapoint: integer;  audioleveldata: array of cfloat;begin  audioleveldata := uos_InputGetLevelArray(PlayerIndex2, InputIndex1);    // <- this is nil after , should it not be an array of single values  wavecounter:=0;  auddatapoint:=0;  SetLength(Aud,(length(audioleveldata) div 2)+100);  while wavecounter < length(audioleveldata) do  begin    Aud[auddatapoint].Left:=audioleveldata[wavecounter];    Aud[auddatapoint].Right:=audioleveldata[wavecounter+1];    aud[auddatapoint].HasEvent:=random(1000)<3;    inc(wavecounter,2);    inc(auddatapoint);  end;  setlength(Aud,auddatapoint);end;                     // calculate wave data  PlayerIndex2 := 0;  if uos_CreatePlayer(PlayerIndex2) then  begin    InputIndex1 := uos_AddFromMemoryStream(PlayerIndex2,wav_stream,-1,-1,0,-1);        // <- wav_stream is a valid stream as it plays size 33534860    chan := uos_InputGetChannels(PlayerIndex2, InputIndex1);        // <- return 2    filelength := uos_InputLength(PlayerIndex2, InputIndex1);        // < size 8383704    uos_InputSetPositionEnable(PlayerIndex2, InputIndex1, 0);        // tried with and without above no difference    uos_InputSetLevelArrayEnable(PlayerIndex2, InputIndex1, 0);    samplerate:=uos_inputgetSampleRate(PlayerIndex2,InputIndex1);        // <- return48000    DecodeTime(uos_InputLengthTime(PlayerIndex2, InputIndex1), ho, mi, se, ms);        // calculate frames as need 100 levels per second        // ho=0   mi=2   se=54   ms=667    framewanted:=round(filelength/(mi*6000)+(se*100)+(ms div 10));          // <-6165     uos_InputSetFrameCount(PlayerIndex2, InputIndex1,framewanted);    uos_EndProc(PlayerIndex2, @CalcWaveData);    uos_Play(PlayerIndex2);        

Fred vS:
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  [+][-]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";}};} ---uos_InputSetPositionEnable(PlayerIndex2, InputIndex1, 0); // not needed for data calculation but with last parameter = 0 ---> no calculationuos_InputSetLevelArrayEnable(PlayerIndex2, InputIndex1, 0); // with last parameter = 0 ---> no calculation
Should be (please take a look at WaveForm demo):
 
--- 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";}};} ---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  [+][-]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";}};} --- PlayerIndex1 := 0; PlayerIndex2 := 1;
I will try your code this week-end.

Fre;D

Fred vS:
Re-hello Josh.

Here updated code from WaveForm project using a TMemorySteam.

Replace the procedure Button3Click() with this:


--- 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";}};} ---procedure TForm1.Button3Click(Sender: TObject);var  filelength, framewanted: integer;  thememorystream1: Tmemorystream;  // The memorystream that we will use  begin   Edit4.Text := application.Location  + directoryseparator  + 'sound'  + directoryseparator + 'test.flac';    // use libsndfile   form1.Height   := 456;  form1.Position := poScreenCenter;  if fileexists(Edit4.Text) then  begin    if Assigned(waveformBMP) then      waveformBMP.Free;    waveformBMP        := TBitmap.Create;    PaintBox2.Parent.DoubleBuffered := True;    waveformBMP.Height := PaintBox2.Height;    waveformBMP.Width  := PaintBox2.Width;    waveformBMP.Canvas.AntialiasingMode := amOn;    waveformBMP.Canvas.Pen.Width := 1;    waveformBMP.Canvas.brush.Color := clgray;    waveformBMP.Canvas.FillRect(0, 0, PaintBox2.Width, PaintBox2.Height);    PaintBox2.Refresh;     PlayerIndex1 := 0;      //   Create a memory stream from a audio file wav, ogg, flac, mp3, opus.    thememorystream1          := TMemoryStream.Create;    thememorystream1.LoadFromFile(PChar(Edit4.Text));    thememorystream1.Position := 0;     // Create the player.    uos_CreatePlayer(PlayerIndex1);    // PlayerIndex : from 0 to what your computer can do !    // If PlayerIndex exists already, it will be overwritten...      In1Index := uos_AddFromMemoryStream(PlayerIndex1, thememorystream1, 0, -1, 2, 1024 * 8);      // Add a input from memory stream with custom parameters      // MemoryStream : Memory stream of encoded audio.      // TypeAudio : default : -1 --> 0 (0: flac, ogg, wav; 1: mp3; 2:opus)      // OutputIndex : Output index of used output              // -1: all output, -2: no output, other a existing OutputIndex               // (if multi-output then OutName = name of each output separeted by ';')      // SampleFormat : default : -1 (2:Int16) (0: Float32, 1:Int32, 2:Int16)      // FramesCount : default : -1 (4096)      //  Result :  Input Index in array  -1 = error     chan := uos_InputGetChannels(PlayerIndex1, In1Index);    // Get the number of channels.    // no output because only decode the steam for wave form    // get the length of the audio file    filelength := uos_InputLength(PlayerIndex1, In1Index);     ///// set calculation of level/volume into array (useful for wave form procedure)    uos_InputSetLevelArrayEnable(PlayerIndex1, In1Index, 2);    ///////// set level calculation (default is 0)    // 0 => no calcul    // 1 => calcul before all DSP procedures.    // 2 => calcul after all DSP procedures.     //// determine how much frame will be designed    framewanted := filelength div paintbox2.Width;    uos_InputSetFrameCount(PlayerIndex1, In1Index, framewanted);     ///// Assign the procedure of object to execute at end of stream    uos_EndProc(PlayerIndex1, @DrawWaveForm);     uos_Play(PlayerIndex1);  /////// everything is ready, here we are, lets do it...   end  else    MessageDlg(edit4.Text + ' do not exist...', mtWarning, [mbYes], 0); end; 
Compile it and click on "Design Wave Form".

Fre;D

Navigation

[0] Message Index

[*] Previous page

Go to full version