diff options
Diffstat (limited to 'Game/Code/Classes/UAudioPlayback_Portaudio.pas')
-rw-r--r-- | Game/Code/Classes/UAudioPlayback_Portaudio.pas | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/Game/Code/Classes/UAudioPlayback_Portaudio.pas b/Game/Code/Classes/UAudioPlayback_Portaudio.pas index 0f4eb7ae..431fbd43 100644 --- a/Game/Code/Classes/UAudioPlayback_Portaudio.pas +++ b/Game/Code/Classes/UAudioPlayback_Portaudio.pas @@ -66,27 +66,24 @@ var paOutDevice : TPaDeviceIndex;
paOutDeviceInfo : PPaDeviceInfo;
err : TPaError;
- sampleRate : integer;
+ sampleRate : double;
begin
result := false;
Pa_Initialize();
paApiIndex := TAudioCore_Portaudio.GetPreferredApiIndex();
- if(paApiIndex = -1) then - begin - Log.LogError('No working Audio-API found', 'TAudioPlayback_Portaudio.InitializeAudioPlaybackEngine'); - Exit; - end; + if(paApiIndex = -1) then
+ begin
+ Log.LogError('No working Audio-API found', 'TAudioPlayback_Portaudio.InitializeAudioPlaybackEngine');
+ Exit;
+ end;
paApiInfo := Pa_GetHostApiInfo(paApiIndex);
paOutDevice := paApiInfo^.defaultOutputDevice;
paOutDeviceInfo := Pa_GetDeviceInfo(paOutDevice);
- if (paOutDeviceInfo^.defaultSampleRate > 0) then
- sampleRate := Trunc(paOutDeviceInfo^.defaultSampleRate)
- else
- sampleRate := 44100;
+ sampleRate := paOutDeviceInfo^.defaultSampleRate;
with paOutParams do begin
device := paOutDevice;
@@ -96,14 +93,24 @@ begin hostApiSpecificStreamInfo := nil;
end;
+ // check souncard and adjust sample-rate
+ if not TAudioCore_Portaudio.TestDevice(nil, @paOutParams, sampleRate) then
+ begin
+ Log.LogStatus('TestDevice failed!', 'TAudioPlayback_Portaudio.OpenDevice');
+ exit;
+ end;
+
+ // open output stream
err := Pa_OpenStream(paStream, nil, @paOutParams, sampleRate,
paFramesPerBufferUnspecified,
paNoFlag, @PortaudioAudioCallback, Self);
- if(err <> paNoError) then begin
- Log.LogStatus('Pa_OpenStream: '+Pa_GetErrorText(err), 'UAudioPlayback_Portaudio');
+ if(err <> paNoError) then
+ begin
+ Log.LogStatus(Pa_GetErrorText(err), 'TAudioPlayback_Portaudio.OpenDevice');
+ paStream := nil;
exit;
end;
-
+
FormatInfo := TAudioFormatInfo.Create(
paOutParams.channelCount,
sampleRate,
|