Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(208)

Unified Diff: content/browser/speech/endpointer/energy_endpointer.cc

Issue 6597071: Add a noise indicator to the speech bubble volume indicator. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed all review comments. Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/speech/endpointer/energy_endpointer.cc
diff --git a/content/browser/speech/endpointer/energy_endpointer.cc b/content/browser/speech/endpointer/energy_endpointer.cc
index c806aedd0b5c79eb96b8d349725d9e9e60348593..edf3edd7c0a364d3ce44ba2330ff882f4df15fbe 100644
--- a/content/browser/speech/endpointer/energy_endpointer.cc
+++ b/content/browser/speech/endpointer/energy_endpointer.cc
@@ -33,6 +33,13 @@ int64 Secs2Usecs(float seconds) {
return static_cast<int64>(0.5 + (1.0e6 * seconds));
}
+float GetDecibel(float value) {
+ const float kVerySmallValue = 1.0e-100f;
+ if (value < kVerySmallValue)
+ value = kVerySmallValue;
+ return 20 * log10(value);
+}
+
} // namespace
namespace speech_input {
@@ -326,11 +333,12 @@ void EnergyEndpointer::ProcessAudioFrame(int64 time_us,
UpdateLevels(rms);
++frame_counter_;
- if (rms_out) {
- *rms_out = -120.0;
- if ((noise_level_ > 0.0) && ((rms / noise_level_ ) > 0.000001))
- *rms_out = static_cast<float>(20.0 * log10(rms / noise_level_));
- }
+ if (rms_out)
+ *rms_out = GetDecibel(rms);
+}
+
+float EnergyEndpointer::GetNoiseLevelDb() const {
+ return GetDecibel(noise_level_);
}
void EnergyEndpointer::UpdateLevels(float rms) {

Powered by Google App Engine
This is Rietveld 408576698