Chromium Code Reviews| Index: media/audio/pulse/pulse_output.cc |
| diff --git a/media/audio/pulse/pulse_output.cc b/media/audio/pulse/pulse_output.cc |
| index f86860571a03fca4390c4149704888b5c3630d55..76a4bd66750ee49ba20aee4da0df5c554ffac77a 100644 |
| --- a/media/audio/pulse/pulse_output.cc |
| +++ b/media/audio/pulse/pulse_output.cc |
| @@ -12,6 +12,7 @@ |
| #include "media/audio/audio_device_description.h" |
| #include "media/audio/audio_manager_base.h" |
| #include "media/audio/pulse/pulse_util.h" |
| +#include "media/base/audio_sample_types.h" |
| namespace media { |
| @@ -43,7 +44,14 @@ void PulseAudioOutputStream::StreamRequestCallback(pa_stream* s, size_t len, |
| PulseAudioOutputStream::PulseAudioOutputStream(const AudioParameters& params, |
| const std::string& device_id, |
| AudioManagerBase* manager) |
| - : params_(params), |
| + : params_(AudioParameters(params.format(), |
| + params.channel_layout(), |
| + params.sample_rate(), |
| + // Ignore the given bits per sample. We |
| + // want 32 because we're outputting |
| + // floats now. |
|
DaleCurtis
2016/11/01 23:07:53
s/ now// -- no need to document the old state of t
Raymond Toy
2016/11/01 23:18:50
Done.
|
| + 32, |
| + params.frames_per_buffer())), |
| device_id_(device_id), |
| manager_(manager), |
| pa_context_(NULL), |
| @@ -124,6 +132,7 @@ void PulseAudioOutputStream::FulfillWriteRequest(size_t requested_bytes) { |
| while (bytes_remaining > 0) { |
| void* buffer = NULL; |
| size_t bytes_to_fill = params_.GetBytesPerBuffer(); |
| + |
|
DaleCurtis
2016/11/01 23:07:53
Remove?
Raymond Toy
2016/11/01 23:18:50
Done.
|
| CHECK_GE(pa_stream_begin_write(pa_stream_, &buffer, &bytes_to_fill), 0); |
| CHECK_EQ(bytes_to_fill, static_cast<size_t>(params_.GetBytesPerBuffer())); |
| @@ -146,8 +155,13 @@ void PulseAudioOutputStream::FulfillWriteRequest(size_t requested_bytes) { |
| // Note: If this ever changes to output raw float the data must be clipped |
| // and sanitized since it may come from an untrusted source such as NaCl. |
| audio_bus_->Scale(volume_); |
| - audio_bus_->ToInterleaved( |
| - audio_bus_->frames(), params_.bits_per_sample() / 8, buffer); |
| + |
| + // Sanitize the samples. Replace NaN with zero, and then clamp |
|
DaleCurtis
2016/11/01 23:07:53
This should already be done as part of ToInterleav
Raymond Toy
2016/11/01 23:18:50
Dunno. I didn't look. I was just going by the comm
|
| + // everything to the range [-1,1]. |
| + audio_bus_->Clamp(); |
| + |
| + audio_bus_->ToInterleaved<Float32SampleTypeTraits>( |
| + audio_bus_->frames(), reinterpret_cast<float*>(buffer)); |
| } else { |
| memset(buffer, 0, bytes_to_fill); |
| } |