audiocogs / mp3.js

A JavaScript MP3 decoder for Aurora.js
http://audiocogs.org/codecs/mp3
263 stars 45 forks source link

Saner error reporting #10

Open ghost opened 10 years ago

ghost commented 10 years ago

Listening for the error event when decoding an MP3 Asset often reports bad main_data_begin pointer or Huffman data overrun errors. Contrary to the Asset class documentation, the decoding process finishes afterwards, apparently successfully. Errors of the type UnderflowError and Error: Invalid layer, however, are thrown as simple exceptions - and being thrown asynchronously, they are impossible for client code to catch. It'd be useful if they were reported through the error event, with the less fatal errors being perhaps moved to a warning event.

ghost commented 10 years ago

Bumping this issue in case @audiocogs didn't get a notification when I created it (my account was flagged as a robot at the time, and thus rendered invisible to other users.)

NekR commented 8 years ago

So what actually means bad main_data_begin pointer error?

DeusExLibris commented 8 years ago

Answering this so that others looking for an answer might find it in the future.

The main_data_begin value is part of the "side information" of every MP3 frame. It follows the frame header (or the CRC if used) and points to the location of the data to be decoded in the bit reservoir (that is, a pointer into the data area of previous frames where the decoder should start decoding).

The "bad main_data_begin" error means that the main_data_begin pointer references a frame that doesn't exist. I have encountered it when I take a live stream and start decoding in the middle of the stream. If the bit reservoir is enabled, the main_data_begin pointer could point to frames that weren't received since they occurred before the player started.