aboutsummaryrefslogtreecommitdiffstats
path: root/Game/Code/Classes/UAudioInput_Portaudio.pas
diff options
context:
space:
mode:
authortobigun <tobigun@b956fd51-792f-4845-bead-9b4dfca2ff2c>2008-04-10 15:04:18 +0000
committertobigun <tobigun@b956fd51-792f-4845-bead-9b4dfca2ff2c>2008-04-10 15:04:18 +0000
commit596265628f267cd0d91f6e834a0f78c591cd8a3e (patch)
tree67fc18e2b457b270b73a4739cb37998dea249f99 /Game/Code/Classes/UAudioInput_Portaudio.pas
parentde19222a6fc53d455a91a8e5c8c99c080408392b (diff)
downloadusdx-596265628f267cd0d91f6e834a0f78c591cd8a3e.tar.gz
usdx-596265628f267cd0d91f6e834a0f78c591cd8a3e.tar.xz
usdx-596265628f267cd0d91f6e834a0f78c591cd8a3e.zip
workaround for erroneously detection of 48000Hz-only devices as 44100Hz devices in portaudio
git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1017 b956fd51-792f-4845-bead-9b4dfca2ff2c
Diffstat (limited to 'Game/Code/Classes/UAudioInput_Portaudio.pas')
-rw-r--r--Game/Code/Classes/UAudioInput_Portaudio.pas66
1 files changed, 13 insertions, 53 deletions
diff --git a/Game/Code/Classes/UAudioInput_Portaudio.pas b/Game/Code/Classes/UAudioInput_Portaudio.pas
index 2883ccb0..90ac41b1 100644
--- a/Game/Code/Classes/UAudioInput_Portaudio.pas
+++ b/Game/Code/Classes/UAudioInput_Portaudio.pas
@@ -145,7 +145,7 @@ var
inputParams: TPaStreamParameters;
stream: PPaStream;
streamInfo: PPaStreamInfo;
- sampleRate: integer;
+ sampleRate: double;
latency: TPaTime;
{$IFDEF UsePortmixer}
sourceIndex: integer;
@@ -206,10 +206,7 @@ begin
paDevice.Description := deviceName;
paDevice.PaDeviceIndex := deviceIndex;
- if (deviceInfo^.defaultSampleRate > 0) then
- sampleRate := Trunc(deviceInfo^.defaultSampleRate)
- else
- sampleRate := 44100;
+ sampleRate := deviceInfo^.defaultSampleRate;
// on vista and xp the defaultLowInputLatency may be set to 0 but it works.
// TODO: correct too low latencies (what is a too low latency, maybe < 10ms?)
@@ -225,21 +222,17 @@ begin
hostApiSpecificStreamInfo := nil;
end;
- // check if device supports our input-format
- // TODO: retry with input-latency set to 20ms (defaultLowInputLatency might
- // not be set correctly in OSS)
- err := Pa_IsFormatSupported(@inputParams, nil, sampleRate);
- if(err <> 0) then
+ // check souncard and adjust sample-rate
+ if (not TAudioCore_Portaudio.TestDevice(@inputParams, nil, sampleRate)) then
begin
- // format not supported -> skip
- errMsg := Pa_GetErrorText(err);
- Log.LogError('Device error: "'+ deviceName +'" ('+ errMsg +')',
- 'TAudioInput_Portaudio.InitializeRecord');
+ // ignore device if it does not work
+ Log.LogError('Device "'+paDevice.Description+'" does not work',
+ 'TAudioInput_Portaudio.EnumDevices');
paDevice.Free();
continue;
end;
- // check if the device really works
+ // open device for further info
err := Pa_OpenStream(stream, @inputParams, nil, sampleRate,
paFramesPerBufferUnspecified, paNoFlag, @MicrophoneTestCallback, nil);
if(err <> paNoError) then
@@ -247,40 +240,7 @@ begin
// unable to open device -> skip
errMsg := Pa_GetErrorText(err);
Log.LogError('Device error: "'+ deviceName +'" ('+ errMsg +')',
- 'TAudioInput_Portaudio.InitializeRecord');
- paDevice.Free();
- continue;
- end;
-
-
- // check if mic-callback works (might not be called on some devices)
-
- // start the callback
- Pa_StartStream(stream);
-
- cbWorks := false;
- // check if the callback was called (poll for max. 200ms)
- for cbPolls := 1 to 20 do
- begin
- // if the test-callback was called it should be aborted now
- if (Pa_IsStreamActive(stream) = 0) then
- begin
- cbWorks := true;
- break;
- end;
- // not yet aborted, wait and try (poll) again
- Pa_Sleep(10);
- end;
-
- // finally abort the stream (Note: Pa_StopStream might hang here)
- Pa_AbortStream(stream);
-
- // ignore device if callback did not work
- if (not cbWorks) then
- begin
- Log.LogError('Device "'+paDevice.Description+'" does not respond',
- 'TAudioInput_Portaudio.InitializeRecord');
- Pa_CloseStream(stream);
+ 'TAudioInput_Portaudio.EnumDevices');
paDevice.Free();
continue;
end;
@@ -289,12 +249,12 @@ begin
streamInfo := Pa_GetStreamInfo(stream);
if (streamInfo <> nil) then
begin
- if (sampleRate <> Trunc(streamInfo^.sampleRate)) then
+ if (sampleRate <> streamInfo^.sampleRate) then
begin
- Log.LogStatus('Portaudio changed Samplerate from ' + IntToStr(sampleRate) +
+ Log.LogStatus('Portaudio changed Samplerate from ' + FloatToStr(sampleRate) +
' to ' + FloatToStr(streamInfo^.sampleRate),
'TAudioInput_Portaudio.InitializeRecord');
- sampleRate := Trunc(streamInfo^.sampleRate);
+ sampleRate := streamInfo^.sampleRate;
end;
end;
@@ -308,7 +268,7 @@ begin
Log.LogStatus('InputDevice "'+paDevice.Description+'"@' +
IntToStr(paDevice.AudioFormat.Channels)+'x'+
- IntToStr(paDevice.AudioFormat.SampleRate)+'Hz ('+
+ FloatToStr(paDevice.AudioFormat.SampleRate)+'Hz ('+
FloatTostr(inputParams.suggestedLatency)+'sec)' ,
'Portaudio.InitializeRecord');