From 543cd19ab514ec632d965acd5177c5bf6695520f Mon Sep 17 00:00:00 2001 From: Jedidiah Barber Date: Sat, 15 Jul 2023 20:18:26 +1200 Subject: Initial commit --- example/saw_back.adb | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 example/saw_back.adb (limited to 'example/saw_back.adb') diff --git a/example/saw_back.adb b/example/saw_back.adb new file mode 100644 index 0000000..c266964 --- /dev/null +++ b/example/saw_back.adb @@ -0,0 +1,80 @@ + + +-- Programmed by Jedidiah Barber +-- Released into the public domain + + +with + + Ada.Text_IO, + Portaudio; + +use type + + Portaudio.Float_32; + + +procedure Saw_Back is + + + Left_Phase, Right_Phase : Portaudio.Float_32 := 0.0; + + + function Saw_Callback + (Input : in Portaudio.Sample_Buffer; + Output : in Portaudio.Sample_Buffer; + Frames : in Portaudio.Frame_Amount; + Timing : in Portaudio.Callback_Time_Info; + Flags : in Portaudio.Callback_Flags) + return Portaudio.Callback_Result is + begin + + for Frame in 1 .. Frames loop + Output.Put (Frame, 1, Left_Phase); + Output.Put (Frame, 2, Right_Phase); + + Left_Phase := Left_Phase + 0.01; + if Left_Phase >= 1.0 then + Left_Phase := -1.0; + end if; + + Right_Phase := Right_Phase + 0.03; + if Right_Phase >= 1.0 then + Right_Phase := -1.0; + end if; + end loop; + + return Portaudio.Continue; + + end Saw_Callback; + + + Saw_Stream : Portaudio.Audio_Stream; + + +begin + + + Ada.Text_IO.Put_Line ("PortAudio Test: output sawtooth wave."); + + Saw_Stream.Open_Default + (Input_Channels => 0, + Output_Channels => 2, + Format => Portaudio.Float_32_Sample, + Sample_Rate => 44100.0, + Buffer_Frames => 256, + Callback => Saw_Callback'Unrestricted_Access); + + Saw_Stream.Start; + + delay 4.0; + + Saw_Stream.Stop; + Saw_Stream.Close; + + Ada.Text_IO.Put_Line ("Test finished."); + + +end Saw_Back; + + -- cgit