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.

108 lines
3.3KB

  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 dac;
  24. // Create Audio connections between the components
  25. //
  26. AudioConnection c1(sound0, 0, mix1, 0);
  27. AudioConnection c2(sound1, 0, mix1, 1);
  28. AudioConnection c3(sound2, 0, mix1, 2);
  29. AudioConnection c4(sound3, 0, mix1, 3);
  30. AudioConnection c5(mix1, 0, mix2, 0); // output of mix1 into 1st input on mix2
  31. AudioConnection c6(sound4, 0, mix2, 1);
  32. AudioConnection c7(sound5, 0, mix2, 2);
  33. AudioConnection c8(mix2, 0, dac, 0);
  34. AudioConnection c9(mix2, 0, dac, 1);
  35. // Create an object to control the audio shield.
  36. //
  37. AudioControlSGTL5000 audioShield;
  38. // Bounce objects to read six pushbuttons (pins 0-5)
  39. //
  40. Bounce button0 = Bounce(0, 5);
  41. Bounce button1 = Bounce(1, 5); // 5 ms debounce time
  42. Bounce button2 = Bounce(2, 5);
  43. Bounce button3 = Bounce(3, 5);
  44. Bounce button4 = Bounce(4, 5);
  45. Bounce button5 = Bounce(5, 5);
  46. void setup() {
  47. // Configure the pushbutton pins for pullups.
  48. // Each button should connect from the pin to GND.
  49. pinMode(0, INPUT_PULLUP);
  50. pinMode(1, INPUT_PULLUP);
  51. pinMode(2, INPUT_PULLUP);
  52. pinMode(3, INPUT_PULLUP);
  53. pinMode(4, INPUT_PULLUP);
  54. pinMode(5, INPUT_PULLUP);
  55. // Audio connections require memory to work. For more
  56. // detailed information, see the MemoryAndCpuUsage example
  57. AudioMemory(10);
  58. // turn on the output
  59. audioShield.enable();
  60. audioShield.volume(50);
  61. }
  62. void loop() {
  63. // Update all the button objects
  64. button0.update();
  65. button1.update();
  66. button2.update();
  67. button3.update();
  68. button4.update();
  69. button5.update();
  70. // When the buttons are pressed, just start a sound playing.
  71. // The audio library will play each sound through the mixers
  72. // so any combination can play simultaneously.
  73. //
  74. if (button0.fallingEdge()) {
  75. sound0.play(AudioSampleSnare);
  76. }
  77. if (button1.fallingEdge()) {
  78. sound1.play(AudioSampleTomtom);
  79. }
  80. if (button2.fallingEdge()) {
  81. sound2.play(AudioSampleHihat);
  82. }
  83. if (button3.fallingEdge()) {
  84. sound3.play(AudioSampleKick);
  85. }
  86. if (button4.fallingEdge()) {
  87. // comment this line to work with Teensy 3.0.
  88. // the Gong sound is very long, too much for 3.0's memory
  89. sound4.play(AudioSampleGong);
  90. }
  91. if (button5.fallingEdge()) {
  92. sound5.play(AudioSampleCashregister);
  93. }
  94. }