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

Side by Side Diff: media/audio/agc_audio_stream.h

Issue 344583002: Modifies AudioInputCallback::OnData and use media::AudioBus instead of plain byte vector (Relanding) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added extra non-pure OnData API Created 6 years, 6 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifndef MEDIA_AUDIO_AGC_AUDIO_STREAM_H_ 5 #ifndef MEDIA_AUDIO_AGC_AUDIO_STREAM_H_
6 #define MEDIA_AUDIO_AGC_AUDIO_STREAM_H_ 6 #define MEDIA_AUDIO_AGC_AUDIO_STREAM_H_
7 7
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/synchronization/lock.h" 10 #include "base/synchronization/lock.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 namespace media { 66 namespace media {
67 67
68 template <typename AudioInterface> 68 template <typename AudioInterface>
69 class MEDIA_EXPORT AgcAudioStream : public AudioInterface { 69 class MEDIA_EXPORT AgcAudioStream : public AudioInterface {
70 public: 70 public:
71 // Time between two successive timer events. 71 // Time between two successive timer events.
72 static const int kIntervalBetweenVolumeUpdatesMs = 1000; 72 static const int kIntervalBetweenVolumeUpdatesMs = 1000;
73 73
74 AgcAudioStream() 74 AgcAudioStream()
75 : agc_is_enabled_(false), max_volume_(0.0), normalized_volume_(0.0) { 75 : agc_is_enabled_(false), max_volume_(0.0), normalized_volume_(0.0) {
76 DVLOG(1) << __FUNCTION__;
77 } 76 }
78 77
79 virtual ~AgcAudioStream() { 78 virtual ~AgcAudioStream() {
80 DCHECK(thread_checker_.CalledOnValidThread()); 79 DCHECK(thread_checker_.CalledOnValidThread());
81 DVLOG(1) << __FUNCTION__;
82 } 80 }
83 81
84 protected: 82 protected:
85 // Starts the periodic timer which periodically checks and updates the 83 // Starts the periodic timer which periodically checks and updates the
86 // current microphone volume level. 84 // current microphone volume level.
87 // The timer is only started if AGC mode is first enabled using the 85 // The timer is only started if AGC mode is first enabled using the
88 // SetAutomaticGainControl() method. 86 // SetAutomaticGainControl() method.
89 void StartAgc() { 87 void StartAgc() {
90 DVLOG(1) << "StartAgc()";
91 DCHECK(thread_checker_.CalledOnValidThread()); 88 DCHECK(thread_checker_.CalledOnValidThread());
92 if (!agc_is_enabled_ || timer_.IsRunning()) 89 if (!agc_is_enabled_ || timer_.IsRunning())
93 return; 90 return;
94 91
95 // Query and cache the volume to avoid sending 0 as volume to AGC at the 92 // Query and cache the volume to avoid sending 0 as volume to AGC at the
96 // beginning of the audio stream, otherwise AGC will try to raise the 93 // beginning of the audio stream, otherwise AGC will try to raise the
97 // volume from 0. 94 // volume from 0.
98 QueryAndStoreNewMicrophoneVolume(); 95 QueryAndStoreNewMicrophoneVolume();
99 96
100 timer_.Start(FROM_HERE, 97 timer_.Start(FROM_HERE,
101 base::TimeDelta::FromMilliseconds(kIntervalBetweenVolumeUpdatesMs), 98 base::TimeDelta::FromMilliseconds(kIntervalBetweenVolumeUpdatesMs),
102 this, &AgcAudioStream::QueryAndStoreNewMicrophoneVolume); 99 this, &AgcAudioStream::QueryAndStoreNewMicrophoneVolume);
103 } 100 }
104 101
105 // Stops the periodic timer which periodically checks and updates the 102 // Stops the periodic timer which periodically checks and updates the
106 // current microphone volume level. 103 // current microphone volume level.
107 void StopAgc() { 104 void StopAgc() {
108 DVLOG(1) << "StopAgc()";
109 DCHECK(thread_checker_.CalledOnValidThread()); 105 DCHECK(thread_checker_.CalledOnValidThread());
110 if (timer_.IsRunning()) 106 if (timer_.IsRunning())
111 timer_.Stop(); 107 timer_.Stop();
112 } 108 }
113 109
114 // Stores a new microphone volume level by checking the audio input device. 110 // Stores a new microphone volume level by checking the audio input device.
115 // Called on the audio manager thread. 111 // Called on the audio manager thread.
116 void UpdateAgcVolume() { 112 void UpdateAgcVolume() {
117 DCHECK(thread_checker_.CalledOnValidThread()); 113 DCHECK(thread_checker_.CalledOnValidThread());
118 114
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 195
200 // Protects |normalized_volume_| . 196 // Protects |normalized_volume_| .
201 base::Lock lock_; 197 base::Lock lock_;
202 198
203 DISALLOW_COPY_AND_ASSIGN(AgcAudioStream<AudioInterface>); 199 DISALLOW_COPY_AND_ASSIGN(AgcAudioStream<AudioInterface>);
204 }; 200 };
205 201
206 } // namespace media 202 } // namespace media
207 203
208 #endif // MEDIA_AUDIO_AGC_AUDIO_STREAM_H_ 204 #endif // MEDIA_AUDIO_AGC_AUDIO_STREAM_H_
OLDNEW
« no previous file with comments | « content/browser/speech/speech_recognizer_impl_unittest.cc ('k') | media/audio/alsa/alsa_input.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698