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; |
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 |
Administrator
|
Re-hello.
I cannot reproduce your problem. Please attach a zip file of a simple project that shows the problem. Thanks. Fre;D |
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]>: |
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]>: К этому письму приложены ссылки на следующие файлы: 1. prDecoderAM_test[1].tar (34.6 Мб) Ссылка для скачивания файлов: https://cloud.mail.ru/stock/6ivPjW9kpxas5CdUi3GPv9VE Файлы будут храниться до 18.08.2021 |
Administrator
|
Hello Andrey.
OK, I will check your code this week-end. Write you later. Fre;D |
Administrator
|
This post was updated on .
CONTENTS DELETED
The author has deleted this message.
|
Administrator
|
This post was updated on .
CONTENTS DELETED
The author has deleted this message.
|
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; |
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]>: |
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? |
You can link to the latest version? Суббота, 20 февраля 2021, 17:53 +05:00 от fredvs [via uos Forum] <[hidden email]>: |
Administrator
|
https://github.com/fredvs/uos Click on the green button [Code] then "Download ZIP". Please tell me if you have still problems. Fre;D |
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 |
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 |
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, 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]>: |
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:
|
Free forum by Nabble | Edit this page |