| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 | 47 |
| 48 // Sets the signal value to increase by |data| with every sample. Floats are | 48 // Sets the signal value to increase by |data| with every sample. Floats are |
| 49 // used so non-integer values result in rounding error, but not an accumulating | 49 // used so non-integer values result in rounding error, but not an accumulating |
| 50 // error. | 50 // error. |
| 51 void SetMonoFrame(AudioFrame* frame, float data, int sample_rate_hz) { | 51 void SetMonoFrame(AudioFrame* frame, float data, int sample_rate_hz) { |
| 52 memset(frame->data_, 0, sizeof(frame->data_)); | 52 memset(frame->data_, 0, sizeof(frame->data_)); |
| 53 frame->num_channels_ = 1; | 53 frame->num_channels_ = 1; |
| 54 frame->sample_rate_hz_ = sample_rate_hz; | 54 frame->sample_rate_hz_ = sample_rate_hz; |
| 55 frame->samples_per_channel_ = sample_rate_hz / 100; | 55 frame->samples_per_channel_ = sample_rate_hz / 100; |
| 56 for (int i = 0; i < frame->samples_per_channel_; i++) { | 56 for (int i = 0; i < frame->samples_per_channel_; i++) { |
| 57 frame->data_[i] = data * i; | 57 frame->data_[i] = static_cast<int16_t>(data * i); |
| 58 } | 58 } |
| 59 } | 59 } |
| 60 | 60 |
| 61 // Keep the existing sample rate. | 61 // Keep the existing sample rate. |
| 62 void SetMonoFrame(AudioFrame* frame, float data) { | 62 void SetMonoFrame(AudioFrame* frame, float data) { |
| 63 SetMonoFrame(frame, data, frame->sample_rate_hz_); | 63 SetMonoFrame(frame, data, frame->sample_rate_hz_); |
| 64 } | 64 } |
| 65 | 65 |
| 66 // Sets the signal value to increase by |left| and |right| with every sample in | 66 // Sets the signal value to increase by |left| and |right| with every sample in |
| 67 // each channel respectively. | 67 // each channel respectively. |
| 68 void SetStereoFrame(AudioFrame* frame, float left, float right, | 68 void SetStereoFrame(AudioFrame* frame, float left, float right, |
| 69 int sample_rate_hz) { | 69 int sample_rate_hz) { |
| 70 memset(frame->data_, 0, sizeof(frame->data_)); | 70 memset(frame->data_, 0, sizeof(frame->data_)); |
| 71 frame->num_channels_ = 2; | 71 frame->num_channels_ = 2; |
| 72 frame->sample_rate_hz_ = sample_rate_hz; | 72 frame->sample_rate_hz_ = sample_rate_hz; |
| 73 frame->samples_per_channel_ = sample_rate_hz / 100; | 73 frame->samples_per_channel_ = sample_rate_hz / 100; |
| 74 for (int i = 0; i < frame->samples_per_channel_; i++) { | 74 for (int i = 0; i < frame->samples_per_channel_; i++) { |
| 75 frame->data_[i * 2] = left * i; | 75 frame->data_[i * 2] = static_cast<int16_t>(left * i); |
| 76 frame->data_[i * 2 + 1] = right * i; | 76 frame->data_[i * 2 + 1] = static_cast<int16_t>(right * i); |
| 77 } | 77 } |
| 78 } | 78 } |
| 79 | 79 |
| 80 // Keep the existing sample rate. | 80 // Keep the existing sample rate. |
| 81 void SetStereoFrame(AudioFrame* frame, float left, float right) { | 81 void SetStereoFrame(AudioFrame* frame, float left, float right) { |
| 82 SetStereoFrame(frame, left, right, frame->sample_rate_hz_); | 82 SetStereoFrame(frame, left, right, frame->sample_rate_hz_); |
| 83 } | 83 } |
| 84 | 84 |
| 85 void VerifyParams(const AudioFrame& ref_frame, const AudioFrame& test_frame) { | 85 void VerifyParams(const AudioFrame& ref_frame, const AudioFrame& test_frame) { |
| 86 EXPECT_EQ(ref_frame.num_channels_, test_frame.num_channels_); | 86 EXPECT_EQ(ref_frame.num_channels_, test_frame.num_channels_); |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 } | 254 } |
| 255 } | 255 } |
| 256 } | 256 } |
| 257 } | 257 } |
| 258 } | 258 } |
| 259 } | 259 } |
| 260 | 260 |
| 261 } // namespace | 261 } // namespace |
| 262 } // namespace voe | 262 } // namespace voe |
| 263 } // namespace webrtc | 263 } // namespace webrtc |
| OLD | NEW |