Reviewers: hongchan
CL:
https://codereview.chromium.org/2537183002/Message:
PTAL
Description:
Encode HRTF database using FLAC
Encoding the HRTF database using FLAC shrinks the database file from
245804 bytes to 145812 bytes (40% less space), while still keeping
exactly the same data.
BUG=669545
TEST=hrtf-database.html
Affected files (+88, -0 lines):
A third_party/WebKit/LayoutTests/webaudio/hrtf-database.html
M third_party/WebKit/LayoutTests/webaudio/resources/audit.js
M third_party/WebKit/LayoutTests/webaudio/resources/buffer-loader.js
A third_party/WebKit/LayoutTests/webaudio/resources/hrtf/Composite.flac
A third_party/WebKit/LayoutTests/webaudio/resources/hrtf/Composite.wav
A third_party/WebKit/Source/platform/audio/resources/Composite.flac
A third_party/WebKit/Source/platform/audio/resources/README
M third_party/WebKit/public/blink_resources.grd
Index: third_party/WebKit/LayoutTests/webaudio/hrtf-database.html
diff --git a/third_party/WebKit/LayoutTests/webaudio/hrtf-database.html b/third_party/WebKit/LayoutTests/webaudio/hrtf-database.html
new file mode 100644
index 0000000000000000000000000000000000000000..a6a876f5da024aaf6a865388b42451defa838363
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/webaudio/hrtf-database.html
@@ -0,0 +1,67 @@
+<!doctype html>
+<html>
+ <head>
+ <title>Test FLAC-encoded HRTF databse</title>
+ <script src="../resources/testharness.js"></script>
+ <script src="../resources/testharnessreport.js"></script>
+ <script src="resources/audit.js"></script>
+ <script src="resources/buffer-loader.js"></script>
+ </head>
+
+ <body>
+ <script>
+ // This MUST be the sample rate used by the HTRF database!
+ var sampleRate = 44100;
+
+ var context;
+ var wavBuffer;
+ var flacBuffer;
+
+ var audit = Audit.createTaskRunner();
+
+ audit.define("loadfiles", function (task, should) {
+ task.describe("Load HRTF database files");
+
+ // Any valid context with the right sample rate will do.
+ context = new OfflineAudioContext(1, 1, sampleRate);
+
+ var bufferLoader = new BufferLoader(
+ context, [
+ // This is a copy of the original file in
+ // Sources/platform/audio/resources/Composite.wav
+ "resources/hrtf/Composite.wav",
+ // This is a copy of the original file in
+ // Sources/platform/audio/resources/Composite.flac.
+ "resources/hrtf/Composite.flac"
+ ],
+ function (bufferList) {
+ should(bufferList.length, "Number of buffers loaded")
+ .beEqualTo(2);
+ wavBuffer = bufferList[0];
+ flacBuffer = bufferList[1];
+ task.done();
+ });
+
+ bufferLoader.load();
+ });
+
+ audit.define("verify-flac", function (task, should) {
+ task.describe("Verify FLAC-encoded HRTF database matches original");
+
+ should(flacBuffer.numberOfChannels, "Number of FLAC channels")
+ .beEqualTo(wavBuffer.numberOfChannels);
+
+ for (var k = 0; k < wavBuffer.numberOfChannels; ++k) {
+ should(flacBuffer.getChannelData(k),
+ "FLAC-encoded HRTF database channel " + k
+ )
+ .beEqualToArray(wavBuffer.getChannelData(k));
+ }
+
+ task.done();
+ });
+
+ audit.run();
+ </script>
+ </body>
+</html>
Index: third_party/WebKit/LayoutTests/webaudio/resources/audit.js
diff --git a/third_party/WebKit/LayoutTests/webaudio/resources/audit.js b/third_party/WebKit/LayoutTests/webaudio/resources/audit.js
index 177484af53389b6e39e49ccb183174e715c552e7..28d291b199765aded3db3d0ae262dfbc72726d98 100644
--- a/third_party/WebKit/LayoutTests/webaudio/resources/audit.js
+++ b/third_party/WebKit/LayoutTests/webaudio/resources/audit.js
@@ -851,7 +851,7 @@ window.Audit = (function () {
let message = '< [' + this._label + '] ';
if (this._result) {
- message += 'All assertion passed. (total ' + this._totalAssertions
+ message += 'All assertions passed. (total ' + this._totalAssertions
+ ' assertions)';
_logPassed(message);
} else {
Index: third_party/WebKit/LayoutTests/webaudio/resources/buffer-loader.js
diff --git a/third_party/WebKit/LayoutTests/webaudio/resources/buffer-loader.js b/third_party/WebKit/LayoutTests/webaudio/resources/buffer-loader.js
index 8aa98b4173a7b34bbeaaeecfbbac0c7ad7ca314b..f089290aace3c67e695cf0a5189bdc62700c14ad 100644
--- a/third_party/WebKit/LayoutTests/webaudio/resources/buffer-loader.js
+++ b/third_party/WebKit/LayoutTests/webaudio/resources/buffer-loader.js
@@ -23,7 +23,8 @@ BufferLoader.prototype.loadBuffer = function(url, index) {
if (++loader.loadCount == loader.urlList.length)
loader.onload(loader.bufferList);
} catch(e) {
- alert('BufferLoader: unable to load buffer' + index);
+ console.log(e);
+ alert('BufferLoader: unable to load buffer ' + index + ", url: " + loader.urlList[index]);
}
},
function () {
Index: third_party/WebKit/LayoutTests/webaudio/resources/hrtf/Composite.flac
diff --git a/third_party/WebKit/LayoutTests/webaudio/resources/hrtf/Composite.flac b/third_party/WebKit/LayoutTests/webaudio/resources/hrtf/Composite.flac
new file mode 100644
index 0000000000000000000000000000000000000000..d67abe48d57ddee360d98191cc1f212d22742b6a
Binary files /dev/null and b/third_party/WebKit/LayoutTests/webaudio/resources/hrtf/Composite.flac differ
Index: third_party/WebKit/LayoutTests/webaudio/resources/hrtf/Composite.wav
diff --git a/third_party/WebKit/LayoutTests/webaudio/resources/hrtf/Composite.wav b/third_party/WebKit/LayoutTests/webaudio/resources/hrtf/Composite.wav
new file mode 100644
index 0000000000000000000000000000000000000000..fab198d7727ba9038314f106df26ac1e2fa39981
Binary files /dev/null and b/third_party/WebKit/LayoutTests/webaudio/resources/hrtf/Composite.wav differ
Index: third_party/WebKit/Source/platform/audio/resources/Composite.flac
diff --git a/third_party/WebKit/Source/platform/audio/resources/Composite.flac b/third_party/WebKit/Source/platform/audio/resources/Composite.flac
new file mode 100644
index 0000000000000000000000000000000000000000..d67abe48d57ddee360d98191cc1f212d22742b6a
Binary files /dev/null and b/third_party/WebKit/Source/platform/audio/resources/Composite.flac differ
Index: third_party/WebKit/Source/platform/audio/resources/README
diff --git a/third_party/WebKit/Source/platform/audio/resources/README b/third_party/WebKit/Source/platform/audio/resources/README
new file mode 100644
index 0000000000000000000000000000000000000000..90d3fd6255e9ef5f682e949ec50f8364e6c27550
--- /dev/null
+++ b/third_party/WebKit/Source/platform/audio/resources/README
@@ -0,0 +1,20 @@
+See
https://bugs.webkit.org/show_bug.cgi?id=98294#c9.
+
+Here is how to create Composite.wav from the indidividual responses:
+
+AUDIO_DIR="WebKit/Source/platform/audio/resources"
+sox $( \
+ for azimuth in {0..23}; do \
+ for elevation in 0 15 30 45 60 75 90 315 330 345; do \
+ printf "$AUDIO_DIR/IRC_Composite_C_R0195_T%03d_P%03d.wav\n" "$(expr $azimuth \* 15)" "$elevation"; \
+ done; \
+ done;) \
+Composite.wav
+
+To create the FLAC-encoded version:
+
+avconv -i Composite.wav Composite.flac
+
+If you change Composite.flac (or Composite.wav), be sure to update
+LayoutTests/webaudio/resources/hrtf with the updated files!
+
Index: third_party/WebKit/public/blink_resources.grd
diff --git a/third_party/WebKit/public/blink_resources.grd b/third_party/WebKit/public/blink_resources.grd
index 41fdee88f6d711121d6c462c5954f399c6a30ac3..12d68904b359d2eb6b0b2f9c7630d8fcfec33b51 100644
--- a/third_party/WebKit/public/blink_resources.grd
+++ b/third_party/WebKit/public/blink_resources.grd
@@ -50,7 +50,7 @@
<include name="IDR_LIST_PICKER_JS" file="../Source/web/resources/listPicker.js" type="BINDATA"/>
</if>
<if expr="use_concatenated_impulse_responses">
- <include name="IDR_AUDIO_SPATIALIZATION_COMPOSITE" file="../Source/platform/audio/resources/Composite.wav" type="BINDATA"/>
+ <include name="IDR_AUDIO_SPATIALIZATION_COMPOSITE" file="../Source/platform/audio/resources/Composite.flac" type="BINDATA"/>
</if>
<if expr="not use_concatenated_impulse_responses">
<include name="IDR_AUDIO_SPATIALIZATION_T000_P000" file="..\Source\platform\audio\resources\IRC_Composite_C_R0195_T000_P000.wav" type="BINDATA"/>