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.

46 lines
1009B

  1. /*
  2. Simple wave table VCO.
  3. Author: Leonardo Laguna Ruiz - leonardo@vult-dsp.com
  4. Check the API documentation in the basic.vult example
  5. */
  6. fun pitchToFreq(cv) @[table(size=128, min=-10.0, max=10.0)] {
  7. return 261.6256 * exp(cv * 0.69314718056);
  8. }
  9. // Generates (at compile time) a wave table based on the provided harmonics
  10. // To change the wave table, change the 'harmonics' array
  11. fun wavetable(phase) @[table(size=128, min=0.0, max=1.0)] {
  12. val harmonics = [0.0, 1.0, 0.7, 0.5, 0.3];
  13. val n = size(harmonics);
  14. val acc = 0.0;
  15. val i = 0;
  16. while(i < n) {
  17. acc = acc + harmonics[i] * sin(2.0 * pi() * real(i) * phase);
  18. i = i + 1;
  19. }
  20. return acc / sqrt(real(n));
  21. }
  22. fun process(input_cv:real) {
  23. mem phase;
  24. val knob_cv = getKnob(1) - 0.5;
  25. val cv = 10.0 * (input_cv + knob_cv);
  26. val freq = pitchToFreq(cv);
  27. val delta = sampletime() * freq;
  28. phase = phase + delta;
  29. if(phase > 1.0) {
  30. phase = phase - 1.0;
  31. }
  32. return wavetable(phase);
  33. }
  34. and update() {
  35. }