MichaelMeissner
Senior Member+
According to the Teensy 3.1 breakout, pins 26 and 31 underneath the Teensy are alternate pins for Serial2. I don't know if Paul has a way switch to use those pins in the current library.
Is there a way to either remap some of the audio library pins to free serial port 2 or 3 or even remap the serial ports?
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
// AUDIO lib objects:
AudioSynthWaveform someWaveform;
AudioOutputAnalog DAC;
AudioConnection patchCord1(someWaveform, DAC);
#define MAX_FREQ 600 // max frequency < - > arbitraryWaveform(array, maxFreq);
/* include some wavetables: the files need to contain arrays [256] of type const short int wt1[] = { ... } */
#include </path/to/wt1.h>
#include </path/to/wt2.h>
...
etc
...
#include </path/to/wt10.h>
// the following presumably is needlessly complicated:
struct WaveTable {
int16_t const* table;
};
#define TABLE_NUM 10 //
WaveTable waveTables[TABLE_NUM] {
wt1,
wt2,
wt3,
wt4,
wt5,
wt6,
wt7,
wt8,
wt9,
wt10
};
const uint16_t sequence[] = {220, 440, 261, 587}; // a little sequence
#define SEQ_L 3 // sequence length
#define SEQ_SPEED 400 // sequence speed (ms)
uint8_t waveselect=3, pos; // variable to select wavetable, and position in sequence
void setup() {
AudioMemory(12);
/* // basic usage would be:
someWaveform.arbitraryWaveform(wt1, MAX_FREQ);
someWaveform.begin(0.5, 440, WAVEFORM_ARBITRARY);
*/
// here we want to randomly select from the 10 wavetables above, so:
const struct WaveTable* waveTable = &waveTables[waveselect];
int16_t* wave = const_cast<short int*>(waveTable->table);
someWaveform.arbitraryWaveform(wave, MAX_FREQ);
someWaveform.begin(0.5, 440, WAVEFORM_ARBITRARY);
}
void loop() {
delay(SEQ_SPEED);
if (pos > SEQ_L) {
pos = 0; // reset sequence
waveselect = random(10); // and pick a new wavetable
const struct WaveTable* waveTable = &waveTables[waveselect];
int16_t* wave = const_cast<short int*>(waveTable->table);
someWaveform.arbitraryWaveform(wave, MAX_FREQ);
}
// play next note in sequence
someWaveform.frequency(sequence[pos++]);
}
Yes, there is a way. You'll need to write directly to the port config registers. It's been posted previously on another thread.
LINK TO REMAP SERIAL2 port
To connect these, the following registers need to be set (have not tried yet, but I'm sure it will be fine)
PORTE_PCR0 = 0x00000300 (mux 3) - connects alternative function UART1_TX to pin PTE0
PORTE_PCR1 = 0x00000300 (mux 3) - connects alternative function UART1_RX to pin PTE1
or
CORE_PIN26_CONFIG = PORT_PCR_MUX(3);
CORE_PIN31_CONFIG = PORT_PCR_MUX(3);
Thank you sir, I'm sure you do not get thanked enough for your work. Keep on with the amazing product. I hope to buy a vast number of bootloader chips to help fund your projects after we get the new prototypes built up in 2-3 months.
//CORE_PIN26_CONFIG = PORT_PCR_MUX(3);
//CORE_PIN31_CONFIG = PORT_PCR_MUX(3);
PORTE_PCR0 = 0x00000300;// (mux 3) - connects alternative function UART1_TX to pin PTE0
PORTE_PCR1 = 0x00000300;// (mux 3) - connects alternative function UART1_RX to pin PTE1
Serial.begin(9600);
Serial1.begin(9600);
Serial2.begin(9600); //moved slave/android to pins that were used by audio
As soon as I comment out Serial2.begin, it will play audio again!?
I'll investigate, but only if you post a complete program that demonstrates the problem.
If you've watched the forum for any length of time, or read the forum rules, the one main rule around here is THOU SHALT POST COMPLETE CODE TO REPRODUCE THE PROBLEM.
#include <Audio.h>
#include <Wire.h>
#include <SD.h>
#include <SPI.h>
// Create the Audio components. These should be created in the
// order data flows, inputs/sources -> processing -> outputs
//
AudioPlaySdWav wav;
AudioOutputI2S dac;
// Create Audio connections between the components
//
AudioConnection c1(wav, 0, dac, 0);
AudioConnection c2(wav, 1, dac, 1);
// Create an object to control the audio shield.
//
AudioControlSGTL5000 audioShield;
void setup()
{
//CORE_PIN26_CONFIG = PORT_PCR_MUX(3); //alternate means to toggle serial port 2 to different pins
// CORE_PIN31_CONFIG = PORT_PCR_MUX(3); //alternate means to toggle serial port 2 to different pins
PORTE_PCR0 = 0x00000300;// (mux 3) - connects alternative function UART1_TX to pin PTE0
PORTE_PCR1 = 0x00000300;// (mux 3) - connects alternative function UART1_RX to pin PTE1
Serial2.begin(9600); //comment this out and code works fine, put it back in and you can use pins 26 and 31 to talk to Serial2
// Audio connections require memory to work. For more
// detailed information, see the MemoryAndCpuUsage example
AudioMemory(50);
audioShield.enable();
audioShield.volume(0.7);
SPI.setMOSI(7);
SPI.setSCK(14);
if (SD.begin(10)) {
wav.play("290MSG.WAV");
//wav.play("01_16M.WAV");
}
}
void loop()
{
}
/* Formant values for vowels taken from CSound manual appendix:
http://csound.github.io/docs/manual/MiscFormants.html
*/
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
// GUItool: begin automatically generated code
AudioSynthNoisePink noise1; //xy=65,218
AudioSynthWaveform waveform1; //xy=65,264
AudioSynthWaveform waveform2; //xy=65,305
AudioEffectMultiply multiply1; //xy=152,361
AudioMixer4 mixer2; //xy=229,233
AudioFilterStateVariable filter2; //xy=388,263
AudioFilterStateVariable filter3; //xy=389,323
AudioFilterStateVariable filter1; //xy=390,200
AudioFilterStateVariable filter4; //xy=393,384
AudioMixer4 mixer1; //xy=584,253
AudioEffectEnvelope envelope1; //xy=724,254
AudioOutputI2S i2s1; //xy=749,374
AudioConnection patchCord1(noise1, 0, mixer2, 0);
AudioConnection patchCord2(waveform1, 0, multiply1, 0);
AudioConnection patchCord3(waveform2, 0, multiply1, 1);
AudioConnection patchCord4(multiply1, 0, mixer2, 1);
AudioConnection patchCord5(mixer2, 0, filter1, 0);
AudioConnection patchCord6(mixer2, 0, filter2, 0);
AudioConnection patchCord7(mixer2, 0, filter3, 0);
AudioConnection patchCord8(mixer2, 0, filter4, 0);
AudioConnection patchCord9(filter1, 1, mixer1, 0);
AudioConnection patchCord10(filter2, 1, mixer1, 1);
AudioConnection patchCord11(filter3, 1, mixer1, 2);
AudioConnection patchCord12(filter4, 1, mixer1, 3);
AudioConnection patchCord13(mixer1, envelope1);
AudioConnection patchCord14(envelope1, 0, i2s1, 0);
AudioConnection patchCord15(envelope1, 0, i2s1, 1);
// GUItool: end automatically generated code
AudioControlSGTL5000 audioShield;
void setup(void)
{
// Set up
AudioMemory(16);
audioShield.enable();
audioShield.volume(0.45);
// Sound source
waveform1.begin(0.4, 30, WAVEFORM_SQUARE);
waveform2.begin(0.4, 30.2, WAVEFORM_SQUARE); // A little variation
waveform2.phase(80); // Kind of PWM? 2 sq waves out of phase, multiplied to gether
noise1.amplitude(0.1); // Some breathiness
// Volume of each formant
mixer1.gain(0, 0.9);
mixer1.gain(1, 0.8);
mixer1.gain(2, 0.7);
mixer1.gain(3, 0.4);
// Q of each formant.
filter1.resonance(5);
filter2.resonance(4.8);
filter3.resonance(4.6);
filter4.resonance(4.2);
// Envelope of each utterance
envelope1.attack(20);
envelope1.hold(200);
envelope1.decay(50);
envelope1.release(200);
}
void loop(void)
{
// Table D.8. bass “i”
filter1.frequency(250);
filter2.frequency(1750);
filter3.frequency(2600);
filter4.frequency(3050);
envelope1.noteOn();
delay(600);
envelope1.noteOff();
delay(400);
// Table D.7. bass “e”
filter1.frequency(400);
filter2.frequency(1620);
filter3.frequency(2400);
filter4.frequency(2800);
envelope1.noteOn();
delay(600);
envelope1.noteOff();
delay(400);
// Table D.9. bass “o”
filter1.frequency(400);
filter2.frequency(750);
filter3.frequency(2400);
filter4.frequency(2600);
envelope1.noteOn();
delay(700);
envelope1.noteOff();
delay(500);
// Table D.10. bass “u”
filter1.frequency(350);
filter2.frequency(600);
filter3.frequency(2400);
filter4.frequency(2675);
envelope1.noteOn();
delay(800);
envelope1.noteOff();
delay(600);
}
hey guys - is it possible to do variable speed sample playback with this library?
Thanks
Zach
Thanks for the quick reply, here is a modified version of the SD card example. I really need access to another serial port.
#include <Audio.h>
#include <Wire.h>
#include <SD.h>
#include <SPI.h>
AudioPlaySdWav wav;
AudioOutputI2S dac;
AudioConnection c1(wav, 0, dac, 0);
AudioConnection c2(wav, 1, dac, 1);
AudioControlSGTL5000 audioShield;
void setup()
{
Serial2.begin(9600);
CORE_PIN9_CONFIG = PORT_PCR_MUX(6);
CORE_PIN10_CONFIG = PORT_PCR_MUX(1);
CORE_PIN26_CONFIG = PORT_PCR_MUX(3);
CORE_PIN31_CONFIG = PORT_PCR_MUX(3);
AudioMemory(50);
audioShield.enable();
audioShield.volume(0.7);
SPI.setMOSI(7);
SPI.setSCK(14);
if (SD.begin(10)) {
//wav.play("290MSG.WAV");
wav.play("01_16M.WAV");
}
}
void loop()
{
}
no, see my post #856 above. (ie, if "variable speed" is referring to resampling (or "varispeed", as in tape players), but for even that to sound nice, linear interpolation probably won't do; if "time stretching", that'll be an entirely different story, and probably not doable - i don't know).
Yes, you can change the Q of the SVF.I know the variable filter object is brand new, but... is there a way to change the bandwidth of the bandpass output? I am playing with formants to make vowel sounds (sets of 3-5 bandpass filters) and would love to use the variable filter to transition between formants.
This is missing functionality, agreed. Need to have a pulse wave (variable mark/space ratio) , and also a pulse wave with an audio PWM input.Also what's a reasonable way to generate a pulse wave with a variable duty cycle? That would be my ideal sound source for the formants. Variable PWM is a way to make some really great sounds on other synths as well.
Currently none of the play objects supports this.
If you or someone else (not me) wanted to work on this, slowing playback ought to be fairly simple. Just take the output data and repeat samples or use linear interpolation to lengthen the data size. Each update sends 128 samples, so you'll have to either read the correct number to be scaled up to 128, or keep some in a buffer between updates. It'll take some work coding, but not impossible. There's already linear interpolation code in several places within the library.
OH HO! Tested and working, excellent customer service. Guys at work couldn't believe I got a response so quick or how fast the prototype is coming along. So much more powerful than all the Arduino chips, including DUE! I've used almost every chip in Arduino lineup quite extensively and made many custom boards. ARM w/ Teensy IDE is the way to go for a project like this, love it.Try this:
Code:#include <Audio.h> #include <Wire.h> #include <SD.h> #include <SPI.h> AudioPlaySdWav wav; AudioOutputI2S dac; AudioConnection c1(wav, 0, dac, 0); AudioConnection c2(wav, 1, dac, 1); AudioControlSGTL5000 audioShield; void setup() { Serial2.begin(9600); CORE_PIN9_CONFIG = PORT_PCR_MUX(6); CORE_PIN10_CONFIG = PORT_PCR_MUX(1); CORE_PIN26_CONFIG = PORT_PCR_MUX(3); CORE_PIN31_CONFIG = PORT_PCR_MUX(3); AudioMemory(50); audioShield.enable(); audioShield.volume(0.7); SPI.setMOSI(7); SPI.setSCK(14); if (SD.begin(10)) { //wav.play("290MSG.WAV"); wav.play("01_16M.WAV"); } } void loop() { }
This is missing functionality, agreed. Need to have a pulse wave (variable mark/space ratio) , and also a pulse wave with an audio PWM input.
Square wave is a rather special case of a pulse; at exactly 50% mark/space it has no even harmonics. The other pulse types sound rather different. Audio frequency PWM is also a standard sound for synths.
Ideally there would also be a frequency modulation input on the waveform object as well.
So much more powerful than all the Arduino chips, including DUE!
... Can any help test the mic input and new micGain() function? I wrecked the 2 mics I bought earlier. Will get more on order today....