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

Side by Side 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, 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 // To know more about the algorithm used and the original code which this is 5 // To know more about the algorithm used and the original code which this is
6 // based of, see 6 // based of, see
7 // https://wiki.corp.google.com/twiki/bin/view/Main/ChromeGoogleCodeXRef 7 // https://wiki.corp.google.com/twiki/bin/view/Main/ChromeGoogleCodeXRef
8 8
9 #include "content/browser/speech/endpointer/energy_endpointer.h" 9 #include "content/browser/speech/endpointer/energy_endpointer.h"
10 10
(...skipping 15 matching lines...) Expand all
26 double sum = static_cast<double>(sum_int64); 26 double sum = static_cast<double>(sum_int64);
27 sum /= num_samples; 27 sum /= num_samples;
28 double ssq = static_cast<double>(ssq_int64); 28 double ssq = static_cast<double>(ssq_int64);
29 return static_cast<float>(sqrt((ssq / num_samples) - (sum * sum))); 29 return static_cast<float>(sqrt((ssq / num_samples) - (sum * sum)));
30 } 30 }
31 31
32 int64 Secs2Usecs(float seconds) { 32 int64 Secs2Usecs(float seconds) {
33 return static_cast<int64>(0.5 + (1.0e6 * seconds)); 33 return static_cast<int64>(0.5 + (1.0e6 * seconds));
34 } 34 }
35 35
36 float GetDecibel(float value) {
37 const float kVerySmallValue = 1.0e-100f;
38 if (value < kVerySmallValue)
39 value = kVerySmallValue;
40 return 20 * log10(value);
41 }
42
36 } // namespace 43 } // namespace
37 44
38 namespace speech_input { 45 namespace speech_input {
39 46
40 // Stores threshold-crossing histories for making decisions about the speech 47 // Stores threshold-crossing histories for making decisions about the speech
41 // state. 48 // state.
42 class EnergyEndpointer::HistoryRing { 49 class EnergyEndpointer::HistoryRing {
43 public: 50 public:
44 HistoryRing() : insertion_index_(0) {} 51 HistoryRing() : insertion_index_(0) {}
45 52
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 326
320 // Set a floor 327 // Set a floor
321 if (decision_threshold_ < params_.min_decision_threshold()) 328 if (decision_threshold_ < params_.min_decision_threshold())
322 decision_threshold_ = params_.min_decision_threshold(); 329 decision_threshold_ = params_.min_decision_threshold();
323 } 330 }
324 331
325 // Update speech and noise levels. 332 // Update speech and noise levels.
326 UpdateLevels(rms); 333 UpdateLevels(rms);
327 ++frame_counter_; 334 ++frame_counter_;
328 335
329 if (rms_out) { 336 if (rms_out)
330 *rms_out = -120.0; 337 *rms_out = GetDecibel(rms);
331 if ((noise_level_ > 0.0) && ((rms / noise_level_ ) > 0.000001)) 338 }
332 *rms_out = static_cast<float>(20.0 * log10(rms / noise_level_)); 339
333 } 340 float EnergyEndpointer::GetNoiseLevelDb() const {
341 return GetDecibel(noise_level_);
334 } 342 }
335 343
336 void EnergyEndpointer::UpdateLevels(float rms) { 344 void EnergyEndpointer::UpdateLevels(float rms) {
337 // Update quickly initially. We assume this is noise and that 345 // Update quickly initially. We assume this is noise and that
338 // speech is 6dB above the noise. 346 // speech is 6dB above the noise.
339 if (frame_counter_ < fast_update_frames_) { 347 if (frame_counter_ < fast_update_frames_) {
340 // Alpha increases from 0 to (k-1)/k where k is the number of time 348 // Alpha increases from 0 to (k-1)/k where k is the number of time
341 // steps in the initial adaptation period. 349 // steps in the initial adaptation period.
342 float alpha = static_cast<float>(frame_counter_) / 350 float alpha = static_cast<float>(frame_counter_) /
343 static_cast<float>(fast_update_frames_); 351 static_cast<float>(fast_update_frames_);
(...skipping 16 matching lines...) Expand all
360 decision_threshold_ = params_.min_decision_threshold(); 368 decision_threshold_ = params_.min_decision_threshold();
361 } 369 }
362 } 370 }
363 371
364 EpStatus EnergyEndpointer::Status(int64* status_time) const { 372 EpStatus EnergyEndpointer::Status(int64* status_time) const {
365 *status_time = history_->EndTime(); 373 *status_time = history_->EndTime();
366 return status_; 374 return status_;
367 } 375 }
368 376
369 } // namespace speech 377 } // namespace speech
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698