| OLD | NEW |
| 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> |
| 11 #include <cmath> | 11 #include <cmath> |
| 12 #include <limits> | 12 #include <limits> |
| 13 #include <memory> |
| 13 | 14 |
| 14 #include "base/logging.h" | 15 #include "base/logging.h" |
| 15 #include "base/memory/scoped_ptr.h" | |
| 16 #include "media/base/audio_bus.h" | 16 #include "media/base/audio_bus.h" |
| 17 | 17 |
| 18 namespace media { | 18 namespace media { |
| 19 | 19 |
| 20 namespace internal { | 20 namespace internal { |
| 21 | 21 |
| 22 bool InInterval(int n, Interval q) { | 22 bool InInterval(int n, Interval q) { |
| 23 return n >= q.first && n <= q.second; | 23 return n >= q.first && n <= q.second; |
| 24 } | 24 } |
| 25 | 25 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 | 107 |
| 108 int DecimatedSearch(int decimation, | 108 int DecimatedSearch(int decimation, |
| 109 Interval exclude_interval, | 109 Interval exclude_interval, |
| 110 const AudioBus* target_block, | 110 const AudioBus* target_block, |
| 111 const AudioBus* search_segment, | 111 const AudioBus* search_segment, |
| 112 const float* energy_target_block, | 112 const float* energy_target_block, |
| 113 const float* energy_candidate_blocks) { | 113 const float* energy_candidate_blocks) { |
| 114 int channels = search_segment->channels(); | 114 int channels = search_segment->channels(); |
| 115 int block_size = target_block->frames(); | 115 int block_size = target_block->frames(); |
| 116 int num_candidate_blocks = search_segment->frames() - (block_size - 1); | 116 int num_candidate_blocks = search_segment->frames() - (block_size - 1); |
| 117 scoped_ptr<float[]> dot_prod(new float[channels]); | 117 std::unique_ptr<float[]> dot_prod(new float[channels]); |
| 118 float similarity[3]; // Three elements for cubic interpolation. | 118 float similarity[3]; // Three elements for cubic interpolation. |
| 119 | 119 |
| 120 int n = 0; | 120 int n = 0; |
| 121 MultiChannelDotProduct(target_block, 0, search_segment, n, block_size, | 121 MultiChannelDotProduct(target_block, 0, search_segment, n, block_size, |
| 122 dot_prod.get()); | 122 dot_prod.get()); |
| 123 similarity[0] = MultiChannelSimilarityMeasure( | 123 similarity[0] = MultiChannelSimilarityMeasure( |
| 124 dot_prod.get(), energy_target_block, | 124 dot_prod.get(), energy_target_block, |
| 125 &energy_candidate_blocks[n * channels], channels); | 125 &energy_candidate_blocks[n * channels], channels); |
| 126 | 126 |
| 127 // Set the starting point as optimal point. | 127 // Set the starting point as optimal point. |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 | 185 |
| 186 int FullSearch(int low_limit, | 186 int FullSearch(int low_limit, |
| 187 int high_limit, | 187 int high_limit, |
| 188 Interval exclude_interval, | 188 Interval exclude_interval, |
| 189 const AudioBus* target_block, | 189 const AudioBus* target_block, |
| 190 const AudioBus* search_block, | 190 const AudioBus* search_block, |
| 191 const float* energy_target_block, | 191 const float* energy_target_block, |
| 192 const float* energy_candidate_blocks) { | 192 const float* energy_candidate_blocks) { |
| 193 int channels = search_block->channels(); | 193 int channels = search_block->channels(); |
| 194 int block_size = target_block->frames(); | 194 int block_size = target_block->frames(); |
| 195 scoped_ptr<float[]> dot_prod(new float[channels]); | 195 std::unique_ptr<float[]> dot_prod(new float[channels]); |
| 196 | 196 |
| 197 float best_similarity = std::numeric_limits<float>::min(); | 197 float best_similarity = std::numeric_limits<float>::min(); |
| 198 int optimal_index = 0; | 198 int optimal_index = 0; |
| 199 | 199 |
| 200 for (int n = low_limit; n <= high_limit; ++n) { | 200 for (int n = low_limit; n <= high_limit; ++n) { |
| 201 if (InInterval(n, exclude_interval)) { | 201 if (InInterval(n, exclude_interval)) { |
| 202 continue; | 202 continue; |
| 203 } | 203 } |
| 204 MultiChannelDotProduct(target_block, 0, search_block, n, block_size, | 204 MultiChannelDotProduct(target_block, 0, search_block, n, block_size, |
| 205 dot_prod.get()); | 205 dot_prod.get()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 226 int num_candidate_blocks = search_block->frames() - (target_size - 1); | 226 int num_candidate_blocks = search_block->frames() - (target_size - 1); |
| 227 | 227 |
| 228 // This is a compromise between complexity reduction and search accuracy. I | 228 // This is a compromise between complexity reduction and search accuracy. I |
| 229 // don't have a proof that down sample of order 5 is optimal. One can compute | 229 // don't have a proof that down sample of order 5 is optimal. One can compute |
| 230 // a decimation factor that minimizes complexity given the size of | 230 // a decimation factor that minimizes complexity given the size of |
| 231 // |search_block| and |target_block|. However, my experiments show the rate of | 231 // |search_block| and |target_block|. However, my experiments show the rate of |
| 232 // missing the optimal index is significant. This value is chosen | 232 // missing the optimal index is significant. This value is chosen |
| 233 // heuristically based on experiments. | 233 // heuristically based on experiments. |
| 234 const int kSearchDecimation = 5; | 234 const int kSearchDecimation = 5; |
| 235 | 235 |
| 236 scoped_ptr<float[]> energy_target_block(new float[channels]); | 236 std::unique_ptr<float[]> energy_target_block(new float[channels]); |
| 237 scoped_ptr<float[]> energy_candidate_blocks( | 237 std::unique_ptr<float[]> energy_candidate_blocks( |
| 238 new float[channels * num_candidate_blocks]); | 238 new float[channels * num_candidate_blocks]); |
| 239 | 239 |
| 240 // Energy of all candid frames. | 240 // Energy of all candid frames. |
| 241 MultiChannelMovingBlockEnergies(search_block, target_size, | 241 MultiChannelMovingBlockEnergies(search_block, target_size, |
| 242 energy_candidate_blocks.get()); | 242 energy_candidate_blocks.get()); |
| 243 | 243 |
| 244 // Energy of target frame. | 244 // Energy of target frame. |
| 245 MultiChannelDotProduct(target_block, 0, target_block, 0, | 245 MultiChannelDotProduct(target_block, 0, target_block, 0, |
| 246 target_size, energy_target_block.get()); | 246 target_size, energy_target_block.get()); |
| 247 | 247 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 261 void GetSymmetricHanningWindow(int window_length, float* window) { | 261 void GetSymmetricHanningWindow(int window_length, float* window) { |
| 262 const float scale = 2.0f * M_PI / window_length; | 262 const float scale = 2.0f * M_PI / window_length; |
| 263 for (int n = 0; n < window_length; ++n) | 263 for (int n = 0; n < window_length; ++n) |
| 264 window[n] = 0.5f * (1.0f - cosf(n * scale)); | 264 window[n] = 0.5f * (1.0f - cosf(n * scale)); |
| 265 } | 265 } |
| 266 | 266 |
| 267 } // namespace internal | 267 } // namespace internal |
| 268 | 268 |
| 269 } // namespace media | 269 } // namespace media |
| 270 | 270 |
| OLD | NEW |