-- Programmed by Jedidiah Barber -- Released into the public domain pragma Ada_2012; private with Ada.Finalization, Interfaces.C.Strings, System.Storage_Elements; package Portaudio is --------------------------------- -- Data Types and Structures -- --------------------------------- type Version_Number is record Major : Natural; Minor : Natural; Subminor : Natural; end record; function "<" (A, B : in Version_Number) return Boolean; function Image (Num : in Version_Number) return String; type Version_Info is tagged private; function Major (Version : in Version_Info) return Natural; function Minor (Version : in Version_Info) return Natural; function Subminor (Version : in Version_Info) return Natural; function Revision (Version : in Version_Info) return String; function Text (Version : in Version_Info) return String; type Host_API_Kind is (In_Development, Direct_Sound_Host, MME_Host, ASIO_Host, Sound_Manager_Host, Core_Audio_Host, OSS_Host, ALSA_Host, AL_Host, BeOS_Host, WDMKS_Host, JACK_Host, WASAPI_Host, Audio_Science_HPI_Host, Sndio_Host); type Host_API_Index is new Positive; type Device_Index is new Natural; No_Device : constant Device_Index; type Time is delta 10.0**(-4) digits 12; function Image (Num : in Time) return String; subtype Hertz is Long_Float with Static_Predicate => Hertz >= 0.0; function Hertz_Image (Num : in Hertz) return String; subtype Load is Long_Float with Static_Predicate => Load >= 0.0; function Load_Image (Num : in Load) return String; ------------------ -- Exceptions -- ------------------ Not_Initialized_Error : exception; Unanticipated_Host_Error : exception; Invalid_Channel_Count_Error : exception; Invalid_Sample_Rate_Error : exception; Invalid_Device_Error : exception; Invalid_Flag_Error : exception; Sample_Format_Not_Supported_Error : exception; Bad_IO_Device_Combination_Error : exception; Buffer_Too_Big_Error : exception; Buffer_Too_Small_Error : exception; Null_Callback_Error : exception; Bad_Stream_Pointer_Error : exception; Timed_Out_Error : exception; Internal_Error : exception; Device_Unavailable_Error : exception; Incompatible_Host_API_Specific_Stream_Info_Error : exception; Stream_Is_Stopped_Error : exception; Stream_Is_Not_Stopped_Error : exception; Input_Overflowed_Error : exception; Output_Underflowed_Error : exception; Host_API_Not_Found_Error : exception; Invalid_Host_API_Error : exception; Can_Not_Read_From_A_Callback_Stream_Error : exception; Can_Not_Write_To_A_Callback_Stream_Error : exception; Can_Not_Read_From_An_Output_Only_Stream_Error : exception; Can_Not_Write_To_An_Input_Only_Stream_Error : exception; Incompatible_Stream_Host_API_Error : exception; Bad_Buffer_Pointer_Error : exception; Can_Not_Initialize_Recursively_Error : exception; General_Failure : exception; ----------------------- -- API Subprograms -- ----------------------- function Get_Version return Version_Number; function Get_Version_Info return Version_Info; private package Storage renames System.Storage_Elements; use type Interfaces.C.size_t, Storage.Integer_Address; Null_Pointer : constant Storage.Integer_Address := Storage.To_Integer (System.Null_Address); pragma Linker_Options ("-lportaudio"); function c_pointer_size return Interfaces.C.size_t; pragma Import (C, c_pointer_size, "c_pointer_size"); -- If this fails then we are on an architecture that for whatever reason -- has significant problems interfacing between C and Ada pragma Assert (c_pointer_size * Interfaces.C.CHAR_BIT = Storage.Integer_Address'Size, "Size of C void pointers and size of Ada address values do not match"); type C_Version_Info is record My_Major : Interfaces.C.int; My_Minor : Interfaces.C.int; My_Subminor : Interfaces.C.int; My_Revision : Interfaces.C.Strings.chars_ptr; My_Text : Interfaces.C.Strings.chars_ptr; end record with Convention => C; type Version_Info is tagged record Ptr : System.Address; end record; type C_Host_Error_Info is record My_Host_API_Type : Interfaces.C.int; My_Error_Code : Interfaces.C.long; My_Error_Text : Interfaces.C.Strings.chars_ptr; end record with Convention => C; No_Device : constant Device_Index := 0; pa_no_error : constant Interfaces.C.int; pragma Import (C, pa_no_error, "pa_no_error"); procedure Raise_Error (Num : in Interfaces.C.int); function To_Hat_Kind (Num : in Interfaces.C.int) return Host_API_Kind; function To_Cint (Ident : in Host_API_Kind) return Interfaces.C.int; -- The clunky way of ensuring that PortAudio is always shut down properly type Final_Controller is new Ada.Finalization.Controlled with null record; overriding procedure Finalize (This : in out Final_Controller); Cleanup : Final_Controller; end Portaudio;