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

Side by Side Diff: media/filters/wsola_internals.cc

Issue 217553004: Handle near-colinear case in WSOLAS QuadraticInterpolation better. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Simplify cases handled. Created 6 years, 8 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
« no previous file with comments | « media/filters/wsola_internals.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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 // MSVC++ requires this to be set before any other includes to get M_PI. 5 // MSVC++ requires this to be set before any other includes to get M_PI.
6 #define _USE_MATH_DEFINES 6 #define _USE_MATH_DEFINES
7 7
8 #include "media/filters/wsola_internals.h" 8 #include "media/filters/wsola_internals.h"
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 const float* slide_out = input_channel; 77 const float* slide_out = input_channel;
78 const float* slide_in = input_channel + frames_per_block; 78 const float* slide_in = input_channel + frames_per_block;
79 for (int n = 1; n < num_blocks; ++n, ++slide_in, ++slide_out) { 79 for (int n = 1; n < num_blocks; ++n, ++slide_in, ++slide_out) {
80 energy[k + n * channels] = energy[k + (n - 1) * channels] - *slide_out * 80 energy[k + n * channels] = energy[k + (n - 1) * channels] - *slide_out *
81 *slide_out + *slide_in * *slide_in; 81 *slide_out + *slide_in * *slide_in;
82 } 82 }
83 } 83 }
84 } 84 }
85 85
86 // Fit the curve f(x) = a * x^2 + b * x + c such that 86 // Fit the curve f(x) = a * x^2 + b * x + c such that
87 // f(-1) = |y[0]| 87 // f(-1) = y[0]
88 // f(0) = |y[1]| 88 // f(0) = y[1]
89 // f(1) = |y[2]|. 89 // f(1) = y[2]
90 void CubicInterpolation(const float* y_values, 90 // and return the maximum, assuming that y[0] <= y[1] >= y[2].
91 float* extremum, 91 void QuadraticInterpolation(const float* y_values,
92 float* extremum_value) { 92 float* extremum,
93 float* extremum_value) {
93 float a = 0.5f * (y_values[2] + y_values[0]) - y_values[1]; 94 float a = 0.5f * (y_values[2] + y_values[0]) - y_values[1];
94 float b = 0.5f * (y_values[2] - y_values[0]); 95 float b = 0.5f * (y_values[2] - y_values[0]);
95 float c = y_values[1]; 96 float c = y_values[1];
96 97
97 DCHECK_NE(a, 0); 98 if (a == 0.f) {
98 *extremum = -b / (2.f * a); 99 // The coordinates are colinear (within floating-point error).
99 *extremum_value = a * (*extremum) * (*extremum) + b * (*extremum) + c; 100 *extremum = 0;
101 *extremum_value = y_values[1];
102 } else {
103 *extremum = -b / (2.f * a);
104 *extremum_value = a * (*extremum) * (*extremum) + b * (*extremum) + c;
105 }
100 } 106 }
101 107
102 int DecimatedSearch(int decimation, 108 int DecimatedSearch(int decimation,
103 Interval exclude_interval, 109 Interval exclude_interval,
104 const AudioBus* target_block, 110 const AudioBus* target_block,
105 const AudioBus* search_segment, 111 const AudioBus* search_segment,
106 const float* energy_target_block, 112 const float* energy_target_block,
107 const float* energy_candidate_blocks) { 113 const float* energy_candidate_blocks) {
108 int channels = search_segment->channels(); 114 int channels = search_segment->channels();
109 int block_size = target_block->frames(); 115 int block_size = target_block->frames();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 similarity[2] = MultiChannelSimilarityMeasure( 153 similarity[2] = MultiChannelSimilarityMeasure(
148 dot_prod.get(), energy_target_block, 154 dot_prod.get(), energy_target_block,
149 &energy_candidate_blocks[n * channels], channels); 155 &energy_candidate_blocks[n * channels], channels);
150 156
151 if ((similarity[1] > similarity[0] && similarity[1] >= similarity[2]) || 157 if ((similarity[1] > similarity[0] && similarity[1] >= similarity[2]) ||
152 (similarity[1] >= similarity[0] && similarity[1] > similarity[2])) { 158 (similarity[1] >= similarity[0] && similarity[1] > similarity[2])) {
153 // A local maximum is found. Do a cubic interpolation for a better 159 // A local maximum is found. Do a cubic interpolation for a better
154 // estimate of candidate maximum. 160 // estimate of candidate maximum.
155 float normalized_candidate_index; 161 float normalized_candidate_index;
156 float candidate_similarity; 162 float candidate_similarity;
157 CubicInterpolation(similarity, &normalized_candidate_index, 163 QuadraticInterpolation(similarity, &normalized_candidate_index,
158 &candidate_similarity); 164 &candidate_similarity);
159 165
160 int candidate_index = n - decimation + static_cast<int>( 166 int candidate_index = n - decimation + static_cast<int>(
161 normalized_candidate_index * decimation + 0.5f); 167 normalized_candidate_index * decimation + 0.5f);
162 if (candidate_similarity > best_similarity && 168 if (candidate_similarity > best_similarity &&
163 !InInterval(candidate_index, exclude_interval)) { 169 !InInterval(candidate_index, exclude_interval)) {
164 optimal_index = candidate_index; 170 optimal_index = candidate_index;
165 best_similarity = candidate_similarity; 171 best_similarity = candidate_similarity;
166 } 172 }
167 } else if (n + decimation >= num_candidate_blocks && 173 } else if (n + decimation >= num_candidate_blocks &&
168 similarity[2] > best_similarity && 174 similarity[2] > best_similarity &&
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 void GetSymmetricHanningWindow(int window_length, float* window) { 261 void GetSymmetricHanningWindow(int window_length, float* window) {
256 const float scale = 2.0f * M_PI / window_length; 262 const float scale = 2.0f * M_PI / window_length;
257 for (int n = 0; n < window_length; ++n) 263 for (int n = 0; n < window_length; ++n)
258 window[n] = 0.5f * (1.0f - cosf(n * scale)); 264 window[n] = 0.5f * (1.0f - cosf(n * scale));
259 } 265 }
260 266
261 } // namespace internal 267 } // namespace internal
262 268
263 } // namespace media 269 } // namespace media
264 270
OLDNEW
« no previous file with comments | « media/filters/wsola_internals.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698