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

Side by Side Diff: third_party/WebKit/Source/platform/audio/AudioBus.cpp

Issue 2384073002: reflow comments in platform/audio (Closed)
Patch Set: comments (heh!) Created 4 years, 2 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 /* 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 } 67 }
68 68
69 m_layout = LayoutCanonical; // for now this is the only layout we define 69 m_layout = LayoutCanonical; // for now this is the only layout we define
70 } 70 }
71 71
72 void AudioBus::setChannelMemory(unsigned channelIndex, 72 void AudioBus::setChannelMemory(unsigned channelIndex,
73 float* storage, 73 float* storage,
74 size_t length) { 74 size_t length) {
75 if (channelIndex < m_channels.size()) { 75 if (channelIndex < m_channels.size()) {
76 channel(channelIndex)->set(storage, length); 76 channel(channelIndex)->set(storage, length);
77 m_length = 77 // FIXME: verify that this length matches all the other channel lengths
78 length; // FIXME: verify that this length matches all the other channel lengths 78 m_length = length;
79 } 79 }
80 } 80 }
81 81
82 void AudioBus::resizeSmaller(size_t newLength) { 82 void AudioBus::resizeSmaller(size_t newLength) {
83 ASSERT(newLength <= m_length); 83 ASSERT(newLength <= m_length);
84 if (newLength <= m_length) 84 if (newLength <= m_length)
85 m_length = newLength; 85 m_length = newLength;
86 86
87 for (unsigned i = 0; i < m_channels.size(); ++i) 87 for (unsigned i = 0; i < m_channels.size(); ++i)
88 m_channels[i]->resizeSmaller(newLength); 88 m_channels[i]->resizeSmaller(newLength);
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 488
489 AudioBus& sourceBusSafe = const_cast<AudioBus&>(sourceBus); 489 AudioBus& sourceBusSafe = const_cast<AudioBus&>(sourceBus);
490 const float* sources[MaxBusChannels]; 490 const float* sources[MaxBusChannels];
491 float* destinations[MaxBusChannels]; 491 float* destinations[MaxBusChannels];
492 492
493 for (unsigned i = 0; i < numberOfChannels; ++i) { 493 for (unsigned i = 0; i < numberOfChannels; ++i) {
494 sources[i] = sourceBusSafe.channel(i)->data(); 494 sources[i] = sourceBusSafe.channel(i)->data();
495 destinations[i] = channel(i)->mutableData(); 495 destinations[i] = channel(i)->mutableData();
496 } 496 }
497 497
498 // We don't want to suddenly change the gain from mixing one time slice to the next, 498 // We don't want to suddenly change the gain from mixing one time slice to
499 // so we "de-zipper" by slowly changing the gain each sample-frame until we've achieved the target gain. 499 // the next, so we "de-zipper" by slowly changing the gain each sample-frame
500 // until we've achieved the target gain.
500 501
501 // Take master bus gain into account as well as the targetGain. 502 // Take master bus gain into account as well as the targetGain.
502 float totalDesiredGain = static_cast<float>(m_busGain * targetGain); 503 float totalDesiredGain = static_cast<float>(m_busGain * targetGain);
503 504
504 // First time, snap directly to totalDesiredGain. 505 // First time, snap directly to totalDesiredGain.
505 float gain = 506 float gain =
506 static_cast<float>(m_isFirstTime ? totalDesiredGain : *lastMixGain); 507 static_cast<float>(m_isFirstTime ? totalDesiredGain : *lastMixGain);
507 m_isFirstTime = false; 508 m_isFirstTime = false;
508 509
509 const float DezipperRate = 0.005f; 510 const float DezipperRate = 0.005f;
510 unsigned framesToProcess = length(); 511 unsigned framesToProcess = length();
511 512
512 // If the gain is within epsilon of totalDesiredGain, we can skip dezippering. 513 // If the gain is within epsilon of totalDesiredGain, we can skip dezippering.
513 // FIXME: this value may need tweaking. 514 // FIXME: this value may need tweaking.
514 const float epsilon = 0.001f; 515 const float epsilon = 0.001f;
515 float gainDiff = fabs(totalDesiredGain - gain); 516 float gainDiff = fabs(totalDesiredGain - gain);
516 517
517 // Number of frames to de-zipper before we are close enough to the target gain . 518 // Number of frames to de-zipper before we are close enough to the target
518 // FIXME: framesToDezipper could be smaller when target gain is close enough w ithin this process loop. 519 // gain.
520 // FIXME: framesToDezipper could be smaller when target gain is close enough
521 // within this process loop.
519 unsigned framesToDezipper = (gainDiff < epsilon) ? 0 : framesToProcess; 522 unsigned framesToDezipper = (gainDiff < epsilon) ? 0 : framesToProcess;
520 523
521 if (framesToDezipper) { 524 if (framesToDezipper) {
522 if (!m_dezipperGainValues.get() || 525 if (!m_dezipperGainValues.get() ||
523 m_dezipperGainValues->size() < framesToDezipper) 526 m_dezipperGainValues->size() < framesToDezipper)
524 m_dezipperGainValues = wrapUnique(new AudioFloatArray(framesToDezipper)); 527 m_dezipperGainValues = wrapUnique(new AudioFloatArray(framesToDezipper));
525 528
526 float* gainValues = m_dezipperGainValues->data(); 529 float* gainValues = m_dezipperGainValues->data();
527 for (unsigned i = 0; i < framesToDezipper; ++i) { 530 for (unsigned i = 0; i < framesToDezipper; ++i) {
528 gain += (totalDesiredGain - gain) * DezipperRate; 531 gain += (totalDesiredGain - gain) * DezipperRate;
529 532
530 // FIXME: If we are clever enough in calculating the framesToDezipper valu e, we can probably get 533 // FIXME: If we are clever enough in calculating the framesToDezipper
531 // rid of this DenormalDisabler::flushDenormalFloatToZero() call. 534 // value, we can probably get rid of this
535 // DenormalDisabler::flushDenormalFloatToZero() call.
532 gain = DenormalDisabler::flushDenormalFloatToZero(gain); 536 gain = DenormalDisabler::flushDenormalFloatToZero(gain);
533 *gainValues++ = gain; 537 *gainValues++ = gain;
534 } 538 }
535 539
536 for (unsigned channelIndex = 0; channelIndex < numberOfChannels; 540 for (unsigned channelIndex = 0; channelIndex < numberOfChannels;
537 ++channelIndex) { 541 ++channelIndex) {
538 vmul(sources[channelIndex], 1, m_dezipperGainValues->data(), 1, 542 vmul(sources[channelIndex], 1, m_dezipperGainValues->data(), 1,
539 destinations[channelIndex], 1, framesToDezipper); 543 destinations[channelIndex], 1, framesToDezipper);
540 sources[channelIndex] += framesToDezipper; 544 sources[channelIndex] += framesToDezipper;
541 destinations[channelIndex] += framesToDezipper; 545 destinations[channelIndex] += framesToDezipper;
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 // If the bus needs no conversion then return as is. 758 // If the bus needs no conversion then return as is.
755 if ((!mixToMono || audioBus->numberOfChannels() == 1) && 759 if ((!mixToMono || audioBus->numberOfChannels() == 1) &&
756 audioBus->sampleRate() == sampleRate) 760 audioBus->sampleRate() == sampleRate)
757 return audioBus; 761 return audioBus;
758 762
759 return AudioBus::createBySampleRateConverting(audioBus.get(), mixToMono, 763 return AudioBus::createBySampleRateConverting(audioBus.get(), mixToMono,
760 sampleRate); 764 sampleRate);
761 } 765 }
762 766
763 } // namespace blink 767 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/audio/AudioBus.h ('k') | third_party/WebKit/Source/platform/audio/AudioChannel.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698