@@ -45,12 +45,26 @@ public: | |||
} | |||
float read(void) { | |||
__disable_irq(); | |||
int diff = max_sample - min_sample; | |||
int min = min_sample; | |||
int max = max_sample; | |||
min_sample = 32767; | |||
max_sample = -32768; | |||
__enable_irq(); | |||
return diff / 65535.0; | |||
min = abs(min); | |||
max = abs(max); | |||
if (min > max) max = min; | |||
return (float)max / 32767.0f; | |||
} | |||
float readPeakToPeak(void) { | |||
__disable_irq(); | |||
int min = min_sample; | |||
int max = max_sample; | |||
min_sample = 32767; | |||
max_sample = -32768; | |||
__enable_irq(); | |||
return (float)(max - min) / 32767.0f; | |||
} | |||
virtual void update(void); | |||
private: | |||
audio_block_t *inputQueueArray[1]; |
@@ -2082,9 +2082,13 @@ double s_freq = .0625;</p> | |||
<p class=desc>Returns true each time new peak data is available. | |||
</p> | |||
<p class=func><span class=keyword>read</span>();</p> | |||
<p class=desc>Read the highest peak value since the last read. | |||
<p class=desc>Read the highest peak amplitude value since the last read. | |||
Return is from 0.0 to 1.0. | |||
</p> | |||
<p class=func><span class=keyword>readPeakToPeak</span>();</p> | |||
<p class=desc>Read the highest peak-to-peak amplitude since the last read. | |||
Return is from 0.0 to 2.0. | |||
</p> | |||
<h3>Examples</h3> | |||
<p class=exam>File > Examples > Audio > Analysis > PeakMeterMono | |||
</p> |