Add audio buffer setting and optimize overlays

This commit is contained in:
2026-05-22 18:07:05 +03:00
parent 26aa55ddde
commit c5f225332b
6 changed files with 327 additions and 38 deletions
+15 -3
View File
@@ -10,7 +10,7 @@ unit AudioOutput;
- Callback читает по одному сэмплу, обновляет outpt внутри цикла
- Low water mark: вставляет тишину + полбуфера silence
- High water mark: удаляет лишние сэмплы
- MY_AUDIO_BUFFER_SIZE = 128 frames (низкая латентность)
- output buffer size defaults to 128 frames (низкая латентность)
}
{$IFDEF FPC}
@@ -24,7 +24,7 @@ uses
Classes, SysUtils, Math, SyncObjs, DynLibs;
const
MY_AUDIO_BUFFER_SIZE = 128; // PA frames per callback — как piHPSDR
MY_AUDIO_BUFFER_SIZE = 128; // default PA frames per callback — как piHPSDR
MY_RING_BUFFER_SIZE = 9600; // как piHPSDR
MY_RING_LOW_WATER = 512; // как piHPSDR
MY_RING_HIGH_WATER = 9000; // как piHPSDR
@@ -95,6 +95,7 @@ type
FLibHandle: TLibHandle;
FStream: TPaStream;
FSampleRate: Integer;
FOutputBufferSize: Integer;
FOpen: Boolean;
FPAInited: Boolean; // Pa_Initialize прошла
FLastError: string;
@@ -120,6 +121,7 @@ type
function LoadLib: Boolean;
function GetLastError: string;
procedure SetOutputBufferSize(V: Integer);
public
constructor Create(SampleRate: Integer = 48000);
@@ -148,6 +150,7 @@ type
property LastError: string read GetLastError;
property DeviceIndex: Integer read FDeviceIndex write FDeviceIndex;
property SampleRate: Integer read FSampleRate write FSampleRate;
property OutputBufferSize: Integer read FOutputBufferSize write SetOutputBufferSize;
end;
// Глобальный callback (cdecl, не метод)
@@ -239,6 +242,7 @@ constructor TAudioOutput.Create(SampleRate: Integer);
begin
inherited Create;
FSampleRate := SampleRate;
FOutputBufferSize := MY_AUDIO_BUFFER_SIZE;
FDeviceIndex := -1; // -1 = default output device
FOpen := False;
FPAInited := False;
@@ -493,7 +497,7 @@ begin
nil, // no input
@OutParam,
FSampleRate,
MY_AUDIO_BUFFER_SIZE, // 128 frames как в оригинале
FOutputBufferSize,
PA_NO_FLAG,
@PaOutCallback,
Self
@@ -531,6 +535,14 @@ begin
Result := True;
end;
procedure TAudioOutput.SetOutputBufferSize(V: Integer);
begin
if V <= 128 then V := 128
else if V <= 256 then V := 256
else V := 512;
FOutputBufferSize := V;
end;
procedure TAudioOutput.Close;
begin
if not FOpen then Exit;