richrarobi
Member
1) I used two mixers to make an audio "balance" for headphone use (first time in 30 years I have been able to listen to stereo in both sides (bad tinnitus and consequential hearing loss in right ear)).
Question is: is this the best way? I am only using one channel in each of the two mixers. when balance is centred, the values are both 0.5, full either way is 0.0 to 1.0. It seems a bit (sort of) wasteful, somehow.
2) I used combine to pull the inputs together for fft (partly for interest at the moment). However, I cannot see what the syntax structure is for combine parameters. Can someone point me at a good example?
3) I think I want to use filters to try to remove unwanted jangly music from tv broadcasts (if possible) so I can hear the commentary better.
Is there a laymans guide anywhere for a dumb programmer to read up audio and electronics? I can bluff my way through the c used in Arduino, my background is mainly in various high level languages apart from some ancient assembler code!!
4) The (old now) audio tutorial mentions (on page 25) the use of bins. It says only the first 30 are important, promises to explain later. I can't find the explanation.... I found that there seemed some useful data in the first 50 in the fft analysis.
Am I imagining this? Is my code daft? Did I miss the explanation somewhere?
p.s. I have put together a box with an adafruit MPR121 for 12 capacitive touch buttons (using 3mm bolts as contacts in a circle on lid) (working, but not used yet), and three pots (volume, balance and a spare)
Question is: is this the best way? I am only using one channel in each of the two mixers. when balance is centred, the values are both 0.5, full either way is 0.0 to 1.0. It seems a bit (sort of) wasteful, somehow.
2) I used combine to pull the inputs together for fft (partly for interest at the moment). However, I cannot see what the syntax structure is for combine parameters. Can someone point me at a good example?
3) I think I want to use filters to try to remove unwanted jangly music from tv broadcasts (if possible) so I can hear the commentary better.
Is there a laymans guide anywhere for a dumb programmer to read up audio and electronics? I can bluff my way through the c used in Arduino, my background is mainly in various high level languages apart from some ancient assembler code!!
4) The (old now) audio tutorial mentions (on page 25) the use of bins. It says only the first 30 are important, promises to explain later. I can't find the explanation.... I found that there seemed some useful data in the first 50 in the fft analysis.
Am I imagining this? Is my code daft? Did I miss the explanation somewhere?
p.s. I have put together a box with an adafruit MPR121 for 12 capacitive touch buttons (using 3mm bolts as contacts in a circle on lid) (working, but not used yet), and three pots (volume, balance and a spare)
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include "Adafruit_MPR121.h"
// GUItool: begin automatically generated code
AudioInputI2S i2s1; //xy=79,223
AudioMixer4 mixer1; //xy=367,143
AudioMixer4 mixer2; //xy=367,270
AudioEffectDigitalCombine combine1; //xy=373,387
AudioAnalyzeFFT1024 fft1024_1; //xy=627,388
AudioOutputI2S i2s2; //xy=917,149
AudioConnection patchCord1(i2s1, 0, mixer1, 0);
AudioConnection patchCord2(i2s1, 0, combine1, 0);
AudioConnection patchCord3(i2s1, 1, mixer2, 0);
AudioConnection patchCord4(i2s1, 1, combine1, 1);
AudioConnection patchCord5(mixer1, 0, i2s2, 0);
AudioConnection patchCord6(mixer2, 0, i2s2, 1);
AudioConnection patchCord7(combine1, fft1024_1);
AudioControlSGTL5000 sgtl5000_1; //xy=730,491
// GUItool: end automatically generated code
Adafruit_MPR121 cap = Adafruit_MPR121();
static int vol = 0;
static int bal = 511;
void setup() {
Serial.begin(115200);
cap.begin(0x5A);
AudioMemory(100);
sgtl5000_1.enable();
sgtl5000_1.volume(0.2);
// Butterworth filter, 12 db/octave
// biquad1.setLowpass(0, 800, 0.707);
// Linkwitz-Riley filter, 48 dB/octave
//biquad1.setLowpass(0, 800, 0.54);
//biquad1.setLowpass(1, 800, 1.3);
//biquad1.setLowpass(2, 800, 0.54);
//biquad1.setLowpass(3, 800, 1.3);
fft1024_1.windowFunction(AudioWindowHanning1024);
mixer1.gain(0, 0.5);
mixer1.gain(1, 0.0);
mixer1.gain(2, 0.0);
mixer1.gain(3, 0.0);
mixer2.gain(0, 0.5);
mixer2.gain(1, 0.0);
mixer2.gain(2, 0.0);
mixer2.gain(3, 0.0);
/*
mixer3.gain(0, 0.5);
mixer3.gain(1, 0.5);
mixer2.gain(2, 0.0);
mixer2.gain(3, 0.0);
*/
sgtl5000_1.inputSelect(AUDIO_INPUT_LINEIN);
// sgtl5000_1.inputSelect(AUDIO_INPUT_MIC);
// sgtl5000_1.micGain(63);
// sgtl5000_1.lineInLevel(7,7);
delay(1000);
}
void loop() {
float n;
int i;
float gain1;
float gain2;
// get volume from knob1
int knob1 = analogRead(A1);
if ((knob1 < vol-9)||(knob1 > vol+9)) { // allow for a bit of wobble
vol = knob1;
// Serial.print("vol = ");
// Serial.println(vol);
sgtl5000_1.volume(knob1 / 1023.0); //note decimal point on the float constant
}
// get balance from knob0
int knob0 = analogRead(A0);
if ((knob0 < bal-9)||(knob0 > bal+9)) { // allow for a bit of wobble
bal = knob0;
// Serial.print("bal = ");
// Serial.println(bal);
gain1 = bal / 1023.0;
// Serial.print("gain1 = ");
// Serial.print(gain1);
// Serial.print(" ");
gain2 = (1023 - bal) / 1023.0; //note decimal point on the float constant
// Serial.print("gain2 = ");
// Serial.println(gain2);
mixer1.gain(0, gain2); //left right swapped....
mixer2.gain(0, gain1);
}
if (fft1024_1.available()) {
// Serial.print("FFT: ");
for (i = 0; i < 52; i=i+4) {
n = fft1024_1.read(i);
// printNum(n * 1024);
// Serial.print(" ");
}
// Serial.println();
}
if (cap.touched() & (1 << 0)) {
}
if (cap.touched() & (1 << 1)) {
}
if (cap.touched() & (1 << 2)) {
}
if (cap.touched() & (1 << 3)) {
}
if (cap.touched() & (1 << 4)) {
}
if (cap.touched() & (1 << 5)) {
}
if (cap.touched() & (1 << 6)) {
}
if (cap.touched() & (1 << 7)) {
}
if (cap.touched() & (1 << 8)) {
}
if (cap.touched() & (1 << 9)) {
}
if (cap.touched() & (1 << 10)) {
}
if (cap.touched() & (1 << 11)) {
}
}
void printNum(float n) {
if (n >= 0.004) {
Serial.print(n, 2);
Serial.print(" ");
} else {
Serial.print(" "); // don't print "0.00"
}
}