// A Dalek sort of effect for Teensy 3.2 (or higher) and the audio board.
// Also needs a microphone and headphones.
// Copyright 2017 by Pete (El_Supremo) but
#define ARM_MATH_CM4
#include <arm_math.h>
#include <Audio.h>
#include <Wire.h>
#include <SD.h>
#include <SPI.h>
const int myInput = AUDIO_INPUT_MIC;
//const int myInput = AUDIO_INPUT_LINEIN;
AudioInputI2S audioInput; // audio shield: mic or line-in
AudioSynthWaveformSine sine1; //xy=357,126
AudioEffectMultiply multiply1; //xy=521,242
AudioEffectMultiply multiply2; //xy=522,443
AudioOutputI2S i2s1; //xy=781,308
// See comment about mixers below (mixer_gain)
AudioMixer4 mix1;
AudioMixer4 mix2;
AudioConnection patchCord1a(audioInput,0,mix1,0);
AudioConnection patchCord1b(audioInput,1,mix2,0);
AudioConnection patchCord2a(mix1, 0, multiply1, 0);
AudioConnection patchCord3a(sine1, 0, multiply1, 1);
AudioConnection patchCord2b(mix2, 0, multiply2, 0);
AudioConnection patchCord3b(sine1, 0, multiply2, 1);
AudioConnection patchCord4a(multiply1, 0, i2s1, 0);
AudioConnection patchCord4b(multiply2, 0, i2s1, 1);
AudioControlSGTL5000 audioShield;
void setup() {
Serial.begin(9600);
unsigned long t_start = millis();
// wait for Serial to instantiate or for 10 seconds to elapse
// whichever comes first.
while (!Serial && (millis() - t_start < 10000)) ;
// 16 is plenty of memory
AudioMemory(16);
audioShield.enable();
audioShield.inputSelect(myInput);
// The MEMS microphone already has 60dB of gain.
// It doesn't need any more!
audioShield.micGain(0);
audioShield.volume(.5);
AudioProcessorUsageMaxReset();
AudioMemoryUsageMaxReset();
// Play with the frequency of the sine wave.
// 25 seems to give a nice growl
sine1.frequency(25);
// amplitude of sine wave is floating point number from 0 to 1
sine1.amplitude(1.0);
/* The mixers are used to reduce the gain on a MEMS microphone
which has a builtin gain of 60dB (or more). With that much gain
the microphone picks up room noises, such as the computer fans,
and amplifies and "daleks" them. Reducing the gain reduces the
sensitivity to background noise.
If you aren't using a MEMS microphone, you might find it best to
increase audioShield.micGain and set mixer_gain to 1.0
*/
float mixer_gain = 0.25;
mix1.gain(0, mixer_gain);
mix2.gain(0, mixer_gain);
Serial.println("setup done");
}
void loop() {
static int volume = 0;
int n = analogRead(15);
if (n != volume) {
volume = n;
audioShield.volume(n / 1023.);
}
}