Flac has -6dB gain in mixxx 2.1.0

Bug #1766042 reported by Jamie Gifford
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Mixxx
High
Jamie Gifford

Bug Description

In Mixxx 2.1.0, FLAC files are decoded with a -6dB gain. Tested on Linux and Mac.

The problem is reproducible always. Eg, create a 440Hz full-scale sine in both WAV and FLAC formats with "sox -r 44100 -n a440.wav synth 20 sine 440" and "sox -r 44100 -n a440.flac synth 20 sine 440". The WAV file plays correctly; the FLAC file will play at -6dB.

Looks to me that the problem is in soundsourceflac.cpp, in void SoundSourceFLAC::flacMetadata(const FLAC__StreamMetadata* metadata), in the code:

m_sampleScaleFactor = CSAMPLE_PEAK
                    / CSAMPLE(FLAC__int32(1) << bitsPerSample);

Since FLAC samples are signed, a FLAC full-scale sample will only reach bitsPerSample-1, not bitsPerSample (eg, in a 24 bit stream the maximum sample magnitude would be 1<<23). This means that m_sampleScaleFactor is out by a factor of two, hence -6dB.

I think the code should read

m_sampleScaleFactor = CSAMPLE_PEAK
                    / CSAMPLE(FLAC__int32(1) << (bitsPerSample - 1));

Revision history for this message
Sean M. Pappalardo (pegasus-renegadetech) wrote :

I /thought/ my FLAC files sounded quieter! Thank you very much for the detailed analysis! (Do you use GitHub and want to make a pull request so you get credit in the commit history?)

Changed in mixxx:
status: New → Confirmed
Revision history for this message
Jamie Gifford (jamie.gifford) wrote :

Pull request sent...

Uwe Klotz (uklotzde)
Changed in mixxx:
assignee: nobody → Jamie Gifford (jamie.gifford)
status: Confirmed → In Progress
importance: Undecided → High
milestone: none → 2.1.1
Revision history for this message
Uwe Klotz (uklotzde) wrote :
Uwe Klotz (uklotzde)
Changed in mixxx:
status: In Progress → Fix Committed
Changed in mixxx:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers