diff options
author | Chris Robinson <[email protected]> | 2021-04-11 17:09:52 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2021-04-11 17:09:52 -0700 |
commit | f403fbd2e949ae296897eb2d7e9984da53d2de42 (patch) | |
tree | 3706b027728b5482e50953629e72685bc0f4c634 /utils/uhjdecoder.cpp | |
parent | 4af6cfac7d1dab526526684089ee3c5439874feb (diff) |
Fix UHJ encoding/decoding factors
Classic B-Format uses scaling factors W=1, X=sqrt(2), Y=sqrt(2), and Z=sqrt(2),
which is +3dB louder than FuMa. The base factors are designed assuming classic
scaling, so encoding a 0dBFS FuMa signal without accounting for this would
result in the UHJ signal peaking at about -3dBFS. Similarly, decoding UHJ to
FuMa B-Format would be +3dB louder than intended.
So encoding needs to implicitly boost the signal by +3dB, and decoding needs to
attenuate by -3dB.
Diffstat (limited to 'utils/uhjdecoder.cpp')
-rw-r--r-- | utils/uhjdecoder.cpp | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/utils/uhjdecoder.cpp b/utils/uhjdecoder.cpp index f9db4895..cda16a40 100644 --- a/utils/uhjdecoder.cpp +++ b/utils/uhjdecoder.cpp @@ -492,8 +492,10 @@ int main(int argc, char **argv) decoder->decode2(inmem.get(), decmem, got); for(size_t i{0};i < got;++i) { + /* Attenuate by -3dB for FuMa output levels. */ + constexpr float sqrt1_2{0.707106781187f}; for(size_t j{0};j < outchans;++j) - outmem[i*outchans + j] = f32AsLEBytes(decmem[j][i]); + outmem[i*outchans + j] = f32AsLEBytes(decmem[j][i] * sqrt1_2); } size_t wrote{fwrite(outmem.get(), sizeof(byte4)*outchans, got, outfile.get())}; |