Memory is not cleared

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

Memory is not cleared

Andrey
This post was updated on .
Hello freq. I once asked you how to implement reading the write buffer and then clearing it (http://uos-forum.2369694.n4.nabble.com/How-to-record-from-a-microphone-without-output-to-the-speakers-tp739p744.html). You have advised a two-player algorithm with alternating start and stop. The algorithm works, but there is a memory problem. For some reason, memory began to grow, although I destroy and recreate the players.

Listing

//Create Player number "aPlayer"
function StartMediaPlayer(aPlayer:integer;MemBuf:PDArFloat):boolean;
var MediaInput:integer;
    s:string;
begin
  result:=false;
  //Free buffer for Player "aPlayer"
  if aPlayer=MediaPlayer1
  then
    SetLength(MemBuf1, 0)
  else
    SetLength(MemBuf2, 0);

  //Если плейер был остановлен, очищаем его
  if uos_GetStatus(aPlayer)=0
  then
    uos_FreePlayer(aPlayer);
  //
  if not uos_CreatePlayer(aPlayer) then exit;
  //
  uos_AddIntoMemoryBuffer(aPlayer,MemBuf);
  MediaInput:=uos_AddFromDevIn(aPlayer,-1, -1, 8192, 0, 0, 1024, 256);
  //
  if MediaInput<0
  then
    begin
      uos_Stop(aPlayer);
      //uos_FreePlayer(aPlayer);
      exit;
    end;
  //
  uos_InputAddDSPVolume(aPlayer,MediaInput,1,1);
  uos_InputSetDSPVolume(aPlayer,MediaInput,1,1,true);
  //
  result:=true;
end;

procedure Execute;
var cnt : Integer;
    i:Integer;
    PleerNum : Integer;  //select Player
begin
  //
  PleerNum:=2;
  SetLength(MemBuf2, 0); //Free Buf2
  //If start Player2
  if StartMediaPlayer(MediaPlayer2,@MemBuf2)
  then
    //play Player2
    uos_Play(MediaPlayer2)
  else
    begin
      //exit
    end;
  //
  while (not Terminated) do
  begin

    if PleerNum=2 then
    begin
      sleep(1);
      while (Length(MemBuf2)<8192*2) and (not Terminated) do begin Sleep(1); end;

      //Start Player1
      while (not Terminated) and (not StartMediaPlayer(MediaPlayer1,@MemBuf1)) do
        sleep(2);
      //
      if Terminated then Break;

      //stop Player2
      uos_Stop(MediaPlayer2);
      //uos_FreePlayer(MediaPlayer2);
      //play Player1
      uos_Play(MediaPlayer1);

      //Read Data from buf2
      ReadDataFromBuff(MemBuf2);

      //Select Player1
      PleerNum:=1;
    end else
      if PleerNum=1 then
      begin
        sleep(1);
        while (Length(MemBuf1)<8192*2) and (not Terminated) do begin Sleep(1);end;

        //start Player2
        while (not Terminated) and (not StartMediaPlayer(MediaPlayer2,@MemBuf2)) do
          sleep(2);
        //
        if Terminated then Break;
        //stop Player1
        uos_Stop(MediaPlayer1);
        //uos_FreePlayer(MediaPlayer1);
        //play Player2
        uos_Play(MediaPlayer2);

        //Read Data from buf1
        ReadDataFromBuff(MemBuf1);

        //SelectPlayer2
        PleerNum:=2;
        //
        Sleep(1);
    end;
  end;

  //Останавливаем плейеры
  try
    uos_Stop(MediaPlayer1);
    uos_FreePlayer(MediaPlayer1);
    uos_Stop(MediaPlayer2);
    uos_FreePlayer(MediaPlayer2);
  finally
  end;
  sleep(2);
  //Free buffers
  SetLength(MemBuf1, 0);
  SetLength(MemBuf2, 0);
end;
Reply | Threaded
Open this post in threaded view
|

Re: Memory is not cleared

fredvs
Administrator
Hello.

> For some reason, memory began to grow, although I destroy and recreate the players.

Sorry I dont understand.
When do you assign the size of the buffer?
It cannot grow if you dont do setlength(thebuffer).

> procedure Execute;

When do you call it?

> while (not Terminated) do  begin

Why dont you use LoopProc like explained before?
Please re-take a look at morseTL.lpi demo how to use "ping-pong" players and loopproc.


Fre;D






Reply | Threaded
Open this post in threaded view
|

Re: Memory is not cleared

fredvs
Administrator
Re-hello.

I cannot reproduce your problem.

Please attach a zip file of a simple project that shows the problem.

Thanks.

Fre;D
Reply | Threaded
Open this post in threaded view
|

Re[2]: Memory is not cleared

Andrey
Hello
There is no time now. Once again, I will carefully look at what I have written, I will check it myself again. Then I'll unsubscribe, maybe I'm not clearing the buffer correctly.
 
Понедельник, 15 февраля 2021, 21:20 +05:00 от fredvs [via uos Forum] <[hidden email]>:
 
Re-hello.

I cannot reproduce your problem.

Please attach a zip file of a simple project that shows the problem.

Thanks.

Fre;D
 
If you reply to this email, your message will be added to the discussion below:
http://uos-forum.2369694.n4.nabble.com/Memory-is-not-cleared-tp805p807.html
To unsubscribe from Memory is not cleared, click here.
NAML
 
 
С уважением,
Андрей Батраков
[hidden email]
 
Reply | Threaded
Open this post in threaded view
|

Re[3]: Memory is not cleared

Andrey
Hello Fred.
I want to formulate the task correctly.
I need to extract data blocks of a certain size from the active recording stream for analysis. In this case, it is necessary that the stream itself or on command clears the buffer so that it does not overflow. I present the algorithm, but I cannot determine which function from the library I should use. Examples in demo versions are mainly focused on reading ready-made records.
I have a working example (not mine) on two players. If the problem can be solved with one player without interrupting the recording? My example is in the attachment.
 
Вторник, 16 февраля 2021, 13:30 +05:00 от Andrey [via uos Forum] <[hidden email]>:
 
Hello
There is no time now. Once again, I will carefully look at what I have written, I will check it myself again. Then I'll unsubscribe, maybe I'm not clearing the buffer correctly.
 
Понедельник, 15 февраля 2021, 21:20 +05:00 от fredvs [via uos Forum] <[hidden email]>:
 
Re-hello.

I cannot reproduce your problem.

Please attach a zip file of a simple project that shows the problem.

Thanks.

Fre;D
 
If you reply to this email, your message will be added to the discussion below:
http://uos-forum.2369694.n4.nabble.com/Memory-is-not-cleared-tp805p807.html
To unsubscribe from Memory is not cleared, click here.
NAML
 
 
С уважением,
Андрей Батраков
[hidden email]
 
 
If you reply to this email, your message will be added to the discussion below:
http://uos-forum.2369694.n4.nabble.com/Memory-is-not-cleared-tp805p808.html
To unsubscribe from Memory is not cleared, click here.
NAML
 
 
С уважением,
Андрей Батраков
[hidden email]
 


К этому письму приложены ссылки на следующие файлы:

1. prDecoderAM_test[1].tar (34.6 Мб)

Ссылка для скачивания файлов: https://cloud.mail.ru/stock/6ivPjW9kpxas5CdUi3GPv9VE

Файлы будут храниться до 18.08.2021
Reply | Threaded
Open this post in threaded view
|

Re: Re[3]: Memory is not cleared

fredvs
Administrator
Hello Andrey.

OK, I will check your code this week-end.

Write you later.

Fre;D
Reply | Threaded
Open this post in threaded view
|

Re: Re[3]: Memory is not cleared

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

Re: Re[3]: Memory is not cleared

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

Re: Re[3]: Memory is not cleared

fredvs
Administrator
This post was updated on .
Hello.

In attachment your project with only one player.
I hope it is what you want.

Fre;D

prDecoderAM_test_oneplayer.zip

procedure ListenMedia(WorkFreqL, WorkFreqR:Integer);
begin
  MediaPlayer:=0;
  SetLength(MemBuf, 0);
  uos_CreatePlayer(MediaPlayer);
  uos_AddIntoMemoryBuffer(MediaPlayer, @MemBuf);
  uos_AddFromDevIn(MediaPlayer, -1, -1, 8192, -1, 0, 1024, 256);

  uos_LoopProcIn(MediaPlayer, 0, @form1.LoopProc); // This to change the size and do what you want

  uos_Play(MediaPlayer);
end;  

 // And the LoopProc in unmain:

procedure TForm1.LoopProc();
begin
 if Length(MemBuf)>8192*2 then
  begin

    // your analyses ...

    setlength(MemBuf,0); // release buffer
  end;  
end;
Reply | Threaded
Open this post in threaded view
|

Re[5]: Memory is not cleared

Andrey
Hello.
As they say, all ingenious is simple.
Only an error appeared:
 
« External:SIGSEGV
  In file ‘uos/uos.pas’ in line 8710:
Streamout[x].Data.BufferOut^[Streamout[x].Data.posmem+x2]:=StreamOut[x].Data.Buffer[x2]»
 
I tried to remove the setlength(MemBuf), the error disappears.
 
Суббота, 20 февраля 2021, 5:31 +05:00 от fredvs [via uos Forum] <[hidden email]>:
 
Hello.

In attachment your project with only one player.
I hope it is what you want.

Fre;DprDecoderAM_test_oneplayer.zip
 
If you reply to this email, your message will be added to the discussion below:
http://uos-forum.2369694.n4.nabble.com/Memory-is-not-cleared-tp805p813.html
To unsubscribe from Memory is not cleared, click here.
NAML
 
 
С уважением,
Андрей Батраков
[hidden email]
 
Reply | Threaded
Open this post in threaded view
|

Re: Re[5]: Memory is not cleared

fredvs
Administrator
Hello.

> External:SIGSEGV
>  In file ‘uos/uos.pas’ in line 8710:
>Streamout[x].Data.BufferOut^[Streamout[x].Data.posmem+x2]:=StreamOut[x].Data.Buffer[x2]»

I have seen that you used a old version of  uos.

Do you have problems with the last commit?
Reply | Threaded
Open this post in threaded view
|

Re[7]: Memory is not cleared

Andrey

You can link to the latest version?
 
Суббота, 20 февраля 2021, 17:53 +05:00 от fredvs [via uos Forum] <[hidden email]>:
 
Hello.

> External:SIGSEGV
>  In file ‘uos/uos.pas’ in line 8710:
>Streamout[x].Data.BufferOut^[Streamout[x].Data.posmem+x2]:=StreamOut[x].Data.Buffer[x2]»

I have seen that you used a old version of  uos.

Do you have problems with the last commit?

 
If you reply to this email, your message will be added to the discussion below:
http://uos-forum.2369694.n4.nabble.com/Memory-is-not-cleared-tp805p815.html
To unsubscribe from Memory is not cleared, click here.
NAML
 
 
С уважением,
Андрей Батраков
[hidden email]
 
Reply | Threaded
Open this post in threaded view
|

Re: Re[7]: Memory is not cleared

fredvs
Administrator

Andrey wrote
You can link to the latest version?
https://github.com/fredvs/uos

Click on the green button  [Code] then "Download ZIP".

Please tell me if you have still problems.

Fre;D
Reply | Threaded
Open this post in threaded view
|

Re: Re[7]: Memory is not cleared

fredvs
Administrator
This post was updated on .
Re-re....re hello Andrey.

> External:SIGSEGV
>  In file ‘uos/uos.pas’ in line 8710:
>Streamout[x].Data.BufferOut^[Streamout[x].Data.posmem+x2]:=StreamOut[x].Data.Buffer[x2]»

Ok, I see the problem.

Please give me one hour, I will fix it and then, please re-download the last commit.

Thanks.

Fre;D
Reply | Threaded
Open this post in threaded view
|

Re: Re[7]: Memory is not cleared

fredvs
Administrator
This post was updated on .
Hello.

OK, I did commit e445df3 with fix buffer-length change at run time..

Could you try with last changes and say the result?

https://github.com/fredvs/uos

Thanks.

[EDIT]

Maybe you have to test also the synchronize of "LoopProc".
With last fpc 3.2.0. it seems that thread.synchronize is not working well and it is better to use thread.queue.

So you may configure it depending on your system.
For that, just edit /uos/define.inc
and un-comment (remove the "." before "$") of that line:

{.$DEFINE usequeue}   // uncomment to use Thread.Queue instead of Thread.Synchronize for fpc threads, better for LCL widgets.

Maybe uos should define usequeue as default now.

Note also that when you are ready you may comment all the define that your project will not use.
Doing this, at compilation, only what your project need will be compiled.
Fre;D

Reply | Threaded
Open this post in threaded view
|

Re[9]: Memory is not cleared

Andrey

Hello, Fred.
 
I can only try on Wednesday. I'll write right away.
 
Суббота, 20 февраля 2021, 19:28 +05:00 от fredvs [via uos Forum] <[hidden email]>:
 
Hello.

OK, I did commit e445df3 with fix buffer-length change at run time..

Could you try with last changes and say the result?

https://github.com/fredvs/uos

Thanks.

Fre;D


 
If you reply to this email, your message will be added to the discussion below:
http://uos-forum.2369694.n4.nabble.com/Memory-is-not-cleared-tp805p819.html
To unsubscribe from Memory is not cleared, click here.
NAML
 
 
С уважением,
Андрей Батраков
[hidden email]
 
Reply | Threaded
Open this post in threaded view
|

Re[10]: Memory is not cleared

Andrey
Hello, Fred!
 
I checked it works. The memory does not grow, there are no errors.
Thank you so much. I will continue to test if I find anything I will write.
 
Воскресенье, 21 февраля 2021, 17:40 +05:00 от Andrey [via uos Forum] <[hidden email]>:
 

Hello, Fred.
 
I can only try on Wednesday. I'll write right away.
 
Суббота, 20 февраля 2021, 19:28 +05:00 от fredvs [via uos Forum] <[hidden email]>:
 
Hello.

OK, I did commit e445df3 with fix buffer-length change at run time..

Could you try with last changes and say the result?

https://github.com/fredvs/uos

Thanks.

Fre;D


 
If you reply to this email, your message will be added to the discussion below:
http://uos-forum.2369694.n4.nabble.com/Memory-is-not-cleared-tp805p819.html
To unsubscribe from Memory is not cleared, click here.
NAML
 
 
С уважением,
Андрей Батраков
[hidden email]
 
 
If you reply to this email, your message will be added to the discussion below:
http://uos-forum.2369694.n4.nabble.com/Memory-is-not-cleared-tp805p820.html
To unsubscribe from Memory is not cleared, click here.
NAML
 
 
С уважением,
Андрей Батраков
[hidden email]
 
Reply | Threaded
Open this post in threaded view
|

Re: Re[10]: Memory is not cleared

fredvs
Administrator
Hello Andrey.

I am happy that it works for you.

By the way, did you see the [EDIT] of my last post?
It was this:

Fredvs wrote
[EDIT]

Maybe you have to test also the synchronize of "LoopProc".
With last fpc 3.2.0. it seems that thread.synchronize is not working well and it is better to use thread.queue.

So you may configure it depending on your system.
For that, just edit /uos/define.inc
and un-comment (remove the "." before "$") of that line:

{.$DEFINE usequeue}   // uncomment to use Thread.Queue instead of Thread.Synchronize for fpc threads, better for LCL widgets.

Maybe uos should define usequeue as default now.

Note also that when you are ready you may comment all the define that your project will not use.
Doing this, at compilation, only what your project need will be compiled.