| 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 #include "media/base/audio_buffer.h" | 5 #include "media/base/audio_buffer.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "media/base/audio_bus.h" | 10 #include "media/base/audio_bus.h" |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 return sample >> 16; | 201 return sample >> 16; |
| 202 } | 202 } |
| 203 | 203 |
| 204 template <> | 204 template <> |
| 205 inline int16_t ConvertSample<float, int16_t>(float sample) { | 205 inline int16_t ConvertSample<float, int16_t>(float sample) { |
| 206 return static_cast<int16_t>( | 206 return static_cast<int16_t>( |
| 207 nearbyint(sample < 0 ? (-sample) * std::numeric_limits<int16_t>::min() | 207 nearbyint(sample < 0 ? (-sample) * std::numeric_limits<int16_t>::min() |
| 208 : sample * std::numeric_limits<int16_t>::max())); | 208 : sample * std::numeric_limits<int16_t>::max())); |
| 209 } | 209 } |
| 210 | 210 |
| 211 void AudioBuffer::AdjustSampleRate(int sample_rate) { |
| 212 DCHECK(!end_of_stream_); |
| 213 sample_rate_ = sample_rate; |
| 214 duration_ = CalculateDuration(adjusted_frame_count_, sample_rate_); |
| 215 } |
| 216 |
| 211 void AudioBuffer::ReadFrames(int frames_to_copy, | 217 void AudioBuffer::ReadFrames(int frames_to_copy, |
| 212 int source_frame_offset, | 218 int source_frame_offset, |
| 213 int dest_frame_offset, | 219 int dest_frame_offset, |
| 214 AudioBus* dest) { | 220 AudioBus* dest) { |
| 215 // Deinterleave each channel (if necessary) and convert to 32bit | 221 // Deinterleave each channel (if necessary) and convert to 32bit |
| 216 // floating-point with nominal range -1.0 -> +1.0 (if necessary). | 222 // floating-point with nominal range -1.0 -> +1.0 (if necessary). |
| 217 | 223 |
| 218 // |dest| must have the same number of channels, and the number of frames | 224 // |dest| must have the same number of channels, and the number of frames |
| 219 // specified must be in range. | 225 // specified must be in range. |
| 220 DCHECK(!end_of_stream()); | 226 DCHECK(!end_of_stream()); |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 } | 424 } |
| 419 } else { | 425 } else { |
| 420 CHECK_EQ(frames_to_copy, 0); | 426 CHECK_EQ(frames_to_copy, 0); |
| 421 } | 427 } |
| 422 | 428 |
| 423 // Trim the leftover data off the end of the buffer and update duration. | 429 // Trim the leftover data off the end of the buffer and update duration. |
| 424 TrimEnd(frames_to_trim); | 430 TrimEnd(frames_to_trim); |
| 425 } | 431 } |
| 426 | 432 |
| 427 } // namespace media | 433 } // namespace media |
| OLD | NEW |