Skip to content

Commit

Permalink
Mixer gets a work buffer rt. a stack allocated work buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
raph-amiard committed Oct 21, 2018
1 parent 847625d commit 65a97a0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/effects.adb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ package body Effects is
overriding procedure Next_Samples
(Self : in out Mixer; Buffer : in out Generator_Buffer)
is
Tmp_Buffer : Generator_Buffer;
Work_Buffer : Generator_Buffer renames Self.Work_Buffer;
begin
-- Set every element of the buffer to 0.0
Buffer := (others => 0.0);
Expand All @@ -64,25 +64,25 @@ package body Effects is
for I in 0 .. Self.Length - 1 loop

-- Compute the samples of the channel's generator
Self.Generators (I).Gen.Next_Samples (Tmp_Buffer);
Self.Generators (I).Gen.Next_Samples (Work_Buffer);

-- And add the samples to the buffer
for J in Buffer'Range loop
Buffer (J) :=
Buffer (J)
+ (Tmp_Buffer (J) * Sample (Self.Generators (I).Level));
+ (Work_Buffer (J) * Sample (Self.Generators (I).Level));
end loop;
end loop;

if Self.Env /= null then
Self.Env.Next_Samples (Tmp_Buffer);
Self.Env.Next_Samples (Work_Buffer);
for J in Buffer'Range loop
Buffer (J) := Buffer (J) * Tmp_Buffer (J);
Buffer (J) := Buffer (J) * Work_Buffer (J);
end loop;
elsif Self.Env /= null and then Self.Saturate then
Self.Env.Next_Samples (Tmp_Buffer);
Self.Env.Next_Samples (Work_Buffer);
for J in Buffer'Range loop
Buffer (J) := Saturate (Buffer (J) * Tmp_Buffer (J));
Buffer (J) := Saturate (Buffer (J) * Work_Buffer (J));
end loop;
elsif Self.Saturate then
for J in Buffer'Range loop
Expand Down
1 change: 1 addition & 0 deletions src/effects.ads
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ package Effects is
Length : Natural := 0;
Env : access ADSR;
Saturate : Boolean := False;
Work_Buffer : Generator_Buffer;
end record;

type Generators_Arg_Array is array (Natural range <>) of Mixer_Generator;
Expand Down

0 comments on commit 65a97a0

Please sign in to comment.