summaryrefslogtreecommitdiff
path: root/src/libao.ads
diff options
context:
space:
mode:
authorJedidiah Barber <contact@jedbarber.id.au>2024-09-16 12:25:41 +1200
committerJedidiah Barber <contact@jedbarber.id.au>2024-09-16 12:25:41 +1200
commit87e42e46a5d898698ad5cbcd71b3877d2c319084 (patch)
tree5416594999b269e4890e0cb8a0d1c66a4f48a383 /src/libao.ads
parenta9a297e8f7282bcc9b3ffb14862160bb1abad511 (diff)
Off-by-one bugs fixed, more testing programs, change to Integer_AddressHEADmaster
Diffstat (limited to 'src/libao.ads')
-rw-r--r--src/libao.ads94
1 files changed, 76 insertions, 18 deletions
diff --git a/src/libao.ads b/src/libao.ads
index db5f7ce..c2013c5 100644
--- a/src/libao.ads
+++ b/src/libao.ads
@@ -16,7 +16,7 @@ private with
Ada.Finalization,
Ada.Containers.Vectors,
Interfaces.C.Strings,
- System;
+ System.Storage_Elements;
package Libao is
@@ -58,7 +58,7 @@ package Libao is
function Priority_Level
(Attributes : in Info)
- return Positive;
+ return Natural;
function Comment
(Attributes : in Info)
@@ -78,19 +78,54 @@ package Libao is
Empty_Options : constant Option_List;
+ function Length
+ (Options : in Option_List)
+ return Natural;
+
+ function Key
+ (Options : in Option_List;
+ Index : in Positive)
+ return String;
+
+ function Value
+ (Options : in Option_List;
+ Index : in Positive)
+ return String;
+
type Sample_Format is tagged private;
type Channel_Mnemonic is (L, R, C, M, CL, CR, BL, BR, BC, SL, SR, LFE, A1, A2, A3, A4, X);
type Mnemonic_Array is array (Positive range <>) of Channel_Mnemonic;
+ Stereo : constant Mnemonic_Array := (L, R);
+ Quadraphonic : constant Mnemonic_Array := (L, R, BL, BR);
+
function Create
(Bits, Rate, Channels : in Positive;
Byte_Format : in Endianness;
Channel_Matrix : in Mnemonic_Array)
- return Sample_Format;
+ return Sample_Format
+ with Pre => Channel_Matrix'Length = Channels;
- Stereo : constant Mnemonic_Array := (L, R);
- Quadraphonic : constant Mnemonic_Array := (L, R, BL, BR);
+ function Bits
+ (Format : in Sample_Format)
+ return Positive;
+
+ function Rate
+ (Format : in Sample_Format)
+ return Positive;
+
+ function Channels
+ (Format : in Sample_Format)
+ return Positive;
+
+ function Byte_Format
+ (Format : in Sample_Format)
+ return Endianness;
+
+ function Channel_Matrix
+ (Format : in Sample_Format)
+ return Mnemonic_Array;
@@ -211,33 +246,61 @@ package Libao is
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 ("-lao");
+ 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");
+
+
for Data_Buffer'Component_Size use Interfaces.C.CHAR_BIT;
+ package Address_Vectors is new Ada.Containers.Vectors
+ (Index_Type => Positive,
+ Element_Type => Storage.Integer_Address,
+ "=" => Storage."=");
+
+
procedure Do_Append
- (Ptr : in out System.Address;
- Key : in Interfaces.C.char_array;
- Value : in Interfaces.C.char_array);
+ (Ptr_List : in out Address_Vectors.Vector;
+ Key : in Interfaces.C.char_array;
+ Value : in Interfaces.C.char_array);
procedure Do_Close
- (Ptr : in System.Address);
+ (Ptr : in Storage.Integer_Address);
+
+ function Head_Pointer
+ (This : in Address_Vectors.Vector)
+ return Storage.Integer_Address;
type Device is tagged record
- Ptr : System.Address := System.Null_Address;
+ Ptr : Storage.Integer_Address := Null_Pointer;
end record;
type Info is tagged record
- Ptr : System.Address := System.Null_Address;
+ Ptr : Storage.Integer_Address := Null_Pointer;
end record;
type Option_List is new Ada.Finalization.Controlled with record
- Ptr : System.Address := System.Null_Address;
+ Ptr_List : Address_Vectors.Vector := Address_Vectors.Empty_Vector;
end record;
overriding procedure Adjust
@@ -247,7 +310,7 @@ private
(This : in out Option_List);
Empty_Options : constant Option_List :=
- (Ada.Finalization.Controlled with Ptr => System.Null_Address);
+ (Ada.Finalization.Controlled with Ptr_List => Address_Vectors.Empty_Vector);
type C_Sample_Format is record
@@ -270,11 +333,6 @@ private
-- Keep track of open devices
- package Address_Vectors is new Ada.Containers.Vectors
- (Index_Type => Positive,
- Element_Type => System.Address,
- "=" => System."=");
-
Device_List : Address_Vectors.Vector := Address_Vectors.Empty_Vector;