summaryrefslogtreecommitdiff
path: root/src/portaudio-devices.adb
diff options
context:
space:
mode:
Diffstat (limited to 'src/portaudio-devices.adb')
-rw-r--r--src/portaudio-devices.adb389
1 files changed, 389 insertions, 0 deletions
diff --git a/src/portaudio-devices.adb b/src/portaudio-devices.adb
new file mode 100644
index 0000000..7e0e5e6
--- /dev/null
+++ b/src/portaudio-devices.adb
@@ -0,0 +1,389 @@
+
+
+-- Programmed by Jedidiah Barber
+-- Released into the public domain
+
+
+pragma Ada_2012;
+
+
+with
+
+ Interfaces.C.Strings,
+ System;
+
+use type
+
+ Interfaces.C.int,
+ System.Address;
+
+
+package body Portaudio.Devices is
+
+
+ ------------------------
+ -- Constants From C --
+ ------------------------
+
+ pa_no_device : constant Interfaces.C.int;
+ pragma Import (C, pa_no_device, "pa_no_device");
+
+
+
+
+ ------------------------
+ -- Functions From C --
+ ------------------------
+
+ function pa_get_host_api_count
+ return Interfaces.C.int;
+ pragma Import (C, pa_get_host_api_count, "Pa_GetHostApiCount");
+
+ function pa_get_default_host_api
+ return Interfaces.C.int;
+ pragma Import (C, pa_get_default_host_api, "Pa_GetDefaultHostApi");
+
+ function pa_get_host_api_info
+ (Index : in Interfaces.C.int)
+ return System.Address;
+ pragma Import (C, pa_get_host_api_info, "Pa_GetHostApiInfo");
+
+ function pa_host_api_type_id_to_host_api_index
+ (Kind : in Interfaces.C.int)
+ return Interfaces.C.int;
+ pragma Import (C, pa_host_api_type_id_to_host_api_index, "Pa_HostApiTypeIdToHostApiIndex");
+
+ function pa_host_api_device_index_to_device_index
+ (Host : in Interfaces.C.int;
+ Dev : in Interfaces.C.int)
+ return Interfaces.C.int;
+ pragma Import (C, pa_host_api_device_index_to_device_index,
+ "Pa_HostApiDeviceIndexToDeviceIndex");
+
+ function pa_get_device_count
+ return Interfaces.C.int;
+ pragma Import (C, pa_get_device_count, "Pa_GetDeviceCount");
+
+ function pa_get_default_input_device
+ return Interfaces.C.int;
+ pragma Import (C, pa_get_default_input_device, "Pa_GetDefaultInputDevice");
+
+ function pa_get_default_output_device
+ return Interfaces.C.int;
+ pragma Import (C, pa_get_default_output_device, "Pa_GetDefaultOutputDevice");
+
+ function pa_get_device_info
+ (Index : in Interfaces.C.int)
+ return System.Address;
+ pragma Import (C, pa_get_device_info, "Pa_GetDeviceInfo");
+
+
+
+
+ ---------------------------------
+ -- Data Types and Structures --
+ ---------------------------------
+
+ function Kind
+ (Info : in Host_API_Info)
+ return Host_API_Kind
+ is
+ Internal : C_Host_API_Info;
+ for Internal'Address use Info.Ptr;
+ pragma Import (Ada, Internal);
+ begin
+ return To_Hat_Kind (Internal.My_Host_API_Type);
+ end Kind;
+
+ function Name
+ (Info : in Host_API_Info)
+ return String
+ is
+ Internal : C_Host_API_Info;
+ for Internal'Address use Info.Ptr;
+ pragma Import (Ada, Internal);
+ begin
+ return Interfaces.C.Strings.Value (Internal.My_Name);
+ end Name;
+
+ function Device_Count
+ (Info : in Host_API_Info)
+ return Natural
+ is
+ Internal : C_Host_API_Info;
+ for Internal'Address use Info.Ptr;
+ pragma Import (Ada, Internal);
+ begin
+ return Natural (Internal.My_Device_Count);
+ end Device_Count;
+
+ function Default_Input_Device
+ (Info : in Host_API_Info)
+ return Device_Index
+ is
+ Internal : C_Host_API_Info;
+ for Internal'Address use Info.Ptr;
+ pragma Import (Ada, Internal);
+ begin
+ if Internal.My_Default_Input = pa_no_device then
+ return No_Device;
+ else
+ return Device_Index (Internal.My_Default_Input) + 1;
+ end if;
+ end Default_Input_Device;
+
+ function Default_Output_Device
+ (Info : in Host_API_Info)
+ return Device_Index
+ is
+ Internal : C_Host_API_Info;
+ for Internal'Address use Info.Ptr;
+ pragma Import (Ada, Internal);
+ begin
+ if Internal.My_Default_Output = pa_no_device then
+ return No_Device;
+ else
+ return Device_Index (Internal.My_Default_Output) + 1;
+ end if;
+ end Default_Output_Device;
+
+
+ function Name
+ (Info : in Device_Info)
+ return String
+ is
+ Internal : C_Device_Info;
+ for Internal'Address use Info.Ptr;
+ pragma Import (Ada, Internal);
+ begin
+ return Interfaces.C.Strings.Value (Internal.My_Name);
+ end Name;
+
+ function Host_API
+ (Info : in Device_Info)
+ return Host_API_Index
+ is
+ Internal : C_Device_Info;
+ for Internal'Address use Info.Ptr;
+ pragma Import (Ada, Internal);
+ begin
+ return Host_API_Index (Internal.My_Host_API_Index + 1);
+ end Host_API;
+
+ function Max_Input_Channels
+ (Info : in Device_Info)
+ return Natural
+ is
+ Internal : C_Device_Info;
+ for Internal'Address use Info.Ptr;
+ pragma Import (Ada, Internal);
+ begin
+ return Natural (Internal.My_Input_Channels);
+ end Max_Input_Channels;
+
+ function Max_Output_Channels
+ (Info : in Device_Info)
+ return Natural
+ is
+ Internal : C_Device_Info;
+ for Internal'Address use Info.Ptr;
+ pragma Import (Ada, Internal);
+ begin
+ return Natural (Internal.My_Output_Channels);
+ end Max_Output_Channels;
+
+ function Default_Low_Input_Latency
+ (Info : in Device_Info)
+ return Time
+ is
+ Internal : C_Device_Info;
+ for Internal'Address use Info.Ptr;
+ pragma Import (Ada, Internal);
+ begin
+ return Time (Internal.My_Low_Input_Latency);
+ end Default_Low_Input_Latency;
+
+ function Default_Low_Output_Latency
+ (Info : in Device_Info)
+ return Time
+ is
+ Internal : C_Device_Info;
+ for Internal'Address use Info.Ptr;
+ pragma Import (Ada, Internal);
+ begin
+ return Time (Internal.My_Low_Output_Latency);
+ end Default_Low_Output_Latency;
+
+ function Default_High_Input_Latency
+ (Info : in Device_Info)
+ return Time
+ is
+ Internal : C_Device_Info;
+ for Internal'Address use Info.Ptr;
+ pragma Import (Ada, Internal);
+ begin
+ return Time (Internal.My_High_Input_Latency);
+ end Default_High_Input_Latency;
+
+ function Default_High_Output_Latency
+ (Info : in Device_Info)
+ return Time
+ is
+ Internal : C_Device_Info;
+ for Internal'Address use Info.Ptr;
+ pragma Import (Ada, Internal);
+ begin
+ return Time (Internal.My_High_Output_Latency);
+ end Default_High_Output_Latency;
+
+ function Default_Sample_Rate
+ (Info : in Device_Info)
+ return Hertz
+ is
+ Internal : C_Device_Info;
+ for Internal'Address use Info.Ptr;
+ pragma Import (Ada, Internal);
+ begin
+ return Hertz (Internal.My_Sample_Rate);
+ end Default_Sample_Rate;
+
+
+
+
+ -----------------------
+ -- API Subprograms --
+ -----------------------
+
+ function Get_Host_API_Count
+ return Natural
+ is
+ Code : Interfaces.C.int;
+ begin
+ Code := pa_get_host_api_count;
+ if Code < 0 then
+ Raise_Error (Code);
+ raise Program_Error;
+ else
+ return Natural (Code);
+ end if;
+ end Get_Host_API_Count;
+
+ function Get_Default_Host_API
+ return Host_API_Index
+ is
+ Code : Interfaces.C.int;
+ begin
+ Code := pa_get_default_host_api;
+ if Code < 0 then
+ Raise_Error (Code);
+ raise Program_Error;
+ else
+ return Host_API_Index (Code) + 1;
+ end if;
+ end Get_Default_Host_API;
+
+ function Get_Host_API_Info
+ (Index : in Host_API_Index)
+ return Host_API_Info
+ is
+ Result : System.Address;
+ begin
+ Result := pa_get_host_api_info (Interfaces.C.int (Index) - 1);
+ if Result = System.Null_Address then
+ raise General_Failure;
+ else
+ return (Ptr => Result);
+ end if;
+ end Get_Host_API_Info;
+
+ function To_Host_API_Index
+ (Kind : in Host_API_Kind)
+ return Host_API_Index
+ is
+ Code : Interfaces.C.int;
+ begin
+ Code := pa_host_api_type_id_to_host_api_index (To_Cint (Kind));
+ if Code < 0 then
+ Raise_Error (Code);
+ raise Program_Error;
+ else
+ return Host_API_Index (Code) + 1;
+ end if;
+ end To_Host_API_Index;
+
+ function To_Device_Index
+ (Host_API : in Host_API_Index;
+ Host_Device : in Positive)
+ return Device_Index
+ is
+ Code : Interfaces.C.int;
+ begin
+ Code := pa_host_api_device_index_to_device_index
+ (Interfaces.C.int (Host_API) - 1,
+ Interfaces.C.int (Host_API) - 1);
+ if Code < 0 then
+ Raise_Error (Code);
+ raise Program_Error;
+ else
+ return Device_Index (Code + 1);
+ end if;
+ end To_Device_Index;
+
+ function Get_Device_Count
+ return Natural
+ is
+ Code : Interfaces.C.int;
+ begin
+ Code := pa_get_device_count;
+ if Code < 0 then
+ Raise_Error (Code);
+ raise Program_Error;
+ else
+ return Natural (Code);
+ end if;
+ end Get_Device_Count;
+
+ function Get_Default_Input_Device
+ return Device_Index
+ is
+ Code : Interfaces.C.int;
+ begin
+ Code := pa_get_default_input_device;
+ if Code = pa_no_device then
+ return No_Device;
+ else
+ return Device_Index (Code + 1);
+ end if;
+ end Get_Default_Input_Device;
+
+ function Get_Default_Output_Device
+ return Device_Index
+ is
+ Code : Interfaces.C.int;
+ begin
+ Code := pa_get_default_output_device;
+ if Code = pa_no_device then
+ return No_Device;
+ else
+ return Device_Index (Code + 1);
+ end if;
+ end Get_Default_Output_Device;
+
+ function Get_Device_Info
+ (Index : in Device_Index)
+ return Device_Info
+ is
+ Result : System.Address;
+ begin
+ Result := pa_get_device_info (Interfaces.C.int (Index) - 1);
+ if Result = System.Null_Address then
+ raise General_Failure;
+ else
+ return (Ptr => Result);
+ end if;
+ end Get_Device_Info;
+
+
+end Portaudio.Devices;
+
+