From 6880109d9d38abfed6dececf863fdb7430fbb837 Mon Sep 17 00:00:00 2001 From: tobigun Date: Mon, 3 Mar 2008 03:16:57 +0000 Subject: - 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 --- Game/Code/Classes/UAudioPlayback_Portaudio.pas | 38 +++++++++++++------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'Game/Code/Classes/UAudioPlayback_Portaudio.pas') 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? ); -- cgit v1.2.3