summaryrefslogtreecommitdiff
path: root/example/saw_back.adb
diff options
context:
space:
mode:
authorJedidiah Barber <contact@jedbarber.id.au>2023-07-15 20:18:26 +1200
committerJedidiah Barber <contact@jedbarber.id.au>2023-07-15 20:18:26 +1200
commit543cd19ab514ec632d965acd5177c5bf6695520f (patch)
treee15caec44e57a91c608f48c4f9a2bb38d4e76727 /example/saw_back.adb
Initial commit
Diffstat (limited to 'example/saw_back.adb')
-rw-r--r--example/saw_back.adb80
1 files changed, 80 insertions, 0 deletions
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;
+
+