PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
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.

143 line
3.7KB

  1. #include <Audio.h>
  2. #include <Wire.h>
  3. #include <SD.h>
  4. #include <SPI.h>
  5. #include <SerialFlash.h>
  6. #include "chords.h"
  7. // Special thanks to Matthew Rahtz - http://amid.fish/karplus-strong/
  8. AudioSynthKarplusStrong string1;
  9. AudioSynthKarplusStrong string2;
  10. AudioSynthKarplusStrong string3;
  11. AudioSynthKarplusStrong string4;
  12. AudioSynthKarplusStrong string5;
  13. AudioSynthKarplusStrong string6;
  14. AudioMixer4 mixer1;
  15. AudioMixer4 mixer2;
  16. AudioOutputI2S i2s1;
  17. AudioConnection patchCord1(string1, 0, mixer1, 0);
  18. AudioConnection patchCord2(string2, 0, mixer1, 1);
  19. AudioConnection patchCord3(string3, 0, mixer1, 2);
  20. AudioConnection patchCord4(string4, 0, mixer1, 3);
  21. AudioConnection patchCord5(mixer1, 0, mixer2, 0);
  22. AudioConnection patchCord6(string5, 0, mixer2, 1);
  23. AudioConnection patchCord7(string6, 0, mixer2, 2);
  24. AudioConnection patchCord8(mixer2, 0, i2s1, 0);
  25. AudioConnection patchCord9(mixer2, 0, i2s1, 1);
  26. AudioControlSGTL5000 sgtl5000_1;
  27. const int finger_delay = 5;
  28. const int hand_delay = 220;
  29. int chordnum=0;
  30. void setup() {
  31. AudioMemory(15);
  32. sgtl5000_1.enable();
  33. sgtl5000_1.volume(0.6);
  34. mixer1.gain(0, 0.15);
  35. mixer1.gain(1, 0.15);
  36. mixer1.gain(2, 0.15);
  37. mixer1.gain(3, 0.15);
  38. mixer2.gain(1, 0.15);
  39. mixer2.gain(2, 0.15);
  40. delay(700);
  41. }
  42. void strum_up(const float *chord, float velocity);
  43. void strum_dn(const float *chord, float velocity);
  44. void loop() {
  45. const float *chord;
  46. // each time through the loop, play a different chord
  47. if (chordnum == 0) {
  48. chord = Cmajor;
  49. Serial.println("C major");
  50. chordnum = 1;
  51. } else if (chordnum == 1) {
  52. chord = Gmajor;
  53. Serial.println("G major");
  54. chordnum = 2;
  55. } else if (chordnum == 2) {
  56. chord = Aminor;
  57. Serial.println("A minor");
  58. chordnum = 3;
  59. } else {
  60. chord = Eminor;
  61. Serial.println("E minor");
  62. chordnum = 0;
  63. }
  64. // then strum the 6 string several times
  65. strum_up(chord, 1.0);
  66. delay(hand_delay);
  67. delay(hand_delay);
  68. strum_up(chord, 1.0);
  69. delay(hand_delay);
  70. strum_dn(chord, 0.8);
  71. delay(hand_delay);
  72. delay(hand_delay);
  73. strum_dn(chord, 0.8);
  74. delay(hand_delay);
  75. strum_up(chord, 1.0);
  76. delay(hand_delay);
  77. strum_dn(chord, 0.8);
  78. delay(hand_delay);
  79. strum_up(chord, 1.0);
  80. delay(hand_delay);
  81. delay(hand_delay);
  82. strum_up(chord, 1.0);
  83. delay(hand_delay);
  84. strum_dn(chord, 0.7);
  85. delay(hand_delay);
  86. delay(hand_delay);
  87. strum_dn(chord, 0.7);
  88. delay(hand_delay);
  89. strum_up(chord, 1.0);
  90. delay(hand_delay);
  91. strum_dn(chord, 0.7);
  92. delay(hand_delay);
  93. Serial.print("Max CPU Usage = ");
  94. Serial.print(AudioProcessorUsageMax(), 1);
  95. Serial.println("%");
  96. }
  97. void strum_up(const float *chord, float velocity)
  98. {
  99. if (chord[0] > 20.0) string1.noteOn(chord[0], velocity);
  100. delay(finger_delay);
  101. if (chord[1] > 20.0) string2.noteOn(chord[1], velocity);
  102. delay(finger_delay);
  103. if (chord[2] > 20.0) string3.noteOn(chord[2], velocity);
  104. delay(finger_delay);
  105. if (chord[3] > 20.0) string4.noteOn(chord[3], velocity);
  106. delay(finger_delay);
  107. if (chord[4] > 20.0) string5.noteOn(chord[4], velocity);
  108. delay(finger_delay);
  109. if (chord[5] > 20.0) string6.noteOn(chord[5], velocity);
  110. delay(finger_delay);
  111. }
  112. void strum_dn(const float *chord, float velocity)
  113. {
  114. if (chord[5] > 20.0) string1.noteOn(chord[5], velocity);
  115. delay(finger_delay);
  116. if (chord[4] > 20.0) string2.noteOn(chord[4], velocity);
  117. delay(finger_delay);
  118. if (chord[3] > 20.0) string3.noteOn(chord[3], velocity);
  119. delay(finger_delay);
  120. if (chord[2] > 20.0) string4.noteOn(chord[2], velocity);
  121. delay(finger_delay);
  122. if (chord[1] > 20.0) string5.noteOn(chord[1], velocity);
  123. delay(finger_delay);
  124. if (chord[0] > 20.0) string6.noteOn(chord[0], velocity);
  125. delay(finger_delay);
  126. }