OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // The format of these tests are to enqueue a known amount of data and then | 5 // The format of these tests are to enqueue a known amount of data and then |
6 // request the exact amount we expect in order to dequeue the known amount of | 6 // request the exact amount we expect in order to dequeue the known amount of |
7 // data. This ensures that for any rate we are consuming input data at the | 7 // data. This ensures that for any rate we are consuming input data at the |
8 // correct rate. We always pass in a very large destination buffer with the | 8 // correct rate. We always pass in a very large destination buffer with the |
9 // expectation that FillBuffer() will fill as much as it can but no more. | 9 // expectation that FillBuffer() will fill as much as it can but no more. |
10 | 10 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 | 84 |
85 void Initialize() { | 85 void Initialize() { |
86 Initialize(CHANNEL_LAYOUT_STEREO, kSampleFormatS16, kSamplesPerSecond, | 86 Initialize(CHANNEL_LAYOUT_STEREO, kSampleFormatS16, kSamplesPerSecond, |
87 kSamplesPerSecond / 10); | 87 kSamplesPerSecond / 10); |
88 } | 88 } |
89 | 89 |
90 void Initialize(ChannelLayout channel_layout, | 90 void Initialize(ChannelLayout channel_layout, |
91 SampleFormat sample_format, | 91 SampleFormat sample_format, |
92 int samples_per_second, | 92 int samples_per_second, |
93 int frames_per_buffer) { | 93 int frames_per_buffer) { |
94 Initialize(channel_layout, sample_format, samples_per_second, | 94 Initialize( |
95 frames_per_buffer, std::vector<bool>()); | 95 channel_layout, sample_format, samples_per_second, frames_per_buffer, |
| 96 std::vector<bool>(ChannelLayoutToChannelCount(channel_layout), true)); |
96 } | 97 } |
97 | 98 |
98 void Initialize(ChannelLayout channel_layout, | 99 void Initialize(ChannelLayout channel_layout, |
99 SampleFormat sample_format, | 100 SampleFormat sample_format, |
100 int samples_per_second, | 101 int samples_per_second, |
101 int frames_per_buffer, | 102 int frames_per_buffer, |
102 std::vector<bool> channel_mask) { | 103 std::vector<bool> channel_mask) { |
103 channels_ = ChannelLayoutToChannelCount(channel_layout); | 104 channels_ = ChannelLayoutToChannelCount(channel_layout); |
104 samples_per_second_ = samples_per_second; | 105 samples_per_second_ = samples_per_second; |
105 channel_layout_ = channel_layout; | 106 channel_layout_ = channel_layout; |
106 sample_format_ = sample_format; | 107 sample_format_ = sample_format; |
107 bytes_per_sample_ = SampleFormatToBytesPerChannel(sample_format); | 108 bytes_per_sample_ = SampleFormatToBytesPerChannel(sample_format); |
108 AudioParameters params(media::AudioParameters::AUDIO_PCM_LINEAR, | 109 AudioParameters params(media::AudioParameters::AUDIO_PCM_LINEAR, |
109 channel_layout, samples_per_second, | 110 channel_layout, samples_per_second, |
110 bytes_per_sample_ * 8, frames_per_buffer); | 111 bytes_per_sample_ * 8, frames_per_buffer); |
111 algorithm_.Initialize(params, channel_mask); | 112 algorithm_.Initialize(params); |
| 113 algorithm_.SetChannelMask(std::move(channel_mask)); |
112 FillAlgorithmQueue(); | 114 FillAlgorithmQueue(); |
113 } | 115 } |
114 | 116 |
115 void FillAlgorithmQueue() { | 117 void FillAlgorithmQueue() { |
116 // The value of the data is meaningless; we just want non-zero data to | 118 // The value of the data is meaningless; we just want non-zero data to |
117 // differentiate it from muted data. | 119 // differentiate it from muted data. |
118 scoped_refptr<AudioBuffer> buffer; | 120 scoped_refptr<AudioBuffer> buffer; |
119 while (!algorithm_.IsQueueFull()) { | 121 while (!algorithm_.IsQueueFull()) { |
120 switch (sample_format_) { | 122 switch (sample_format_) { |
121 case kSampleFormatU8: | 123 case kSampleFormatU8: |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 | 245 |
244 void WsolaTest(double playback_rate) { | 246 void WsolaTest(double playback_rate) { |
245 const int kSampleRateHz = 48000; | 247 const int kSampleRateHz = 48000; |
246 const ChannelLayout kChannelLayout = CHANNEL_LAYOUT_STEREO; | 248 const ChannelLayout kChannelLayout = CHANNEL_LAYOUT_STEREO; |
247 const int kBytesPerSample = 2; | 249 const int kBytesPerSample = 2; |
248 const int kNumFrames = kSampleRateHz / 100; // 10 milliseconds. | 250 const int kNumFrames = kSampleRateHz / 100; // 10 milliseconds. |
249 | 251 |
250 channels_ = ChannelLayoutToChannelCount(kChannelLayout); | 252 channels_ = ChannelLayoutToChannelCount(kChannelLayout); |
251 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, | 253 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, |
252 kSampleRateHz, kBytesPerSample * 8, kNumFrames); | 254 kSampleRateHz, kBytesPerSample * 8, kNumFrames); |
253 algorithm_.Initialize(params, std::vector<bool>()); | 255 algorithm_.Initialize(params); |
254 | 256 |
255 // A pulse is 6 milliseconds (even number of samples). | 257 // A pulse is 6 milliseconds (even number of samples). |
256 const int kPulseWidthSamples = 6 * kSampleRateHz / 1000; | 258 const int kPulseWidthSamples = 6 * kSampleRateHz / 1000; |
257 const int kHalfPulseWidthSamples = kPulseWidthSamples / 2; | 259 const int kHalfPulseWidthSamples = kPulseWidthSamples / 2; |
258 | 260 |
259 // For the ease of implementation get 1 frame every call to FillBuffer(). | 261 // For the ease of implementation get 1 frame every call to FillBuffer(). |
260 std::unique_ptr<AudioBus> output = AudioBus::Create(channels_, 1); | 262 std::unique_ptr<AudioBus> output = AudioBus::Create(channels_, 1); |
261 | 263 |
262 // Input buffer to inject pulses. | 264 // Input buffer to inject pulses. |
263 scoped_refptr<AudioBuffer> input = | 265 scoped_refptr<AudioBuffer> input = |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
696 FillAlgorithmQueue(); | 698 FillAlgorithmQueue(); |
697 } | 699 } |
698 } | 700 } |
699 | 701 |
700 TEST_F(AudioRendererAlgorithmTest, FillBuffer_ChannelMask) { | 702 TEST_F(AudioRendererAlgorithmTest, FillBuffer_ChannelMask) { |
701 // Setup a quad channel layout where even channels are always muted. | 703 // Setup a quad channel layout where even channels are always muted. |
702 Initialize(CHANNEL_LAYOUT_QUAD, kSampleFormatS16, 44100, 441, | 704 Initialize(CHANNEL_LAYOUT_QUAD, kSampleFormatS16, 44100, 441, |
703 {true, false, true, false}); | 705 {true, false, true, false}); |
704 | 706 |
705 std::unique_ptr<AudioBus> bus = AudioBus::Create(channels_, kFrameSize); | 707 std::unique_ptr<AudioBus> bus = AudioBus::Create(channels_, kFrameSize); |
706 const int frames_filled = | 708 int frames_filled = algorithm_.FillBuffer(bus.get(), 0, kFrameSize, 2.0); |
707 algorithm_.FillBuffer(bus.get(), 0, kFrameSize, 2.0); | |
708 ASSERT_GT(frames_filled, 0); | 709 ASSERT_GT(frames_filled, 0); |
709 | 710 |
710 // Verify the channels are muted appropriately; even though the created buffer | 711 // Verify the channels are muted appropriately; even though the created buffer |
711 // actually has audio data in it. | 712 // actually has audio data in it. |
712 for (int ch = 0; ch < bus->channels(); ++ch) { | 713 for (int ch = 0; ch < bus->channels(); ++ch) { |
713 double sum = 0; | 714 double sum = 0; |
714 for (int i = 0; i < bus->frames(); ++i) | 715 for (int i = 0; i < bus->frames(); ++i) |
715 sum += bus->channel(ch)[i]; | 716 sum += bus->channel(ch)[i]; |
716 if (ch % 2 == 1) | 717 if (ch % 2 == 1) |
717 ASSERT_EQ(sum, 0); | 718 ASSERT_EQ(sum, 0); |
718 else | 719 else |
719 ASSERT_NE(sum, 0); | 720 ASSERT_NE(sum, 0); |
720 } | 721 } |
| 722 |
| 723 // Update the channel mask and verify it's reflected correctly. |
| 724 algorithm_.SetChannelMask({true, true, true, true}); |
| 725 frames_filled = algorithm_.FillBuffer(bus.get(), 0, kFrameSize, 2.0); |
| 726 ASSERT_GT(frames_filled, 0); |
| 727 |
| 728 // Verify no channels are muted now. |
| 729 for (int ch = 0; ch < bus->channels(); ++ch) { |
| 730 double sum = 0; |
| 731 for (int i = 0; i < bus->frames(); ++i) |
| 732 sum += bus->channel(ch)[i]; |
| 733 ASSERT_NE(sum, 0); |
| 734 } |
721 } | 735 } |
722 | 736 |
723 } // namespace media | 737 } // namespace media |
OLD | NEW |