voices.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include "voices.h"
  2. extern uint16_t envelope_index;
  3. extern float note_timbre;
  4. voice_type voice = default_voice;
  5. void set_voice(voice_type v) {
  6. voice = v;
  7. }
  8. float voice_envelope(float frequency) {
  9. // envelope_index ranges from 0 to 0xFFFF, which is preserved at 880.0 Hz
  10. uint16_t compensated_index = (uint16_t)((float)envelope_index * (880.0 / frequency));
  11. switch (voice) {
  12. case default_voice:
  13. // nothing here on purpose
  14. break;
  15. case butts_fader:
  16. switch (compensated_index) {
  17. case 0 ... 9:
  18. frequency = frequency / 4;
  19. note_timbre = TIMBRE_12;
  20. break;
  21. case 10 ... 19:
  22. frequency = frequency / 2;
  23. note_timbre = TIMBRE_12;
  24. break;
  25. case 20 ... 200:
  26. note_timbre = .125 - pow(((float)compensated_index - 20) / (200 - 20), 2)*.125;
  27. break;
  28. default:
  29. note_timbre = 0;
  30. break;
  31. }
  32. break;
  33. case octave_crunch:
  34. switch (compensated_index) {
  35. case 0 ... 9:
  36. case 20 ... 24:
  37. case 30 ... 32:
  38. frequency = frequency / 2;
  39. note_timbre = TIMBRE_12;
  40. break;
  41. case 10 ... 19:
  42. case 25 ... 29:
  43. case 33 ... 35:
  44. frequency = frequency * 2;
  45. note_timbre = TIMBRE_12;
  46. break;
  47. default:
  48. note_timbre = TIMBRE_12;
  49. break;
  50. }
  51. break;
  52. }
  53. return frequency;
  54. }