From 87b89d768d367a475bb553de295ac867909c28c9 Mon Sep 17 00:00:00 2001 From: Jedidiah Barber Date: Thu, 12 Oct 2023 17:39:45 +1300 Subject: Added callbacks for streams finishing --- src/portaudio-streams.ads | 78 +++++++++++++++++++++++++++-------------------- 1 file changed, 45 insertions(+), 33 deletions(-) (limited to 'src/portaudio-streams.ads') diff --git a/src/portaudio-streams.ads b/src/portaudio-streams.ads index c8d3e92..0f3d2ba 100644 --- a/src/portaudio-streams.ads +++ b/src/portaudio-streams.ads @@ -272,6 +272,8 @@ package Portaudio.Streams is Bunting : in Callback_Flags) return Callback_Result; + type Stream_Finished_Function is access procedure; + @@ -297,33 +299,33 @@ package Portaudio.Streams is return Boolean; procedure Open_Input - (Stream : in out Audio_Stream; - Input_Params : in Parameters; - Sample_Rate : in Hertz; - Buffer_Frames : in Frame_Amount; - Bunting : in Stream_Flags; - Callback : in Callback_Function) + (Stream : in out Audio_Stream; + Input_Params : in Parameters; + Sample_Rate : in Hertz; + Buffer_Frames : in Frame_Amount; + Bunting : in Stream_Flags; + Callback : in not null Callback_Function) with Pre => not Stream.Is_Open, Post => Stream.Is_Open; procedure Open_Output - (Stream : in out Audio_Stream; - Output_Params : in Parameters; - Sample_Rate : in Hertz; - Buffer_Frames : in Frame_Amount; - Bunting : in Stream_Flags; - Callback : in Callback_Function) + (Stream : in out Audio_Stream; + Output_Params : in Parameters; + Sample_Rate : in Hertz; + Buffer_Frames : in Frame_Amount; + Bunting : in Stream_Flags; + Callback : in not null Callback_Function) with Pre => not Stream.Is_Open, Post => Stream.Is_Open; procedure Open_Full - (Stream : in out Audio_Stream; - Input_Params : in Parameters; - Output_Params : in Parameters; - Sample_Rate : in Hertz; - Buffer_Frames : in Frame_Amount; - Bunting : in Stream_Flags; - Callback : in Callback_Function) + (Stream : in out Audio_Stream; + Input_Params : in Parameters; + Output_Params : in Parameters; + Sample_Rate : in Hertz; + Buffer_Frames : in Frame_Amount; + Bunting : in Stream_Flags; + Callback : in not null Callback_Function) with Pre => not Stream.Is_Open, Post => Stream.Is_Open; @@ -356,13 +358,13 @@ package Portaudio.Streams is Post => Stream.Is_Open; procedure Open_Default - (Stream : in out Audio_Stream; - Input_Channels : in Natural; - Output_Channels : in Natural; - Format : in Sample_Format; - Sample_Rate : in Hertz; - Buffer_Frames : in Frame_Amount; - Callback : in Callback_Function) + (Stream : in out Audio_Stream; + Input_Channels : in Natural; + Output_Channels : in Natural; + Format : in Sample_Format; + Sample_Rate : in Hertz; + Buffer_Frames : in Frame_Amount; + Callback : in not null Callback_Function) with Pre => not Stream.Is_Open and (Input_Channels > 0 or Output_Channels > 0), Post => Stream.Is_Open; @@ -383,6 +385,15 @@ package Portaudio.Streams is with Pre => Stream.Is_Open, Post => not Stream.Is_Open; + procedure Set_Finished_Callback + (Stream : in out Audio_Stream; + Callback : in not null Stream_Finished_Function) + with Pre => Stream.Is_Open and then Stream.Is_Stopped; + + procedure Clear_Finished_Callback + (Stream : in out Audio_Stream) + with Pre => Stream.Is_Open and then Stream.Is_Stopped; + procedure Start (Stream : in Audio_Stream) with Pre => Stream.Is_Open; @@ -495,13 +506,14 @@ private type Audio_Stream is tagged limited record - Ptr : System.Address; - Open : Boolean := False; - Func : Callback_Function; - Chin : Interfaces.C.int := 0; - Chout : Interfaces.C.int := 0; - Sin : Interfaces.C.unsigned_long := 0; - Sout : Interfaces.C.unsigned_long := 0; + Ptr : System.Address; + Open : Boolean := False; + Callfun : Callback_Function; + Finfun : Stream_Finished_Function; + Chin : Interfaces.C.int := 0; + Chout : Interfaces.C.int := 0; + Sin : Interfaces.C.unsigned_long := 0; + Sout : Interfaces.C.unsigned_long := 0; end record; -- cgit