Viking Skull Lamp  V1.0.1
Loading...
Searching...
No Matches
musicVisualizer.hpp
Go to the documentation of this file.
1/*
2 * Created on May 28 2022
3 *
4 * Copyright (c) 2022 - Daniel Hajnal
5 * hajnal.daniel96@gmail.com
6 * This file is part of the Viking Skull Lamp project.
7 * Modified 2022.06.27
8*/
9
10/*
11MIT License
12Copyright (c) 2022 Daniel Hajnal
13Permission is hereby granted, free of charge, to any person obtaining a copy
14of this software and associated documentation files (the "Software"), to deal
15in the Software without restriction, including without limitation the rights
16to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17copies of the Software, and to permit persons to whom the Software is
18furnished to do so, subject to the following conditions:
19The above copyright notice and this permission notice shall be included in all
20copies or substantial portions of the Software.
21THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27SOFTWARE.
28*/
29
30#ifndef MUSIC_MISUALIZER_HPP__
31#define MUSIC_MISUALIZER_HPP__
32
33#include "Arduino.h"
34
36#define SOUND_MID A0
37
39#define SOUND_HIGH A1
40
42#define SOUND_LOW A3
43
45#define SOUND_PEAK A2
46
52
53public:
57 musicChannel( int pin_p, float silentLimit_p );
58
63 musicChannel( int pin_p, float silentLimit_p, float offset_p );
64
71 musicChannel( int pin_p, float silentLimit_p, float offset_p, float avgSampleFilterBeta_p, float sampleFilterBeta_p );
72
77 void update();
78
84 void attachPeakFunction( void(*peakFunc_p)(void) );
85
87 bool peak;
88
90 float signal = 0.0;
91
94 float signalMax = 0.0;
95
96
97private:
98
101 float silentLimit = 0.0;
102
104 int pin = A0;
105
108 float avgSample = 0.0;
109
111 float sample = 0;
112
114 float signalPrev = 0.0;
115
117 float avgPeak = 0.0;
118
120 float offset = 512.0;
121
124
126 float sampleFilterBeta = 0.5;
127
129 void(*peakFunc)(void) = NULL;
130
131};
132
134extern musicChannel peak;
135
136#endif
This object is used to process audio data.
float signal
The filtered signal will be stored in this variable.
void update()
Update function.
float signalMax
The maximum level of the signal is stored in this variable.
int pin
Analog input pin of the channel.
float avgPeak
Average peak signal.
float sample
The raw sample will be processed to this variable.
float silentLimit
Silent limit.
float offset
Offset of the ADC result.
void(* peakFunc)(void)
Function pointer to peak event function.
float avgSampleFilterBeta
Filter constant for average sample.
float sampleFilterBeta
Filter constant for sample.
void attachPeakFunction(void(*peakFunc_p)(void))
Attach a function to every peak event.
float signalPrev
Previous value of the signal.
float avgSample
Holds the average filter level.
bool peak
Flag, that indicates a peak event.
musicChannel peak
Peak detector object.