b=815643 Use symmetry to halve the number of HRTF kernels calculated and cached r=ehsan

--HG--
extra : rebase_source : 12e4a114630e793c22d3e335c38c641a6bc20ee2
This commit is contained in:
Karl Tomlinson 2013-08-08 21:38:29 +12:00
parent 8c052323df
commit 715c2a763f
2 changed files with 26 additions and 35 deletions

View File

@ -52,8 +52,8 @@ const unsigned HRTFElevation::NumberOfTotalAzimuths = NumberOfRawAzimuths * Inte
// Number of frames in an individual impulse response. // Number of frames in an individual impulse response.
const size_t ResponseFrameSize = 256; const size_t ResponseFrameSize = 256;
bool HRTFElevation::calculateKernelsForAzimuthElevation(int azimuth, int elevation, float sampleRate, const String& subjectName, bool HRTFElevation::calculateKernelForAzimuthElevation(int azimuth, int elevation, float sampleRate, const String& subjectName,
RefPtr<HRTFKernel>& kernelL, RefPtr<HRTFKernel>& kernelR) RefPtr<HRTFKernel>& kernelL)
{ {
// Valid values for azimuth are 0 -> 345 in 15 degree increments. // Valid values for azimuth are 0 -> 345 in 15 degree increments.
// Valid values for elevation are -45 -> +90 in 15 degree increments. // Valid values for elevation are -45 -> +90 in 15 degree increments.
@ -92,7 +92,6 @@ bool HRTFElevation::calculateKernelsForAzimuthElevation(int azimuth, int elevati
return false; return false;
AudioChannel* leftEarImpulseResponse = impulseResponse->channelByType(AudioBus::ChannelLeft); AudioChannel* leftEarImpulseResponse = impulseResponse->channelByType(AudioBus::ChannelLeft);
AudioChannel* rightEarImpulseResponse = impulseResponse->channelByType(AudioBus::ChannelRight);
// Note that depending on the fftSize returned by the panner, we may be truncating the impulse response we just loaded in. // Note that depending on the fftSize returned by the panner, we may be truncating the impulse response we just loaded in.
const size_t fftSize = HRTFPanner::fftSizeForSampleRate(sampleRate); const size_t fftSize = HRTFPanner::fftSizeForSampleRate(sampleRate);
@ -101,7 +100,6 @@ bool HRTFElevation::calculateKernelsForAzimuthElevation(int azimuth, int elevati
return false; return false;
kernelL = HRTFKernel::create(leftEarImpulseResponse, fftSize / 2, sampleRate); kernelL = HRTFKernel::create(leftEarImpulseResponse, fftSize / 2, sampleRate);
kernelR = HRTFKernel::create(rightEarImpulseResponse, fftSize / 2, sampleRate);
return true; return true;
} }
@ -146,7 +144,6 @@ PassOwnPtr<HRTFElevation> HRTFElevation::createForSubject(const String& subjectN
return nullptr; return nullptr;
OwnPtr<HRTFKernelList> kernelListL = adoptPtr(new HRTFKernelList(NumberOfTotalAzimuths)); OwnPtr<HRTFKernelList> kernelListL = adoptPtr(new HRTFKernelList(NumberOfTotalAzimuths));
OwnPtr<HRTFKernelList> kernelListR = adoptPtr(new HRTFKernelList(NumberOfTotalAzimuths));
// Load convolution kernels from HRTF files. // Load convolution kernels from HRTF files.
int interpolatedIndex = 0; int interpolatedIndex = 0;
@ -155,7 +152,7 @@ PassOwnPtr<HRTFElevation> HRTFElevation::createForSubject(const String& subjectN
int maxElevation = maxElevations[rawIndex]; int maxElevation = maxElevations[rawIndex];
int actualElevation = min(elevation, maxElevation); int actualElevation = min(elevation, maxElevation);
bool success = calculateKernelsForAzimuthElevation(rawIndex * AzimuthSpacing, actualElevation, sampleRate, subjectName, kernelListL->at(interpolatedIndex), kernelListR->at(interpolatedIndex)); bool success = calculateKernelForAzimuthElevation(rawIndex * AzimuthSpacing, actualElevation, sampleRate, subjectName, kernelListL->at(interpolatedIndex));
if (!success) if (!success)
return nullptr; return nullptr;
@ -171,11 +168,10 @@ PassOwnPtr<HRTFElevation> HRTFElevation::createForSubject(const String& subjectN
float x = float(jj) / float(InterpolationFactor); // interpolate from 0 -> 1 float x = float(jj) / float(InterpolationFactor); // interpolate from 0 -> 1
(*kernelListL)[i + jj] = HRTFKernel::createInterpolatedKernel(kernelListL->at(i).get(), kernelListL->at(j).get(), x); (*kernelListL)[i + jj] = HRTFKernel::createInterpolatedKernel(kernelListL->at(i).get(), kernelListL->at(j).get(), x);
(*kernelListR)[i + jj] = HRTFKernel::createInterpolatedKernel(kernelListR->at(i).get(), kernelListR->at(j).get(), x);
} }
} }
OwnPtr<HRTFElevation> hrtfElevation = adoptPtr(new HRTFElevation(kernelListL.release(), kernelListR.release(), elevation, sampleRate)); OwnPtr<HRTFElevation> hrtfElevation = adoptPtr(new HRTFElevation(kernelListL.release(), elevation, sampleRate));
return hrtfElevation.release(); return hrtfElevation.release();
} }
@ -188,23 +184,19 @@ PassOwnPtr<HRTFElevation> HRTFElevation::createByInterpolatingSlices(HRTFElevati
ASSERT(x >= 0.0 && x < 1.0); ASSERT(x >= 0.0 && x < 1.0);
OwnPtr<HRTFKernelList> kernelListL = adoptPtr(new HRTFKernelList(NumberOfTotalAzimuths)); OwnPtr<HRTFKernelList> kernelListL = adoptPtr(new HRTFKernelList(NumberOfTotalAzimuths));
OwnPtr<HRTFKernelList> kernelListR = adoptPtr(new HRTFKernelList(NumberOfTotalAzimuths));
HRTFKernelList* kernelListL1 = hrtfElevation1->kernelListL(); HRTFKernelList* kernelListL1 = hrtfElevation1->kernelListL();
HRTFKernelList* kernelListR1 = hrtfElevation1->kernelListR();
HRTFKernelList* kernelListL2 = hrtfElevation2->kernelListL(); HRTFKernelList* kernelListL2 = hrtfElevation2->kernelListL();
HRTFKernelList* kernelListR2 = hrtfElevation2->kernelListR();
// Interpolate kernels of corresponding azimuths of the two elevations. // Interpolate kernels of corresponding azimuths of the two elevations.
for (unsigned i = 0; i < NumberOfTotalAzimuths; ++i) { for (unsigned i = 0; i < NumberOfTotalAzimuths; ++i) {
(*kernelListL)[i] = HRTFKernel::createInterpolatedKernel(kernelListL1->at(i).get(), kernelListL2->at(i).get(), x); (*kernelListL)[i] = HRTFKernel::createInterpolatedKernel(kernelListL1->at(i).get(), kernelListL2->at(i).get(), x);
(*kernelListR)[i] = HRTFKernel::createInterpolatedKernel(kernelListR1->at(i).get(), kernelListR2->at(i).get(), x);
} }
// Interpolate elevation angle. // Interpolate elevation angle.
double angle = (1.0 - x) * hrtfElevation1->elevationAngle() + x * hrtfElevation2->elevationAngle(); double angle = (1.0 - x) * hrtfElevation1->elevationAngle() + x * hrtfElevation2->elevationAngle();
OwnPtr<HRTFElevation> hrtfElevation = adoptPtr(new HRTFElevation(kernelListL.release(), kernelListR.release(), static_cast<int>(angle), sampleRate)); OwnPtr<HRTFElevation> hrtfElevation = adoptPtr(new HRTFElevation(kernelListL.release(), static_cast<int>(angle), sampleRate));
return hrtfElevation.release(); return hrtfElevation.release();
} }
@ -225,16 +217,19 @@ void HRTFElevation::getKernelsFromAzimuth(double azimuthBlend, unsigned azimuthI
return; return;
} }
// Return the left and right kernels. // Return the left and right kernels,
// using symmetry to produce the right kernel.
kernelL = m_kernelListL->at(azimuthIndex).get(); kernelL = m_kernelListL->at(azimuthIndex).get();
kernelR = m_kernelListR->at(azimuthIndex).get(); int azimuthIndexR = (numKernels - azimuthIndex) % numKernels;
kernelR = m_kernelListL->at(azimuthIndexR).get();
frameDelayL = m_kernelListL->at(azimuthIndex)->frameDelay(); frameDelayL = kernelL->frameDelay();
frameDelayR = m_kernelListR->at(azimuthIndex)->frameDelay(); frameDelayR = kernelR->frameDelay();
int azimuthIndex2 = (azimuthIndex + 1) % numKernels; int azimuthIndex2L = (azimuthIndex + 1) % numKernels;
double frameDelay2L = m_kernelListL->at(azimuthIndex2)->frameDelay(); double frameDelay2L = m_kernelListL->at(azimuthIndex2L)->frameDelay();
double frameDelay2R = m_kernelListR->at(azimuthIndex2)->frameDelay(); int azimuthIndex2R = (numKernels - azimuthIndex2L) % numKernels;
double frameDelay2R = m_kernelListL->at(azimuthIndex2R)->frameDelay();
// Linearly interpolate delays. // Linearly interpolate delays.
frameDelayL = (1.0 - azimuthBlend) * frameDelayL + azimuthBlend * frameDelay2L; frameDelayL = (1.0 - azimuthBlend) * frameDelayL + azimuthBlend * frameDelay2L;
@ -245,7 +240,6 @@ void HRTFElevation::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
{ {
MemoryClassInfo info(memoryObjectInfo, this, PlatformMemoryTypes::AudioSharedData); MemoryClassInfo info(memoryObjectInfo, this, PlatformMemoryTypes::AudioSharedData);
info.addMember(m_kernelListL, "kernelListL"); info.addMember(m_kernelListL, "kernelListL");
info.addMember(m_kernelListR, "kernelListR");
} }
} // namespace WebCore } // namespace WebCore

View File

@ -55,10 +55,6 @@ public:
// Given two HRTFElevations, and an interpolation factor x: 0 -> 1, returns an interpolated HRTFElevation. // Given two HRTFElevations, and an interpolation factor x: 0 -> 1, returns an interpolated HRTFElevation.
static PassOwnPtr<HRTFElevation> createByInterpolatingSlices(HRTFElevation* hrtfElevation1, HRTFElevation* hrtfElevation2, float x, float sampleRate); static PassOwnPtr<HRTFElevation> createByInterpolatingSlices(HRTFElevation* hrtfElevation1, HRTFElevation* hrtfElevation2, float x, float sampleRate);
// Returns the list of left or right ear HRTFKernels for all the azimuths going from 0 to 360 degrees.
HRTFKernelList* kernelListL() { return m_kernelListL.get(); }
HRTFKernelList* kernelListR() { return m_kernelListR.get(); }
double elevationAngle() const { return m_elevationAngle; } double elevationAngle() const { return m_elevationAngle; }
unsigned numberOfAzimuths() const { return NumberOfTotalAzimuths; } unsigned numberOfAzimuths() const { return NumberOfTotalAzimuths; }
float sampleRate() const { return m_sampleRate; } float sampleRate() const { return m_sampleRate; }
@ -79,26 +75,27 @@ public:
// Total number of azimuths after interpolation. // Total number of azimuths after interpolation.
static const unsigned NumberOfTotalAzimuths; static const unsigned NumberOfTotalAzimuths;
// Given a specific azimuth and elevation angle, returns the left and right HRTFKernel.
// Valid values for azimuth are 0 -> 345 in 15 degree increments.
// Valid values for elevation are -45 -> +90 in 15 degree increments.
// Returns true on success.
static bool calculateKernelsForAzimuthElevation(int azimuth, int elevation, float sampleRate, const String& subjectName,
RefPtr<HRTFKernel>& kernelL, RefPtr<HRTFKernel>& kernelR);
void reportMemoryUsage(MemoryObjectInfo*) const; void reportMemoryUsage(MemoryObjectInfo*) const;
private: private:
HRTFElevation(PassOwnPtr<HRTFKernelList> kernelListL, PassOwnPtr<HRTFKernelList> kernelListR, int elevation, float sampleRate) HRTFElevation(PassOwnPtr<HRTFKernelList> kernelListL, int elevation, float sampleRate)
: m_kernelListL(kernelListL) : m_kernelListL(kernelListL)
, m_kernelListR(kernelListR)
, m_elevationAngle(elevation) , m_elevationAngle(elevation)
, m_sampleRate(sampleRate) , m_sampleRate(sampleRate)
{ {
} }
// Returns the list of left ear HRTFKernels for all the azimuths going from 0 to 360 degrees.
HRTFKernelList* kernelListL() { return m_kernelListL.get(); }
// Given a specific azimuth and elevation angle, returns the left HRTFKernel.
// Valid values for azimuth are 0 -> 345 in 15 degree increments.
// Valid values for elevation are -45 -> +90 in 15 degree increments.
// Returns true on success.
static bool calculateKernelForAzimuthElevation(int azimuth, int elevation, float sampleRate, const String& subjectName,
RefPtr<HRTFKernel>& kernelL);
OwnPtr<HRTFKernelList> m_kernelListL; OwnPtr<HRTFKernelList> m_kernelListL;
OwnPtr<HRTFKernelList> m_kernelListR;
double m_elevationAngle; double m_elevationAngle;
float m_sampleRate; float m_sampleRate;
}; };