Last Comment Bug 524109 - Support 24-bit (and 32-bit?) PCM WAV files (not just 8- and 16-bit) in <audio> tag
: Support 24-bit (and 32-bit?) PCM WAV files (not just 8- and 16-bit) in <audio...
Status: RESOLVED FIXED
[parity-chrome]
:
Product: Core
Classification: Components
Component: Audio/Video: Playback (show other bugs)
: unspecified
: All All
: -- enhancement with 5 votes (vote)
: mozilla46
Assigned To: Louis Christie [:lchristie]
:
Mentors: Paul Adenot (:padenot) (in PTO until early September)
: 656939 1074141 (view as bug list)
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2009-10-23 06:57 PDT by Dan S
Modified: 2016-01-17 19:02 PST (History)
15 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---
fixed


Attachments
bug-524109-fix.patch (8.03 KB, patch)
2015-11-22 16:24 PST, Louis Christie [:lchristie]
cpearce: review+
Details | Diff | Splinter Review
bug-524109-fix.patch (8.25 KB, patch)
2015-12-10 08:44 PST, Louis Christie [:lchristie]
cpearce: review+
Details | Diff | Splinter Review
bug-524109-fix.patch (8.26 KB, patch)
2015-12-13 18:09 PST, Louis Christie [:lchristie]
no flags Details | Diff | Splinter Review

Description Dan S 2009-10-23 06:57:29 PDT
User-Agent:       Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3
Build Identifier: 

As discussed in bug 523837: 24-bit PCM WAV files are quite common but only 8-bit and 16-bit are currently supported in the <audio> tag. (Observed in Firefox 3.5.3 and 3.6.)

The original 1991 WAV specification actually specifies arbitrary bit depths (12 and 20 are mentioned as examples - http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/Docs/riffmci.pdf pages 59&60). Note that I'm not talking about the later "extended" WAV specs. I don't believe that arbitrary bit depths are common but I work with audio and routinely encounter 24-bit integer PCM WAVs, so I would request that those be supported. 32-bit may also be worth adding at the same time (although theoretically 24-bit is sufficient to cover the dynamic range that we hear, 32-bit is encountered too).

In bug 523837 comment 4 MG suggests 32-bit float may also be worth supporting. (He also points out that the HTML 5 draft doesn't quite make clear what the baseline supported format for audio should be, if any.)


Reproducible: Always
Comment 1 Boris Zbarsky [:bz] 2011-05-13 09:45:14 PDT
*** Bug 656939 has been marked as a duplicate of this bug. ***
Comment 2 Grant Galitz 2011-11-18 01:44:06 PST
Also see about adding the legacy a-log, u-log, float-32, and float-64 if possible.

I wrote a WAV file decoder+player in javascript that handles and plays the major wav types, not just PCM: http://www.grantgalitz.org/wav_player/ , so a future patch be tested against for reproduction quality.

Some notes on a-log and u-log: They're 8-bit, but just have the 8-bit data run through specific lookup tables (a-log and u-log tables each are 256 entries, obviously.). Said lookup tables are in http://www.grantgalitz.org/wav_player/WAVDecoder.js as well as the other codec processing.
Comment 3 Grant Galitz 2011-11-18 01:50:41 PST
Also a future patch should consider the non-byte aligned bit rates (Like 7, 30, 4, etc.). They are still valid, but require a separate path in code if it's going to be optimized or hacked in (Normalization and bit clears need to be added possibly).
Comment 4 Grant Galitz 2011-11-18 01:52:33 PST
Even possibly support the big-endian version of WAVE, that has the RIFX/FFIR master ID instead of RIFF.
Comment 5 Grant Galitz 2011-11-18 05:57:57 PST
Moved some stuff around with the WAV decoder, so the a-law and u-law lookup tables are now in http://www.grantgalitz.org/wav_player/decode.js .

Got bored added AIFF and AIFF-C support to the javascript audio binary decoder & player as well: http://www.grantgalitz.org/wav_player/AIFFDecoder.js
Comment 6 somelinguist 2013-02-07 18:45:25 PST
Is there any update on supporting 24-bit or better PCM WAV files?
Comment 7 Ralph Giles (:rillian) needinfo me 2013-02-08 08:49:50 PST
(In reply to somelinguist from comment #6)
> Is there any update on supporting 24-bit or better PCM WAV files?

I'm not aware of anyone working on this. We mostly use WAV support for testing; because of the bandwidth use it's not popular for sites. It's also a simple format to parse in javascript, as discussed above.

If this feature is important to you, I can suggest:

- patches and test cases always help
- test other current browsers and report how broad support for particular PCM wav variants is.
Comment 8 somelinguist 2013-02-09 10:42:50 PST
(In reply to Ralph Giles (:rillian) from comment #7)

I agree that WAV generally isn't that useful in a browser because of bandwidth. 

I'm writing a language-learning program in HTML5/Javascript that will run in XULRunner (possibly with a web-based port eventually), and it would be ideal to be able to play a wider variety of WAV audio formats. The program plays audio referenced in XML-based dictionaries exported from other programs. The other programs do support higher quality WAV formats, so it would be nice not to need to have users convert them if they've already used higher quality files.

I looked at the Javascript decoder above, but I couldn't figure out how to use it. Would it be possible to use such a decoder in conjunction with the audio tag so that other formats would still be supported natively? Or if I go the Javascript decoding route, do I need to dump the audio tag and decode other formats, too?

It's my understanding that in the future Firefox will support MP3 (etc) if a third-party decoder is installed on the system. Will this also work for other formats such as the unsupported WAV formats?

Regarding browser support: Chrome will also play signed 24-bit and 32-bit float PCM WAV files. IE 10 doesn't. I don't have Opera or Safari to test.

Thanks for your help.
Comment 9 PTO until Sep 5 NZ time; Chris Pearce (:cpearce) 2013-02-10 14:49:44 PST
(In reply to somelinguist from comment #8)
> It's my understanding that in the future Firefox will support MP3 (etc) if a
> third-party decoder is installed on the system. Will this also work for
> other formats such as the unsupported WAV formats?

No.

Our intention is to be very strict with what formats we enable in platform decoders, as we want to limit codec fragmentation on the web and we also have limited ability prevent or work around bugs found in platform decoders.
Comment 10 Ralph Giles (:rillian) needinfo me 2013-02-12 10:43:46 PST
(In reply to somelinguist from comment #8)

> I looked at the Javascript decoder above, but I couldn't figure out how to
> use it. Would it be possible to use such a decoder in conjunction with the
> audio tag so that other formats would still be supported natively?

Yes. For example you can go through the document at load time and replace all <audio> elements referencing wav files with the javascript decoder.

> Regarding browser support: Chrome will also play signed 24-bit and 32-bit
> float PCM WAV files. IE 10 doesn't. I don't have Opera or Safari to test.

Thanks for testing. If you put up a public page with test files for the formats you want to support I can test Safari and Opera.
Comment 11 somelinguist 2013-02-13 19:53:16 PST
Thanks for the tip about replacing audio tags. I'll try it out when I get a chance. 

I don't have a place I can put the files I have publicly, but I was able to test them in Opera 12.14 and Safari for Windows (the latest version (5.1.7) I could find was from last May). I was able to load and play:
Signed 16-bit PCM
Signed 24-bit PCM
Signed 32-bit PCM
32-bit float
64-bit float

Additionally, Safari for Windows would play U-Law and A-Law files.

It would be great to see similar native support in Firefox!
Comment 12 Stephen E. Baker 2013-11-06 12:22:21 PST
The same arguments that have brought about support in Chrome likely apply: http://code.google.com/p/chromium/issues/detail?id=217772

mu-law and a-law wav files are small enough to be used on the web and are used by telephone companies for voicemail messages and call recordings.
Comment 13 Daniel Davis 2014-09-25 22:35:00 PDT
It seems the request for a test page is still open so here goes:
http://daniemon.com/test/wav/

Results as of Sep 2014 are as follows:
16-bit, 24-bit and 32-bit work in WebKit (tested in Midori)

16-bit and 24-bit work in Blink (tested in Chromium and Opera)

Only 16-bit works in Mozilla (tested in Firefox)

For what it's worth, old Opera (Presto) plays all three files.
Comment 14 Paul Adenot (:padenot) (in PTO until early September) 2015-05-07 02:01:27 PDT
Now that the Web Audio API starts to get used a lot, this is becoming a lot more important. It's very common in the music production world to use 24bits files, and it would be great to have support for them in Firefox.
Comment 15 Louis Christie [:lchristie] 2015-11-22 16:24:17 PST
Created attachment 8690595 [details] [diff] [review]
bug-524109-fix.patch
Comment 16 PTO until Sep 5 NZ time; Chris Pearce (:cpearce) 2015-11-22 16:58:47 PST
Comment on attachment 8690595 [details] [diff] [review]
bug-524109-fix.patch

Review of attachment 8690595 [details] [diff] [review]:
-----------------------------------------------------------------

You also need to run dom/media/test/make-headers.sh and `hg add dom/media/test/wavedata_s24.wav^headers^`.

You also need a commit message of the form "Bug XXX - What change your patch makes. r=cpearce".

r=cpearce, with the changes made.

::: dom/media/wave/WaveReader.cpp
@@ +194,5 @@
>  
> +template <> inline float
> +Signed24bIntToAudioSample<float>(int32_t aValue)
> +{
> +  return aValue / 8388608.0f;

Windows calculator tells me that 0x7fffff is 8388607, not 8388608.

So shouldn't you be dividing by 8388607?

@@ +483,4 @@
>    } else {
>      mSampleFormat = FORMAT_S16;
>    }
> +

Looks like you're adding trailing whitespace to the line here. Don't.
Comment 17 Louis Christie [:lchristie] 2015-11-22 17:17:18 PST
Fixed comments 1,2, and 4. The division is by 0x800000 not 0x7fffff because there is one more negative number than positive, so changing this could result in a float (just) outside the expected [-1.0, 1.0] range.
Comment 18 Louis Christie [:lchristie] 2015-12-10 08:44:48 PST
Created attachment 8697299 [details] [diff] [review]
bug-524109-fix.patch
Comment 19 Carsten Book [:Tomcat] - PTO-back Sept 4th 2015-12-11 00:08:06 PST
sorry failed to apply:

patching file dom/media/wave/WaveReader.cpp
Hunk #2 FAILED at 162
1 out of 5 hunks FAILED -- saving rejects to file dom/media/wave/WaveReader.cpp.rej
patch failed, unable to continue (try -v)
patch failed, rejects left in working directory
errors during apply, please fix and qrefresh bug-524109-fix.patch
Comment 20 Louis Christie [:lchristie] 2015-12-13 18:09:06 PST
Created attachment 8697902 [details] [diff] [review]
bug-524109-fix.patch
Comment 22 Carsten Book [:Tomcat] - PTO-back Sept 4th 2015-12-14 01:59:01 PST
sorry had to back this out seems this or the other change caused test failures like https://treeherder.mozilla.org/logviewer.html#?job_id=18535643&repo=mozilla-inbound
Comment 25 Carsten Book [:Tomcat] - PTO-back Sept 4th 2015-12-17 03:02:26 PST
https://hg.mozilla.org/mozilla-central/rev/14b8a98aff19
Comment 26 Louis Christie [:lchristie] 2016-01-17 19:02:12 PST
*** Bug 1074141 has been marked as a duplicate of this bug. ***

Note You need to log in before you can comment on or make changes to this bug.