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 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 unsigned numberOfSourceChannels = sourceBus.numberOfChannels(); |
| 220 unsigned numberOfDestinationChannels = numberOfChannels(); | 220 unsigned numberOfDestinationChannels = numberOfChannels(); |
| 221 | 221 |
| 222 if (numberOfDestinationChannels == numberOfSourceChannels) { | 222 // If the channel numbers are equal, perform channels-wise copy. |
| 223 if (numberOfSourceChannels == numberOfDestinationChannels) { | |
| 223 for (unsigned i = 0; i < numberOfSourceChannels; ++i) | 224 for (unsigned i = 0; i < numberOfSourceChannels; ++i) |
| 224 channel(i)->copyFrom(sourceBus.channel(i)); | 225 channel(i)->copyFrom(sourceBus.channel(i)); |
| 225 } else { | 226 |
| 226 switch (channelInterpretation) { | 227 return; |
| 227 case Speakers: | 228 } |
| 228 speakersCopyFrom(sourceBus); | 229 |
| 229 break; | 230 // Otherwise perform up/down-mix or the discrete transfer based on the |
| 230 case Discrete: | 231 // number of channels and the channel interpretation. |
| 231 discreteCopyFrom(sourceBus); | 232 switch (channelInterpretation) { |
| 232 break; | 233 case Speakers: |
| 233 default: | 234 // Copying effectively replaces the current bus content. |
| 234 ASSERT_NOT_REACHED(); | 235 zero(); |
|
Raymond Toy
2016/03/08 18:04:07
Don't quite understand why you need to zero the bu
hongchan
2016/03/08 23:53:35
Because copying is basically zeroing-out and then
| |
| 235 } | 236 |
| 237 if (numberOfSourceChannels < numberOfDestinationChannels) | |
| 238 processUpMix(sourceBus); | |
| 239 else | |
| 240 processDownMix(sourceBus); | |
| 241 break; | |
| 242 case Discrete: | |
| 243 discreteCopyFrom(sourceBus); | |
| 244 break; | |
| 245 default: | |
|
Raymond Toy
2016/03/08 18:04:07
This shouldn't be needed since channelInterpretati
hongchan
2016/03/08 23:53:35
Then I will remove this.
| |
| 246 ASSERT_NOT_REACHED(); | |
| 236 } | 247 } |
| 237 } | 248 } |
| 238 | 249 |
| 239 void AudioBus::sumFrom(const AudioBus& sourceBus, ChannelInterpretation channelI nterpretation) | 250 void AudioBus::sumFrom(const AudioBus& sourceBus, ChannelInterpretation channelI nterpretation) |
| 240 { | 251 { |
| 241 if (&sourceBus == this) | 252 if (&sourceBus == this) |
| 242 return; | 253 return; |
| 243 | 254 |
| 244 unsigned numberOfSourceChannels = sourceBus.numberOfChannels(); | 255 unsigned numberOfSourceChannels = sourceBus.numberOfChannels(); |
| 245 unsigned numberOfDestinationChannels = numberOfChannels(); | 256 unsigned numberOfDestinationChannels = numberOfChannels(); |
| 246 | 257 |
| 247 if (numberOfDestinationChannels == numberOfSourceChannels) { | 258 // If the channel numbers are equal, perform channels-wise summing. |
| 259 if (numberOfSourceChannels == numberOfDestinationChannels) { | |
| 248 for (unsigned i = 0; i < numberOfSourceChannels; ++i) | 260 for (unsigned i = 0; i < numberOfSourceChannels; ++i) |
| 249 channel(i)->sumFrom(sourceBus.channel(i)); | 261 channel(i)->sumFrom(sourceBus.channel(i)); |
| 250 } else { | 262 |
| 251 switch (channelInterpretation) { | 263 return; |
| 252 case Speakers: | 264 } |
| 253 speakersSumFrom(sourceBus); | 265 |
| 254 break; | 266 // Otherwise perform up/down-mix or the discrete transfer based on the |
| 255 case Discrete: | 267 // number of channels and the channel interpretation. |
| 256 discreteSumFrom(sourceBus); | 268 switch (channelInterpretation) { |
| 257 break; | 269 case Speakers: |
| 258 default: | 270 if (numberOfSourceChannels < numberOfDestinationChannels) |
| 259 ASSERT_NOT_REACHED(); | 271 processUpMix(sourceBus); |
| 260 } | 272 else |
| 273 processDownMix(sourceBus); | |
| 274 break; | |
| 275 case Discrete: | |
| 276 discreteSumFrom(sourceBus); | |
| 277 break; | |
| 278 default: | |
| 279 ASSERT_NOT_REACHED(); | |
|
Raymond Toy
2016/03/08 18:04:07
This switch statement is almost identical to the s
hongchan
2016/03/08 23:53:35
We discussed this offline and decided to keep them
| |
| 261 } | 280 } |
| 262 } | 281 } |
| 263 | 282 |
| 264 void AudioBus::speakersCopyFrom(const AudioBus& sourceBus) | 283 void AudioBus::processUpMix(const AudioBus& sourceBus) |
| 265 { | 284 { |
| 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(); | 285 unsigned numberOfSourceChannels = sourceBus.numberOfChannels(); |
| 270 unsigned numberOfDestinationChannels = numberOfChannels(); | 286 unsigned numberOfDestinationChannels = numberOfChannels(); |
| 271 | 287 |
| 272 if (numberOfDestinationChannels == 2 && numberOfSourceChannels == 1) { | 288 // Up-mixing: 1 -> 2, 1 -> 4 |
| 273 // Handle mono -> stereo case (for now simply copy mono channel into bot h left and right) | 289 // output.L = input |
| 274 // FIXME: Really we should apply an equal-power scaling factor here, sin ce we're effectively panning center... | 290 // output.R = input |
| 275 const AudioChannel* sourceChannel = sourceBus.channel(0); | 291 // output.SL = 0 (in the case of 1 -> 4) |
| 276 channel(0)->copyFrom(sourceChannel); | 292 // output.SR = 0 (in the case of 1 -> 4) |
| 277 channel(1)->copyFrom(sourceChannel); | 293 if ((numberOfSourceChannels == 1 && numberOfDestinationChannels == 2) || (nu mberOfSourceChannels == 1 && numberOfDestinationChannels == 4)) { |
| 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); | 294 const AudioChannel* sourceChannel = sourceBus.channel(0); |
| 318 channel(0)->sumFrom(sourceChannel); | 295 channel(0)->sumFrom(sourceChannel); |
| 319 channel(1)->sumFrom(sourceChannel); | 296 channel(1)->sumFrom(sourceChannel); |
| 320 } else if (numberOfDestinationChannels == 1 && numberOfSourceChannels == 2) { | 297 |
| 321 // Handle stereo -> mono case. output += 0.5 * (input.L + input.R). | 298 return; |
|
Raymond Toy
2016/03/08 18:04:07
Is it obvious that channels 2 and 3 are always zer
hongchan
2016/03/08 23:53:35
All up/down-mixing is in-place summing. The destin
| |
| 322 AudioBus& sourceBusSafe = const_cast<AudioBus&>(sourceBus); | 299 } |
| 323 | 300 |
| 324 const float* sourceL = sourceBusSafe.channelByType(ChannelLeft)->data(); | 301 // Up-mixing: 1 -> 5.1 |
| 325 const float* sourceR = sourceBusSafe.channelByType(ChannelRight)->data() ; | 302 // output.L = 0 |
| 303 // output.R = 0 | |
| 304 // output.C = input (put in center channel) | |
| 305 // output.LFE = 0 | |
| 306 // output.SL = 0 | |
| 307 // output.SR = 0 | |
| 308 if (numberOfSourceChannels == 1 && numberOfDestinationChannels == 6) { | |
| 309 channel(2)->sumFrom(sourceBus.channel(0)); | |
| 310 | |
| 311 return; | |
|
Raymond Toy
2016/03/08 18:04:08
Are the other channels always zero? Same question
hongchan
2016/03/08 23:53:35
Unlike the comment, all up/down-mixing is in-place
| |
| 312 } | |
| 313 | |
| 314 // Up-mixing: 2 -> 4, 2 -> 5.1 | |
| 315 // output.L = input.L | |
| 316 // output.R = input.R | |
| 317 // output.C = 0 (in the case of 2 -> 5.1) | |
| 318 // output.LFE = 0 (in the case of 2 -> 5.1) | |
| 319 // output.SL = 0 | |
| 320 // output.SR = 0 | |
| 321 if ((numberOfSourceChannels == 2 && numberOfDestinationChannels == 4) || (nu mberOfSourceChannels == 2 && numberOfDestinationChannels == 6)) { | |
| 322 channel(0)->sumFrom(sourceBus.channel(0)); | |
| 323 channel(1)->sumFrom(sourceBus.channel(1)); | |
| 324 | |
| 325 return; | |
| 326 } | |
| 327 | |
| 328 // Up-mixing: 4 -> 5.1 | |
| 329 // output.L = input.L | |
| 330 // output.R = input.R | |
| 331 // output.C = 0 | |
| 332 // output.LFE = 0 | |
| 333 // output.SL = input.SL | |
| 334 // output.SR = input.SR | |
| 335 if (numberOfSourceChannels == 4 && numberOfDestinationChannels == 6) { | |
| 336 channel(0)->sumFrom(sourceBus.channel(0)); | |
| 337 channel(1)->sumFrom(sourceBus.channel(1)); | |
| 338 channel(4)->sumFrom(sourceBus.channel(2)); | |
| 339 channel(5)->sumFrom(sourceBus.channel(3)); | |
| 340 | |
| 341 return; | |
| 342 } | |
| 343 | |
| 344 // All other cases, fall back to the discrete sum. This will silence the | |
| 345 // excessive channels. | |
| 346 discreteSumFrom(sourceBus); | |
| 347 } | |
| 348 | |
| 349 void AudioBus::processDownMix(const AudioBus& sourceBus) | |
| 350 { | |
| 351 unsigned numberOfSourceChannels = sourceBus.numberOfChannels(); | |
| 352 unsigned numberOfDestinationChannels = numberOfChannels(); | |
| 353 | |
| 354 // Down-mixing: 2 -> 1 | |
| 355 // output = 0.5 * (input.L + input.R) | |
|
Raymond Toy
2016/03/08 18:04:08
It would be nice if this comment and the code used
hongchan
2016/03/08 23:53:35
The situation is different with the test code - he
| |
| 356 if (numberOfSourceChannels == 2 && numberOfDestinationChannels == 1) { | |
| 357 AudioBus& sourceBusConst = const_cast<AudioBus&>(sourceBus); | |
| 358 const float* sourceL = sourceBusConst.channelByType(ChannelLeft)->data() ; | |
| 359 const float* sourceR = sourceBusConst.channelByType(ChannelRight)->data( ); | |
| 326 | 360 |
| 327 float* destination = channelByType(ChannelLeft)->mutableData(); | 361 float* destination = channelByType(ChannelLeft)->mutableData(); |
|
Raymond Toy
2016/03/08 18:04:07
Although you didn't change this, I wonder why dest
hongchan
2016/03/08 23:53:35
I believe Chris did this for the readability, but
| |
| 328 float scale = 0.5; | 362 float scale = 0.5; |
| 363 | |
| 329 vsma(sourceL, 1, &scale, destination, 1, length()); | 364 vsma(sourceL, 1, &scale, destination, 1, length()); |
|
Raymond Toy
2016/03/08 18:04:07
Is there some implicit guarantee that destination
hongchan
2016/03/08 23:53:35
All up/down-mixing is in-place summing. The destin
| |
| 330 vsma(sourceR, 1, &scale, destination, 1, length()); | 365 vsma(sourceR, 1, &scale, destination, 1, length()); |
| 331 } else if (numberOfDestinationChannels == 6 && numberOfSourceChannels == 1) { | 366 return; |
| 332 // Handle mono -> 5.1 case, sum mono channel into center. | 367 } |
| 333 channel(2)->sumFrom(sourceBus.channel(0)); | 368 |
| 334 } else if (numberOfDestinationChannels == 1 && numberOfSourceChannels == 6) { | 369 // Down-mixing: 4 -> 1 |
| 335 // Handle 5.1 -> mono case. | 370 // output = 0.25 * (input.L + input.R + input.SL + input.SR) |
| 336 speakersSumFrom5_1_ToMono(sourceBus); | 371 if (numberOfSourceChannels == 4 && numberOfDestinationChannels == 1) { |
| 337 } else { | 372 AudioBus& sourceBusConst = const_cast<AudioBus&>(sourceBus); |
| 338 // Fallback for unknown combinations. | 373 const float* sourceL = sourceBusConst.channelByType(ChannelLeft)->data() ; |
| 339 discreteSumFrom(sourceBus); | 374 const float* sourceR = sourceBusConst.channelByType(ChannelRight)->data( ); |
| 340 } | 375 const float* sourceSL = sourceBusConst.channelByType(ChannelSurroundLeft )->data(); |
| 376 const float* sourceSR = sourceBusConst.channelByType(ChannelSurroundRigh t)->data(); | |
| 377 | |
| 378 float* destination = channelByType(ChannelLeft)->mutableData(); | |
|
Raymond Toy
2016/03/08 18:04:07
Is destination guaranteed to be zero?
hongchan
2016/03/08 23:53:35
All up/down-mixing is in-place summing. The destin
| |
| 379 float scale = 0.25; | |
| 380 | |
| 381 vsma(sourceL, 1, &scale, destination, 1, length()); | |
| 382 vsma(sourceR, 1, &scale, destination, 1, length()); | |
| 383 vsma(sourceSL, 1, &scale, destination, 1, length()); | |
| 384 vsma(sourceSR, 1, &scale, destination, 1, length()); | |
| 385 return; | |
| 386 } | |
| 387 | |
| 388 // Down-mixing: 5.1 -> 1 | |
| 389 // output = sqrt(1/2) * (input.L + input.R) + input.C | |
| 390 // + 0.5 * (input.SL + input.SR) | |
| 391 if (numberOfSourceChannels == 6 && numberOfDestinationChannels == 1) { | |
| 392 AudioBus& sourceBusConst = const_cast<AudioBus&>(sourceBus); | |
| 393 const float* sourceL = sourceBusConst.channelByType(ChannelLeft)->data() ; | |
| 394 const float* sourceR = sourceBusConst.channelByType(ChannelRight)->data( ); | |
| 395 const float* sourceC = sourceBusConst.channelByType(ChannelCenter)->data (); | |
| 396 const float* sourceSL = sourceBusConst.channelByType(ChannelSurroundLeft )->data(); | |
| 397 const float* sourceSR = sourceBusConst.channelByType(ChannelSurroundRigh t)->data(); | |
| 398 | |
| 399 float* destination = channelByType(ChannelLeft)->mutableData(); | |
| 400 float scaleSqrtHalf = sqrtf(0.5); | |
| 401 float scaleHalf = 0.5; | |
| 402 | |
| 403 vsma(sourceL, 1, &scaleSqrtHalf, destination, 1, length()); | |
| 404 vsma(sourceR, 1, &scaleSqrtHalf, destination, 1, length()); | |
| 405 vadd(sourceC, 1, destination, 1, destination, 1, length()); | |
| 406 vsma(sourceSL, 1, &scaleHalf, destination, 1, length()); | |
| 407 vsma(sourceSR, 1, &scaleHalf, destination, 1, length()); | |
| 408 return; | |
| 409 } | |
| 410 | |
| 411 // Down-mixing: 4 -> 2 | |
| 412 // output.L = 0.5 * (input.L + input.SL) | |
| 413 // output.R = 0.5 * (input.R + input.SR) | |
| 414 if (numberOfSourceChannels == 4 && numberOfDestinationChannels == 2) { | |
| 415 AudioBus& sourceBusConst = const_cast<AudioBus&>(sourceBus); | |
| 416 const float* sourceL = sourceBusConst.channelByType(ChannelLeft)->data() ; | |
| 417 const float* sourceR = sourceBusConst.channelByType(ChannelRight)->data( ); | |
| 418 const float* sourceSL = sourceBusConst.channelByType(ChannelSurroundLeft )->data(); | |
| 419 const float* sourceSR = sourceBusConst.channelByType(ChannelSurroundRigh t)->data(); | |
| 420 | |
| 421 float* destinationL = channelByType(ChannelLeft)->mutableData(); | |
| 422 float* destinationR = channelByType(ChannelRight)->mutableData(); | |
|
Raymond Toy
2016/03/08 18:04:07
Again, are destinationL and destinationR guarantee
hongchan
2016/03/08 23:53:35
All up/down-mixing is in-place summing. The destin
| |
| 423 float scaleHalf = 0.5; | |
| 424 | |
| 425 vsma(sourceL, 1, &scaleHalf, destinationL, 1, length()); | |
| 426 vsma(sourceSL, 1, &scaleHalf, destinationL, 1, length()); | |
| 427 vsma(sourceR, 1, &scaleHalf, destinationR, 1, length()); | |
| 428 vsma(sourceSR, 1, &scaleHalf, destinationR, 1, length()); | |
| 429 return; | |
| 430 } | |
| 431 | |
| 432 // Down-mixing: 5.1 -> 2 | |
| 433 // output.L = input.L + sqrt(1/2) * (input.C + input.SL) | |
| 434 // output.R = input.R + sqrt(1/2) * (input.C + input.SR) | |
| 435 if (numberOfSourceChannels == 6 && numberOfDestinationChannels == 2) { | |
| 436 AudioBus& sourceBusConst = const_cast<AudioBus&>(sourceBus); | |
| 437 const float* sourceL = sourceBusConst.channelByType(ChannelLeft)->data() ; | |
| 438 const float* sourceR = sourceBusConst.channelByType(ChannelRight)->data( ); | |
| 439 const float* sourceC = sourceBusConst.channelByType(ChannelCenter)->data (); | |
| 440 const float* sourceSL = sourceBusConst.channelByType(ChannelSurroundLeft )->data(); | |
| 441 const float* sourceSR = sourceBusConst.channelByType(ChannelSurroundRigh t)->data(); | |
| 442 | |
| 443 float* destinationL = channelByType(ChannelLeft)->mutableData(); | |
| 444 float* destinationR = channelByType(ChannelRight)->mutableData(); | |
|
Raymond Toy
2016/03/08 18:04:07
Are destinationL and destinationR guaranteed to be
hongchan
2016/03/08 23:53:35
All up/down-mixing is in-place summing. The destin
| |
| 445 float scaleSqrtHalf = sqrtf(0.5); | |
| 446 | |
| 447 vadd(sourceL, 1, destinationL, 1, destinationL, 1, length()); | |
| 448 vsma(sourceC, 1, &scaleSqrtHalf, destinationL, 1, length()); | |
| 449 vsma(sourceSL, 1, &scaleSqrtHalf, destinationL, 1, length()); | |
| 450 vadd(sourceR, 1, destinationR, 1, destinationR, 1, length()); | |
| 451 vsma(sourceC, 1, &scaleSqrtHalf, destinationR, 1, length()); | |
| 452 vsma(sourceSR, 1, &scaleSqrtHalf, destinationR, 1, length()); | |
| 453 return; | |
| 454 } | |
| 455 | |
| 456 // Down-mixing: 5.1 -> 4 | |
| 457 // output.L = input.L + sqrt(1/2) * input.C | |
| 458 // output.R = input.R + sqrt(1/2) * input.C | |
| 459 // output.SL = input.SL | |
| 460 // output.SR = input.SR | |
| 461 if (numberOfSourceChannels == 6 && numberOfDestinationChannels == 4) { | |
| 462 AudioBus& sourceBusConst = const_cast<AudioBus&>(sourceBus); | |
| 463 const float* sourceL = sourceBusConst.channelByType(ChannelLeft)->data() ; | |
| 464 const float* sourceR = sourceBusConst.channelByType(ChannelRight)->data( ); | |
| 465 const float* sourceC = sourceBusConst.channelByType(ChannelCenter)->data (); | |
| 466 | |
| 467 float* destinationL = channelByType(ChannelLeft)->mutableData(); | |
| 468 float* destinationR = channelByType(ChannelRight)->mutableData(); | |
| 469 float scaleSqrtHalf = sqrtf(0.5); | |
| 470 | |
| 471 vadd(sourceL, 1, destinationL, 1, destinationL, 1, length()); | |
| 472 vsma(sourceC, 1, &scaleSqrtHalf, destinationL, 1, length()); | |
| 473 vadd(sourceR, 1, destinationR, 1, destinationR, 1, length()); | |
| 474 vsma(sourceC, 1, &scaleSqrtHalf, destinationR, 1, length()); | |
| 475 channel(2)->sumFrom(sourceBus.channel(4)); | |
| 476 channel(3)->sumFrom(sourceBus.channel(5)); | |
| 477 return; | |
| 478 } | |
| 479 | |
| 480 // All other cases, fall back to the discrete sum. This will perform | |
| 481 // channel-wise sum until the destination channels run out. | |
| 482 discreteSumFrom(sourceBus); | |
| 341 } | 483 } |
| 342 | 484 |
| 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) | 485 void AudioBus::discreteCopyFrom(const AudioBus& sourceBus) |
| 375 { | 486 { |
| 376 unsigned numberOfSourceChannels = sourceBus.numberOfChannels(); | 487 unsigned numberOfSourceChannels = sourceBus.numberOfChannels(); |
| 377 unsigned numberOfDestinationChannels = numberOfChannels(); | 488 unsigned numberOfDestinationChannels = numberOfChannels(); |
| 378 | 489 |
| 379 if (numberOfDestinationChannels < numberOfSourceChannels) { | 490 if (numberOfDestinationChannels < numberOfSourceChannels) { |
| 380 // Down-mix by copying channels and dropping the remaining. | 491 // Down-mix by copying channels and dropping the remaining. |
| 381 for (unsigned i = 0; i < numberOfDestinationChannels; ++i) | 492 for (unsigned i = 0; i < numberOfDestinationChannels; ++i) |
| 382 channel(i)->copyFrom(sourceBus.channel(i)); | 493 channel(i)->copyFrom(sourceBus.channel(i)); |
| 383 } else if (numberOfDestinationChannels > numberOfSourceChannels) { | 494 } else if (numberOfDestinationChannels > numberOfSourceChannels) { |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 676 | 787 |
| 677 // If the bus needs no conversion then return as is. | 788 // If the bus needs no conversion then return as is. |
| 678 if ((!mixToMono || audioBus->numberOfChannels() == 1) && audioBus->sampleRat e() == sampleRate) | 789 if ((!mixToMono || audioBus->numberOfChannels() == 1) && audioBus->sampleRat e() == sampleRate) |
| 679 return audioBus; | 790 return audioBus; |
| 680 | 791 |
| 681 return AudioBus::createBySampleRateConverting(audioBus.get(), mixToMono, sam pleRate); | 792 return AudioBus::createBySampleRateConverting(audioBus.get(), mixToMono, sam pleRate); |
| 682 } | 793 } |
| 683 | 794 |
| 684 } // namespace blink | 795 } // namespace blink |
| 685 | 796 |
| OLD | NEW |