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

Side by Side Diff: third_party/WebKit/Source/platform/audio/AudioDestination.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 : m_callback(callback), 67 : m_callback(callback),
68 m_numberOfOutputChannels(numberOfOutputChannels), 68 m_numberOfOutputChannels(numberOfOutputChannels),
69 m_inputBus(AudioBus::create(numberOfInputChannels, renderBufferSize)), 69 m_inputBus(AudioBus::create(numberOfInputChannels, renderBufferSize)),
70 m_renderBus( 70 m_renderBus(
71 AudioBus::create(numberOfOutputChannels, renderBufferSize, false)), 71 AudioBus::create(numberOfOutputChannels, renderBufferSize, false)),
72 m_sampleRate(sampleRate), 72 m_sampleRate(sampleRate),
73 m_isPlaying(false) { 73 m_isPlaying(false) {
74 // Histogram for audioHardwareBufferSize 74 // Histogram for audioHardwareBufferSize
75 DEFINE_STATIC_LOCAL(SparseHistogram, hardwareBufferSizeHistogram, 75 DEFINE_STATIC_LOCAL(SparseHistogram, hardwareBufferSizeHistogram,
76 ("WebAudio.AudioDestination.HardwareBufferSize")); 76 ("WebAudio.AudioDestination.HardwareBufferSize"));
77 // Histogram for the actual callback size used. Typically, this is the same a s 77 // Histogram for the actual callback size used. Typically, this is the same
78 // audioHardwareBufferSize, but can be adjusted depending on some heuristics b elow. 78 // as audioHardwareBufferSize, but can be adjusted depending on some
79 // heuristics below.
79 DEFINE_STATIC_LOCAL(SparseHistogram, callbackBufferSizeHistogram, 80 DEFINE_STATIC_LOCAL(SparseHistogram, callbackBufferSizeHistogram,
80 ("WebAudio.AudioDestination.CallbackBufferSize")); 81 ("WebAudio.AudioDestination.CallbackBufferSize"));
81 82
82 // Use the optimal buffer size recommended by the audio backend. 83 // Use the optimal buffer size recommended by the audio backend.
83 size_t recommendedHardwareBufferSize = 84 size_t recommendedHardwareBufferSize =
84 Platform::current()->audioHardwareBufferSize(); 85 Platform::current()->audioHardwareBufferSize();
85 m_callbackBufferSize = recommendedHardwareBufferSize; 86 m_callbackBufferSize = recommendedHardwareBufferSize;
86 87
87 #if OS(ANDROID) 88 #if OS(ANDROID)
88 // The optimum low-latency hardware buffer size is usually too small on Androi d for WebAudio to 89 // The optimum low-latency hardware buffer size is usually too small on
89 // render without glitching. So, if it is small, use a larger size. If it was already large, use 90 // Android for WebAudio to render without glitching. So, if it is small, use
90 // the requested size. 91 // a larger size. If it was already large, use the requested size.
91 // 92 //
92 // Since WebAudio renders in 128-frame blocks, the small buffer sizes (144 for a Galaxy Nexus), 93 // Since WebAudio renders in 128-frame blocks, the small buffer sizes (144
93 // cause significant processing jitter. Sometimes multiple blocks will process ed, but other 94 // for a Galaxy Nexus), cause significant processing jitter. Sometimes
94 // times will not be since the FIFO can satisfy the request. By using a larger 95 // multiple blocks will processed, but other times will not be since the FIFO
95 // callbackBufferSize, we smooth out the jitter. 96 // can satisfy the request. By using a larger callbackBufferSize, we smooth
97 // out the jitter.
96 const size_t kSmallBufferSize = 1024; 98 const size_t kSmallBufferSize = 1024;
97 const size_t kDefaultCallbackBufferSize = 2048; 99 const size_t kDefaultCallbackBufferSize = 2048;
98 100
99 if (m_callbackBufferSize <= kSmallBufferSize) 101 if (m_callbackBufferSize <= kSmallBufferSize)
100 m_callbackBufferSize = kDefaultCallbackBufferSize; 102 m_callbackBufferSize = kDefaultCallbackBufferSize;
101 #endif 103 #endif
102 104
103 // Quick exit if the requested size is too large. 105 // Quick exit if the requested size is too large.
104 ASSERT(m_callbackBufferSize + renderBufferSize <= fifoSize); 106 ASSERT(m_callbackBufferSize + renderBufferSize <= fifoSize);
105 if (m_callbackBufferSize + renderBufferSize > fifoSize) 107 if (m_callbackBufferSize + renderBufferSize > fifoSize)
(...skipping 12 matching lines...) Expand all
118 // not being a multiple of the render size. If the FIFO already 120 // not being a multiple of the render size. If the FIFO already
119 // contains enough data, the data will be provided directly. 121 // contains enough data, the data will be provided directly.
120 // Otherwise, the FIFO will call the provider enough times to 122 // Otherwise, the FIFO will call the provider enough times to
121 // satisfy the request for data. 123 // satisfy the request for data.
122 m_fifo = wrapUnique(new AudioPullFIFO(*this, numberOfOutputChannels, fifoSize, 124 m_fifo = wrapUnique(new AudioPullFIFO(*this, numberOfOutputChannels, fifoSize,
123 renderBufferSize)); 125 renderBufferSize));
124 126
125 // Input buffering. 127 // Input buffering.
126 m_inputFifo = wrapUnique(new AudioFIFO(numberOfInputChannels, fifoSize)); 128 m_inputFifo = wrapUnique(new AudioFIFO(numberOfInputChannels, fifoSize));
127 129
128 // If the callback size does not match the render size, then we need to buffer some 130 // If the callback size does not match the render size, then we need to
129 // extra silence for the input. Otherwise, we can over-consume the input FIFO. 131 // buffer some extra silence for the input. Otherwise, we can over-consume
132 // the input FIFO.
130 if (m_callbackBufferSize != renderBufferSize) { 133 if (m_callbackBufferSize != renderBufferSize) {
131 // FIXME: handle multi-channel input and don't hard-code to stereo. 134 // FIXME: handle multi-channel input and don't hard-code to stereo.
132 RefPtr<AudioBus> silence = AudioBus::create(2, renderBufferSize); 135 RefPtr<AudioBus> silence = AudioBus::create(2, renderBufferSize);
133 m_inputFifo->push(silence.get()); 136 m_inputFifo->push(silence.get());
134 } 137 }
135 } 138 }
136 139
137 AudioDestination::~AudioDestination() { 140 AudioDestination::~AudioDestination() {
138 stop(); 141 stop();
139 } 142 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 AudioBus* sourceBus = nullptr; 197 AudioBus* sourceBus = nullptr;
195 if (m_inputFifo->framesInFifo() >= framesToProcess) { 198 if (m_inputFifo->framesInFifo() >= framesToProcess) {
196 m_inputFifo->consume(m_inputBus.get(), framesToProcess); 199 m_inputFifo->consume(m_inputBus.get(), framesToProcess);
197 sourceBus = m_inputBus.get(); 200 sourceBus = m_inputBus.get();
198 } 201 }
199 202
200 m_callback.render(sourceBus, bus, framesToProcess); 203 m_callback.render(sourceBus, bus, framesToProcess);
201 } 204 }
202 205
203 } // namespace blink 206 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/audio/AudioDestination.h ('k') | third_party/WebKit/Source/platform/audio/AudioFIFO.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698