Skip to content

Commit

Permalink
139 LED tri-band
Browse files Browse the repository at this point in the history
  • Loading branch information
gearsincorg committed Aug 12, 2021
1 parent 02e6867 commit 41c3196
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 29 deletions.
21 changes: 17 additions & 4 deletions VisualEar.ino
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ float downGainAccumulator = 0;

// -- LED Display Data
uint32_t bandValues[NUM_BANDS];
uint16_t LO_bandBins[NUM_LO_BANDS + 1] = {11,12,13,14,15,16,17,18,19,20,21,22,24,25,27,28,30,32,33,35,38,40,42,45,47,50,53,56,60,63,67,71,75,80,84,89,95,100,106,112,119,126};
uint16_t HI_bandBins[NUM_HI_BANDS + 1] = {21,22,24,25,27,28,30,32,33,35,37,40,42,45,47,50,53,56,60,63,67,71,75,79,84,89,94,100,106,112,119,126,134,142,150,159,168,178,189,200,212,225,238,252,267,283,300,318,337,357,378,400,424,449,476,504,534,566,600,636,673,713,756,801};
uint16_t LO_bandBins[NUM_LO_BANDS + 1] = {17,18,19,20,21,22,23,24,25,26,27,28,30,31,32,34,35,37,38,40,42,44,46,48,50,52,54,57,59,62,64,67,70,73,77,80,84};
uint16_t MD_bandBins[NUM_MD_BANDS + 1] = {42,44,46,48,50,52,54,57,59,62,64,67,70,73,77,80,84,87,91,95,99,104,108,113,118,123,129,135,141,147,153,160,167,174,182,190,199,207,217,226,236,247,258,269,281,293,306,320,334};
uint16_t HI_bandBins[NUM_HI_BANDS + 1] = {42,44,46,48,50,52,54,57,59,62,64,67,70,73,77,80,84,87,91,95,99,104,108,113,118,123,129,135,141,147,153,160,167,174,182,190,199,207,217,226,236,247,258,269,281,293,306,320,334,349,364,381,397};

// Create the Audio components. These should be created in the
AudioInputI2S audioInput; // audio shield: mic or line-in
Expand Down Expand Up @@ -239,7 +240,19 @@ void fillBands (void){

for (int b = 0; b < NUM_LO_BANDS; b++, band++){
// Accumulate freq values from all bins that match this LED band,
bandValues[band] = (uint32_t)myFFT.read(false, LO_bandBins[b], LO_bandBins[b+1], noiseFloor);
bandValues[band] = (uint32_t)myFFT.read(0, LO_bandBins[b], LO_bandBins[b+1], noiseFloor);
if (bandValues[band] > 2)
activeBands++;

// Adjust Noise Floor
if (noiseFloor > BASE_NOISE_FLOOR) {
noiseFloor = 97 * noiseFloor / 100; // equiv 0.97 factor.
}
}

for (int b = 0; b < NUM_MD_BANDS; b++, band++){
// Accumulate freq values from all bins that match this LED band,
bandValues[band] = (uint32_t)myFFT.read(1, MD_bandBins[b], MD_bandBins[b+1], noiseFloor);
if (bandValues[band] > 2)
activeBands++;

Expand All @@ -251,7 +264,7 @@ void fillBands (void){

for (int b = 0; b < NUM_HI_BANDS; b++, band++){
// Accumulate freq values from all bins that match this LED band,
bandValues[band] = (uint32_t)myFFT.read(true, HI_bandBins[b], HI_bandBins[b+1], noiseFloor);
bandValues[band] = (uint32_t)myFFT.read(2, HI_bandBins[b], HI_bandBins[b+1], noiseFloor);
if (bandValues[band] > 2)
activeBands++;

Expand Down
25 changes: 16 additions & 9 deletions audioAnalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@ AudioAnalyzeFFT::AudioAnalyzeFFT(void) : AudioStream(1, inputQueueArray)
LO_FFT = arduinoFFT_float(LO_vReal, LO_vImag, LO_weights, LO_FFT_SAMPLES, LO_SAMPLING_FREQ, FFT_WIN_TYP_HAMMING);
LO_Buffer = BufferManager(LO_vReal, LO_weights, LO_short, LO_FFT_SAMPLES, LO_SAMPLE_SKIP);

MD_FFT = arduinoFFT_float(MD_vReal, MD_vImag, MD_weights, MD_FFT_SAMPLES, MD_SAMPLING_FREQ, FFT_WIN_TYP_HAMMING);
MD_Buffer = BufferManager(MD_vReal, MD_weights, MD_short, MD_FFT_SAMPLES, MD_SAMPLE_SKIP);

HI_FFT = arduinoFFT_float(HI_vReal, HI_vImag, HI_weights, HI_FFT_SAMPLES, HI_SAMPLING_FREQ, FFT_WIN_TYP_HAMMING);
HI_Buffer = BufferManager(HI_vReal, HI_weights, HI_short, HI_FFT_SAMPLES, HI_SAMPLE_SKIP);

state = 0;
outputflag = false;

// memset(LO_vReal, 0, sizeof(LO_vReal));
// memset(Hi_vReal, 0, sizeof(Hi_vReal));
memset(LO_short, 0, sizeof(LO_short));
memset(MD_short, 0, sizeof(MD_short));
memset(HI_short, 0, sizeof(HI_short));

}
Expand All @@ -50,12 +52,14 @@ void AudioAnalyzeFFT::setInputScale(float scale){
inputScale = scale;
}

float AudioAnalyzeFFT::read(bool hiRange, unsigned short binNumber, float noiseThreshold) {
float AudioAnalyzeFFT::read(int range, unsigned short binNumber, float noiseThreshold) {
float tempVal;

if (!hiRange && (binNumber < LO_FREQ_BINS)) {
if ((range==0) && (binNumber < LO_FREQ_BINS)) {
tempVal = LO_vReal[binNumber];
} else if (hiRange && (binNumber < HI_FREQ_BINS)) {
} else if ((range==1) && (binNumber < MD_FREQ_BINS)) {
tempVal = MD_vReal[binNumber];
} else if ((range==2) && (binNumber < HI_FREQ_BINS)) {
tempVal = HI_vReal[binNumber];
} else {
tempVal = 0;
Expand All @@ -67,15 +71,15 @@ float AudioAnalyzeFFT::read(bool hiRange, unsigned short binNumber, float noise
return (tempVal);
}

float AudioAnalyzeFFT::read(bool hiRange, unsigned short binNumber) {
return (read(hiRange, binNumber, 0.0));
float AudioAnalyzeFFT::read(int range, unsigned short binNumber) {
return (read(range, binNumber, 0.0));
}

float AudioAnalyzeFFT::read(bool hiRange, unsigned short binFirst, unsigned short binLast, float noiseThreshold) {
float AudioAnalyzeFFT::read(int range, unsigned short binFirst, unsigned short binLast, float noiseThreshold) {

float sum = 0.0;
do {
sum += read(hiRange, binFirst++, noiseThreshold);
sum += read(range, binFirst++, noiseThreshold);
} while (binFirst <= binLast);
return sum;
}
Expand All @@ -99,6 +103,7 @@ void AudioAnalyzeFFT::update(void)
// add the latest block to the hi and low buffers
for (short sample = 0; sample < BURST_SAMPLES; sample++) {
LO_Buffer.addSample(*src);
MD_Buffer.addSample(*src);
HI_Buffer.addSample(*src);
src++;
}
Expand All @@ -112,10 +117,12 @@ void AudioAnalyzeFFT::update(void)

// transfer the accumulated buffers to the FFT. Remove bias and apply weights along the way
LO_Buffer.transfer(inputScale);
MD_Buffer.transfer(inputScale);
HI_Buffer.transfer(inputScale);

// Process the FFT
LO_FFT.RunFFT();
MD_FFT.RunFFT();
HI_FFT.RunFFT();

outputflag = true;
Expand Down
31 changes: 20 additions & 11 deletions audioAnalyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,26 @@
#define UNUSED_AUDIO_BITS 16 // Bits do discard from the 32 bit audio sample.

// Low Range Constants
const unsigned short LO_SAMPLE_SKIP = 6; // How many samples to combine
const unsigned short LO_SAMPLE_SKIP = 16; // How many samples to combine
const unsigned short LO_SAMPLING_FREQ = 44100 / LO_SAMPLE_SKIP; // Frequency at which microphone is sampled
const unsigned short LO_FFT_SAMPLES = 2048; // Number of samples used to do FFT.
const unsigned short LO_FFT_SAMPLES = 1024; // Number of samples used to do FFT.
const unsigned short LO_FREQ_BINS = LO_FFT_SAMPLES >> 1; // Number of results
//const unsigned short LO_BURSTS_PER_AUDIO = 16 * LO_SAMPLE_SKIP ;

// Low Range Constants
const unsigned short MD_SAMPLE_SKIP = 8; // How many samples to combine
const unsigned short MD_SAMPLING_FREQ = 44100 / MD_SAMPLE_SKIP; // Frequency at which microphone is sampled
const unsigned short MD_FFT_SAMPLES = 1024; // Number of samples used to do FFT.
const unsigned short MD_FREQ_BINS = MD_FFT_SAMPLES >> 1; // Number of results

// High Range Constants
const unsigned short HI_SAMPLE_SKIP = 1; // How many samples to combine
const unsigned short HI_SAMPLING_FREQ = 44100 / HI_SAMPLE_SKIP; // Frequency at which microphone is sampled
const unsigned short HI_FFT_SAMPLES = 2048; // Number of samples used to do FFT.
const unsigned short HI_FFT_SAMPLES = 1024; // Number of samples used to do FFT.
const unsigned short HI_FREQ_BINS = HI_FFT_SAMPLES >> 1; // Number of results
//const unsigned short HI_BURSTS_PER_AUDIO = 16 * HI_SAMPLE_SKIP ;

// Audio Sample constants
const unsigned short BURST_SAMPLES = 128; // Number of audio samples taken in one "Burst"
//const unsigned short BURSTS_PER_AUDIO = LO_BURSTS_PER_AUDIO; // Number of Burst Buffers used to create a single Audio Packet
const unsigned short BURSTS_PER_FFT_UPDATE = 4; // Number of Burst received before doing an FFT update
//const unsigned short SAMPLES_AVG_SHIFT = 13; // Bit shift required to average one full Sample
//const unsigned short EXTRA_BURSTS = 16; // Extra Burst packets to avoid overlap
const unsigned short NUM_BURSTS = 8;
const unsigned short SIZEOF_BURST = (BURST_SAMPLES << 2); // Number of bytes in a Burst Buffer

Expand All @@ -67,9 +68,9 @@ class AudioAnalyzeFFT : public AudioStream
AudioAnalyzeFFT(void);
bool available(void);
bool missingBlocks(void);
float read(bool hiRange, unsigned short binNumber);
float read(bool hiRange, unsigned short binNumber, float noiseThreshold);
float read(bool hiRange, unsigned short binFirst, unsigned short binLast, float noiseThreshold);
float read(int range, unsigned short binNumber);
float read(int range, unsigned short binNumber, float noiseThreshold);
float read(int range, unsigned short binFirst, unsigned short binLast, float noiseThreshold);
void setInputScale(float scale);
virtual void update(void);

Expand All @@ -96,6 +97,14 @@ class AudioAnalyzeFFT : public AudioStream
arduinoFFT_float LO_FFT;
BufferManager LO_Buffer;

short MD_short[MD_FFT_SAMPLES];
float MD_vReal[MD_FFT_SAMPLES];
float MD_vImag[MD_FFT_SAMPLES];
float MD_weights[MD_FFT_SAMPLES];

arduinoFFT_float MD_FFT;
BufferManager MD_Buffer;

short HI_short[LO_FFT_SAMPLES];
float HI_vReal[HI_FFT_SAMPLES];
float HI_vImag[HI_FFT_SAMPLES];
Expand Down
7 changes: 4 additions & 3 deletions devconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
#define FLIP_LED_ORDER true
#define NUM_MODES 4

#define NUM_LO_BANDS 41 // Number of LOW frequency bands
#define NUM_HI_BANDS 63 // Number of HIGH frequency bands
#define NUM_BANDS (NUM_LO_BANDS + NUM_HI_BANDS) // Total Number of frequency bands being displayed
#define NUM_LO_BANDS 37 // Number of LOW frequency bands
#define NUM_MD_BANDS 48 // Number of MID frequency bands
#define NUM_HI_BANDS 52 // Number of HIGH frequency bands
#define NUM_BANDS (NUM_LO_BANDS + NUM_MD_BANDS + NUM_HI_BANDS) // Total Number of frequency bands being displayed

#define NUM_LEDS NUM_BANDS // One LED per Band
#define MIN_DB 30.0
Expand Down
4 changes: 2 additions & 2 deletions display.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

#define TOP_HUE_NUMBER 240.0

//#define GRAVITY -9.8 //
#define GRAVITY -2.0 //
//#define GRAVITY -2.0 //
#define GRAVITY -1.5 //
#define LED_PER_METER 60

extern double minScale;
Expand Down

0 comments on commit 41c3196

Please sign in to comment.