I am puzzled why uploading the code below onto my Teensy 4.0 makes it lose its connection (com port) with my computer. It is a modified SamplePlayer from the PJRC Audio Library.
I am trying to make a simple drum project with 30 triggers (without MIDI), but unable to get past 7 triggers with a number of code rewrites.
I am using Windows 8.1 and a Teensy Audio Shield. Everything is hooked up property because a similar code (with fewer inputs) runs fine and I get output from my headphones connected to the Audio Shield.
I have added a flash chip to the Audio Board for extra memory, because my sounds (cpp files) are large.
I do not get any compilation errors with the code.
Before I run the code, I have erased all flash memory (erase everything) and verified that the Teensy is indeed connected to the computer and running the blink program. The port says “hid#vid_16c0&pid_0486 RawHID (Teensy 4.0)”
When I upload the code, I get a message that the “Sketch uses 512128 bytes (25%) of program storage space. Maximum is 2031616 bytes.
Global variables use 522176 bytes (49%) of dynamic memory, leaving 526400 bytes for local variables. Maximum is 1048576 bytes.”
Perhaps the Teensy (even with extra flash memory on the Audio Board) is not enough to run my code?
Any ideas?
I am trying to make a simple drum project with 30 triggers (without MIDI), but unable to get past 7 triggers with a number of code rewrites.
I am using Windows 8.1 and a Teensy Audio Shield. Everything is hooked up property because a similar code (with fewer inputs) runs fine and I get output from my headphones connected to the Audio Shield.
I have added a flash chip to the Audio Board for extra memory, because my sounds (cpp files) are large.
I do not get any compilation errors with the code.
Before I run the code, I have erased all flash memory (erase everything) and verified that the Teensy is indeed connected to the computer and running the blink program. The port says “hid#vid_16c0&pid_0486 RawHID (Teensy 4.0)”
When I upload the code, I get a message that the “Sketch uses 512128 bytes (25%) of program storage space. Maximum is 2031616 bytes.
Global variables use 522176 bytes (49%) of dynamic memory, leaving 526400 bytes for local variables. Maximum is 1048576 bytes.”
Perhaps the Teensy (even with extra flash memory on the Audio Board) is not enough to run my code?
Any ideas?
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include <Bounce.h>
// WAV files converted to code by wav2sketch
#include "AudioSampleC_drum.h" // AudioSampleC1_drum (C4)
#include "AudioSampleD_drum.h" // AudioSampleD_drum (D4)
#include "AudioSampleE_drum.h" // AudioSampleE_drum (E4)
#include "AudioSampleF_drum.h" // AudioSampleF_drum (F4)
#include "AudioSampleG_drum.h" // AudioSampleG_drum (G4)
#include "AudioSampleA_drum.h" // AudioSampleA_drum (A4)
#include "AudioSampleB_drum.h" // AudioSampleB_drum (B4)
#include "AudioSampleC1_drum.h" // AudioSampleC2_drum (C5)
//#include "AudioSampleD1_drum.h" // AudioSampleD1_drum (D5)
// GUItool: begin automatically generated code
AudioPlayMemory playMem2; //xy=62,73
AudioPlayMemory playMem1; //xy=63,34
AudioPlayMemory playMem4; //xy=71,160
AudioPlayMemory playMem3; //xy=72,117
AudioPlayMemory playMem5; //xy=74,215
AudioPlayMemory playMem6; //xy=77,257
//AudioPlayMemory playMem9; //xy=97,400
AudioPlayMemory playMem7; //xy=103,302
AudioPlayMemory playMem8; //xy=108,342
AudioMixer4 mixer1; //xy=249,47
AudioMixer4 mixer3; //xy=295,259
AudioMixer4 mixer4; //xy=301,353
AudioMixer4 mixer2; //xy=462,162
AudioOutputI2S headphones;
AudioOutputAnalog dac; // play to both I2S audio board and on-chip DAC
AudioConnection patchCord1(playMem2, 0, mixer1, 1);
AudioConnection patchCord2(playMem1, 0, mixer1, 0);
AudioConnection patchCord3(playMem4, 0, mixer1, 3);
AudioConnection patchCord4(playMem3, 0, mixer1, 2);
AudioConnection patchCord5(playMem5, 0, mixer3, 0);
AudioConnection patchCord6(playMem6, 0, mixer3, 1);
//AudioConnection patchCord7(playMem9, 0, mixer4, 0);
AudioConnection patchCord8(playMem7, 0, mixer3, 2);
AudioConnection patchCord9(playMem8, 0, mixer3, 3);
AudioConnection patchCord10(mixer1, 0, mixer2, 0);
AudioConnection patchCord11(mixer3, 0, mixer2, 1);
AudioConnection patchCord12(mixer4, 0, mixer2, 2);
AudioConnection patchCord13(mixer2, 0, headphones, 0);
AudioConnection patchCord14(mixer2, 0, headphones, 1);
AudioConnection patchCord15(mixer2, 0, dac, 0);
AudioControlSGTL5000 audioShield;
// GUItool: end automatically generated code
// Bounce objects to read six pushbuttons (pins 0-5)
//
Bounce button0 = Bounce(0, 5);
Bounce button1 = Bounce(1, 5); // 5 ms debounce time
Bounce button2 = Bounce(2, 5);
Bounce button3 = Bounce(3, 5);
Bounce button4 = Bounce(4, 5);
Bounce button5 = Bounce(5, 5);
Bounce button9 = Bounce (9, 5); // added this button 080919
Bounce button14 = Bounce (14, 5); // added this button 080919
//Bounce button16 = Bounce (16, 5); // added this button 080919
void setup() {
// Configure the pushbutton pins for pullups.
// Each button should connect from the pin to GND.
pinMode(0, INPUT_PULLUP);
pinMode(1, INPUT_PULLUP);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(9, INPUT_PULLUP); // added this pin 080919
pinMode(14, INPUT_PULLUP); // added this pin 080919
//pinMode(16, INPUT_PULLUP); // added this pin 080919
// Audio connections require memory to work. For more
// detailed information, see the MemoryAndCpuUsage example
AudioMemory(10);
// turn on the output
audioShield.enable();
audioShield.volume(0.5);
// by default the Teensy 3.1 DAC uses 3.3Vp-p output
// if your 3.3V power has noise, switching to the
// internal 1.2V reference can give you a clean signal
//dac.analogReference(INTERNAL);
// reduce the gain on mixer channels, so more than 1
// sound can play simultaneously without clipping
mixer1.gain(0, 0.4);
mixer1.gain(1, 0.4);
mixer1.gain(2, 0.4);
mixer1.gain(3, 0.4);
mixer2.gain(1, 0.4);
mixer2.gain(2, 0.4);
mixer3.gain(2, 0.4); //
mixer3.gain(2, 0.4); //
}
void loop() {
// Update all the button objects
button0.update();
button1.update();
button2.update();
button3.update();
button4.update();
button5.update();
button9.update(); //
button14.update(); //
// button16.update(); //
// When the buttons are pressed, just start a sound playing.
// The audio library will play each sound through the mixers
// so any combination can play simultaneously.
//
if (button0.fallingEdge()) {
playMem1.play(AudioSampleC_drum);
}
if (button1.fallingEdge()) {
playMem2.play(AudioSampleD_drum);
}
if (button2.fallingEdge()) {
playMem3.play(AudioSampleE_drum);
}
if (button3.fallingEdge()) {
playMem4.play(AudioSampleF_drum);
}
if (button4.fallingEdge()) {
playMem5.play(AudioSampleG_drum);
}
if (button5.fallingEdge()) {
playMem6.play(AudioSampleA_drum);
}
if (button9.fallingEdge()) {
playMem7.play(AudioSampleB_drum);
}
if (button14.fallingEdge()) {
playMem8.play(AudioSampleC1_drum);
//}
//if (button16.fallingEdge()) {
// playMem9.play(AudioSampleD1_drum);
//I have commented to take all of the gong stuff out of the sketch
// comment this line to work with Teensy 3.0.
// the Gong sound is very long, too much for 3.0's memory
// sound4.play(AudioSampleGong);
// }
// if (button5.fallingEdge()) {
//
}
//}
}