Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(188)

Side by Side Diff: media/base/audio_buffer.cc

Issue 2158923004: Convert media constants to constexpr. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 } 114 }
115 115
116 // static 116 // static
117 scoped_refptr<AudioBuffer> AudioBuffer::CreateBuffer( 117 scoped_refptr<AudioBuffer> AudioBuffer::CreateBuffer(
118 SampleFormat sample_format, 118 SampleFormat sample_format,
119 ChannelLayout channel_layout, 119 ChannelLayout channel_layout,
120 int channel_count, 120 int channel_count,
121 int sample_rate, 121 int sample_rate,
122 int frame_count) { 122 int frame_count) {
123 CHECK_GT(frame_count, 0); // Otherwise looks like an EOF buffer. 123 CHECK_GT(frame_count, 0); // Otherwise looks like an EOF buffer.
124 return make_scoped_refptr(new AudioBuffer(sample_format, 124 return make_scoped_refptr(
125 channel_layout, 125 new AudioBuffer(sample_format, channel_layout, channel_count, sample_rate,
126 channel_count, 126 frame_count, true, NULL, kNoTimestamp));
127 sample_rate,
128 frame_count,
129 true,
130 NULL,
131 kNoTimestamp()));
132 } 127 }
133 128
134 // static 129 // static
135 scoped_refptr<AudioBuffer> AudioBuffer::CreateEmptyBuffer( 130 scoped_refptr<AudioBuffer> AudioBuffer::CreateEmptyBuffer(
136 ChannelLayout channel_layout, 131 ChannelLayout channel_layout,
137 int channel_count, 132 int channel_count,
138 int sample_rate, 133 int sample_rate,
139 int frame_count, 134 int frame_count,
140 const base::TimeDelta timestamp) { 135 const base::TimeDelta timestamp) {
141 CHECK_GT(frame_count, 0); // Otherwise looks like an EOF buffer. 136 CHECK_GT(frame_count, 0); // Otherwise looks like an EOF buffer.
142 // Since data == NULL, format doesn't matter. 137 // Since data == NULL, format doesn't matter.
143 return make_scoped_refptr(new AudioBuffer(kSampleFormatF32, 138 return make_scoped_refptr(new AudioBuffer(kSampleFormatF32,
144 channel_layout, 139 channel_layout,
145 channel_count, 140 channel_count,
146 sample_rate, 141 sample_rate,
147 frame_count, 142 frame_count,
148 false, 143 false,
149 NULL, 144 NULL,
150 timestamp)); 145 timestamp));
151 } 146 }
152 147
153 // static 148 // static
154 scoped_refptr<AudioBuffer> AudioBuffer::CreateEOSBuffer() { 149 scoped_refptr<AudioBuffer> AudioBuffer::CreateEOSBuffer() {
155 return make_scoped_refptr(new AudioBuffer(kUnknownSampleFormat, 150 return make_scoped_refptr(new AudioBuffer(kUnknownSampleFormat,
156 CHANNEL_LAYOUT_NONE, 151 CHANNEL_LAYOUT_NONE, 0, 0, 0, false,
157 0, 152 NULL, kNoTimestamp));
158 0,
159 0,
160 false,
161 NULL,
162 kNoTimestamp()));
163 } 153 }
164 154
165 template <typename Target, typename Dest> 155 template <typename Target, typename Dest>
166 static inline Dest ConvertSample(Target value); 156 static inline Dest ConvertSample(Target value);
167 157
168 // Convert int16_t values in the range [INT16_MIN, INT16_MAX] to [-1.0, 1.0]. 158 // Convert int16_t values in the range [INT16_MIN, INT16_MAX] to [-1.0, 1.0].
169 template <> 159 template <>
170 inline float ConvertSample<int16_t, float>(int16_t value) { 160 inline float ConvertSample<int16_t, float>(int16_t value) {
171 return value * (value < 0 ? -1.0f / std::numeric_limits<int16_t>::min() 161 return value * (value < 0 ? -1.0f / std::numeric_limits<int16_t>::min()
172 : 1.0f / std::numeric_limits<int16_t>::max()); 162 : 1.0f / std::numeric_limits<int16_t>::max());
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 } 414 }
425 } else { 415 } else {
426 CHECK_EQ(frames_to_copy, 0); 416 CHECK_EQ(frames_to_copy, 0);
427 } 417 }
428 418
429 // Trim the leftover data off the end of the buffer and update duration. 419 // Trim the leftover data off the end of the buffer and update duration.
430 TrimEnd(frames_to_trim); 420 TrimEnd(frames_to_trim);
431 } 421 }
432 422
433 } // namespace media 423 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698