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

Side by Side Diff: services/media/audio/platform/generic/mixer.cc

Issue 1455303003: Add a linear interpolation resampler. (Closed) Base URL: https://github.com/domokit/mojo.git@change6
Patch Set: Final rebase before landing Created 4 years, 10 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 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #include "base/logging.h" 5 #include "base/logging.h"
6 #include "mojo/services/media/common/cpp/linear_transform.h"
6 #include "services/media/audio/platform/generic/mixer.h" 7 #include "services/media/audio/platform/generic/mixer.h"
8 #include "services/media/audio/platform/generic/mixers/linear_sampler.h"
7 #include "services/media/audio/platform/generic/mixers/no_op.h" 9 #include "services/media/audio/platform/generic/mixers/no_op.h"
8 #include "services/media/audio/platform/generic/mixers/point_sampler.h" 10 #include "services/media/audio/platform/generic/mixers/point_sampler.h"
9 11
10 namespace mojo { 12 namespace mojo {
11 namespace media { 13 namespace media {
12 namespace audio { 14 namespace audio {
13 15
14 constexpr uint32_t Mixer::FRAC_ONE; 16 constexpr uint32_t Mixer::FRAC_ONE;
15 constexpr uint32_t Mixer::FRAC_MASK; 17 constexpr uint32_t Mixer::FRAC_MASK;
16 18
17 Mixer::~Mixer() {} 19 Mixer::~Mixer() {}
18 20
19 Mixer::Mixer(uint32_t pos_filter_width, 21 Mixer::Mixer(uint32_t pos_filter_width,
20 uint32_t neg_filter_width) 22 uint32_t neg_filter_width)
21 : pos_filter_width_(pos_filter_width), 23 : pos_filter_width_(pos_filter_width),
22 neg_filter_width_(neg_filter_width) { 24 neg_filter_width_(neg_filter_width) {
23 } 25 }
24 26
25 MixerPtr Mixer::Select(const LpcmMediaTypeDetailsPtr& src_format, 27 MixerPtr Mixer::Select(const LpcmMediaTypeDetailsPtr& src_format,
26 const LpcmMediaTypeDetailsPtr& dst_format) { 28 const LpcmMediaTypeDetailsPtr& dst_format) {
27 // We should always have a source format. 29 // We should always have a source format.
28 DCHECK(src_format); 30 DCHECK(src_format);
29 31
30 // If we don't have a destination format, just stick with no-op. This is 32 // If we don't have a destination format, just stick with no-op. This is
31 // probably the ThrottleOutput we are picking a mixer for. 33 // probably the ThrottleOutput we are picking a mixer for.
32 if (!dst_format) { return MixerPtr(new mixers::NoOp()); } 34 if (!dst_format) { return MixerPtr(new mixers::NoOp()); }
33 35
34 return mixers::PointSampler::Select(src_format, dst_format); 36 // If the source sample rate is an integer multiple of the destination sample
37 // rate, just use the point sampler. Otherwise, use the linear re-sampler.
38 LinearTransform::Ratio src_to_dst(src_format->frames_per_second,
39 dst_format->frames_per_second);
40 if (src_to_dst.numerator == 1) {
41 return mixers::PointSampler::Select(src_format, dst_format);
42 } else {
43 return mixers::LinearSampler::Select(src_format, dst_format);
44 }
35 } 45 }
36 46
37 } // namespace audio 47 } // namespace audio
38 } // namespace media 48 } // namespace media
39 } // namespace mojo 49 } // namespace mojo
OLDNEW
« no previous file with comments | « services/media/audio/BUILD.gn ('k') | services/media/audio/platform/generic/mixers/linear_sampler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698