Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#5727 closed defect (fixed)

HDCD should not apply gain unless the values match in both channels

Reported by: bp0 Owned by:
Priority: normal Component: avfilter
Version: git-master Keywords: hdcd
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no


The HDCD filter should not apply gain to a channel unless both channels have a matching target gain decoded from a valid packet.

Using the attached sample with ffmpeg 3.1+

% ffmpeg -i ava16.flac -af hdcd ava24.flac

The sample is from The Avalanches - [2000] Since I Left You, about 17m40s from the beginning of the CD. This is not an HDCD encoded sample, but by coincidence has a sequence that is a valid HDCD packet in one channel. That channel will drop 6dB for 10 seconds after passing through the filter, when it should not.

From a paper by Kieth Johnson, the designer of the original HDCD encoder chip:

The arrival of a valid packet for a channel resets a code detect timer for that channel. If both channels have active timers, then code is deemed to be present and the filter select data is considered valid immediately. However, any command data which would effect the level of the signal must match between the two channels in order to take effect. The primary reason for this is to handle the case where an error on one channel destroys the code. In such a case, the decoder will mistrack for a short time until the next command comes along, which is much less audible than a change in gain on only one channel, causing a shift in balance and lateral image movement. If either of the code detect timers times out, then code is deemed not to be present, and all commands are canceled, returning the decode system to its default state. If the conditions on the encoder side are not changing, then command packets are inserted on a regular basis to keep the code detect timers in the decoder active and to update the decoder if one starts playing a selection in the middle of a continuous recording.

The HDCD filter in ffmpeg, and the fb2k plugin that it is based on, decode HDCD in each channel separately. The code detect timer is implemented, which is why the error only lasts for 10 seconds. Decoding the channels separately, however, prevents it from knowing the gain value for the other channel, and this would have to be changed to fix this bug.

Attachments (1)

ava16.flac (2.5 MB) - added by bp0 4 years ago.
The Avalanches - [2000] Since I Left You @17:40, 20 second sample

Change History (6)

Changed 4 years ago by bp0

The Avalanches - [2000] Since I Left You @17:40, 20 second sample

comment:1 Changed 4 years ago by cehoyos

  • Keywords hdcd added

comment:2 Changed 4 years ago by bp0

Apologies for spelling Keith Johnson's name wrong.

comment:4 Changed 4 years ago by bp0

  • Resolution set to fixed
  • Status changed from new to closed

comment:5 Changed 4 years ago by bp0

This also fixes the 1998 Depeche Mode tribute album "For the Masses", which for some reason has -4.0db gain adjust throughout, but in one channel only. Now LLE will be ignored, but PE will still be used.

Note: See TracTickets for help on using tickets.