refactoring SettingsForm

This commit is contained in:
2026-04-25 14:50:52 +03:00
parent 4c48f22447
commit 537d288e1e
6 changed files with 710 additions and 512 deletions
+47 -7
View File
@@ -15,6 +15,7 @@ unit AudioOutput;
{$IFDEF FPC}
{$MODE Delphi}
{$PACKRECORDS C}
{$ENDIF}
interface
@@ -166,9 +167,13 @@ const
'libportaudio.so.0'
);
{$ELSE}
PA_LIBS: array[0..1] of AnsiString = (
PA_LIBS: array[0..5] of AnsiString = (
'portaudio_x64.dll',
'portaudio.dll'
'portaudio_x86.dll',
'portaudio.dll',
'libportaudio-2.dll',
'libportaudio.dll',
'libportaudio64.dll'
);
{$ENDIF}
PA_NO_ERROR = 0;
@@ -282,7 +287,11 @@ begin
if FLibHandle = NilHandle then
begin
{$IFDEF WINDOWS}
FLastError := 'PortAudio DLL not found. Put portaudio_x64.dll, portaudio.dll, or libportaudio-2.dll next to ewsdr.exe';
{$ELSE}
FLastError := 'libportaudio not found. sudo apt install libportaudio2';
{$ENDIF}
Exit;
end;
@@ -297,7 +306,16 @@ begin
FPa_CloseStream := TPa_CloseStream(GetProcAddress(FLibHandle, 'Pa_CloseStream'));
FPa_GetErrorText := TPa_GetErrorText(GetProcAddress(FLibHandle, 'Pa_GetErrorText'));
if not Assigned(FPa_Initialize) or not Assigned(FPa_OpenStream) then
if not Assigned(FPa_Initialize) or
not Assigned(FPa_Terminate) or
not Assigned(FPa_GetDefaultOutputDevice) or
not Assigned(FPa_GetDeviceCount) or
not Assigned(FPa_GetDeviceInfo) or
not Assigned(FPa_OpenStream) or
not Assigned(FPa_StartStream) or
not Assigned(FPa_StopStream) or
not Assigned(FPa_CloseStream) or
not Assigned(FPa_GetErrorText) then
begin
FLastError := 'libportaudio: symbols not found';
FreeLibrary(FLibHandle);
@@ -350,10 +368,27 @@ begin
Count := 0;
Result := False;
if not Initialize then Exit;
if not Assigned(FPa_GetDeviceCount) or not Assigned(FPa_GetDeviceInfo) then Exit;
if not Assigned(FPa_GetDeviceCount) or not Assigned(FPa_GetDeviceInfo) then
begin
FLastError := 'PortAudio device enumeration is not available';
Exit;
end;
N := FPa_GetDeviceCount();
if N <= 0 then Exit;
if N < 0 then
begin
FLastError := 'Pa_GetDeviceCount: ';
if Assigned(FPa_GetErrorText) then
FLastError := FLastError + string(FPa_GetErrorText(N))
else
FLastError := FLastError + IntToStr(N);
Exit;
end;
if N = 0 then
begin
FLastError := 'No PortAudio devices found';
Exit;
end;
for I := 0 to N - 1 do
begin
@@ -416,6 +451,7 @@ var
OutParam: TPaStreamParameters;
Err: TPaError;
Dev: TPaDeviceIndex;
Info: PPaDeviceInfo;
begin
Result := False;
if FOpen then begin Result := True; Exit; end;
@@ -441,8 +477,12 @@ begin
OutParam.hostApiSpecificStreamInfo := nil;
OutParam.sampleFormat := PA_FLOAT32;
{$IFDEF WINDOWS}
// На Windows latency=0 вызывает фризы — используем разумный минимум
OutParam.suggestedLatency := 0.050; // 50ms — стабильно на Windows WASAPI/MME
// На Windows latency=0 часто ломает WASAPI/MME; берём значение от устройства.
Info := FPa_GetDeviceInfo(Dev);
if (Info <> nil) and (Info^.defaultLowOutputLatency > 0.0) then
OutParam.suggestedLatency := Info^.defaultLowOutputLatency
else
OutParam.suggestedLatency := 0.050;
{$ELSE}
OutParam.suggestedLatency := 0.0; // на Linux ALSA справляется с минимумом
{$ENDIF}