content/media/webaudio/blink/HRTFPanner.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /*
michael@0 2 * Copyright (C) 2010, Google Inc. All rights reserved.
michael@0 3 *
michael@0 4 * Redistribution and use in source and binary forms, with or without
michael@0 5 * modification, are permitted provided that the following conditions
michael@0 6 * are met:
michael@0 7 * 1. Redistributions of source code must retain the above copyright
michael@0 8 * notice, this list of conditions and the following disclaimer.
michael@0 9 * 2. Redistributions in binary form must reproduce the above copyright
michael@0 10 * notice, this list of conditions and the following disclaimer in the
michael@0 11 * documentation and/or other materials provided with the distribution.
michael@0 12 *
michael@0 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
michael@0 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
michael@0 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
michael@0 16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
michael@0 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
michael@0 18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
michael@0 19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
michael@0 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
michael@0 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
michael@0 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
michael@0 23 */
michael@0 24
michael@0 25 #ifndef HRTFPanner_h
michael@0 26 #define HRTFPanner_h
michael@0 27
michael@0 28 #include "FFTConvolver.h"
michael@0 29 #include "DelayBuffer.h"
michael@0 30 #include "mozilla/MemoryReporting.h"
michael@0 31
michael@0 32 namespace mozilla {
michael@0 33 struct AudioChunk;
michael@0 34 }
michael@0 35
michael@0 36 namespace WebCore {
michael@0 37
michael@0 38 class HRTFDatabaseLoader;
michael@0 39
michael@0 40 using mozilla::AudioChunk;
michael@0 41
michael@0 42 class HRTFPanner {
michael@0 43 public:
michael@0 44 HRTFPanner(float sampleRate, mozilla::TemporaryRef<HRTFDatabaseLoader> databaseLoader);
michael@0 45 ~HRTFPanner();
michael@0 46
michael@0 47 // chunk durations must be 128
michael@0 48 void pan(double azimuth, double elevation, const AudioChunk* inputBus, AudioChunk* outputBus);
michael@0 49 void reset();
michael@0 50
michael@0 51 size_t fftSize() const { return m_convolverL1.fftSize(); }
michael@0 52
michael@0 53 float sampleRate() const { return m_sampleRate; }
michael@0 54
michael@0 55 int maxTailFrames() const;
michael@0 56
michael@0 57 size_t sizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
michael@0 58
michael@0 59 private:
michael@0 60 // Given an azimuth angle in the range -180 -> +180, returns the corresponding azimuth index for the database,
michael@0 61 // and azimuthBlend which is an interpolation value from 0 -> 1.
michael@0 62 int calculateDesiredAzimuthIndexAndBlend(double azimuth, double& azimuthBlend);
michael@0 63
michael@0 64 mozilla::RefPtr<HRTFDatabaseLoader> m_databaseLoader;
michael@0 65
michael@0 66 float m_sampleRate;
michael@0 67
michael@0 68 // We maintain two sets of convolvers for smooth cross-faded interpolations when
michael@0 69 // then azimuth and elevation are dynamically changing.
michael@0 70 // When the azimuth and elevation are not changing, we simply process with one of the two sets.
michael@0 71 // Initially we use CrossfadeSelection1 corresponding to m_convolverL1 and m_convolverR1.
michael@0 72 // Whenever the azimuth or elevation changes, a crossfade is initiated to transition
michael@0 73 // to the new position. So if we're currently processing with CrossfadeSelection1, then
michael@0 74 // we transition to CrossfadeSelection2 (and vice versa).
michael@0 75 // If we're in the middle of a transition, then we wait until it is complete before
michael@0 76 // initiating a new transition.
michael@0 77
michael@0 78 // Selects either the convolver set (m_convolverL1, m_convolverR1) or (m_convolverL2, m_convolverR2).
michael@0 79 enum CrossfadeSelection {
michael@0 80 CrossfadeSelection1,
michael@0 81 CrossfadeSelection2
michael@0 82 };
michael@0 83
michael@0 84 CrossfadeSelection m_crossfadeSelection;
michael@0 85
michael@0 86 // azimuth/elevation for CrossfadeSelection1.
michael@0 87 int m_azimuthIndex1;
michael@0 88 double m_elevation1;
michael@0 89
michael@0 90 // azimuth/elevation for CrossfadeSelection2.
michael@0 91 int m_azimuthIndex2;
michael@0 92 double m_elevation2;
michael@0 93
michael@0 94 // A crossfade value 0 <= m_crossfadeX <= 1.
michael@0 95 float m_crossfadeX;
michael@0 96
michael@0 97 // Per-sample-frame crossfade value increment.
michael@0 98 float m_crossfadeIncr;
michael@0 99
michael@0 100 FFTConvolver m_convolverL1;
michael@0 101 FFTConvolver m_convolverR1;
michael@0 102 FFTConvolver m_convolverL2;
michael@0 103 FFTConvolver m_convolverR2;
michael@0 104
michael@0 105 mozilla::DelayBuffer m_delayLine;
michael@0 106
michael@0 107 AudioFloatArray m_tempL1;
michael@0 108 AudioFloatArray m_tempR1;
michael@0 109 AudioFloatArray m_tempL2;
michael@0 110 AudioFloatArray m_tempR2;
michael@0 111 };
michael@0 112
michael@0 113 } // namespace WebCore
michael@0 114
michael@0 115 #endif // HRTFPanner_h

mercurial