DPF Plugin examples
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.6KB

  1. with Interfaces.C;
  2. use Interfaces.C;
  3. with Ada.Numerics.Generic_Elementary_Functions;
  4. with Super_Saw;
  5. package body Polyphony is
  6. procedure Add_Note (Pitch : C_Float) is
  7. begin
  8. if Note_Count <= Voices then
  9. for I in Notes'Range loop
  10. if Notes(I) = 0.0 then
  11. Notes(I) := Float(Pitch);
  12. Note_Count := Note_Count + 1;
  13. exit;
  14. end if;
  15. end loop;
  16. end if;
  17. end Add_Note;
  18. procedure Remove_Note (Pitch : C_Float) is
  19. begin
  20. if Note_Count > 0 then
  21. for I in Notes'Range loop
  22. if Notes(I) = Float(Pitch) then
  23. Notes(I) := 0.0;
  24. Note_Count := Note_Count - 1;
  25. exit;
  26. end if;
  27. end loop;
  28. end if;
  29. end Remove_Note;
  30. function Compute_Polyphony (Time : C_Float;
  31. Detune : C_Float; Mix : C_Float;
  32. Sample_Rate : C_Float) return C_Float is
  33. package Float_Functions is new Ada.Numerics.Generic_Elementary_Functions (Float);
  34. Sample : C_Float := 0.0;
  35. begin
  36. for I in Notes'Range loop
  37. if Notes(I) /= 0.0 then
  38. -- Compensate for changes in volume by dividing output by logarithm of frequency
  39. Sample := Sample + Super_Saw.Super_Saw(Time => Time, Pitch => C_Float(Notes(I)),
  40. Detune => Detune, Mix => Mix,
  41. Sample_Rate => Sample_Rate)/C_Float(Float_Functions.Log(Notes(I)*30.0,10.0));
  42. end if;
  43. end loop;
  44. return Sample;
  45. end Compute_Polyphony;
  46. end Polyphony;