| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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 16 matching lines...) Expand all Loading... |
| 27 const size_t num_channels = input.num_channels(); | 27 const size_t num_channels = input.num_channels(); |
| 28 const size_t total_frames = input.num_frames(); | 28 const size_t total_frames = input.num_frames(); |
| 29 AudioRingBuffer buf(num_channels, buffer_frames); | 29 AudioRingBuffer buf(num_channels, buffer_frames); |
| 30 rtc::scoped_ptr<float* []> slice(new float* [num_channels]); | 30 rtc::scoped_ptr<float* []> slice(new float* [num_channels]); |
| 31 | 31 |
| 32 size_t input_pos = 0; | 32 size_t input_pos = 0; |
| 33 size_t output_pos = 0; | 33 size_t output_pos = 0; |
| 34 while (input_pos + buf.WriteFramesAvailable() < total_frames) { | 34 while (input_pos + buf.WriteFramesAvailable() < total_frames) { |
| 35 // Write until the buffer is as full as possible. | 35 // Write until the buffer is as full as possible. |
| 36 while (buf.WriteFramesAvailable() >= num_write_chunk_frames) { | 36 while (buf.WriteFramesAvailable() >= num_write_chunk_frames) { |
| 37 buf.Write(input.Slice(slice.get(), static_cast<int>(input_pos)), | 37 buf.Write(input.Slice(slice.get(), input_pos), num_channels, |
| 38 num_channels, num_write_chunk_frames); | 38 num_write_chunk_frames); |
| 39 input_pos += num_write_chunk_frames; | 39 input_pos += num_write_chunk_frames; |
| 40 } | 40 } |
| 41 // Read until the buffer is as empty as possible. | 41 // Read until the buffer is as empty as possible. |
| 42 while (buf.ReadFramesAvailable() >= num_read_chunk_frames) { | 42 while (buf.ReadFramesAvailable() >= num_read_chunk_frames) { |
| 43 EXPECT_LT(output_pos, total_frames); | 43 EXPECT_LT(output_pos, total_frames); |
| 44 buf.Read(output->Slice(slice.get(), static_cast<int>(output_pos)), | 44 buf.Read(output->Slice(slice.get(), output_pos), num_channels, |
| 45 num_channels, num_read_chunk_frames); | 45 num_read_chunk_frames); |
| 46 output_pos += num_read_chunk_frames; | 46 output_pos += num_read_chunk_frames; |
| 47 } | 47 } |
| 48 } | 48 } |
| 49 | 49 |
| 50 // Write and read the last bit. | 50 // Write and read the last bit. |
| 51 if (input_pos < total_frames) { | 51 if (input_pos < total_frames) { |
| 52 buf.Write(input.Slice(slice.get(), static_cast<int>(input_pos)), | 52 buf.Write(input.Slice(slice.get(), input_pos), num_channels, |
| 53 num_channels, total_frames - input_pos); | 53 total_frames - input_pos); |
| 54 } | 54 } |
| 55 if (buf.ReadFramesAvailable()) { | 55 if (buf.ReadFramesAvailable()) { |
| 56 buf.Read(output->Slice(slice.get(), static_cast<int>(output_pos)), | 56 buf.Read(output->Slice(slice.get(), output_pos), num_channels, |
| 57 num_channels, buf.ReadFramesAvailable()); | 57 buf.ReadFramesAvailable()); |
| 58 } | 58 } |
| 59 EXPECT_EQ(0u, buf.ReadFramesAvailable()); | 59 EXPECT_EQ(0u, buf.ReadFramesAvailable()); |
| 60 } | 60 } |
| 61 | 61 |
| 62 TEST_P(AudioRingBufferTest, ReadDataMatchesWrittenData) { | 62 TEST_P(AudioRingBufferTest, ReadDataMatchesWrittenData) { |
| 63 const size_t kFrames = 5000; | 63 const size_t kFrames = 5000; |
| 64 const size_t num_channels = ::testing::get<3>(GetParam()); | 64 const size_t num_channels = ::testing::get<3>(GetParam()); |
| 65 | 65 |
| 66 // Initialize the input data to an increasing sequence. | 66 // Initialize the input data to an increasing sequence. |
| 67 ChannelBuffer<float> input(kFrames, static_cast<int>(num_channels)); | 67 ChannelBuffer<float> input(kFrames, static_cast<int>(num_channels)); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 buf.MoveReadPositionForward(3); | 101 buf.MoveReadPositionForward(3); |
| 102 ChannelBuffer<float> output(1, kNumChannels); | 102 ChannelBuffer<float> output(1, kNumChannels); |
| 103 buf.Read(output.channels(), kNumChannels, 1); | 103 buf.Read(output.channels(), kNumChannels, 1); |
| 104 EXPECT_EQ(4, output.channels()[0][0]); | 104 EXPECT_EQ(4, output.channels()[0][0]); |
| 105 buf.MoveReadPositionBackward(3); | 105 buf.MoveReadPositionBackward(3); |
| 106 buf.Read(output.channels(), kNumChannels, 1); | 106 buf.Read(output.channels(), kNumChannels, 1); |
| 107 EXPECT_EQ(2, output.channels()[0][0]); | 107 EXPECT_EQ(2, output.channels()[0][0]); |
| 108 } | 108 } |
| 109 | 109 |
| 110 } // namespace webrtc | 110 } // namespace webrtc |
| OLD | NEW |