summaryrefslogtreecommitdiff
path: root/src/portaudio.ads
blob: 282f99465f3c4c2ba858ef8186dc6bf00fcd0b3c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264


--  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;