Encode HRTF database using FLAC (issue 2537183002 by rtoy@chromium.org)

1 view
Skip to first unread message

rtoy@chromium.org via codereview.chromium.org

unread,
Nov 30, 2016, 12:31:46 PM11/30/16
to hongchan...@chromium.org, chromium...@chromium.org, blink-...@chromium.org, dglazko...@chromium.org, blink-re...@chromium.org, hongchan...@chromium.org
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"/>


rtoy@chromium.org via codereview.chromium.org

unread,
Nov 30, 2016, 2:57:25 PM11/30/16
to hongchan...@chromium.org, chromium...@chromium.org, blink-...@chromium.org, dglazko...@chromium.org, blink-re...@chromium.org, hongchan...@chromium.org
Did some rough timing by adding some LOG's in DecodeAudioFileData (in
audio_decoder.cc) that decodes the HRTF audio file.

With the original WAV file, it seems to take 4.73 ms (average of 4 separate
runs). (Min = 3.58, max = 6.46)

With the new FLAC file, we have an average of 5.25 ms (of 4). Min = 3.16, max =
7.00)

So the FLAC file takes, roughly, 10% more time to decode.

This is probably acceptable to reduce the file size by half.

I am surprised it takes about 5 ms to decode 61440 frames of data at 44100 Hz
(stereo)

https://codereview.chromium.org/2537183002/

hong...@chromium.org

unread,
Dec 2, 2016, 12:59:41 PM12/2/16
to rt...@chromium.org, chromium...@chromium.org, blink-...@chromium.org, dglazko...@chromium.org, rt...@chromium.org, blink-re...@chromium.org
Why do we need two copies of 'flac' files in two different places?


https://codereview.chromium.org/2537183002/diff/60001/third_party/WebKit/LayoutTests/webaudio/resources/buffer-loader.js
File third_party/WebKit/LayoutTests/webaudio/resources/buffer-loader.js
(right):

https://codereview.chromium.org/2537183002/diff/60001/third_party/WebKit/LayoutTests/webaudio/resources/buffer-loader.js#newcode27
third_party/WebKit/LayoutTests/webaudio/resources/buffer-loader.js:27:

alert('BufferLoader: unable to load buffer ' + index + ", url: " +
loader.urlList[index]);
Since you've got this working, can we revert this logging change so we
can remove this file from the CL?

We can still use this, but we don't want any more edit on this.

https://codereview.chromium.org/2537183002/

rtoy@chromium.org via codereview.chromium.org

unread,
Dec 2, 2016, 1:12:06 PM12/2/16
to hongchan...@chromium.org, chromium...@chromium.org, blink-...@chromium.org, dglazko...@chromium.org, blink-re...@chromium.org, hongchan...@chromium.org
On 2016/12/02 17:59:40, hongchan wrote:
> Why do we need two copies of 'flac' files in two different places?

I'm pretty sure run-webkit-tests can't go out and reach files outside of the
LayoutTests directory.

I'm also guessing it would be bad to have such a critical file listed in the grd
file and existing in the LayoutTests directory (if that's even possible).

rtoy@chromium.org via codereview.chromium.org

unread,
Dec 2, 2016, 1:19:36 PM12/2/16
to hongchan...@chromium.org, chromium...@chromium.org, blink-...@chromium.org, dglazko...@chromium.org, blink-re...@chromium.org, hongchan...@chromium.org
On 2016/12/02 18:12:03, Raymond Toy wrote:
> On 2016/12/02 17:59:40, hongchan wrote:
> > Why do we need two copies of 'flac' files in two different places?
>
> I'm pretty sure run-webkit-tests can't go out and reach files outside of the
> LayoutTests directory.

I'm mistaken. It seems as if you can. Let me try this on the bots....

rtoy@chromium.org via codereview.chromium.org

unread,
Dec 2, 2016, 1:19:46 PM12/2/16
to hongchan...@chromium.org, chromium...@chromium.org, blink-...@chromium.org, dglazko...@chromium.org, blink-re...@chromium.org, hongchan...@chromium.org

https://codereview.chromium.org/2537183002/diff/60001/third_party/WebKit/LayoutTests/webaudio/resources/buffer-loader.js
File third_party/WebKit/LayoutTests/webaudio/resources/buffer-loader.js
(right):

https://codereview.chromium.org/2537183002/diff/60001/third_party/WebKit/LayoutTests/webaudio/resources/buffer-loader.js#newcode27
third_party/WebKit/LayoutTests/webaudio/resources/buffer-loader.js:27:
alert('BufferLoader: unable to load buffer ' + index + ", url: " +
loader.urlList[index]);
I can, but it's a useful fix to make it slightly easier to find out what
caused the problem. At least until fetch() works better for us at which
point we can stop using this completely.

https://codereview.chromium.org/2537183002/

hong...@chromium.org

unread,
Dec 2, 2016, 3:31:30 PM12/2/16
to rt...@chromium.org, chromium...@chromium.org, blink-...@chromium.org, dglazko...@chromium.org, blink-re...@chromium.org

commit-bot@chromium.org via codereview.chromium.org

unread,
Dec 5, 2016, 11:34:28 AM12/5/16
to rt...@chromium.org, hongchan...@chromium.org, commi...@chromium.org, chromium...@chromium.org, blink-...@chromium.org, dglazko...@chromium.org, blink-re...@chromium.org, hongchan...@chromium.org

commit-bot@chromium.org via codereview.chromium.org

unread,
Dec 5, 2016, 11:41:12 AM12/5/16
to rt...@chromium.org, hongchan...@chromium.org, commi...@chromium.org, chromium...@chromium.org, blink-...@chromium.org, dglazko...@chromium.org, blink-re...@chromium.org, hongchan...@chromium.org
Try jobs failed on following builders:
chromium_presubmit on master.tryserver.chromium.linux (JOB_FAILED,
http://build.chromium.org/p/tryserver.chromium.linux/builders/chromium_presubmit/builds/318541)

https://codereview.chromium.org/2537183002/

rtoy@chromium.org via codereview.chromium.org

unread,
Dec 5, 2016, 12:03:50 PM12/5/16
to hongchan...@chromium.org, foo...@chromium.org, chromium...@chromium.org, blink-...@chromium.org, dglazko...@chromium.org, blink-re...@chromium.org, hongchan...@chromium.org
foolip: PTAL at blink_resources.grd.

https://codereview.chromium.org/2537183002/

foo...@chromium.org

unread,
Dec 7, 2016, 11:05:08 AM12/7/16
to rt...@chromium.org, hongchan...@chromium.org, chromium...@chromium.org, blink-...@chromium.org, dglazko...@chromium.org, blink-re...@chromium.org, hongchan...@chromium.org

commit-bot@chromium.org via codereview.chromium.org

unread,
Dec 7, 2016, 11:05:31 AM12/7/16
to rt...@chromium.org, hongchan...@chromium.org, foo...@chromium.org, commi...@chromium.org, chromium...@chromium.org, blink-...@chromium.org, dglazko...@chromium.org, blink-re...@chromium.org, hongchan...@chromium.org

commit-bot@chromium.org via codereview.chromium.org

unread,
Dec 7, 2016, 2:14:07 PM12/7/16
to rt...@chromium.org, hongchan...@chromium.org, foo...@chromium.org, commi...@chromium.org, chromium...@chromium.org, blink-...@chromium.org, dglazko...@chromium.org, blink-re...@chromium.org, hongchan...@chromium.org
Committed patchset #6 (id:100001)

https://codereview.chromium.org/2537183002/

commit-bot@chromium.org via codereview.chromium.org

unread,
Dec 7, 2016, 2:15:51 PM12/7/16
to rt...@chromium.org, hongchan...@chromium.org, foo...@chromium.org, commi...@chromium.org, chromium...@chromium.org, blink-...@chromium.org, dglazko...@chromium.org, blink-re...@chromium.org, hongchan...@chromium.org
Patchset 6 (id:??) landed as
https://crrev.com/625aefda371b1533682cf59b9332404a913651f4
Cr-Commit-Position: refs/heads/master@{#437026}

https://codereview.chromium.org/2537183002/
Reply all
Reply to author
Forward
0 new messages