/* * Copyright (C) 2010, Google Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
usingnamespace mozilla; using dom::ChannelInterpretation;
namespace WebCore {
// The value of 2 milliseconds is larger than the largest delay which exists in // any HRTFKernel from the default HRTFDatabase (0.0136 seconds). We ASSERT the // delay values used in process() with this value. constfloat MaxDelayTimeSeconds = 0.002f;
// NB: m_databaseLoader can be shared, so it is not measured here
amount += m_convolverL1.sizeOfExcludingThis(aMallocSizeOf);
amount += m_convolverR1.sizeOfExcludingThis(aMallocSizeOf);
amount += m_convolverL2.sizeOfExcludingThis(aMallocSizeOf);
amount += m_convolverR2.sizeOfExcludingThis(aMallocSizeOf);
amount += m_delayLine.SizeOfExcludingThis(aMallocSizeOf);
int HRTFPanner::calculateDesiredAzimuthIndexAndBlend(double azimuth, double& azimuthBlend) { // Convert the azimuth angle from the range -180 -> +180 into the range 0 -> // 360. The azimuth index may then be calculated from this positive value. if (azimuth < 0) azimuth += 360.0;
int numberOfAzimuths = HRTFDatabase::numberOfAzimuths(); constdouble angleBetweenAzimuths = 360.0 / numberOfAzimuths;
// Calculate the azimuth index and the blend (0 -> 1) for interpolation. double desiredAzimuthIndexFloat = azimuth / angleBetweenAzimuths; int desiredAzimuthIndex = static_cast<int>(desiredAzimuthIndexFloat);
azimuthBlend =
desiredAzimuthIndexFloat - static_cast<double>(desiredAzimuthIndex);
// We don't immediately start using this azimuth index, but instead approach // this index from the last index we rendered at. This minimizes the clicks // and graininess for moving sources which occur otherwise.
desiredAzimuthIndex = std::max(0, desiredAzimuthIndex);
desiredAzimuthIndex = std::min(numberOfAzimuths - 1, desiredAzimuthIndex); return desiredAzimuthIndex;
}
// Normally, we'll just be dealing with mono sources. // If we have a stereo input, implement stereo panning with left source // processed by left HRTF, and right source by right HRTF.
double azimuthBlend; int desiredAzimuthIndex =
calculateDesiredAzimuthIndexAndBlend(azimuth, azimuthBlend);
// Initially snap azimuth and elevation values to first values encountered. if (m_azimuthIndex1 == UninitializedAzimuth) {
m_azimuthIndex1 = desiredAzimuthIndex;
m_elevation1 = elevation;
} if (m_azimuthIndex2 == UninitializedAzimuth) {
m_azimuthIndex2 = desiredAzimuthIndex;
m_elevation2 = elevation;
}
// Cross-fade / transition over a period of around 45 milliseconds. // This is an empirical value tuned to be a reasonable trade-off between // smoothness and speed. constdouble fadeFrames = sampleRate() <= 48000 ? 2048 : 4096;
// Check for azimuth and elevation changes, initiating a cross-fade if needed. if (!m_crossfadeX && m_crossfadeSelection == CrossfadeSelection1) { if (desiredAzimuthIndex != m_azimuthIndex1 || elevation != m_elevation1) { // Cross-fade from 1 -> 2
m_crossfadeIncr = 1 / fadeFrames;
m_azimuthIndex2 = desiredAzimuthIndex;
m_elevation2 = elevation;
}
} if (m_crossfadeX == 1 && m_crossfadeSelection == CrossfadeSelection2) { if (desiredAzimuthIndex != m_azimuthIndex2 || elevation != m_elevation2) { // Cross-fade from 2 -> 1
m_crossfadeIncr = -1 / fadeFrames;
m_azimuthIndex1 = desiredAzimuthIndex;
m_elevation1 = elevation;
}
}
// Crossfade inter-aural delays based on transitions. float frameDelaysL[WEBAUDIO_BLOCK_SIZE]; float frameDelaysR[WEBAUDIO_BLOCK_SIZE];
{ float x = m_crossfadeX; float incr = m_crossfadeIncr; for (unsigned i = 0; i < WEBAUDIO_BLOCK_SIZE; ++i) {
frameDelaysL[i] = (1 - x) * frameDelayL1 + x * frameDelayL2;
frameDelaysR[i] = (1 - x) * frameDelayR1 + x * frameDelayR2;
x += incr;
}
}
// First run through delay lines for inter-aural time difference.
m_delayLine.Write(*inputBus); // "Speakers" means a mono input is read into both outputs (with possibly // different delays).
m_delayLine.ReadChannel(frameDelaysL, outputBus, 0,
ChannelInterpretation::Speakers);
m_delayLine.ReadChannel(frameDelaysR, outputBus, 1,
ChannelInterpretation::Speakers);
m_delayLine.NextBlock();
int HRTFPanner::maxTailFrames() const { // Although the ideal tail time would be the length of the impulse // response, there is additional tail time from the approximations in the // implementation. Because HRTFPanner is implemented with a DelayKernel // and a FFTConvolver, the tailTime of the HRTFPanner is the sum of the // tailTime of the DelayKernel and the tailTime of the FFTConvolver. The // FFTs of the convolver are fftSize(), half of which is latency, but this // is aligned with blocks and so is reduced by the one block which is // processed immediately. return m_delayLine.MaxDelayTicks() + m_convolverL1.fftSize() / 2 +
m_convolverL1.latencyFrames();
}
} // namespace WebCore
Messung V0.5
¤ Dauer der Verarbeitung: 0.11 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.