content/media/webaudio/blink/HRTFElevation.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/media/webaudio/blink/HRTFElevation.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,103 @@
     1.4 +/*
     1.5 + * Copyright (C) 2010 Google Inc. All rights reserved.
     1.6 + *
     1.7 + * Redistribution and use in source and binary forms, with or without
     1.8 + * modification, are permitted provided that the following conditions
     1.9 + * are met:
    1.10 + *
    1.11 + * 1.  Redistributions of source code must retain the above copyright
    1.12 + *     notice, this list of conditions and the following disclaimer.
    1.13 + * 2.  Redistributions in binary form must reproduce the above copyright
    1.14 + *     notice, this list of conditions and the following disclaimer in the
    1.15 + *     documentation and/or other materials provided with the distribution.
    1.16 + * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
    1.17 + *     its contributors may be used to endorse or promote products derived
    1.18 + *     from this software without specific prior written permission.
    1.19 + *
    1.20 + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
    1.21 + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    1.22 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    1.23 + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
    1.24 + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    1.25 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
    1.26 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    1.27 + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    1.28 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
    1.29 + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.30 + */
    1.31 +
    1.32 +#ifndef HRTFElevation_h
    1.33 +#define HRTFElevation_h
    1.34 +
    1.35 +#include "HRTFKernel.h"
    1.36 +#include "nsAutoRef.h"
    1.37 +#include "mozilla/MemoryReporting.h"
    1.38 +
    1.39 +struct SpeexResamplerState_;
    1.40 +typedef struct SpeexResamplerState_ SpeexResamplerState;
    1.41 +
    1.42 +namespace WebCore {
    1.43 +
    1.44 +// HRTFElevation contains all of the HRTFKernels (one left ear and one right ear per azimuth angle) for a particular elevation.
    1.45 +
    1.46 +class HRTFElevation {
    1.47 +public:
    1.48 +    // Loads and returns an HRTFElevation with the given HRTF database subject name and elevation from browser (or WebKit.framework) resources.
    1.49 +    // Normally, there will only be a single HRTF database set, but this API supports the possibility of multiple ones with different names.
    1.50 +    // Interpolated azimuths will be generated based on InterpolationFactor.
    1.51 +    // Valid values for elevation are -45 -> +90 in 15 degree increments.
    1.52 +    static nsReturnRef<HRTFElevation> createBuiltin(int elevation, float sampleRate);
    1.53 +
    1.54 +    // Given two HRTFElevations, and an interpolation factor x: 0 -> 1, returns an interpolated HRTFElevation.
    1.55 +    static nsReturnRef<HRTFElevation> createByInterpolatingSlices(HRTFElevation* hrtfElevation1, HRTFElevation* hrtfElevation2, float x, float sampleRate);
    1.56 +
    1.57 +    double elevationAngle() const { return m_elevationAngle; }
    1.58 +    unsigned numberOfAzimuths() const { return NumberOfTotalAzimuths; }
    1.59 +    float sampleRate() const { return m_sampleRate; }
    1.60 +    
    1.61 +    // Returns the left and right kernels for the given azimuth index.
    1.62 +    // The interpolated delays based on azimuthBlend: 0 -> 1 are returned in frameDelayL and frameDelayR.
    1.63 +    void getKernelsFromAzimuth(double azimuthBlend, unsigned azimuthIndex, HRTFKernel* &kernelL, HRTFKernel* &kernelR, double& frameDelayL, double& frameDelayR);
    1.64 +    
    1.65 +    // Total number of azimuths after interpolation.
    1.66 +    static const unsigned NumberOfTotalAzimuths;
    1.67 +
    1.68 +    static size_t fftSizeForSampleRate(float sampleRate);
    1.69 +
    1.70 +    size_t sizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
    1.71 +
    1.72 +private:
    1.73 +    HRTFElevation(const HRTFElevation& other) MOZ_DELETE;
    1.74 +    void operator=(const HRTFElevation& other) MOZ_DELETE;
    1.75 +
    1.76 +    HRTFElevation(HRTFKernelList *kernelListL, int elevation, float sampleRate)
    1.77 +        : m_elevationAngle(elevation)
    1.78 +        , m_sampleRate(sampleRate)
    1.79 +    {
    1.80 +        m_kernelListL.SwapElements(*kernelListL);
    1.81 +    }
    1.82 +
    1.83 +    // Returns the list of left ear HRTFKernels for all the azimuths going from 0 to 360 degrees.
    1.84 +    const HRTFKernelList& kernelListL() { return m_kernelListL; }
    1.85 +
    1.86 +    // Given a specific azimuth and elevation angle, returns the left HRTFKernel.
    1.87 +    // Values for azimuth must be multiples of 15 in 0 -> 345,
    1.88 +    // but not all azimuths are available for elevations > +45.
    1.89 +    // Valid values for elevation are -45 -> +90 in 15 degree increments.
    1.90 +    static nsReturnRef<HRTFKernel> calculateKernelForAzimuthElevation(int azimuth, int elevation, SpeexResamplerState* resampler, float sampleRate);
    1.91 +
    1.92 +    HRTFKernelList m_kernelListL;
    1.93 +    double m_elevationAngle;
    1.94 +    float m_sampleRate;
    1.95 +};
    1.96 +
    1.97 +} // namespace WebCore
    1.98 +
    1.99 +template <>
   1.100 +class nsAutoRefTraits<WebCore::HRTFElevation> :
   1.101 +    public nsPointerRefTraits<WebCore::HRTFElevation> {
   1.102 +public:
   1.103 +    static void Release(WebCore::HRTFElevation* ptr) { delete(ptr); }
   1.104 +};
   1.105 +
   1.106 +#endif // HRTFElevation_h

mercurial