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.

59 lines
2.3KB

  1. with Interfaces.C;
  2. use Interfaces.C;
  3. with Ada.Numerics;
  4. use Ada.Numerics;
  5. with Ada.Numerics.Elementary_Functions;
  6. use Ada.Numerics.Elementary_Functions;
  7. with Blep;
  8. package body Super_Saw is
  9. function Super_Saw(Time : Interfaces.C.C_Float; Pitch : Interfaces.C.C_Float;
  10. Detune : Interfaces.C.C_Float; Mix : Interfaces.C.C_Float;
  11. Sample_Rate : Interfaces.C.C_Float)
  12. return Interfaces.C.C_Float is
  13. Offsets : Offset_Array_Type := (0.01952356,0.06288439,0.11002313);
  14. Sample : Float := 0.0;
  15. Mix_Level : Mix_Level_Type := Compute_Mix(Float(Mix));
  16. begin
  17. -- Main oscillator
  18. Sample := Sample + Saw(Float(Time),Float(Pitch), Float(Sample_Rate))*Mix_Level.Master;
  19. -- 3 oscillators of higher pitch than main
  20. Higher_Oscillators:for D in 1 .. 3 loop
  21. Sample := Sample + Saw(Float(Time),Float(Pitch)*(1.0+Offsets(D)*Compute_Detune(Float(Detune))),
  22. Float(Sample_Rate))*Mix_Level.Slave;
  23. end loop Higher_Oscillators;
  24. -- 3 oscillators of lower pitch than main
  25. Lower_Oscillators:for D in 1 .. 3 loop
  26. Sample := Sample + Saw(Float(Time),Float(Pitch)*(1.0+Offsets(D)*Compute_Detune(Float(Detune))),
  27. Float(Sample_Rate))*Mix_Level.Slave;
  28. end loop Lower_Oscillators;
  29. return Interfaces.C.C_FLoat(Sample)*Interfaces.C.C_Float(0.1);
  30. end Super_Saw;
  31. function Saw(Time : Float; Pitch : Float; Sample_Rate : Float) return Float is
  32. begin
  33. return Blep.BLEP_Saw(Time,Pitch/Sample_Rate);
  34. end Saw;
  35. function Compute_Detune(Amount : Float) return Float is
  36. begin
  37. return (10028.7312891634*Amount**11)-(50818.8652045924*Amount**10)
  38. +(111363.4808729368*Amount**9)-(138150.6761080548*Amount**8)+
  39. (106649.6679158292*Amount**7)-(53046.9642751875*Amount**6)+
  40. (17019.9518580080*Amount**5)-(3425.0836591318*Amount**4)+
  41. (404.2703938388*Amount**3)-(24.1878824391*Amount**2)+
  42. (0.6717417634*Amount)+0.0030115596;
  43. end Compute_Detune;
  44. function Compute_Mix(Level : Float) return Mix_Level_Type is
  45. Mix_Level : Mix_Level_Type;
  46. begin
  47. Mix_Level.Master := -0.55366*Level + 0.99785;
  48. Mix_Level.Slave := -0.73764*Level**2 + 1.2841*Level + 0.044372;
  49. return Mix_Level;
  50. end Compute_Mix;
  51. end Super_Saw;