OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // Software adjust volume of samples, allows each audio stream its own | 5 // Software adjust volume of samples, allows each audio stream its own |
6 // volume without impacting master volume for chrome and other applications. | 6 // volume without impacting master volume for chrome and other applications. |
7 | 7 |
8 // Implemented as templates to allow 8, 16 and 32 bit implementations. | 8 // Implemented as templates to allow 8, 16 and 32 bit implementations. |
9 // 8 bit is unsigned and biased by 128. | 9 // 8 bit is unsigned and biased by 128. |
10 | 10 |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 reinterpret_cast<int32*>(buf), | 151 reinterpret_cast<int32*>(buf), |
152 sample_count, | 152 sample_count, |
153 volume, | 153 volume, |
154 channels); | 154 channels); |
155 return true; | 155 return true; |
156 } | 156 } |
157 } | 157 } |
158 return false; | 158 return false; |
159 } | 159 } |
160 | 160 |
| 161 bool DeinterleaveAudioChannel(void* source, |
| 162 float* destination, |
| 163 int channels, |
| 164 int channel_index, |
| 165 int bytes_per_sample, |
| 166 size_t number_of_frames) { |
| 167 switch (bytes_per_sample) { |
| 168 case 1: |
| 169 { |
| 170 uint8* source8 = static_cast<uint8*>(source) + channel_index; |
| 171 const float kScale = 1.0f / 128.0f; |
| 172 for (unsigned i = 0; i < number_of_frames; ++i) { |
| 173 destination[i] = kScale * static_cast<int>(*source8 + 128); |
| 174 source8 += channels; |
| 175 } |
| 176 return true; |
| 177 } |
| 178 |
| 179 case 2: |
| 180 { |
| 181 int16* source16 = static_cast<int16*>(source) + channel_index; |
| 182 const float kScale = 1.0f / 32768.0f; |
| 183 for (unsigned i = 0; i < number_of_frames; ++i) { |
| 184 destination[i] = kScale * *source16; |
| 185 source16 += channels; |
| 186 } |
| 187 return true; |
| 188 } |
| 189 |
| 190 case 4: |
| 191 { |
| 192 int32* source32 = static_cast<int32*>(source) + channel_index; |
| 193 const float kScale = 1.0f / (1L << 31); |
| 194 for (unsigned i = 0; i < number_of_frames; ++i) { |
| 195 destination[i] = kScale * *source32; |
| 196 source32 += channels; |
| 197 } |
| 198 return true; |
| 199 } |
| 200 |
| 201 default: |
| 202 break; |
| 203 } |
| 204 return false; |
| 205 } |
| 206 |
161 } // namespace media | 207 } // namespace media |
OLD | NEW |