File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -64,6 +64,7 @@ void AudioAnalyzePeak_F32::update(void) {
6464 min_sample = min;
6565 max_sample = max;
6666 new_output = true ; // Tell available() that data is available
67+ count++; // Number of blocks involved in peak determination
6768 AudioStream_F32::release (blockIn);
6869 }
6970
@@ -77,6 +78,7 @@ float AudioAnalyzePeak_F32::read(void) {
7778 min = abs (min);
7879 max = abs (max);
7980 if (min > max) max = min;
81+ count = 0 ; // Reset
8082 return max;
8183 }
8284
@@ -86,5 +88,6 @@ float AudioAnalyzePeak_F32:: readPeakToPeak(void) {
8688 float32_t min = min_sample;
8789 float32_t max = max_sample;
8890 __enable_irq ();
91+ count = 0 ; // Reset
8992 return (max - min);
9093 }
Original file line number Diff line number Diff line change @@ -81,6 +81,11 @@ class AudioAnalyzePeak_F32 : public AudioStream_F32 {
8181 errorPrint = e;
8282 }
8383
84+ // Returns the number blocks included in peak calculation.
85+ uint32_t getCount (void ) {
86+ return count;
87+ }
88+
8489 virtual void update (void );
8590 float32_t read (void );
8691 float32_t readPeakToPeak (void );
@@ -92,7 +97,8 @@ class AudioAnalyzePeak_F32 : public AudioStream_F32 {
9297 volatile bool just_read = true ;
9398 float32_t min_sample;
9499 float32_t max_sample;
95-
100+ uint32_t count = 0 ;
101+
96102 // Control error printing in update(). Should never be enabled
97103 // until all audio objects have been initialized.
98104 // Only used as 0 or 1 now, but 16 bits are available.
Original file line number Diff line number Diff line change @@ -78,10 +78,17 @@ class AudioAnalyzeRMS_F32 : public AudioStream_F32 {
7878 return count > 0 ;
7979 }
8080
81+ // Returns the number of 128 sample blocks included in rms calculation.
82+ uint32_t getCount (void ) {
83+ return count;
84+ }
85+
8186 void showError (uint16_t e) { // 0/1 Disables/Enables printing of update() errors
8287 errorPrint = e;
8388 }
8489
90+ // Returns the square root of average power over count blocks of 128 power samples.
91+ // Also clears the power accumulator and can be used for this.
8592 float read (void );
8693
8794 virtual void update (void );
@@ -93,7 +100,7 @@ class AudioAnalyzeRMS_F32 : public AudioStream_F32 {
93100 // whereas float range for positive numbers is 2^23 =~ 1E7 so double is easily justified for accuracy.
94101 // The timing 7 microseconds per 128, includes using double for accum, so the price is reasonable.
95102 double accum = 0.0 ;
96- uint32_t count = 0 ;
103+ uint32_t count = 0 ;
97104
98105 // Control error printing in update(). Should never be enabled
99106 // until all audio objects have been initialized.
You can’t perform that action at this time.
0 commit comments