1bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen/* 2bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen * Copyright (C) 2010 Google Inc. All rights reserved. 3bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen * 4bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen * Redistribution and use in source and binary forms, with or without 5bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen * modification, are permitted provided that the following conditions 6bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen * are met: 7bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen * 8bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen * 1. Redistributions of source code must retain the above copyright 9bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen * notice, this list of conditions and the following disclaimer. 10bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen * 2. Redistributions in binary form must reproduce the above copyright 11bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen * notice, this list of conditions and the following disclaimer in the 12bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen * documentation and/or other materials provided with the distribution. 13bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of 14bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen * its contributors may be used to endorse or promote products derived 15bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen * from this software without specific prior written permission. 16bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen * 17bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 18bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 21bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen */ 28bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 29bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen#ifndef HRTFDatabase_h 30bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen#define HRTFDatabase_h 31bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 32bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen#include "HRTFElevation.h" 33bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen#include <wtf/HashMap.h> 34bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen#include <wtf/Noncopyable.h> 35bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen#include <wtf/OwnPtr.h> 36bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen#include <wtf/PassRefPtr.h> 37bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen#include <wtf/Vector.h> 38bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen#include <wtf/text/CString.h> 39bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen#include <wtf/text/StringHash.h> 40bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen#include <wtf/text/WTFString.h> 41bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 42bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsennamespace WebCore { 43bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 44bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsenclass HRTFKernel; 45bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 46ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdochclass HRTFDatabase { 47ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch WTF_MAKE_NONCOPYABLE(HRTFDatabase); 48bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsenpublic: 49bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen static PassOwnPtr<HRTFDatabase> create(double sampleRate); 50bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 51bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // getKernelsFromAzimuthElevation() returns a left and right ear kernel, and an interpolated left and right frame delay for the given azimuth and elevation. 52bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // azimuthBlend must be in the range 0 -> 1. 53bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // Valid values for azimuthIndex are 0 -> HRTFElevation::NumberOfTotalAzimuths - 1 (corresponding to angles of 0 -> 360). 54bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // Valid values for elevationAngle are MinElevation -> MaxElevation. 55bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen void getKernelsFromAzimuthElevation(double azimuthBlend, unsigned azimuthIndex, double elevationAngle, HRTFKernel* &kernelL, HRTFKernel* &kernelR, double& frameDelayL, double& frameDelayR); 56bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 57bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // Returns the number of different azimuth angles. 58bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen static unsigned numberOfAzimuths() { return HRTFElevation::NumberOfTotalAzimuths; } 59bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 60bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen double sampleRate() const { return m_sampleRate; } 61bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 62bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsenprivate: 63bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen explicit HRTFDatabase(double sampleRate); 64bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 65bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // Minimum and maximum elevation angles (inclusive) for a HRTFDatabase. 66bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen static const int MinElevation; 67bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen static const int MaxElevation; 68bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen static const unsigned RawElevationAngleSpacing; 69bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 70bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // Number of elevations loaded from resource. 71bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen static const unsigned NumberOfRawElevations; 72bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 73bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // Interpolates by this factor to get the total number of elevations from every elevation loaded from resource. 74bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen static const unsigned InterpolationFactor; 75bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 76bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // Total number of elevations after interpolation. 77bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen static const unsigned NumberOfTotalElevations; 78bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 79bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // Returns the index for the correct HRTFElevation given the elevation angle. 80bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen static unsigned indexFromElevationAngle(double); 81bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 82bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen Vector<OwnPtr<HRTFElevation> > m_elevations; 83bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen double m_sampleRate; 84bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen}; 85bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 86bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen} // namespace WebCore 87bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 88bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen#endif // HRTFDatabase_h 89