Created
October 10, 2017 23:30
-
-
Save nbogie/dd09ec862c9c5ed8f86852f3b1721da2 to your computer and use it in GitHub Desktop.
A quick first noisemaker patch with Teensy Audio library and a single pot.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <synth_simple_drum.h> | |
#include <Audio.h> | |
#include <Wire.h> | |
#include <SPI.h> | |
#include <SD.h> | |
#include <SerialFlash.h> | |
// GUItool: begin automatically generated code | |
AudioSynthWaveformSine sine1; //xy=69.01041030883789,238.01041412353516 | |
AudioSynthKarplusStrong string1; //xy=114.01040649414062,78.01041412353516 | |
AudioSynthSimpleDrum drum2; //xy=163.01040649414062,358.9999921321869 | |
AudioSynthSimpleDrum drum3; //xy=188.01040649414062,424.9999921321869 | |
AudioSynthSimpleDrum drum1; //xy=195.01040649414062,311.9999921321869 | |
AudioSynthNoisePink pink1; //xy=197.01040649414062,160.01041412353516 | |
AudioSynthWaveformSineModulated sine_fm1; //xy=206.01040649414062,229.0103998184204 | |
AudioSynthSimpleDrum drum4; //xy=228.01040649414062,488.9999921321869 | |
AudioMixer4 mixer2; //xy=379.0104064941406,211.01041412353516 | |
AudioMixer4 mixer1; //xy=501.0104064941406,379.9999921321869 | |
AudioMixer4 mixer3; //xy=527.010383605957,251.01041412353516 | |
AudioFilterBiquad biquad1; //xy=650.0103912353516,310.9999942779541 | |
AudioOutputI2S i2s1; //xy=871.010368347168,251.0000410079956 | |
AudioConnection patchCord1(sine1, sine_fm1); | |
AudioConnection patchCord2(string1, 0, mixer2, 1); | |
AudioConnection patchCord3(drum2, 0, mixer1, 1); | |
AudioConnection patchCord4(drum3, 0, mixer1, 2); | |
AudioConnection patchCord5(drum1, 0, mixer1, 0); | |
AudioConnection patchCord6(pink1, 0, mixer2, 0); | |
AudioConnection patchCord7(sine_fm1, 0, mixer2, 2); | |
AudioConnection patchCord8(drum4, 0, mixer1, 3); | |
AudioConnection patchCord9(mixer2, 0, mixer3, 0); | |
AudioConnection patchCord10(mixer1, 0, mixer3, 1); | |
AudioConnection patchCord11(mixer3, biquad1); | |
AudioConnection patchCord12(biquad1, 0, i2s1, 0); | |
AudioConnection patchCord13(biquad1, 0, i2s1, 1); | |
AudioControlSGTL5000 sgtl5000_1; //xy=916.0103530883789,661.0000877380371 | |
// GUItool: end automatically generated code | |
static uint32_t next; | |
void setup() { | |
// put your setup code here, to run once: | |
Serial.begin(115200); | |
// audio library init | |
AudioMemory(15); | |
next = millis() + 1000; | |
AudioNoInterrupts(); | |
drum1.frequency(60); | |
drum1.length(1500); | |
drum1.secondMix(0.0); | |
drum1.pitchMod(0.55); | |
drum2.frequency(60); | |
drum2.length(300); | |
drum2.secondMix(0.0); | |
drum2.pitchMod(1.0); | |
drum3.frequency(550); | |
drum3.length(400); | |
drum3.secondMix(1.0); | |
drum3.pitchMod(0.5); | |
drum4.frequency(700); | |
drum4.length(150); | |
drum4.secondMix(0.0); | |
drum4.pitchMod(0.0); | |
pink1.amplitude(0.5); | |
sine1.frequency(8); | |
sine1.amplitude(1); | |
sine_fm1.amplitude(0.5); | |
sine_fm1.frequency(440); | |
// Butterworth filter, 12 db/octave | |
biquad1.setLowpass(0, 800, 0.707); | |
sgtl5000_1.enable(); | |
sgtl5000_1.volume(0.5); | |
AudioInterrupts(); | |
} | |
void loop() { | |
// put your main code here, to run repeatedly: | |
int ar = analogRead(0); | |
int filtFreq = map(ar, 0, 1023, 40, 1000); | |
biquad1.setLowpass(0, filtFreq, 0.707); | |
sine1.frequency(map(ar, 0, 1023, 1, 100)); | |
sine_fm1.amplitude(0.01* map(ar, 0, 1023, 50, 5)); | |
static uint32_t num = 0; | |
if(millis() == next) | |
{ | |
next = millis() + 500; // (2*ar) + 100; | |
switch(num % 4) | |
{ | |
case 0: | |
drum1.noteOn(); | |
string1.noteOn(random(40, 800), 0.4); | |
break; | |
case 1: | |
drum2.noteOn(); | |
break; | |
case 2: | |
drum3.noteOn(); | |
break; | |
case 3: | |
drum4.noteOn(); | |
string1.noteOff(0.2); | |
break; | |
} | |
num++; | |
Serial.print("Diagnostics: "); | |
Serial.print(AudioProcessorUsageMax()); | |
Serial.print(" "); | |
Serial.println(AudioMemoryUsageMax()); | |
AudioProcessorUsageMaxReset(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment