aboutsummaryrefslogtreecommitdiffstats
path: root/Game/Code/Classes/UAudioPlayback_Portaudio.pas
diff options
context:
space:
mode:
authortobigun <tobigun@b956fd51-792f-4845-bead-9b4dfca2ff2c>2008-03-03 03:16:57 +0000
committertobigun <tobigun@b956fd51-792f-4845-bead-9b4dfca2ff2c>2008-03-03 03:16:57 +0000
commit6880109d9d38abfed6dececf863fdb7430fbb837 (patch)
tree4c04d9645071121185e69ebca50143b9b33cb46e /Game/Code/Classes/UAudioPlayback_Portaudio.pas
parenta022cbec1cb1245ab81bf008dd8835a860f38999 (diff)
downloadusdx-6880109d9d38abfed6dececf863fdb7430fbb837.tar.gz
usdx-6880109d9d38abfed6dececf863fdb7430fbb837.tar.xz
usdx-6880109d9d38abfed6dececf863fdb7430fbb837.zip
- Input now supports multiple SampleRates (not fixed to 44100Hz anymore)
- Input is not restricted to stereo input-devices anymore (mono and multi-channel devices work too) - Some improvements on the input-device detection - Retrieves native capture sample-rate on Vista and MacOSX with BASS (maybe this solves some problems with wrong sample-rates) - Capture-volume preview: a little modification to jay's approach. Now there are volume bars and pitch-displays. It needs some fine-tuning, maybe mog can do this if he likes. - Some indentation/clean-up/translations git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@900 b956fd51-792f-4845-bead-9b4dfca2ff2c
Diffstat (limited to 'Game/Code/Classes/UAudioPlayback_Portaudio.pas')
-rw-r--r--Game/Code/Classes/UAudioPlayback_Portaudio.pas38
1 files changed, 19 insertions, 19 deletions
diff --git a/Game/Code/Classes/UAudioPlayback_Portaudio.pas b/Game/Code/Classes/UAudioPlayback_Portaudio.pas
index 96fff957..0f4eb7ae 100644
--- a/Game/Code/Classes/UAudioPlayback_Portaudio.pas
+++ b/Game/Code/Classes/UAudioPlayback_Portaudio.pas
@@ -18,6 +18,7 @@ implementation
uses
portaudio,
+ UAudioCore_Portaudio,
UAudioPlayback_SoftMixer,
ULog,
UIni,
@@ -38,7 +39,7 @@ type
var
singleton_AudioPlaybackPortaudio : IAudioPlayback;
-
+
{ TAudioPlayback_Portaudio }
function PortaudioAudioCallback(input: Pointer; output: Pointer; frameCount: Longword;
@@ -59,44 +60,43 @@ end;
function TAudioPlayback_Portaudio.InitializeAudioPlaybackEngine(): boolean;
var
- paApi : TPaHostApiIndex;
+ paApiIndex : TPaHostApiIndex;
paApiInfo : PPaHostApiInfo;
paOutParams : TPaStreamParameters;
paOutDevice : TPaDeviceIndex;
paOutDeviceInfo : PPaDeviceInfo;
err : TPaError;
-const
- sampleFreq = 44100;
+ sampleRate : integer;
begin
result := false;
Pa_Initialize();
- // FIXME: determine automatically
- {$IFDEF WIN32}
- paApi := Pa_HostApiTypeIdToHostApiIndex(paDirectSound);
- {$ELSE}
- paApi := Pa_HostApiTypeIdToHostApiIndex(paALSA);
- {$ENDIF}
- if (paApi < 0) then
- begin
- Log.LogStatus('Pa_HostApiTypeIdToHostApiIndex: '+Pa_GetErrorText(paApi), 'UAudioPlayback_Portaudio');
- exit;
- end;
+ paApiIndex := TAudioCore_Portaudio.GetPreferredApiIndex();
+ if(paApiIndex = -1) then
+ begin
+ Log.LogError('No working Audio-API found', 'TAudioPlayback_Portaudio.InitializeAudioPlaybackEngine');
+ Exit;
+ end;
- paApiInfo := Pa_GetHostApiInfo(paApi);
+ paApiInfo := Pa_GetHostApiInfo(paApiIndex);
paOutDevice := paApiInfo^.defaultOutputDevice;
paOutDeviceInfo := Pa_GetDeviceInfo(paOutDevice);
+ if (paOutDeviceInfo^.defaultSampleRate > 0) then
+ sampleRate := Trunc(paOutDeviceInfo^.defaultSampleRate)
+ else
+ sampleRate := 44100;
+
with paOutParams do begin
device := paOutDevice;
channelCount := 2;
sampleFormat := paInt16;
- suggestedLatency := paOutDeviceInfo^.defaultHighOutputLatency;
+ suggestedLatency := paOutDeviceInfo^.defaultLowOutputLatency;
hostApiSpecificStreamInfo := nil;
end;
- err := Pa_OpenStream(paStream, nil, @paOutParams, sampleFreq,
+ err := Pa_OpenStream(paStream, nil, @paOutParams, sampleRate,
paFramesPerBufferUnspecified,
paNoFlag, @PortaudioAudioCallback, Self);
if(err <> paNoError) then begin
@@ -106,7 +106,7 @@ begin
FormatInfo := TAudioFormatInfo.Create(
paOutParams.channelCount,
- sampleFreq,
+ sampleRate,
asfS16 // FIXME: is paInt16 system-dependant or -independant?
);