blob: e34091bdb6abd1e8a3b31c159f1f024e370d3b16 [file] [log] [blame]
pbos@webrtc.org788acd12014-12-15 09:41:24 +00001/*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_AUDIO_PROCESSING_VAD_VAD_AUDIO_PROC_H_
12#define MODULES_AUDIO_PROCESSING_VAD_VAD_AUDIO_PROC_H_
pbos@webrtc.org788acd12014-12-15 09:41:24 +000013
kwibergdabf07f2016-02-17 07:59:48 -080014#include <memory>
15
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "modules/audio_processing/vad/common.h"
pbos@webrtc.org788acd12014-12-15 09:41:24 +000017
18namespace webrtc {
19
20class AudioFrame;
21class PoleZeroFilter;
22
aluebsecf6b812015-06-25 12:28:48 -070023class VadAudioProc {
pbos@webrtc.org788acd12014-12-15 09:41:24 +000024 public:
25 // Forward declare iSAC structs.
26 struct PitchAnalysisStruct;
27 struct PreFiltBankstr;
28
aluebsecf6b812015-06-25 12:28:48 -070029 VadAudioProc();
30 ~VadAudioProc();
pbos@webrtc.org788acd12014-12-15 09:41:24 +000031
32 int ExtractFeatures(const int16_t* audio_frame,
Peter Kastingdce40cf2015-08-24 14:52:23 -070033 size_t length,
pbos@webrtc.org788acd12014-12-15 09:41:24 +000034 AudioFeatures* audio_features);
35
Peter Kastingdce40cf2015-08-24 14:52:23 -070036 static const size_t kDftSize = 512;
pbos@webrtc.org788acd12014-12-15 09:41:24 +000037
38 private:
Peter Kastingdce40cf2015-08-24 14:52:23 -070039 void PitchAnalysis(double* pitch_gains, double* pitch_lags_hz, size_t length);
40 void SubframeCorrelation(double* corr,
41 size_t length_corr,
42 size_t subframe_index);
43 void GetLpcPolynomials(double* lpc, size_t length_lpc);
44 void FindFirstSpectralPeaks(double* f_peak, size_t length_f_peak);
45 void Rms(double* rms, size_t length_rms);
pbos@webrtc.org788acd12014-12-15 09:41:24 +000046 void ResetBuffer();
47
48 // To compute spectral peak we perform LPC analysis to get spectral envelope.
49 // For every 30 ms we compute 3 spectral peak there for 3 LPC analysis.
50 // LPC is computed over 15 ms of windowed audio. For every 10 ms sub-frame
51 // we need 5 ms of past signal to create the input of LPC analysis.
kwiberg9e2be5f2016-09-14 05:23:22 -070052 enum : size_t {
53 kNumPastSignalSamples = static_cast<size_t>(kSampleRateHz / 200)
54 };
pbos@webrtc.org788acd12014-12-15 09:41:24 +000055
56 // TODO(turajs): maybe defining this at a higher level (maybe enum) so that
57 // all the code recognize it as "no-error."
kwiberg9e2be5f2016-09-14 05:23:22 -070058 enum : int { kNoError = 0 };
pbos@webrtc.org788acd12014-12-15 09:41:24 +000059
kwiberg9e2be5f2016-09-14 05:23:22 -070060 enum : size_t { kNum10msSubframes = 3 };
61 enum : size_t {
62 kNumSubframeSamples = static_cast<size_t>(kSampleRateHz / 100)
63 };
64 enum : size_t {
65 // Samples in 30 ms @ given sampling rate.
66 kNumSamplesToProcess = kNum10msSubframes * kNumSubframeSamples
67 };
68 enum : size_t {
69 kBufferLength = kNumPastSignalSamples + kNumSamplesToProcess
70 };
71 enum : size_t { kIpLength = kDftSize >> 1 };
72 enum : size_t { kWLength = kDftSize >> 1 };
73 enum : size_t { kLpcOrder = 16 };
pbos@webrtc.org788acd12014-12-15 09:41:24 +000074
Peter Kastingdce40cf2015-08-24 14:52:23 -070075 size_t ip_[kIpLength];
pbos@webrtc.org788acd12014-12-15 09:41:24 +000076 float w_fft_[kWLength];
77
78 // A buffer of 5 ms (past audio) + 30 ms (one iSAC frame ).
79 float audio_buffer_[kBufferLength];
Peter Kastingdce40cf2015-08-24 14:52:23 -070080 size_t num_buffer_samples_;
pbos@webrtc.org788acd12014-12-15 09:41:24 +000081
82 double log_old_gain_;
83 double old_lag_;
84
kwibergdabf07f2016-02-17 07:59:48 -080085 std::unique_ptr<PitchAnalysisStruct> pitch_analysis_handle_;
86 std::unique_ptr<PreFiltBankstr> pre_filter_handle_;
87 std::unique_ptr<PoleZeroFilter> high_pass_filter_;
pbos@webrtc.org788acd12014-12-15 09:41:24 +000088};
89
90} // namespace webrtc
91
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020092#endif // MODULES_AUDIO_PROCESSING_VAD_VAD_AUDIO_PROC_H_