Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 209 { | 209 { |
| 210 for (unsigned i = 0; i < numberOfChannels(); ++i) | 210 for (unsigned i = 0; i < numberOfChannels(); ++i) |
| 211 channel(i)->scale(scale); | 211 channel(i)->scale(scale); |
| 212 } | 212 } |
| 213 | 213 |
| 214 void AudioBus::copyFrom(const AudioBus& sourceBus, ChannelInterpretation channel Interpretation) | 214 void AudioBus::copyFrom(const AudioBus& sourceBus, ChannelInterpretation channel Interpretation) |
| 215 { | 215 { |
| 216 if (&sourceBus == this) | 216 if (&sourceBus == this) |
| 217 return; | 217 return; |
| 218 | 218 |
| 219 unsigned numberOfSourceChannels = sourceBus.numberOfChannels(); | 219 // Copying bus is equivalent to zeroing and then summing. |
| 220 unsigned numberOfDestinationChannels = numberOfChannels(); | 220 zero(); |
| 221 | 221 sumFrom(sourceBus, channelInterpretation); |
| 222 if (numberOfDestinationChannels == numberOfSourceChannels) { | |
| 223 for (unsigned i = 0; i < numberOfSourceChannels; ++i) | |
| 224 channel(i)->copyFrom(sourceBus.channel(i)); | |
| 225 } else { | |
| 226 switch (channelInterpretation) { | |
| 227 case Speakers: | |
| 228 speakersCopyFrom(sourceBus); | |
| 229 break; | |
| 230 case Discrete: | |
| 231 discreteCopyFrom(sourceBus); | |
| 232 break; | |
| 233 default: | |
| 234 ASSERT_NOT_REACHED(); | |
| 235 } | |
| 236 } | |
| 237 } | 222 } |
| 238 | 223 |
| 239 void AudioBus::sumFrom(const AudioBus& sourceBus, ChannelInterpretation channelI nterpretation) | 224 void AudioBus::sumFrom(const AudioBus& sourceBus, ChannelInterpretation channelI nterpretation) |
| 240 { | 225 { |
| 241 if (&sourceBus == this) | 226 if (&sourceBus == this) |
| 242 return; | 227 return; |
| 243 | 228 |
| 244 unsigned numberOfSourceChannels = sourceBus.numberOfChannels(); | 229 unsigned numberOfSourceChannels = sourceBus.numberOfChannels(); |
| 245 unsigned numberOfDestinationChannels = numberOfChannels(); | 230 unsigned numberOfDestinationChannels = numberOfChannels(); |
| 246 | 231 |
| 247 if (numberOfDestinationChannels == numberOfSourceChannels) { | 232 // If the channel numbers are equal, perform channels-wise summing. |
| 233 if (numberOfSourceChannels == numberOfDestinationChannels) { | |
| 248 for (unsigned i = 0; i < numberOfSourceChannels; ++i) | 234 for (unsigned i = 0; i < numberOfSourceChannels; ++i) |
| 249 channel(i)->sumFrom(sourceBus.channel(i)); | 235 channel(i)->sumFrom(sourceBus.channel(i)); |
| 250 } else { | 236 |
| 251 switch (channelInterpretation) { | 237 return; |
| 252 case Speakers: | 238 } |
| 253 speakersSumFrom(sourceBus); | 239 |
| 254 break; | 240 // Otherwise perform up/down-mix or the discrete transfer based on the |
| 255 case Discrete: | 241 // number of channels and the channel interpretation. |
| 256 discreteSumFrom(sourceBus); | 242 switch (channelInterpretation) { |
| 257 break; | 243 case Speakers: |
| 258 default: | 244 if (numberOfSourceChannels < numberOfDestinationChannels) |
| 259 ASSERT_NOT_REACHED(); | 245 sumFromByUpMixing(sourceBus); |
| 260 } | 246 else |
| 261 } | 247 sumFromByDownMixing(sourceBus); |
| 262 } | 248 break; |
| 263 | 249 case Discrete: |
| 264 void AudioBus::speakersCopyFrom(const AudioBus& sourceBus) | |
| 265 { | |
| 266 // FIXME: Implement down mixing 5.1 to stereo. | |
| 267 // https://bugs.webkit.org/show_bug.cgi?id=79192 | |
| 268 | |
| 269 unsigned numberOfSourceChannels = sourceBus.numberOfChannels(); | |
| 270 unsigned numberOfDestinationChannels = numberOfChannels(); | |
| 271 | |
| 272 if (numberOfDestinationChannels == 2 && numberOfSourceChannels == 1) { | |
| 273 // Handle mono -> stereo case (for now simply copy mono channel into bot h left and right) | |
| 274 // FIXME: Really we should apply an equal-power scaling factor here, sin ce we're effectively panning center... | |
| 275 const AudioChannel* sourceChannel = sourceBus.channel(0); | |
| 276 channel(0)->copyFrom(sourceChannel); | |
| 277 channel(1)->copyFrom(sourceChannel); | |
| 278 } else if (numberOfDestinationChannels == 1 && numberOfSourceChannels == 2) { | |
| 279 // Handle stereo -> mono case. output = 0.5 * (input.L + input.R). | |
| 280 AudioBus& sourceBusSafe = const_cast<AudioBus&>(sourceBus); | |
| 281 | |
| 282 const float* sourceL = sourceBusSafe.channelByType(ChannelLeft)->data(); | |
| 283 const float* sourceR = sourceBusSafe.channelByType(ChannelRight)->data() ; | |
| 284 | |
| 285 float* destination = channelByType(ChannelLeft)->mutableData(); | |
| 286 vadd(sourceL, 1, sourceR, 1, destination, 1, length()); | |
| 287 float scale = 0.5; | |
| 288 vsmul(destination, 1, &scale, destination, 1, length()); | |
| 289 } else if (numberOfDestinationChannels == 6 && numberOfSourceChannels == 1) { | |
| 290 // Handle mono -> 5.1 case, copy mono channel to center. | |
| 291 channel(2)->copyFrom(sourceBus.channel(0)); | |
| 292 channel(0)->zero(); | |
| 293 channel(1)->zero(); | |
| 294 channel(3)->zero(); | |
| 295 channel(4)->zero(); | |
| 296 channel(5)->zero(); | |
| 297 } else if (numberOfDestinationChannels == 1 && numberOfSourceChannels == 6) { | |
| 298 // Handle 5.1 -> mono case. | |
| 299 zero(); | |
| 300 speakersSumFrom5_1_ToMono(sourceBus); | |
| 301 } else { | |
| 302 // Fallback for unknown combinations. | |
| 303 discreteCopyFrom(sourceBus); | |
| 304 } | |
| 305 } | |
| 306 | |
| 307 void AudioBus::speakersSumFrom(const AudioBus& sourceBus) | |
| 308 { | |
| 309 // FIXME: Implement down mixing 5.1 to stereo. | |
| 310 // https://bugs.webkit.org/show_bug.cgi?id=79192 | |
| 311 | |
| 312 unsigned numberOfSourceChannels = sourceBus.numberOfChannels(); | |
| 313 unsigned numberOfDestinationChannels = numberOfChannels(); | |
| 314 | |
| 315 if (numberOfDestinationChannels == 2 && numberOfSourceChannels == 1) { | |
| 316 // Handle mono -> stereo case (summing mono channel into both left and r ight). | |
| 317 const AudioChannel* sourceChannel = sourceBus.channel(0); | |
| 318 channel(0)->sumFrom(sourceChannel); | |
| 319 channel(1)->sumFrom(sourceChannel); | |
| 320 } else if (numberOfDestinationChannels == 1 && numberOfSourceChannels == 2) { | |
| 321 // Handle stereo -> mono case. output += 0.5 * (input.L + input.R). | |
| 322 AudioBus& sourceBusSafe = const_cast<AudioBus&>(sourceBus); | |
| 323 | |
| 324 const float* sourceL = sourceBusSafe.channelByType(ChannelLeft)->data(); | |
| 325 const float* sourceR = sourceBusSafe.channelByType(ChannelRight)->data() ; | |
| 326 | |
| 327 float* destination = channelByType(ChannelLeft)->mutableData(); | |
| 328 float scale = 0.5; | |
| 329 vsma(sourceL, 1, &scale, destination, 1, length()); | |
| 330 vsma(sourceR, 1, &scale, destination, 1, length()); | |
| 331 } else if (numberOfDestinationChannels == 6 && numberOfSourceChannels == 1) { | |
| 332 // Handle mono -> 5.1 case, sum mono channel into center. | |
| 333 channel(2)->sumFrom(sourceBus.channel(0)); | |
| 334 } else if (numberOfDestinationChannels == 1 && numberOfSourceChannels == 6) { | |
| 335 // Handle 5.1 -> mono case. | |
| 336 speakersSumFrom5_1_ToMono(sourceBus); | |
| 337 } else { | |
| 338 // Fallback for unknown combinations. | |
| 339 discreteSumFrom(sourceBus); | 250 discreteSumFrom(sourceBus); |
| 340 } | 251 break; |
| 341 } | |
| 342 | |
| 343 void AudioBus::speakersSumFrom5_1_ToMono(const AudioBus& sourceBus) | |
| 344 { | |
| 345 AudioBus& sourceBusSafe = const_cast<AudioBus&>(sourceBus); | |
| 346 | |
| 347 const float* sourceL = sourceBusSafe.channelByType(ChannelLeft)->data(); | |
| 348 const float* sourceR = sourceBusSafe.channelByType(ChannelRight)->data(); | |
| 349 const float* sourceC = sourceBusSafe.channelByType(ChannelCenter)->data(); | |
| 350 const float* sourceSL = sourceBusSafe.channelByType(ChannelSurroundLeft)->da ta(); | |
| 351 const float* sourceSR = sourceBusSafe.channelByType(ChannelSurroundRight)->d ata(); | |
| 352 | |
| 353 float* destination = channelByType(ChannelLeft)->mutableData(); | |
| 354 | |
| 355 AudioFloatArray temp(length()); | |
| 356 float* tempData = temp.data(); | |
| 357 | |
| 358 // Sum in L and R. | |
| 359 vadd(sourceL, 1, sourceR, 1, tempData, 1, length()); | |
| 360 float scale = 0.7071; | |
| 361 vsmul(tempData, 1, &scale, tempData, 1, length()); | |
| 362 vadd(tempData, 1, destination, 1, destination, 1, length()); | |
| 363 | |
| 364 // Sum in SL and SR. | |
| 365 vadd(sourceSL, 1, sourceSR, 1, tempData, 1, length()); | |
| 366 scale = 0.5; | |
| 367 vsmul(tempData, 1, &scale, tempData, 1, length()); | |
| 368 vadd(tempData, 1, destination, 1, destination, 1, length()); | |
| 369 | |
| 370 // Sum in center. | |
| 371 vadd(sourceC, 1, destination, 1, destination, 1, length()); | |
| 372 } | |
| 373 | |
| 374 void AudioBus::discreteCopyFrom(const AudioBus& sourceBus) | |
| 375 { | |
| 376 unsigned numberOfSourceChannels = sourceBus.numberOfChannels(); | |
| 377 unsigned numberOfDestinationChannels = numberOfChannels(); | |
| 378 | |
| 379 if (numberOfDestinationChannels < numberOfSourceChannels) { | |
| 380 // Down-mix by copying channels and dropping the remaining. | |
| 381 for (unsigned i = 0; i < numberOfDestinationChannels; ++i) | |
| 382 channel(i)->copyFrom(sourceBus.channel(i)); | |
| 383 } else if (numberOfDestinationChannels > numberOfSourceChannels) { | |
| 384 // Up-mix by copying as many channels as we have, then zeroing remaining channels. | |
| 385 for (unsigned i = 0; i < numberOfSourceChannels; ++i) | |
| 386 channel(i)->copyFrom(sourceBus.channel(i)); | |
| 387 for (unsigned i = numberOfSourceChannels; i < numberOfDestinationChannel s; ++i) | |
| 388 channel(i)->zero(); | |
| 389 } | 252 } |
| 390 } | 253 } |
| 391 | 254 |
| 392 void AudioBus::discreteSumFrom(const AudioBus& sourceBus) | 255 void AudioBus::discreteSumFrom(const AudioBus& sourceBus) |
| 393 { | 256 { |
| 394 unsigned numberOfSourceChannels = sourceBus.numberOfChannels(); | 257 unsigned numberOfSourceChannels = sourceBus.numberOfChannels(); |
| 395 unsigned numberOfDestinationChannels = numberOfChannels(); | 258 unsigned numberOfDestinationChannels = numberOfChannels(); |
| 396 | 259 |
| 397 if (numberOfDestinationChannels < numberOfSourceChannels) { | 260 if (numberOfDestinationChannels < numberOfSourceChannels) { |
| 398 // Down-mix by summing channels and dropping the remaining. | 261 // Down-mix by summing channels and dropping the remaining. |
| 399 for (unsigned i = 0; i < numberOfDestinationChannels; ++i) | 262 for (unsigned i = 0; i < numberOfDestinationChannels; ++i) |
| 400 channel(i)->sumFrom(sourceBus.channel(i)); | 263 channel(i)->sumFrom(sourceBus.channel(i)); |
| 401 } else if (numberOfDestinationChannels > numberOfSourceChannels) { | 264 } else if (numberOfDestinationChannels > numberOfSourceChannels) { |
| 402 // Up-mix by summing as many channels as we have. | 265 // Up-mix by summing as many channels as we have. |
| 403 for (unsigned i = 0; i < numberOfSourceChannels; ++i) | 266 for (unsigned i = 0; i < numberOfSourceChannels; ++i) |
| 404 channel(i)->sumFrom(sourceBus.channel(i)); | 267 channel(i)->sumFrom(sourceBus.channel(i)); |
| 405 } | 268 } |
| 406 } | 269 } |
| 407 | 270 |
| 271 void AudioBus::sumFromByUpMixing(const AudioBus& sourceBus) | |
| 272 { | |
| 273 unsigned numberOfSourceChannels = sourceBus.numberOfChannels(); | |
| 274 unsigned numberOfDestinationChannels = numberOfChannels(); | |
| 275 | |
| 276 if ((numberOfSourceChannels == 1 && numberOfDestinationChannels == 2) || (nu mberOfSourceChannels == 1 && numberOfDestinationChannels == 4)) { | |
|
Raymond Toy
2016/03/10 18:56:47
Not something to fix here, but we should probably
hongchan
2016/03/11 19:48:06
Acknowledged, but "git cl format" always reverts m
Raymond Toy
2016/03/11 19:53:17
Oh well. We'll just have to wait for the Great Ref
| |
| 277 // Up-mixing: 1 -> 2, 1 -> 4 | |
| 278 // output.L = input | |
| 279 // output.R = input | |
| 280 // output.SL = 0 (in the case of 1 -> 4) | |
| 281 // output.SR = 0 (in the case of 1 -> 4) | |
| 282 const AudioChannel* sourceChannel = sourceBus.channel(0); | |
|
Raymond Toy
2016/03/10 18:56:47
Style nit: In sumFromByDownMixing, you access cha
hongchan
2016/03/11 19:48:06
Done, but what about the sources? Should we change
| |
| 283 channel(0)->sumFrom(sourceChannel); | |
| 284 channel(1)->sumFrom(sourceChannel); | |
| 285 } else if (numberOfSourceChannels == 1 && numberOfDestinationChannels == 6) { | |
| 286 // Up-mixing: 1 -> 5.1 | |
| 287 // output.L = 0 | |
| 288 // output.R = 0 | |
| 289 // output.C = input (put in center channel) | |
| 290 // output.LFE = 0 | |
| 291 // output.SL = 0 | |
| 292 // output.SR = 0 | |
| 293 channel(2)->sumFrom(sourceBus.channel(0)); | |
| 294 } else if ((numberOfSourceChannels == 2 && numberOfDestinationChannels == 4) || (numberOfSourceChannels == 2 && numberOfDestinationChannels == 6)) { | |
| 295 // Up-mixing: 2 -> 4, 2 -> 5.1 | |
| 296 // output.L = input.L | |
| 297 // output.R = input.R | |
| 298 // output.C = 0 (in the case of 2 -> 5.1) | |
| 299 // output.LFE = 0 (in the case of 2 -> 5.1) | |
| 300 // output.SL = 0 | |
| 301 // output.SR = 0 | |
| 302 channel(0)->sumFrom(sourceBus.channel(0)); | |
| 303 channel(1)->sumFrom(sourceBus.channel(1)); | |
| 304 } else if (numberOfSourceChannels == 4 && numberOfDestinationChannels == 6) { | |
| 305 // Up-mixing: 4 -> 5.1 | |
| 306 // output.L = input.L | |
| 307 // output.R = input.R | |
| 308 // output.C = 0 | |
| 309 // output.LFE = 0 | |
| 310 // output.SL = input.SL | |
| 311 // output.SR = input.SR | |
| 312 channel(0)->sumFrom(sourceBus.channel(0)); | |
| 313 channel(1)->sumFrom(sourceBus.channel(1)); | |
| 314 channel(4)->sumFrom(sourceBus.channel(2)); | |
| 315 channel(5)->sumFrom(sourceBus.channel(3)); | |
| 316 } else { | |
| 317 // All other cases, fall back to the discrete sum. This will silence the | |
| 318 // excessive channels. | |
| 319 discreteSumFrom(sourceBus); | |
| 320 } | |
| 321 } | |
| 322 | |
| 323 void AudioBus::sumFromByDownMixing(const AudioBus& sourceBus) | |
| 324 { | |
| 325 unsigned numberOfSourceChannels = sourceBus.numberOfChannels(); | |
| 326 unsigned numberOfDestinationChannels = numberOfChannels(); | |
| 327 | |
| 328 if (numberOfSourceChannels == 2 && numberOfDestinationChannels == 1) { | |
| 329 // Down-mixing: 2 -> 1 | |
| 330 // output = 0.5 * (input.L + input.R) | |
| 331 AudioBus& sourceBusConst = const_cast<AudioBus&>(sourceBus); | |
| 332 const float* sourceL = sourceBusConst.channelByType(ChannelLeft)->data() ; | |
| 333 const float* sourceR = sourceBusConst.channelByType(ChannelRight)->data( ); | |
| 334 | |
| 335 float* destination = channelByType(ChannelLeft)->mutableData(); | |
| 336 float scale = 0.5; | |
| 337 | |
| 338 vsma(sourceL, 1, &scale, destination, 1, length()); | |
| 339 vsma(sourceR, 1, &scale, destination, 1, length()); | |
| 340 } else if (numberOfSourceChannels == 4 && numberOfDestinationChannels == 1) { | |
| 341 // Down-mixing: 4 -> 1 | |
| 342 // output = 0.25 * (input.L + input.R + input.SL + input.SR) | |
| 343 AudioBus& sourceBusConst = const_cast<AudioBus&>(sourceBus); | |
| 344 const float* sourceL = sourceBusConst.channelByType(ChannelLeft)->data() ; | |
| 345 const float* sourceR = sourceBusConst.channelByType(ChannelRight)->data( ); | |
| 346 const float* sourceSL = sourceBusConst.channelByType(ChannelSurroundLeft )->data(); | |
| 347 const float* sourceSR = sourceBusConst.channelByType(ChannelSurroundRigh t)->data(); | |
| 348 | |
| 349 float* destination = channelByType(ChannelLeft)->mutableData(); | |
| 350 float scale = 0.25; | |
| 351 | |
| 352 vsma(sourceL, 1, &scale, destination, 1, length()); | |
| 353 vsma(sourceR, 1, &scale, destination, 1, length()); | |
| 354 vsma(sourceSL, 1, &scale, destination, 1, length()); | |
| 355 vsma(sourceSR, 1, &scale, destination, 1, length()); | |
| 356 } else if (numberOfSourceChannels == 6 && numberOfDestinationChannels == 1) { | |
| 357 // Down-mixing: 5.1 -> 1 | |
| 358 // output = sqrt(1/2) * (input.L + input.R) + input.C | |
| 359 // + 0.5 * (input.SL + input.SR) | |
| 360 AudioBus& sourceBusConst = const_cast<AudioBus&>(sourceBus); | |
|
Raymond Toy
2016/03/10 18:56:47
Seems weird that you have to do a const cast. I'm
hongchan
2016/03/11 19:48:06
After the discussion we had, I removed the all con
| |
| 361 const float* sourceL = sourceBusConst.channelByType(ChannelLeft)->data() ; | |
| 362 const float* sourceR = sourceBusConst.channelByType(ChannelRight)->data( ); | |
| 363 const float* sourceC = sourceBusConst.channelByType(ChannelCenter)->data (); | |
| 364 const float* sourceSL = sourceBusConst.channelByType(ChannelSurroundLeft )->data(); | |
| 365 const float* sourceSR = sourceBusConst.channelByType(ChannelSurroundRigh t)->data(); | |
| 366 | |
| 367 float* destination = channelByType(ChannelLeft)->mutableData(); | |
| 368 float scaleSqrtHalf = sqrtf(0.5); | |
| 369 float scaleHalf = 0.5; | |
| 370 | |
| 371 vsma(sourceL, 1, &scaleSqrtHalf, destination, 1, length()); | |
| 372 vsma(sourceR, 1, &scaleSqrtHalf, destination, 1, length()); | |
| 373 vadd(sourceC, 1, destination, 1, destination, 1, length()); | |
| 374 vsma(sourceSL, 1, &scaleHalf, destination, 1, length()); | |
| 375 vsma(sourceSR, 1, &scaleHalf, destination, 1, length()); | |
| 376 } else if (numberOfSourceChannels == 4 && numberOfDestinationChannels == 2) { | |
| 377 // Down-mixing: 4 -> 2 | |
| 378 // output.L = 0.5 * (input.L + input.SL) | |
| 379 // output.R = 0.5 * (input.R + input.SR) | |
| 380 AudioBus& sourceBusConst = const_cast<AudioBus&>(sourceBus); | |
| 381 const float* sourceL = sourceBusConst.channelByType(ChannelLeft)->data() ; | |
| 382 const float* sourceR = sourceBusConst.channelByType(ChannelRight)->data( ); | |
| 383 const float* sourceSL = sourceBusConst.channelByType(ChannelSurroundLeft )->data(); | |
| 384 const float* sourceSR = sourceBusConst.channelByType(ChannelSurroundRigh t)->data(); | |
| 385 | |
| 386 float* destinationL = channelByType(ChannelLeft)->mutableData(); | |
| 387 float* destinationR = channelByType(ChannelRight)->mutableData(); | |
| 388 float scaleHalf = 0.5; | |
| 389 | |
| 390 vsma(sourceL, 1, &scaleHalf, destinationL, 1, length()); | |
| 391 vsma(sourceSL, 1, &scaleHalf, destinationL, 1, length()); | |
| 392 vsma(sourceR, 1, &scaleHalf, destinationR, 1, length()); | |
| 393 vsma(sourceSR, 1, &scaleHalf, destinationR, 1, length()); | |
| 394 } else if (numberOfSourceChannels == 6 && numberOfDestinationChannels == 2) { | |
| 395 // Down-mixing: 5.1 -> 2 | |
| 396 // output.L = input.L + sqrt(1/2) * (input.C + input.SL) | |
| 397 // output.R = input.R + sqrt(1/2) * (input.C + input.SR) | |
| 398 AudioBus& sourceBusConst = const_cast<AudioBus&>(sourceBus); | |
| 399 const float* sourceL = sourceBusConst.channelByType(ChannelLeft)->data() ; | |
| 400 const float* sourceR = sourceBusConst.channelByType(ChannelRight)->data( ); | |
| 401 const float* sourceC = sourceBusConst.channelByType(ChannelCenter)->data (); | |
| 402 const float* sourceSL = sourceBusConst.channelByType(ChannelSurroundLeft )->data(); | |
| 403 const float* sourceSR = sourceBusConst.channelByType(ChannelSurroundRigh t)->data(); | |
| 404 | |
| 405 float* destinationL = channelByType(ChannelLeft)->mutableData(); | |
| 406 float* destinationR = channelByType(ChannelRight)->mutableData(); | |
| 407 float scaleSqrtHalf = sqrtf(0.5); | |
| 408 | |
| 409 vadd(sourceL, 1, destinationL, 1, destinationL, 1, length()); | |
| 410 vsma(sourceC, 1, &scaleSqrtHalf, destinationL, 1, length()); | |
| 411 vsma(sourceSL, 1, &scaleSqrtHalf, destinationL, 1, length()); | |
| 412 vadd(sourceR, 1, destinationR, 1, destinationR, 1, length()); | |
| 413 vsma(sourceC, 1, &scaleSqrtHalf, destinationR, 1, length()); | |
| 414 vsma(sourceSR, 1, &scaleSqrtHalf, destinationR, 1, length()); | |
| 415 } else if (numberOfSourceChannels == 6 && numberOfDestinationChannels == 4) { | |
| 416 // Down-mixing: 5.1 -> 4 | |
| 417 // output.L = input.L + sqrt(1/2) * input.C | |
| 418 // output.R = input.R + sqrt(1/2) * input.C | |
| 419 // output.SL = input.SL | |
| 420 // output.SR = input.SR | |
| 421 AudioBus& sourceBusConst = const_cast<AudioBus&>(sourceBus); | |
| 422 const float* sourceL = sourceBusConst.channelByType(ChannelLeft)->data() ; | |
| 423 const float* sourceR = sourceBusConst.channelByType(ChannelRight)->data( ); | |
| 424 const float* sourceC = sourceBusConst.channelByType(ChannelCenter)->data (); | |
| 425 | |
| 426 float* destinationL = channelByType(ChannelLeft)->mutableData(); | |
| 427 float* destinationR = channelByType(ChannelRight)->mutableData(); | |
| 428 float scaleSqrtHalf = sqrtf(0.5); | |
| 429 | |
| 430 vadd(sourceL, 1, destinationL, 1, destinationL, 1, length()); | |
| 431 vsma(sourceC, 1, &scaleSqrtHalf, destinationL, 1, length()); | |
| 432 vadd(sourceR, 1, destinationR, 1, destinationR, 1, length()); | |
| 433 vsma(sourceC, 1, &scaleSqrtHalf, destinationR, 1, length()); | |
| 434 channel(2)->sumFrom(sourceBus.channel(4)); | |
| 435 channel(3)->sumFrom(sourceBus.channel(5)); | |
| 436 } else { | |
| 437 // All other cases, fall back to the discrete sum. This will perform | |
| 438 // channel-wise sum until the destination channels run out. | |
| 439 discreteSumFrom(sourceBus); | |
| 440 } | |
| 441 } | |
| 442 | |
| 408 void AudioBus::copyWithGainFrom(const AudioBus &sourceBus, float* lastMixGain, f loat targetGain) | 443 void AudioBus::copyWithGainFrom(const AudioBus &sourceBus, float* lastMixGain, f loat targetGain) |
| 409 { | 444 { |
| 410 if (!topologyMatches(sourceBus)) { | 445 if (!topologyMatches(sourceBus)) { |
| 411 ASSERT_NOT_REACHED(); | 446 ASSERT_NOT_REACHED(); |
| 412 zero(); | 447 zero(); |
| 413 return; | 448 return; |
| 414 } | 449 } |
| 415 | 450 |
| 416 if (sourceBus.isSilent()) { | 451 if (sourceBus.isSilent()) { |
| 417 zero(); | 452 zero(); |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 676 | 711 |
| 677 // If the bus needs no conversion then return as is. | 712 // If the bus needs no conversion then return as is. |
| 678 if ((!mixToMono || audioBus->numberOfChannels() == 1) && audioBus->sampleRat e() == sampleRate) | 713 if ((!mixToMono || audioBus->numberOfChannels() == 1) && audioBus->sampleRat e() == sampleRate) |
| 679 return audioBus; | 714 return audioBus; |
| 680 | 715 |
| 681 return AudioBus::createBySampleRateConverting(audioBus.get(), mixToMono, sam pleRate); | 716 return AudioBus::createBySampleRateConverting(audioBus.get(), mixToMono, sam pleRate); |
| 682 } | 717 } |
| 683 | 718 |
| 684 } // namespace blink | 719 } // namespace blink |
| 685 | 720 |
| OLD | NEW |