From 1e0ab3b644f9ab911fde2962abd971b47cb33195 Mon Sep 17 00:00:00 2001 From: Alexander Droste Date: Wed, 14 Apr 2021 19:04:27 +0200 Subject: [PATCH] improve logging of portaudio + sdl audio latency --- src/media/UAudioInput_Portaudio.pas | 10 +++++++++- src/media/UAudioPlayback_Portaudio.pas | 3 +++ src/media/UAudioPlayback_SDL.pas | 5 ++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/media/UAudioInput_Portaudio.pas b/src/media/UAudioInput_Portaudio.pas index c547af85b..fcf2b1fd7 100644 --- a/src/media/UAudioInput_Portaudio.pas +++ b/src/media/UAudioInput_Portaudio.pas @@ -140,6 +140,7 @@ function TPortaudioInputDevice.Open(): boolean; Error: TPaError; inputParams: TPaStreamParameters; deviceInfo: PPaDeviceInfo; + StreamInfo : PPaStreamInfo; {$IFDEF UsePortmixer} SourceIndex: integer; {$ENDIF} @@ -160,7 +161,6 @@ function TPortaudioInputDevice.Open(): boolean; end; Log.LogStatus('Open ' + deviceInfo^.name, 'Portaudio'); - Log.LogStatus('Latency of ' + deviceInfo^.name + ': ' + floatToStr(inputParams.suggestedLatency), 'Portaudio'); // open input stream Error := Pa_OpenStream(RecordStream, @inputParams, nil, @@ -173,6 +173,14 @@ function TPortaudioInputDevice.Open(): boolean; Exit; end; + StreamInfo := Pa_GetStreamInfo(RecordStream); + if (StreamInfo <> nil) then + Log.LogStatus('Latency of ' + deviceInfo^.name + ': ' + + floatToStr(StreamInfo^.inputLatency * 1000) + + 'ms (requested: ' + + floatToStr(inputParams.suggestedLatency * 1000) + + 'ms)', 'Portaudio'); + {$IFDEF UsePortmixer} // open default mixer Mixer := Px_OpenMixer(RecordStream, 0); diff --git a/src/media/UAudioPlayback_Portaudio.pas b/src/media/UAudioPlayback_Portaudio.pas index 10f3ea5c8..72703a85e 100644 --- a/src/media/UAudioPlayback_Portaudio.pas +++ b/src/media/UAudioPlayback_Portaudio.pas @@ -143,6 +143,9 @@ function TAudioPlayback_Portaudio.OpenDevice(deviceIndex: TPaDeviceIndex): boole else Latency := 0; + Log.LogStatus('Audio-Output Latency: ' + floatToStr(Latency * 1000) + + 'ms', 'TAudioPlayback_Portaudio.OpenDevice'); + FormatInfo := TAudioFormatInfo.Create( OutParams.channelCount, SampleRate, diff --git a/src/media/UAudioPlayback_SDL.pas b/src/media/UAudioPlayback_SDL.pas index a4454a710..c65bf3905 100644 --- a/src/media/UAudioPlayback_SDL.pas +++ b/src/media/UAudioPlayback_SDL.pas @@ -142,7 +142,10 @@ function TAudioPlayback_SDL.InitializeAudioPlaybackEngine(): boolean; // So we use the average buffer-size. Latency := (ObtainedAudioSpec.samples/2) / FormatInfo.SampleRate; - Log.LogStatus('Opened audio device', 'TAudioPlayback_SDL.InitializeAudioPlaybackEngine'); + Log.LogStatus('Opened audio device, SampleBufferSize: ' + + IntToStr(ObtainedAudioSpec.samples) + '; SampleRate: ' + + FloatToStr(FormatInfo.SampleRate) + 'Hz', + 'TAudioPlayback_SDL.InitializeAudioPlaybackEngine'); Result := true; end;