您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

125 行
3.9KB

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