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

Side by Side Diff: webrtc/common_audio/vad/vad.cc

Issue 1317243005: Turn webrtc::Vad into a pure virtual interface (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@ifc-merge-2
Patch Set: 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 /* 1 /*
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/common_audio/vad/include/vad.h" 11 #include "webrtc/common_audio/vad/include/vad.h"
12 12
13 #include "webrtc/base/checks.h" 13 #include "webrtc/base/checks.h"
14 14
15 namespace webrtc { 15 namespace webrtc {
16 16
17 Vad::Vad(enum Aggressiveness mode) : handle_(nullptr), aggressiveness_(mode) { 17 namespace {
18 Reset();
19 }
20 18
21 Vad::~Vad() { 19 class VadImpl final : public Vad {
22 WebRtcVad_Free(handle_); 20 public:
23 } 21 explicit VadImpl(Aggressiveness aggressiveness)
22 : handle_(nullptr), aggressiveness_(aggressiveness) {
23 Reset();
24 }
24 25
25 enum Vad::Activity Vad::VoiceActivity(const int16_t* audio, 26 ~VadImpl() override { WebRtcVad_Free(handle_); }
26 size_t num_samples, 27
27 int sample_rate_hz) { 28 Activity VoiceActivity(const int16_t* audio,
28 int ret = WebRtcVad_Process(handle_, sample_rate_hz, audio, num_samples); 29 size_t num_samples,
29 switch (ret) { 30 int sample_rate_hz) override {
30 case 0: 31 int ret = WebRtcVad_Process(handle_, sample_rate_hz, audio, num_samples);
31 return kPassive; 32 switch (ret) {
32 case 1: 33 case 0:
33 return kActive; 34 return kPassive;
34 default: 35 case 1:
35 DCHECK(false) << "WebRtcVad_Process returned an error."; 36 return kActive;
36 return kError; 37 default:
38 DCHECK(false) << "WebRtcVad_Process returned an error.";
39 return kError;
40 }
37 } 41 }
38 }
39 42
40 void Vad::Reset() { 43 void Reset() override {
41 if (handle_) 44 if (handle_)
42 WebRtcVad_Free(handle_); 45 WebRtcVad_Free(handle_);
43 handle_ = WebRtcVad_Create(); 46 handle_ = WebRtcVad_Create();
44 CHECK(handle_); 47 CHECK(handle_);
45 CHECK_EQ(WebRtcVad_Init(handle_), 0); 48 CHECK_EQ(WebRtcVad_Init(handle_), 0);
46 CHECK_EQ(WebRtcVad_set_mode(handle_, aggressiveness_), 0); 49 CHECK_EQ(WebRtcVad_set_mode(handle_, aggressiveness_), 0);
50 }
51
52 private:
53 VadInst* handle_;
54 Aggressiveness aggressiveness_;
55 };
56
57 } // namespace
58
59 rtc::scoped_ptr<Vad> CreateVad(Vad::Aggressiveness aggressiveness) {
60 return rtc::scoped_ptr<Vad>(new VadImpl(aggressiveness));
47 } 61 }
48 62
49 } // namespace webrtc 63 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/common_audio/vad/mock/mock_vad.h ('k') | webrtc/modules/audio_coding/codecs/cng/audio_encoder_cng.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698