OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
71 size_t start_index, | 71 size_t start_index, |
72 size_t length, | 72 size_t length, |
73 int factor, | 73 int factor, |
74 int increment); | 74 int increment); |
75 | 75 |
76 // Peak detection with parabolic fit. Looks for |num_peaks| maxima in |data|, | 76 // Peak detection with parabolic fit. Looks for |num_peaks| maxima in |data|, |
77 // having length |data_length| and sample rate multiplier |fs_mult|. The peak | 77 // having length |data_length| and sample rate multiplier |fs_mult|. The peak |
78 // locations and values are written to the arrays |peak_index| and | 78 // locations and values are written to the arrays |peak_index| and |
79 // |peak_value|, respectively. Both arrays must hold at least |num_peaks| | 79 // |peak_value|, respectively. Both arrays must hold at least |num_peaks| |
80 // elements. | 80 // elements. |
81 static void PeakDetection(int16_t* data, int data_length, | 81 static void PeakDetection(int16_t* data, size_t data_length, |
82 int num_peaks, int fs_mult, | 82 size_t num_peaks, size_t fs_mult, |
hlundin-webrtc
2015/08/10 11:30:01
Again, fs_mult should not be a size_t.
| |
83 int* peak_index, int16_t* peak_value); | 83 size_t* peak_index, int16_t* peak_value); |
84 | 84 |
85 // Estimates the height and location of a maximum. The three values in the | 85 // Estimates the height and location of a maximum. The three values in the |
86 // array |signal_points| are used as basis for a parabolic fit, which is then | 86 // array |signal_points| are used as basis for a parabolic fit, which is then |
87 // used to find the maximum in an interpolated signal. The |signal_points| are | 87 // used to find the maximum in an interpolated signal. The |signal_points| are |
88 // assumed to be from a 4 kHz signal, while the maximum, written to | 88 // assumed to be from a 4 kHz signal, while the maximum, written to |
89 // |peak_index| and |peak_value| is given in the full sample rate, as | 89 // |peak_index| and |peak_value| is given in the full sample rate, as |
90 // indicated by the sample rate multiplier |fs_mult|. | 90 // indicated by the sample rate multiplier |fs_mult|. |
91 static void ParabolicFit(int16_t* signal_points, int fs_mult, | 91 static void ParabolicFit(int16_t* signal_points, size_t fs_mult, |
hlundin-webrtc
2015/08/10 11:30:00
And here.
| |
92 int* peak_index, int16_t* peak_value); | 92 size_t* peak_index, int16_t* peak_value); |
93 | 93 |
94 // Calculates the sum-abs-diff for |signal| when compared to a displaced | 94 // Calculates the sum-abs-diff for |signal| when compared to a displaced |
95 // version of itself. Returns the displacement lag that results in the minimum | 95 // version of itself. Returns the displacement lag that results in the minimum |
96 // distortion. The resulting distortion is written to |distortion_value|. | 96 // distortion. The resulting distortion is written to |distortion_value|. |
97 // The values of |min_lag| and |max_lag| are boundaries for the search. | 97 // The values of |min_lag| and |max_lag| are boundaries for the search. |
98 static int MinDistortion(const int16_t* signal, int min_lag, | 98 static size_t MinDistortion(const int16_t* signal, size_t min_lag, |
99 int max_lag, int length, int32_t* distortion_value); | 99 size_t max_lag, size_t length, |
100 int32_t* distortion_value); | |
100 | 101 |
101 // Mixes |length| samples from |input1| and |input2| together and writes the | 102 // Mixes |length| samples from |input1| and |input2| together and writes the |
102 // result to |output|. The gain for |input1| starts at |mix_factor| (Q14) and | 103 // result to |output|. The gain for |input1| starts at |mix_factor| (Q14) and |
103 // is decreased by |factor_decrement| (Q14) for each sample. The gain for | 104 // is decreased by |factor_decrement| (Q14) for each sample. The gain for |
104 // |input2| is the complement 16384 - mix_factor. | 105 // |input2| is the complement 16384 - mix_factor. |
105 static void CrossFade(const int16_t* input1, const int16_t* input2, | 106 static void CrossFade(const int16_t* input1, const int16_t* input2, |
106 size_t length, int16_t* mix_factor, | 107 size_t length, int16_t* mix_factor, |
107 int16_t factor_decrement, int16_t* output); | 108 int16_t factor_decrement, int16_t* output); |
108 | 109 |
109 // Scales |input| with an increasing gain. Applies |factor| (Q14) to the first | 110 // Scales |input| with an increasing gain. Applies |factor| (Q14) to the first |
110 // sample and increases the gain by |increment| (Q20) for each sample. The | 111 // sample and increases the gain by |increment| (Q20) for each sample. The |
111 // result is written to |output|. |length| samples are processed. | 112 // result is written to |output|. |length| samples are processed. |
112 static void UnmuteSignal(const int16_t* input, size_t length, int16_t* factor, | 113 static void UnmuteSignal(const int16_t* input, size_t length, int16_t* factor, |
113 int increment, int16_t* output); | 114 int increment, int16_t* output); |
114 | 115 |
115 // Starts at unity gain and gradually fades out |signal|. For each sample, | 116 // Starts at unity gain and gradually fades out |signal|. For each sample, |
116 // the gain is reduced by |mute_slope| (Q14). |length| samples are processed. | 117 // the gain is reduced by |mute_slope| (Q14). |length| samples are processed. |
117 static void MuteSignal(int16_t* signal, int mute_slope, size_t length); | 118 static void MuteSignal(int16_t* signal, int mute_slope, size_t length); |
118 | 119 |
119 // Downsamples |input| from |sample_rate_hz| to 4 kHz sample rate. The input | 120 // Downsamples |input| from |sample_rate_hz| to 4 kHz sample rate. The input |
120 // has |input_length| samples, and the method will write |output_length| | 121 // has |input_length| samples, and the method will write |output_length| |
121 // samples to |output|. Compensates for the phase delay of the downsampling | 122 // samples to |output|. Compensates for the phase delay of the downsampling |
122 // filters if |compensate_delay| is true. Returns -1 if the input is too short | 123 // filters if |compensate_delay| is true. Returns -1 if the input is too short |
123 // to produce |output_length| samples, otherwise 0. | 124 // to produce |output_length| samples, otherwise 0. |
124 static int DownsampleTo4kHz(const int16_t* input, size_t input_length, | 125 static int DownsampleTo4kHz(const int16_t* input, size_t input_length, |
125 int output_length, int input_rate_hz, | 126 size_t output_length, int input_rate_hz, |
126 bool compensate_delay, int16_t* output); | 127 bool compensate_delay, int16_t* output); |
127 | 128 |
128 private: | 129 private: |
129 // Table of constants used in method DspHelper::ParabolicFit(). | 130 // Table of constants used in method DspHelper::ParabolicFit(). |
130 static const int16_t kParabolaCoefficients[17][3]; | 131 static const int16_t kParabolaCoefficients[17][3]; |
131 | 132 |
132 DISALLOW_COPY_AND_ASSIGN(DspHelper); | 133 DISALLOW_COPY_AND_ASSIGN(DspHelper); |
133 }; | 134 }; |
134 | 135 |
135 } // namespace webrtc | 136 } // namespace webrtc |
136 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_DSP_HELPER_H_ | 137 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_DSP_HELPER_H_ |
OLD | NEW |