Title: [99934] trunk/Source/WebCore
Revision
99934
Author
[email protected]
Date
2011-11-11 00:40:02 -0800 (Fri, 11 Nov 2011)

Log Message

HRTF Database consolidation
https://bugs.webkit.org/show_bug.cgi?id=69703

Reviewed by Kenneth Russell.

Access to the consolidated parts of the HRTF database by segmented
chunks. A concatenated Composite HRTF database is provided in
Composite.wav. Additionnally a new build step that concatenates
the platform/audio/resources/ files into one (sox can be used for
this) can be configured for specific ports.

* platform/audio/HRTFDatabase.h:
* platform/audio/HRTFElevation.cpp:
(WebCore::getConcatenatedImpulseResponsesForSubject):
(WebCore::HRTFElevation::calculateKernelsForAzimuthElevation):
* platform/audio/resources/Composite.wav: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (99933 => 99934)


--- trunk/Source/WebCore/ChangeLog	2011-11-11 08:37:35 UTC (rev 99933)
+++ trunk/Source/WebCore/ChangeLog	2011-11-11 08:40:02 UTC (rev 99934)
@@ -1,3 +1,22 @@
+2011-10-28  Philippe Normand  <[email protected]>
+
+        HRTF Database consolidation
+        https://bugs.webkit.org/show_bug.cgi?id=69703
+
+        Reviewed by Kenneth Russell.
+
+        Access to the consolidated parts of the HRTF database by segmented
+        chunks. A concatenated Composite HRTF database is provided in
+        Composite.wav. Additionnally a new build step that concatenates
+        the platform/audio/resources/ files into one (sox can be used for
+        this) can be configured for specific ports.
+
+        * platform/audio/HRTFDatabase.h:
+        * platform/audio/HRTFElevation.cpp:
+        (WebCore::getConcatenatedImpulseResponsesForSubject):
+        (WebCore::HRTFElevation::calculateKernelsForAzimuthElevation):
+        * platform/audio/resources/Composite.wav: Added.
+
 2011-11-10  Pavel Feldman  <[email protected]>
 
         Web Inspector: provide an id to the root inspector element for third party UA styling.

Modified: trunk/Source/WebCore/platform/audio/HRTFDatabase.h (99933 => 99934)


--- trunk/Source/WebCore/platform/audio/HRTFDatabase.h	2011-11-11 08:37:35 UTC (rev 99933)
+++ trunk/Source/WebCore/platform/audio/HRTFDatabase.h	2011-11-11 08:40:02 UTC (rev 99934)
@@ -58,7 +58,10 @@
     static unsigned numberOfAzimuths() { return HRTFElevation::NumberOfTotalAzimuths; }
 
     float sampleRate() const { return m_sampleRate; }
-    
+
+    // Number of elevations loaded from resource.
+    static const unsigned NumberOfRawElevations;
+
 private:
     explicit HRTFDatabase(float sampleRate);
 
@@ -66,9 +69,6 @@
     static const int MinElevation;
     static const int MaxElevation;
     static const unsigned RawElevationAngleSpacing;
-    
-    // Number of elevations loaded from resource.
-    static const unsigned NumberOfRawElevations;
 
     // Interpolates by this factor to get the total number of elevations from every elevation loaded from resource.
     static const unsigned InterpolationFactor;

Modified: trunk/Source/WebCore/platform/audio/HRTFElevation.cpp (99933 => 99934)


--- trunk/Source/WebCore/platform/audio/HRTFElevation.cpp	2011-11-11 08:37:35 UTC (rev 99933)
+++ trunk/Source/WebCore/platform/audio/HRTFElevation.cpp	2011-11-11 08:40:02 UTC (rev 99934)
@@ -50,6 +50,50 @@
 const unsigned HRTFElevation::InterpolationFactor = 8;
 const unsigned HRTFElevation::NumberOfTotalAzimuths = NumberOfRawAzimuths * InterpolationFactor;
 
+// Total number of components of an HRTF database.
+const size_t TotalNumberOfResponses = 240;
+
+// Number of frames in an individual impulse response.
+const size_t ResponseFrameSize = 256;
+
+// Sample-rate of the spatialization impulse responses as stored in the resource file.
+// The impulse responses may be resampled to a different sample-rate (depending on the audio hardware) when they are loaded.
+const float ResponseSampleRate = 44100;
+
+#if PLATFORM(GTK)
+#define USE_CONCATENATED_IMPULSE_RESPONSES
+#endif
+
+#ifdef USE_CONCATENATED_IMPULSE_RESPONSES
+// Lazily load a concatenated HRTF database for given subject and store it in a
+// local hash table to ensure quick efficient future retrievals.
+static AudioBus* getConcatenatedImpulseResponsesForSubject(const String& subjectName)
+{
+    typedef HashMap<String, AudioBus*> AudioBusMap;
+    DEFINE_STATIC_LOCAL(AudioBusMap, audioBusMap, ());
+
+    AudioBus* bus;
+    AudioBusMap::iterator iterator = audioBusMap.find(subjectName);
+    if (iterator == audioBusMap.end()) {
+        OwnPtr<AudioBus> concatenatedImpulseResponses = AudioBus::loadPlatformResource(subjectName.utf8().data(), ResponseSampleRate);
+        bus = concatenatedImpulseResponses.leakPtr();
+        audioBusMap.set(subjectName, bus);
+    } else
+        bus = iterator->second;
+
+    size_t responseLength = bus->length();
+    size_t expectedLength = static_cast<size_t>(TotalNumberOfResponses * ResponseFrameSize);
+
+    // Check number of channels and length. For now these are fixed and known.
+    bool isBusGood = responseLength == expectedLength && bus->numberOfChannels() == 2;
+    ASSERT(isBusGood);
+    if (!isBusGood)
+        return 0;
+
+    return bus;
+}
+#endif
+
 // Takes advantage of the symmetry and creates a composite version of the two measured versions.  For example, we have both azimuth 30 and -30 degrees
 // where the roles of left and right ears are reversed with respect to each other.
 bool HRTFElevation::calculateSymmetricKernelsForAzimuthElevation(int azimuth, int elevation, float sampleRate, const String& subjectName,
@@ -98,6 +142,37 @@
     // Note: the passed in subjectName is not a string passed in via _javascript_ or the web.
     // It's passed in as an internal ASCII identifier and is an implementation detail.
     int positiveElevation = elevation < 0 ? elevation + 360 : elevation;
+
+#ifdef USE_CONCATENATED_IMPULSE_RESPONSES
+    AudioBus* bus(getConcatenatedImpulseResponsesForSubject(subjectName));
+
+    if (!bus)
+        return false;
+
+    int elevationIndex = positiveElevation / AzimuthSpacing;
+    if (positiveElevation > 90)
+        elevationIndex -= AzimuthSpacing;
+
+    // The concatenated impulse response is a bus containing all
+    // the elevations per azimuth, for all azimuths by increasing
+    // order. So for a given azimuth and elevation we need to compute
+    // the index of the wanted audio frames in the concatenated table.
+    unsigned index = ((azimuth / AzimuthSpacing) * HRTFDatabase::NumberOfRawElevations) + elevationIndex;
+    bool isIndexGood = index < TotalNumberOfResponses;
+    ASSERT(isIndexGood);
+    if (!isIndexGood)
+        return false;
+
+    // Extract the individual impulse response from the concatenated
+    // responses and potentially sample-rate convert it to the desired
+    // (hardware) sample-rate.
+    unsigned startFrame = index * ResponseFrameSize;
+    unsigned stopFrame = startFrame + ResponseFrameSize;
+    OwnPtr<AudioBus> preSampleRateConvertedResponse = AudioBus::createBufferFromRange(bus, startFrame, stopFrame);
+    OwnPtr<AudioBus> response = AudioBus::createBySampleRateConverting(preSampleRateConvertedResponse.get(), false, sampleRate);
+    AudioChannel* leftEarImpulseResponse = response->channel(AudioBus::ChannelLeft);
+    AudioChannel* rightEarImpulseResponse = response->channel(AudioBus::ChannelRight);
+#else
     String resourceName = String::format("IRC_%s_C_R0195_T%03d_P%03d", subjectName.utf8().data(), azimuth, positiveElevation);
 
     OwnPtr<AudioBus> impulseResponse(AudioBus::loadPlatformResource(resourceName.utf8().data(), sampleRate));
@@ -117,6 +192,7 @@
     
     AudioChannel* leftEarImpulseResponse = impulseResponse->channelByType(AudioBus::ChannelLeft);
     AudioChannel* rightEarImpulseResponse = impulseResponse->channelByType(AudioBus::ChannelRight);
+#endif
 
     // 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);

Added: trunk/Source/WebCore/platform/audio/resources/Composite.wav


(Binary files differ)
Property changes on: trunk/Source/WebCore/platform/audio/resources/Composite.wav ___________________________________________________________________

Added: svn:mime-type

_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to