Giter VIP home page Giter VIP logo

Comments (10)

fredvs avatar fredvs commented on August 25, 2024

Hello.

What do you want to do ?
Wav-file needs a special wav header at begin of file, with some infos like resolution, sample-rate, duration,...

Fre;D

from uos.

akatser avatar akatser commented on August 25, 2024

I want to save input in wave file for a long time. In example SimpleRecorder input stream writes to memory and after stop saves to file. So, recording of one hour uses lots of memory. I want to write buffer to wave file directly.
Wave header is not problem :)

from uos.

fredvs avatar fredvs commented on August 25, 2024

Hello.
When recording, the buffer is saved in a temporally file.
Recording hours uses a big temporally file but not lot of RAM.

from uos.

akatser avatar akatser commented on August 25, 2024

Hi, please check my code:

unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  uos_flat, LazUTF8;

type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    ComboBox1: TComboBox;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1;
  s1,s2 : string;
  PlayerIndex1: cardinal;
  In1Index : integer;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.FormCreate(Sender: TObject);
var x:integer;
begin
  {$IFDEF Windows}
{$if defined(cpu64)}
s1 := application.Location + 'lib\Windows\64bit\LibPortaudio-64.dll';
s2 := application.Location + 'lib\Windows\64bit\LibSndFile-64.dll';
{$else}
s1 := application.Location + 'lib\Windows\32bit\LibPortaudio-32.dll';
s2 := application.Location + 'lib\Windows\32bit\LibSndFile-32.dll';
{$endif}
{$ENDIF}
 x:=0;
uos_LoadLib(Pchar(s1), pchar(s2), nil, nil, nil);
uos_GetInfoDevice();
while x < UOSDeviceCount do
    begin

      if   (uosDeviceInfos[x].ChannelsIn > 0) and (uosDeviceInfos[x].HostAPIName = 'MME') then
            ComboBox1.Items.Add(IntToStr(uosDeviceInfos[x].DeviceNum)+ '-'+  SysToUTF8(uosDeviceInfos[x].DeviceName));
      inc(X);
    end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
PlayerIndex1 := 0;
  uos_CreatePlayer(PlayerIndex1);
  uos_addIntoFile(PlayerIndex1, Pchar('d:\temp\test.wav') ,44100,2,2,-1 );
  In1Index := uos_AddFromDevIn(PlayerIndex1, 2, -1, -1, -1,-1, 4096);
  uos_Play(PlayerIndex1);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  uos_Stop(PlayerIndex1);
end;

end.

This is RAM usage after 12 min of recording :
logger2

This is RAM usage after stop button click :
logger3

from uos.

fredvs avatar fredvs commented on August 25, 2024

Indeed, lot of ram are used.

Does the ram used increase with time or is it stable to 1,2 gigas ?

What if you use cmem (memory manager) instead ?

`unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  cmem, // C memory manager
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  uos_flat, LazUTF8;`

from uos.

akatser avatar akatser commented on August 25, 2024

App can't comlile with cmem
image

Used ram increases with time when recording in on.

from uos.

fredvs avatar fredvs commented on August 25, 2024

cmem must be the first unit of the main code (program).
Tested SimpleRecorder on Windows 10 with cmem and no problem here.

Used ram increases with time when recording in on.

It is normal that recording uses lot of ram.
For latency it will try to use the most ram possible to access less time the disk.
The question was, is all the ram is used, does it still does recording ?
Fre;D

from uos.

akatser avatar akatser commented on August 25, 2024

Hi, after one hour of recording (with cmem and without) programm crashes.

Error string is :
StreamOut[x].Data.Buffer[0], StreamIn[x2].Data.outframes * StreamIn[x2].Data.Channels * rat);

from uos.

fredvs avatar fredvs commented on August 25, 2024

Hello.

Could you try with last commit da316a2..5f11b62 ?

Thanks.

from uos.

fredvs avatar fredvs commented on August 25, 2024

Hello.

Thanks to Phoenix fixed bug in uos_AddIntoFile() --> for recording using TFileStream.
--> max length = Available free-space-disk.

Added also uos_AddIntoFileFromMem() --> --> for recording using TMemoryStream.
--> max length = Available RAM (but it could have a better latency).

All this in last commit: de823d5..af9530b.
Fre;D

from uos.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.