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

Side by Side Diff: content/browser/speech/speech_recognizer_impl.cc

Issue 1304973005: Refactor AudioParameters member setting. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cross-platform fixes. Created 5 years, 3 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 #include "content/browser/speech/speech_recognizer_impl.h" 5 #include "content/browser/speech/speech_recognizer_impl.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/time/time.h" 9 #include "base/time/time.h"
10 #include "content/browser/browser_main_loop.h" 10 #include "content/browser/browser_main_loop.h"
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 } 232 }
233 233
234 bool SpeechRecognizerImpl::IsActive() const { 234 bool SpeechRecognizerImpl::IsActive() const {
235 // Checking the FSM state from another thread (thus, while the FSM is 235 // Checking the FSM state from another thread (thus, while the FSM is
236 // potentially concurrently evolving) is meaningless. 236 // potentially concurrently evolving) is meaningless.
237 DCHECK_CURRENTLY_ON(BrowserThread::IO); 237 DCHECK_CURRENTLY_ON(BrowserThread::IO);
238 return state_ != STATE_IDLE && state_ != STATE_ENDED; 238 return state_ != STATE_IDLE && state_ != STATE_ENDED;
239 } 239 }
240 240
241 bool SpeechRecognizerImpl::IsCapturingAudio() const { 241 bool SpeechRecognizerImpl::IsCapturingAudio() const {
242 DCHECK_CURRENTLY_ON(BrowserThread::IO); // See IsActive(). 242 DCHECK_CURRENTLY_ON(BrowserThread::IO); // See IsActive().
243 const bool is_capturing_audio = state_ >= STATE_STARTING && 243 const bool is_capturing_audio = state_ >= STATE_STARTING &&
244 state_ <= STATE_RECOGNIZING; 244 state_ <= STATE_RECOGNIZING;
245 DCHECK((is_capturing_audio && (audio_controller_.get() != NULL)) || 245 DCHECK((is_capturing_audio && (audio_controller_.get() != NULL)) ||
246 (!is_capturing_audio && audio_controller_.get() == NULL)); 246 (!is_capturing_audio && audio_controller_.get() == NULL));
247 return is_capturing_audio; 247 return is_capturing_audio;
248 } 248 }
249 249
250 const SpeechRecognitionEngine& 250 const SpeechRecognitionEngine&
251 SpeechRecognizerImpl::recognition_engine() const { 251 SpeechRecognizerImpl::recognition_engine() const {
252 return *(recognition_engine_.get()); 252 return *(recognition_engine_.get());
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 state_ <= STATE_RECOGNIZING; 482 state_ <= STATE_RECOGNIZING;
483 const bool clip_detected = DetectClipping(raw_audio); 483 const bool clip_detected = DetectClipping(raw_audio);
484 float rms = 0.0f; 484 float rms = 0.0f;
485 485
486 num_samples_recorded_ += raw_audio.NumSamples(); 486 num_samples_recorded_ += raw_audio.NumSamples();
487 487
488 if (route_to_endpointer) 488 if (route_to_endpointer)
489 endpointer_.ProcessAudio(raw_audio, &rms); 489 endpointer_.ProcessAudio(raw_audio, &rms);
490 490
491 if (route_to_vumeter) { 491 if (route_to_vumeter) {
492 DCHECK(route_to_endpointer); // Depends on endpointer due to |rms|. 492 DCHECK(route_to_endpointer); // Depends on endpointer due to |rms|.
493 UpdateSignalAndNoiseLevels(rms, clip_detected); 493 UpdateSignalAndNoiseLevels(rms, clip_detected);
494 } 494 }
495 if (route_to_sr_engine) { 495 if (route_to_sr_engine) {
496 DCHECK(recognition_engine_.get() != NULL); 496 DCHECK(recognition_engine_.get() != NULL);
497 recognition_engine_->TakeAudioChunk(raw_audio); 497 recognition_engine_->TakeAudioChunk(raw_audio);
498 } 498 }
499 } 499 }
500 500
501 SpeechRecognizerImpl::FSMState 501 SpeechRecognizerImpl::FSMState
502 SpeechRecognizerImpl::StartRecording(const FSMEventArgs&) { 502 SpeechRecognizerImpl::StartRecording(const FSMEventArgs&) {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 // Use native audio parameters but avoid opening up at the native buffer 556 // Use native audio parameters but avoid opening up at the native buffer
557 // size. Instead use same frame size (in milliseconds) as WebSpeech uses. 557 // size. Instead use same frame size (in milliseconds) as WebSpeech uses.
558 // We rely on internal buffers in the audio back-end to fulfill this request 558 // We rely on internal buffers in the audio back-end to fulfill this request
559 // and the idea is to simplify the audio conversion since each Convert() 559 // and the idea is to simplify the audio conversion since each Convert()
560 // call will then render exactly one ProvideInput() call. 560 // call will then render exactly one ProvideInput() call.
561 // in_params.sample_rate() 561 // in_params.sample_rate()
562 frames_per_buffer = 562 frames_per_buffer =
563 ((in_params.sample_rate() * chunk_duration_ms) / 1000.0) + 0.5; 563 ((in_params.sample_rate() * chunk_duration_ms) / 1000.0) + 0.5;
564 input_parameters.Reset(in_params.format(), 564 input_parameters.Reset(in_params.format(),
565 in_params.channel_layout(), 565 in_params.channel_layout(),
566 in_params.channels(),
567 in_params.sample_rate(), 566 in_params.sample_rate(),
568 in_params.bits_per_sample(), 567 in_params.bits_per_sample(),
569 frames_per_buffer); 568 frames_per_buffer);
569 input_parameters.set_channels_for_discrete(in_params.channels());
570 DVLOG(1) << "SRI::input_parameters: " 570 DVLOG(1) << "SRI::input_parameters: "
571 << input_parameters.AsHumanReadableString(); 571 << input_parameters.AsHumanReadableString();
572 } 572 }
573 573
574 // Create an audio converter which converts data between native input format 574 // Create an audio converter which converts data between native input format
575 // and WebSpeech specific output format. 575 // and WebSpeech specific output format.
576 audio_converter_.reset( 576 audio_converter_.reset(
577 new OnDataConverter(input_parameters, output_parameters)); 577 new OnDataConverter(input_parameters, output_parameters));
578 578
579 audio_controller_ = AudioInputController::Create( 579 audio_controller_ = AudioInputController::Create(
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 SpeechRecognizerImpl::FSMEventArgs::FSMEventArgs(FSMEvent event_value) 827 SpeechRecognizerImpl::FSMEventArgs::FSMEventArgs(FSMEvent event_value)
828 : event(event_value), 828 : event(event_value),
829 audio_data(NULL), 829 audio_data(NULL),
830 engine_error(SPEECH_RECOGNITION_ERROR_NONE) { 830 engine_error(SPEECH_RECOGNITION_ERROR_NONE) {
831 } 831 }
832 832
833 SpeechRecognizerImpl::FSMEventArgs::~FSMEventArgs() { 833 SpeechRecognizerImpl::FSMEventArgs::~FSMEventArgs() {
834 } 834 }
835 835
836 } // namespace content 836 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/media/audio_renderer_host_unittest.cc ('k') | content/common/media/media_param_traits.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698