Viking Skull Lamp  V1.0.1
Loading...
Searching...
No Matches
musicChannel Class Reference

This object is used to process audio data. More...

#include <musicVisualizer.hpp>

Public Member Functions

 musicChannel (int pin_p, float silentLimit_p)
 Constructor. More...
 
 musicChannel (int pin_p, float silentLimit_p, float offset_p)
 Constructor. More...
 
 musicChannel (int pin_p, float silentLimit_p, float offset_p, float avgSampleFilterBeta_p, float sampleFilterBeta_p)
 Constructor. More...
 
void update ()
 Update function. More...
 
void attachPeakFunction (void(*peakFunc_p)(void))
 Attach a function to every peak event. More...
 

Public Attributes

bool peak
 Flag, that indicates a peak event. More...
 
float signal = 0.0
 The filtered signal will be stored in this variable. More...
 
float signalMax = 0.0
 The maximum level of the signal is stored in this variable. More...
 

Private Attributes

float silentLimit = 0.0
 Silent limit. More...
 
int pin = A0
 Analog input pin of the channel. More...
 
float avgSample = 0.0
 Holds the average filter level. More...
 
float sample = 0
 The raw sample will be processed to this variable. More...
 
float signalPrev = 0.0
 Previous value of the signal. More...
 
float avgPeak = 0.0
 Average peak signal. More...
 
float offset = 512.0
 Offset of the ADC result. More...
 
float avgSampleFilterBeta = 0.3
 Filter constant for average sample. More...
 
float sampleFilterBeta = 0.5
 Filter constant for sample. More...
 
void(* peakFunc )(void) = NULL
 Function pointer to peak event function. More...
 

Detailed Description

This object is used to process audio data.

It is basically an advanced peak detector. It detects the noise floor dynamically to adjust it to the environment.

Definition at line 51 of file musicVisualizer.hpp.

Constructor & Destructor Documentation

◆ musicChannel() [1/3]

musicChannel::musicChannel ( int  pin_p,
float  silentLimit_p 
)

Constructor.

Parameters
pin_pAnalog input pin.
silentLimit_pSilent limit level. It depends on the exact type of the microphone.

Definition at line 32 of file musicVisualizer.cpp.

◆ musicChannel() [2/3]

musicChannel::musicChannel ( int  pin_p,
float  silentLimit_p,
float  offset_p 
)

Constructor.

Parameters
pin_pAnalog input pin.
silentLimit_pSilent limit level. It depends on the exact type of the microphone.
offset_pADC offset. It is used when the ADC data is shifted. For example to half supply.

Definition at line 40 of file musicVisualizer.cpp.

◆ musicChannel() [3/3]

musicChannel::musicChannel ( int  pin_p,
float  silentLimit_p,
float  offset_p,
float  avgSampleFilterBeta_p,
float  sampleFilterBeta_p 
)

Constructor.

Parameters
pin_pAnalog input pin.
silentLimit_pSilent limit level. It depends on the exact type of the microphone.
offset_pADC offset. It is used when the ADC data is shifted. For example to half supply.
avgSampleFilterBeta_pFilter coefficient for the average sample data. It used by a complementary-filter. Range [ 0.0 - 1.0 ]
sampleFilterBeta_pFilter coefficient for the sample data. It used by a complementary-filter. Range [ 0.0 - 1.0 ]

Definition at line 49 of file musicVisualizer.cpp.

Member Function Documentation

◆ attachPeakFunction()

void musicChannel::attachPeakFunction ( void(*)(void)  peakFunc_p)

Attach a function to every peak event.

You can attach a function to every peak event. It can be useful when you want to respond very fast to a peak.

Parameters
peakFunc_pFunction that will be called when a peak event occurs.

Definition at line 60 of file musicVisualizer.cpp.

◆ update()

void musicChannel::update ( )

Update function.

This function has to be called periodically with fixed timing.

Note
I tested it with various sampling times, in my opinion 30ms is a good choice.

Definition at line 67 of file musicVisualizer.cpp.

Here is the caller graph for this function:

Member Data Documentation

◆ avgPeak

float musicChannel::avgPeak = 0.0
private

Average peak signal.

Definition at line 117 of file musicVisualizer.hpp.

◆ avgSample

float musicChannel::avgSample = 0.0
private

Holds the average filter level.

If the signal level rises above this level, a peak event will trigger.

Definition at line 108 of file musicVisualizer.hpp.

◆ avgSampleFilterBeta

float musicChannel::avgSampleFilterBeta = 0.3
private

Filter constant for average sample.

Definition at line 123 of file musicVisualizer.hpp.

◆ offset

float musicChannel::offset = 512.0
private

Offset of the ADC result.

Definition at line 120 of file musicVisualizer.hpp.

◆ peak

bool musicChannel::peak

Flag, that indicates a peak event.

Definition at line 87 of file musicVisualizer.hpp.

◆ peakFunc

void(* musicChannel::peakFunc) (void) = NULL
private

Function pointer to peak event function.

Definition at line 129 of file musicVisualizer.hpp.

◆ pin

int musicChannel::pin = A0
private

Analog input pin of the channel.

Definition at line 104 of file musicVisualizer.hpp.

◆ sample

float musicChannel::sample = 0
private

The raw sample will be processed to this variable.

Definition at line 111 of file musicVisualizer.hpp.

◆ sampleFilterBeta

float musicChannel::sampleFilterBeta = 0.5
private

Filter constant for sample.

Definition at line 126 of file musicVisualizer.hpp.

◆ signal

float musicChannel::signal = 0.0

The filtered signal will be stored in this variable.

Definition at line 90 of file musicVisualizer.hpp.

◆ signalMax

float musicChannel::signalMax = 0.0

The maximum level of the signal is stored in this variable.

Imagine it like a digital Vu meters output.

Definition at line 94 of file musicVisualizer.hpp.

◆ signalPrev

float musicChannel::signalPrev = 0.0
private

Previous value of the signal.

Definition at line 114 of file musicVisualizer.hpp.

◆ silentLimit

float musicChannel::silentLimit = 0.0
private

Silent limit.

If the signal is less then this value, it wont react to peaks. It has to be tuned for the microphone and the analog stage.

Definition at line 101 of file musicVisualizer.hpp.