aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Game/Code/Classes/UAudioCore_Portaudio.pas99
-rw-r--r--Game/Code/UltraStar.dpr6
2 files changed, 101 insertions, 4 deletions
diff --git a/Game/Code/Classes/UAudioCore_Portaudio.pas b/Game/Code/Classes/UAudioCore_Portaudio.pas
new file mode 100644
index 00000000..952b211b
--- /dev/null
+++ b/Game/Code/Classes/UAudioCore_Portaudio.pas
@@ -0,0 +1,99 @@
+unit UAudioCore_Portaudio;
+
+interface
+
+{$IFDEF FPC}
+ {$MODE Delphi}
+{$ENDIF}
+
+{$I ../switches.inc}
+
+
+uses
+ Classes,
+ SysUtils,
+ portaudio;
+
+type
+ TAudioCore_Portaudio = class
+ public
+ class function GetPreferredApiIndex(): TPaHostApiIndex;
+ end;
+
+implementation
+
+uses
+ ULog;
+
+{*
+ * The default API used by Portaudio is the least common denominator
+ * and might lack efficiency. In addition it might not even work.
+ * We use an array named ApiPreferenceOrder with which we define the order of
+ * preferred APIs to use. The first API-type in the list is tried first.
+ * If it is not available the next one is tried and so on ...
+ * If none of the preferred APIs was found the default API (detected by
+ * portaudio) is used.
+ *
+ * Pascal does not permit zero-length static arrays, so you must use paDefaultApi
+ * as an array's only member if you do not have any preferences.
+ * You can also append paDefaultApi to a non-zero length preferences array but
+ * this is optional because the default API is always used as a fallback.
+ *}
+const
+ paDefaultApi = -1;
+const
+ ApiPreferenceOrder:
+{$IF Defined(MSWINDOWS)}
+ // Note1: Portmixer has no mixer support for paASIO and paWASAPI at the moment
+ // Note2: Windows Default-API is MME, but DirectSound is faster
+ array[0..0] of TPaHostApiTypeId = ( paDirectSound );
+{$ELSEIF Defined(LINUX)}
+ // Note: Portmixer has no mixer support for JACK at the moment
+ array[0..2] of TPaHostApiTypeId = ( paALSA, paJACK, paOSS );
+{$ELSEIF Defined(DARWIN)}
+ array[0..0] of TPaHostApiTypeId = ( paDefaultApi ); // paCoreAudio
+{$ELSE}
+ array[0..0] of TPaHostApiTypeId = ( paDefaultApi );
+{$IFEND}
+
+
+{ TAudioInput_Portaudio }
+
+class function TAudioCore_Portaudio.GetPreferredApiIndex(): TPaHostApiIndex;
+var
+ i: integer;
+ apiIndex: TPaHostApiIndex;
+ apiInfo: PPaHostApiInfo;
+begin
+ result := -1;
+
+ // select preferred sound-API
+ for i:= 0 to High(ApiPreferenceOrder) do
+ begin
+ if(ApiPreferenceOrder[i] <> paDefaultApi) then
+ begin
+ // check if API is available
+ apiIndex := Pa_HostApiTypeIdToHostApiIndex(ApiPreferenceOrder[i]);
+ if(apiIndex >= 0) then
+ begin
+ // we found an API but we must check if it works
+ // (on linux portaudio might detect OSS but does not provide
+ // any devices if ALSA is enabled)
+ apiInfo := Pa_GetHostApiInfo(apiIndex);
+ if (apiInfo^.deviceCount > 0) then
+ begin
+ Result := apiIndex;
+ break;
+ end;
+ end;
+ end;
+ end;
+
+ // None of the preferred APIs is available -> use default
+ if(result < 0) then
+ begin
+ result := Pa_GetDefaultHostApi();
+ end;
+end;
+
+end.
diff --git a/Game/Code/UltraStar.dpr b/Game/Code/UltraStar.dpr
index 55046af3..4acb5d1f 100644
--- a/Game/Code/UltraStar.dpr
+++ b/Game/Code/UltraStar.dpr
@@ -24,6 +24,7 @@ uses
{$ENDIF}
{$IFDEF UsePortaudio}
portaudio in 'lib\portaudio\delphi\portaudio.pas',
+ UAudioCore_Portaudio in 'Classes\UAudioCore_Portaudio.pas',
{$ENDIF}
{$IFDEF UsePortmixer}
portmixer in 'lib\portmixer\delphi\portmixer.pas',
@@ -127,7 +128,7 @@ uses
UPluginInterface in 'Classes\UPluginInterface.pas', //Interface offered by Core to Plugins
uPluginLoader in 'Classes\uPluginLoader.pas', //New Plugin Loader Module
- UParty in 'Classes\UParty.pas', // to - do : rewrite Party Manager as Module, reomplent ability to offer party Mody by Plugin
+ UParty in 'Classes\UParty.pas', // TODO: rewrite Party Manager as Module, reomplent ability to offer party Mody by Plugin
UPlatform in 'Classes\UPlatform.pas',
{$IFDEF WIN32}
UPlatformWindows in 'Classes\UPlatformWindows.pas',
@@ -233,9 +234,6 @@ uses
{$ENDIF}
SysUtils;
-const
- Version = 'UltraStar Deluxe V 1.10 Alpha Build';
-
{$IFNDEF FPC}
begin
Main;