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

Unified Diff: third_party/WebKit/Source/modules/webaudio/RealtimeAnalyser.cpp

Issue 1803233002: AnalyserNode should downmix channels to mono. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/modules/webaudio/RealtimeAnalyser.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/modules/webaudio/RealtimeAnalyser.cpp
diff --git a/third_party/WebKit/Source/modules/webaudio/RealtimeAnalyser.cpp b/third_party/WebKit/Source/modules/webaudio/RealtimeAnalyser.cpp
index 902e7900e11b7fb1fa7bf8dd55f6770fb5a17a6b..4af7a040b5ce785aa7f7b6545f86a0bb860ced61 100644
--- a/third_party/WebKit/Source/modules/webaudio/RealtimeAnalyser.cpp
+++ b/third_party/WebKit/Source/modules/webaudio/RealtimeAnalyser.cpp
@@ -47,6 +47,7 @@ const unsigned RealtimeAnalyser::InputBufferSize = RealtimeAnalyser::MaxFFTSize
RealtimeAnalyser::RealtimeAnalyser()
: m_inputBuffer(InputBufferSize)
, m_writeIndex(0)
+ , m_downMixBus(AudioBus::create(1, AudioUtilities::kRenderQuantumFrames))
, m_fftSize(DefaultFFTSize)
, m_magnitudeBuffer(DefaultFFTSize / 2)
, m_smoothingTimeConstant(DefaultSmoothingTimeConstant)
@@ -92,22 +93,13 @@ void RealtimeAnalyser::writeInput(AudioBus* bus, size_t framesToProcess)
return;
// Perform real-time analysis
- const float* source = bus->channel(0)->data();
float* dest = m_inputBuffer.data() + m_writeIndex;
- // The source has already been sanity checked with isBusGood above.
- memcpy(dest, source, sizeof(float) * framesToProcess);
-
- // Sum all channels in one if numberOfChannels > 1.
- unsigned numberOfChannels = bus->numberOfChannels();
- if (numberOfChannels > 1) {
- for (unsigned i = 1; i < numberOfChannels; ++i) {
- source = bus->channel(i)->data();
- VectorMath::vadd(dest, 1, source, 1, dest, 1, framesToProcess);
- }
- const float scale = 1.0 / numberOfChannels;
- VectorMath::vsmul(dest, 1, &scale, dest, 1, framesToProcess);
- }
+ // Clear the bus and downmix the input according to the down mixing rules. Then save the result
+ // in the m_inputBuffer at the appropriate place.
+ m_downMixBus->zero();
+ m_downMixBus->sumFrom(*bus);
+ memcpy(dest, m_downMixBus->channel(0)->data(), framesToProcess * sizeof(*dest));
m_writeIndex += framesToProcess;
if (m_writeIndex >= InputBufferSize)
« no previous file with comments | « third_party/WebKit/Source/modules/webaudio/RealtimeAnalyser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698