From 6ed2de0c2b29723bec008ee1c20ee88a492154f2 Mon Sep 17 00:00:00 2001
From: "dalecurtis@google.com"
 <dalecurtis@google.com@0039d316-1c4b-4281-b951-d872f2087c98>
Date: Tue, 30 Apr 2013 01:00:23 +0000
Subject: C++ readability review for dalecurtis.

AudioConverter is a tool for mixing and converting audio data from
one format to another; differences may include sample rates, channel
layout, and buffer size.

AudioConverter is the work horse behind several Chrome features:
- Allows mixing and conversion of HTML5 audio streams for thread savings:
https://code.google.com/p/chromium/codesearch#chromium/src/media/base/audio_renderer_mixer.cc

- Allows Pepper clients (like Flash) to be oblivious of hardware requirements:
https://code.google.com/p/chromium/codesearch#chromium/src/media/audio/audio_output_resampler.cc

- Tab Audio Mirroring:
https://code.google.com/p/chromium/codesearch#chromium/src/media/audio/virtual_audio_input_stream.cc

Original CL for context: https://codereview.chromium.org/11410012/

R=fischman@chromium.org, lmendes@google.com

Review URL: https://codereview.chromium.org/12670011

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@197197 0039d316-1c4b-4281-b951-d872f2087c98
---
 media/base/audio_converter.cc | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

(limited to 'media/base/audio_converter.cc')

diff --git a/media/base/audio_converter.cc b/media/base/audio_converter.cc
index 151d88d..6434ee9 100644
--- a/media/base/audio_converter.cc
+++ b/media/base/audio_converter.cc
@@ -1,6 +1,12 @@
 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
+//
+// AudioConverter implementation.  Uses MultiChannelSincResampler for resampling
+// audio, ChannelMixer for channel mixing, and AudioPullFifo for buffering.
+//
+// Delay estimates are provided to InputCallbacks based on the frame delay
+// information reported via the resampler and FIFO units.
 
 #include "media/base/audio_converter.h"
 
@@ -117,10 +123,17 @@ void AudioConverter::Convert(AudioBus* dest) {
     return;
   }
 
+  // Determine if channel mixing should be done and if it should be done before
+  // or after resampling.  If it's possible to reduce the channel count prior to
+  // resampling we can save a lot of processing time.  Vice versa, we don't want
+  // to increase the channel count prior to resampling for the same reason.
   bool needs_mixing = channel_mixer_ && !downmix_early_;
   AudioBus* temp_dest = needs_mixing ? unmixed_audio_.get() : dest;
   DCHECK(temp_dest);
 
+  // Figure out which method to call based on whether we're resampling and
+  // rebuffering, just resampling, or just mixing.  We want to avoid any extra
+  // steps when possible since we may be converting audio data in real time.
   if (!resampler_ && !audio_fifo_) {
     SourceCallback(0, temp_dest);
   } else {
@@ -130,6 +143,7 @@ void AudioConverter::Convert(AudioBus* dest) {
       ProvideInput(0, temp_dest);
   }
 
+  // Finally upmix the channels if we didn't do so earlier.
   if (needs_mixing) {
     DCHECK_EQ(temp_dest->frames(), dest->frames());
     channel_mixer_->Transform(temp_dest, dest);
-- 
cgit v1.1