NanoLux (Device) 3.0
Codebase for the open-source AudioLux device.
Loading...
Searching...
No Matches
core_analysis.cpp File Reference
#include <Arduino.h>
#include "arduinoFFT.h"
#include "nanolux_types.h"
#include "nanolux_util.h"
#include <cmath>

Functions

void sample_audio ()
 Samples incoming audio and stores the signal in vReal.
 
void noise_gate (int threshhold)
 Zeros all audio analysis arrays if the volume is too low.
 
void update_volume ()
 Calculates and stores the current volume.
 
void update_max_delta ()
 Updates the largest frequency change in the last cycle.
 
void update_peak ()
 Updates the current peak frequency.
 

Variables

unsigned int sampling_period_us
 Audio sampling period.
 
double volume
 Global variable used to access the current volume.
 
double peak
 Global variable used to store preak audio frequency.
 
bool is_fft_initalized = false
 
double vReal [SAMPLES]
 
double vRealHist [SAMPLES]
 Last state of the vReal array.
 
double vImag [SAMPLES]
 Imaginary component of vReal. Unused.
 
double delt [SAMPLES]
 
ArduinoFFT< double > FFT = ArduinoFFT<double>(vReal, vImag, SAMPLES, SAMPLING_FREQUENCY)
 FFT used for processing audio.
 
double maxDelt
 

Detailed Description

This file's functions perform basic audio processing.

Many of the functions in ext_analysis.cpp use values calculated here to perform more complex audio analysis.

Function Documentation

◆ noise_gate()

void noise_gate ( int threshhold)

Zeros all audio analysis arrays if the volume is too low.

Parameters
thresholdThe threshold to compare the total volume against.

◆ sample_audio()

void sample_audio ( )

Samples incoming audio and stores the signal in vReal.

Reads from ANALOG_PIN for the calculated sampling period. Once a timestep is sampled, the function sleeps until ready to sample again at the next timestep.

◆ update_max_delta()

void update_max_delta ( )

Updates the largest frequency change in the last cycle.

Places the calculated value in the "maxDelt" variable.

◆ update_peak()

void update_peak ( )

Updates the current peak frequency.

Places the calculated peak frequency in the "peak" variable.

◆ update_volume()

void update_volume ( )

Calculates and stores the current volume.

Volume is stored in the "volume" global variable.

Variable Documentation

◆ delt

double delt[SAMPLES]
extern

Variable used to store the frequency delta between vReal and vRealHist.

◆ maxDelt

double maxDelt
extern

Global variable used to access the frequency band with the largest delta between iterations.

◆ peak

double peak
extern

Global variable used to store preak audio frequency.

Global variable used to store preak audio frequency.

◆ volume

double volume
extern

Global variable used to access the current volume.

Global variable used to access the current volume.

◆ vReal

double vReal[SAMPLES]
extern

Array to store both sampled and FFT'ed audio. Processing is done in place.