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.

124 lines
3.9KB

  1. #include <Audio.h>
  2. #include <Wire.h>
  3. #include <SD.h>
  4. #include <Bounce.h>
  5. // WAV files converted to code by wav2sketch
  6. #include "AudioSampleSnare.h" // http://www.freesound.org/people/KEVOY/sounds/82583/
  7. #include "AudioSampleTomtom.h" // http://www.freesound.org/people/zgump/sounds/86334/
  8. #include "AudioSampleHihat.h" // http://www.freesound.org/people/mhc/sounds/102790/
  9. #include "AudioSampleKick.h" // http://www.freesound.org/people/DWSD/sounds/171104/
  10. #include "AudioSampleGong.h" // http://www.freesound.org/people/juskiddink/sounds/86773/
  11. #include "AudioSampleCashregister.h" // http://www.freesound.org/people/kiddpark/sounds/201159/
  12. // Create the Audio components. These should be created in the
  13. // order data flows, inputs/sources -> processing -> outputs
  14. //
  15. AudioPlayMemory sound0;
  16. AudioPlayMemory sound1; // six memory players, so we can play
  17. AudioPlayMemory sound2; // all six sounds simultaneously
  18. AudioPlayMemory sound3;
  19. AudioPlayMemory sound4;
  20. AudioPlayMemory sound5;
  21. AudioMixer4 mix1; // two 4-channel mixers are needed in
  22. AudioMixer4 mix2; // tandem to combine 6 audio sources
  23. AudioOutputI2S headphones;
  24. AudioOutputAnalog dac; // play to both I2S audio board and on-chip DAC
  25. // Create Audio connections between the components
  26. //
  27. AudioConnection c1(sound0, 0, mix1, 0);
  28. AudioConnection c2(sound1, 0, mix1, 1);
  29. AudioConnection c3(sound2, 0, mix1, 2);
  30. AudioConnection c4(sound3, 0, mix1, 3);
  31. AudioConnection c5(mix1, 0, mix2, 0); // output of mix1 into 1st input on mix2
  32. AudioConnection c6(sound4, 0, mix2, 1);
  33. AudioConnection c7(sound5, 0, mix2, 2);
  34. AudioConnection c8(mix2, 0, headphones, 0);
  35. AudioConnection c9(mix2, 0, headphones, 1);
  36. AudioConnection c10(mix2, 0, dac, 0);
  37. // Create an object to control the audio shield.
  38. //
  39. AudioControlSGTL5000 audioShield;
  40. // Bounce objects to read six pushbuttons (pins 0-5)
  41. //
  42. Bounce button0 = Bounce(0, 5);
  43. Bounce button1 = Bounce(1, 5); // 5 ms debounce time
  44. Bounce button2 = Bounce(2, 5);
  45. Bounce button3 = Bounce(3, 5);
  46. Bounce button4 = Bounce(4, 5);
  47. Bounce button5 = Bounce(5, 5);
  48. void setup() {
  49. // Configure the pushbutton pins for pullups.
  50. // Each button should connect from the pin to GND.
  51. pinMode(0, INPUT_PULLUP);
  52. pinMode(1, INPUT_PULLUP);
  53. pinMode(2, INPUT_PULLUP);
  54. pinMode(3, INPUT_PULLUP);
  55. pinMode(4, INPUT_PULLUP);
  56. pinMode(5, INPUT_PULLUP);
  57. // Audio connections require memory to work. For more
  58. // detailed information, see the MemoryAndCpuUsage example
  59. AudioMemory(10);
  60. // turn on the output
  61. audioShield.enable();
  62. audioShield.volume(0.5);
  63. // by default the Teensy 3.1 DAC uses 3.3Vp-p output
  64. // if your 3.3V power has noise, switching to the
  65. // internal 1.2V reference can give you a clean signal
  66. //dac.analogReference(INTERNAL);
  67. // reduce the gain on mixer channels, so more than 1
  68. // sound can play simultaneously without clipping
  69. mix1.gain(0, 0.4);
  70. mix1.gain(1, 0.4);
  71. mix1.gain(2, 0.4);
  72. mix1.gain(3, 0.4);
  73. mix2.gain(1, 0.4);
  74. mix2.gain(2, 0.4);
  75. }
  76. void loop() {
  77. // Update all the button objects
  78. button0.update();
  79. button1.update();
  80. button2.update();
  81. button3.update();
  82. button4.update();
  83. button5.update();
  84. // When the buttons are pressed, just start a sound playing.
  85. // The audio library will play each sound through the mixers
  86. // so any combination can play simultaneously.
  87. //
  88. if (button0.fallingEdge()) {
  89. sound0.play(AudioSampleSnare);
  90. }
  91. if (button1.fallingEdge()) {
  92. sound1.play(AudioSampleTomtom);
  93. }
  94. if (button2.fallingEdge()) {
  95. sound2.play(AudioSampleHihat);
  96. }
  97. if (button3.fallingEdge()) {
  98. sound3.play(AudioSampleKick);
  99. }
  100. if (button4.fallingEdge()) {
  101. // comment this line to work with Teensy 3.0.
  102. // the Gong sound is very long, too much for 3.0's memory
  103. sound4.play(AudioSampleGong);
  104. }
  105. if (button5.fallingEdge()) {
  106. sound5.play(AudioSampleCashregister);
  107. }
  108. }