The LoopProc does not work in the console program

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

The LoopProc does not work in the console program

Andrey
Hello, I'm doing an audio input analysis service. I run it in a graphical application, Loop Proc is triggered. I try to run the same thing in the console, Loop Proc does not work. Please tell me what am I doing wrong?
(Lazarus 2.0.2 Linux Debian)

Text function


//My LoopProc
procedure TApp.InLoopMemRs;
var
  aBufLen: Integer;
  FBufRcFromUos: TDArFloat;       // My buffer
begin
  FBufRcFromUos:=uos_InputGetBuffer(FPlayerRs, FInputIndexRs);
  aBufLen:=Length(FBufRcFromUos);

  {My Work}
end;

procedure TApp.StartPlay;
var
  aAllBad: Boolean = False;
begin
  //
  FPlayerRs:=0;
  //
  if uos_CreatePlayer(FPlayerRs) then
  begin
    FInputIndexRs := uos_AddFromDevIn(FPlayerRs, DefaultDeviceIn, -1, cSampleRate,
      cChannels, cSampleFormat, cFramesCount, cChunkCount);
    if FInputIndexRs<>-1 then
      uos_LoopProcIn(FPlayerRs, FInputIndexRs, @InLoopMemRs);
  end else
    aAllBad:=True;
  aAllBad:=aAllBad or (FInputIndexRs=-1);
  if aAllBad then
  begin
    Exit;
  end;

  {Create My Class for Math}

  //Start Play
  uos_Play(FPlayerRs);
end;

procedure TApp.StopPlay;
begin
  uos_Stop(FPlayerRs);
  sleep(300);
end;  
Reply | Threaded
Open this post in threaded view
|

Re: The LoopProc does not work in the console program

fredvs
Administrator
This post was updated on .
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: The LoopProc does not work in the console program

fredvs
Administrator
This post was updated on .
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: The LoopProc does not work in the console program

fredvs
Administrator
This post was updated on .
Hello.

Could you try adding some sleep() time after uos_play()?

 //Start Play
  uos_Play(FPlayerRs);
sleep(3000);    // add this with the estimated time of the process

Is the loop done with this?
If yes, I fear that you will need to use a sleep(x) for console app + loopproc.
And for the duration of the sleep(x) it should be the minimum duration of all the process.

It could be done with something like this:

// var  process_terminated : boolean = false;

// create a uos_EndProc() ----> process_terminated := true;
 
//Start Play
  uos_Play(FPlayerRs);

while  process_terminated = false do
sleep(300);    // add this
- --------------
Reply | Threaded
Open this post in threaded view
|

Re: The LoopProc does not work in the console program

Andrey
I found a solution. In the loop of the main program, add the Checksynchronize(Timeout) function
Reply | Threaded
Open this post in threaded view
|

Re: The LoopProc does not work in the console program

fredvs
Administrator
Hello.

Nice that you found a solution.

May I ask you what kind of loop do you have in the main console program?
Usually checksynchronize() is used in graphic application where a main loop is used.
Did you use a main loop also in your console program?
Reply | Threaded
Open this post in threaded view
|

Re: The LoopProc does not work in the console program

Andrey
Hello.

I use the main loop to check the trigger files of the program shutdown.

procedure TApp.DoRun;
begin

{Creating My Class for uos}

//
while not ext do
begin
  //Read trigger-file
  if ReadTriggerFile then break;
  //
  CheckSynchronize(10);
end;

{Destroying My Class for uos}

 //stop program loop
Terminate;
end;
Reply | Threaded
Open this post in threaded view
|

Re: The LoopProc does not work in the console program

fredvs
Administrator
Hello Andrew.

Ha, ok, I see now, thanks for the tip.

Fre;D