Hi,
I am seeking guidance on whether, using the Teensy Audio Adapter, the same sound can be played over the top of itself. All the examples I have seen of polyphony seem to be modelled on a keyboard where you might want to be able to play (say) 8 different notes simultaneously. I do need that functionality but I also need to be able to play the same sound while up to 7 other instances of the same sound are playing "over the top" and they get blended together.
So conceptually my application is more like a sequencer with 8 steps that a 7 key keyboard.
One way perhaps I could do this would be to create 56 sound objects (7 different notes with up to 8 voices) but that seems wasteful and I wonder if I would run out of RAM.
Sorry for the awkward language but I am not a musician.
The 7 notes are triggered by a colour sensor. There are 8 "slots" into which colours can be placed. Because the end user could put the same colour in every slot, and the sound files are up to 4 seconds long, it is theoretically possible that the amount of sustain means you might need to play the A note for example, over the top of itself 8 times. With the code below trying to re-trigger the same sound cause the first instance to glitch off in an ugly way.
Perhaps I am asking if (say) "1c.raw" can be a variable rather than be baked into the "playFlashRaw1.play" object.
Code below:
I am seeking guidance on whether, using the Teensy Audio Adapter, the same sound can be played over the top of itself. All the examples I have seen of polyphony seem to be modelled on a keyboard where you might want to be able to play (say) 8 different notes simultaneously. I do need that functionality but I also need to be able to play the same sound while up to 7 other instances of the same sound are playing "over the top" and they get blended together.
So conceptually my application is more like a sequencer with 8 steps that a 7 key keyboard.
One way perhaps I could do this would be to create 56 sound objects (7 different notes with up to 8 voices) but that seems wasteful and I wonder if I would run out of RAM.
Sorry for the awkward language but I am not a musician.
The 7 notes are triggered by a colour sensor. There are 8 "slots" into which colours can be placed. Because the end user could put the same colour in every slot, and the sound files are up to 4 seconds long, it is theoretically possible that the amount of sustain means you might need to play the A note for example, over the top of itself 8 times. With the code below trying to re-trigger the same sound cause the first instance to glitch off in an ugly way.
Perhaps I am asking if (say) "1c.raw" can be a variable rather than be baked into the "playFlashRaw1.play" object.
Code below:
Code:
//reads the ColorSight and plays sound via the audio adapter
// Audio Adapter stuff based on sample player example
// introduces a function to read the sensor
//#include <MIDI.h>
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include <Bounce.h>
// GUItool: begin automatically generated code
AudioPlaySerialflashRaw playFlashRaw6; //xy=225,390
AudioPlaySerialflashRaw playFlashRaw3; //xy=226,204
AudioPlaySerialflashRaw playFlashRaw7; //xy=226,440
AudioPlaySerialflashRaw playFlashRaw4; //xy=227,262
AudioPlaySerialflashRaw playFlashRaw5; //xy=228,342
AudioPlaySerialflashRaw playFlashRaw1; //xy=232,79
AudioPlaySerialflashRaw playFlashRaw2; //xy=233,144
AudioMixer4 mixer2; //xy=442,411
AudioMixer4 mixer1; //xy=450,169
AudioMixer4 mixer3; //xy=624,302
AudioOutputI2S i2s1; //xy=829,303
AudioConnection patchCord1(playFlashRaw6, 0, mixer2, 1);
AudioConnection patchCord2(playFlashRaw3, 0, mixer1, 2);
AudioConnection patchCord3(playFlashRaw7, 0, mixer2, 2);
AudioConnection patchCord4(playFlashRaw4, 0, mixer1, 3);
AudioConnection patchCord5(playFlashRaw5, 0, mixer2, 0);
AudioConnection patchCord6(playFlashRaw1, 0, mixer1, 0);
AudioConnection patchCord7(playFlashRaw2, 0, mixer1, 1);
AudioConnection patchCord8(mixer2, 0, mixer3, 1);
AudioConnection patchCord9(mixer1, 0, mixer3, 0);
AudioConnection patchCord10(mixer3, 0, i2s1, 0);
AudioConnection patchCord11(mixer3, 0, i2s1, 1);
AudioControlSGTL5000 sgtl5000_1; //xy=760,499
// GUItool: end automatically generated code
//MIDI_CREATE_INSTANCE(HardwareSerial, Serial3, MIDI);
const int channel = 1;
#define Q1 0
#define Q2 1
#define Q3 2
byte inputcolour = 0;
byte colour = 0;
byte oldcolour = 0;
void setup() {
// MIDI.begin();
// SerialFlash.begin(6);
// these two lines are really really important
SPI.setSCK(14); // Audio shield has SCK on pin 14
SPI.setMOSI(7); // Audio shield has MOSI on pin 7
if ( !SerialFlash.begin() )
Serial.println( "Unable to access SPI Flash chip" );
// from example
// Audio connections require memory to work. For more
// detailed information, see the MemoryAndCpuUsage example
AudioMemory(100);
// turn on the output
sgtl5000_1.enable();
sgtl5000_1.volume(0.6);
// 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);
// end from example
pinMode(Q1, INPUT_PULLUP);
pinMode(Q2, INPUT_PULLUP);
pinMode(Q3, INPUT_PULLUP);
}
void loop() {
// int note;
// for (note=10; note <= 127; note++) {
// MIDI.sendNoteOn(note, 69, channel);
// delay(200);
// MIDI.sendNoteOff(note, 0, channel);
//inputcolour = (!digitalRead(Q1)*4 + !digitalRead(Q2)*2 + !digitalRead(Q3)*1);
colour = readColorSight();
if (colour != oldcolour) // if something has changed
{
switch(colour) {
case 0:
Serial.println("Nothing");
break;
case 1:
Serial.println("C");
// MIDI.sendNoteOn(60, 61, 1);
playFlashRaw1.play("1C.raw");
// delay(200);
// MIDI.sendNoteOff(60, 0, 1);
break;
case 2:
Serial.println("D");
// MIDI.sendNoteOn(62, 61, 1);
playFlashRaw2.play("2D.raw");
// delay(200);
// MIDI.sendNoteOff(62, 0, 1);
break;
case 3:
Serial.println("E");
// MIDI.sendNoteOn(64, 61, 1);
playFlashRaw3.play("3E.raw");
// delay(200);
// MIDI.sendNoteOff(64, 0, 1);
break;
case 4:
Serial.println("F");
// MIDI.sendNoteOn(65, 61, 1);
playFlashRaw4.play("4F.raw");
// delay(200);
// MIDI.sendNoteOff(65, 0, 1);
break;
case 5:
Serial.println("G");
// MIDI.sendNoteOn(67, 61, 1);
playFlashRaw5.play("5G.raw");
// delay(200);
// MIDI.sendNoteOff(67, 0, 1);
break;
case 6:
Serial.println("A");
// MIDI.sendNoteOn(69, 61, 1);
playFlashRaw6.play("6A.raw");
// delay(200);
// MIDI.sendNoteOff(69, 0, 1);
break;
case 7:
Serial.println("B");
// MIDI.sendNoteOn(71, 61, 1);
playFlashRaw7.play("7B.raw");
// delay(200);
// MIDI.sendNoteOff(71, 0, 1);
break;
}
}
oldcolour = colour;
//}
//}
//
//Serial.println (inputcolour);
//Serial.println (readColorSight);
//Serial.print(!digitalRead(Q1)),
//Serial.print(!digitalRead(Q2)),
//Serial.print(!digitalRead(Q3)),
//Serial.println(colour);
//Serial.println(" "),
//delay(000);
}
byte readColorSight()
{
delay (10);
byte result = (!digitalRead(Q1)*4 + !digitalRead(Q2)*2 + !digitalRead(Q3)*1);
return result;
}