File tree Expand file tree Collapse file tree 2 files changed +51
-2
lines changed
examples/tests/filters/test-lowpass Expand file tree Collapse file tree 2 files changed +51
-2
lines changed Original file line number Diff line number Diff line change
1
+ #include " AudioTools.h"
2
+
3
+ AudioInfo info (44100 , 2 , 16 );
4
+ VolumeMeter meter;
5
+ FilteredStream<int16_t , float > filtered (meter);
6
+ SineWaveGenerator<int16_t > sine;
7
+ GeneratedSoundStream<int16_t > sine_stream (sine);
8
+ StreamCopy copier (filtered, sine_stream);
9
+ float filter_freq = 8000 ;
10
+
11
+ // Filter: or replace with other filters
12
+ LowPassFilter<float > filter1 (filter_freq, info.sample_rate);
13
+ LowPassFilter<float > filter2 (filter_freq, info.sample_rate);
14
+
15
+ void setup () {
16
+ Serial.begin (115200 );
17
+ AudioToolsLogger.begin (Serial, AudioToolsLogLevel::Warning);
18
+
19
+ sine.begin (info, 0 );
20
+ if (!sine_stream.begin (info)){
21
+ Serial.println (" Generator error" );
22
+ stop ();
23
+ }
24
+
25
+ if (!filtered.begin (info)){
26
+ Serial.println (" filter error" );
27
+ stop ();
28
+ }
29
+ filtered.setFilter (0 , filter1);
30
+ filtered.setFilter (1 , filter2);
31
+
32
+ if (!meter.begin (info)){
33
+ Serial.println (" meter error" );
34
+ stop ();
35
+ }
36
+
37
+ }
38
+
39
+ void loop () {
40
+ for (int freq= 20 ; freq<20000 ; freq+=100 ){
41
+ meter.clear ();
42
+ sine.setFrequency (freq);
43
+ copier.copyN (10 );
44
+ Serial.print (freq);
45
+ Serial.print (" : " );
46
+ Serial.println (meter.volumeRatio ());
47
+ }
48
+ stop ();
49
+ }
Original file line number Diff line number Diff line change @@ -1589,7 +1589,7 @@ class FilteredStream : public ModifyingStream {
1589
1589
bool begin (AudioInfo info){
1590
1590
setAudioInfo (info);
1591
1591
this ->channels = info.channels ;
1592
- if (p_converter !=nullptr && info. channels !=channels){
1592
+ if (p_converter !=nullptr && p_converter-> getChannels () !=channels){
1593
1593
LOGE (" Inconsistent number of channels" );
1594
1594
return false ;
1595
1595
}
@@ -1650,7 +1650,7 @@ class FilteredStream : public ModifyingStream {
1650
1650
int channels=0 ;
1651
1651
Stream *p_stream = nullptr ;
1652
1652
Print *p_print = nullptr ;
1653
- ConverterNChannels<T,TF> *p_converter;
1653
+ ConverterNChannels<T,TF> *p_converter = nullptr ;
1654
1654
1655
1655
};
1656
1656
You can’t perform that action at this time.
0 commit comments