Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File decoding fails #143

Closed
eustas opened this issue Jun 1, 2023 · 0 comments
Closed

File decoding fails #143

eustas opened this issue Jun 1, 2023 · 0 comments

Comments

@eustas
Copy link
Contributor

eustas commented Jun 1, 2023

Tried sample4.aac from https://filesamples.com/formats/aac
Decoder returns Scalefactor out of range (error code 4).
This happens because in the given file "intensity" scale factor is sometimes negative. Overall it ranges -3..4.
Capping to non-negative values results in decoding success. Waveform looks similar to produced with other decoder.

Looking at code, delta applied to each next scale_factor is -60..60. Logically, if we want to have all possibilities for next value, then scale factor range width should be 60. But is it -30..30 or 0..60? Will try to find an answer in internet...

eustas added a commit to eustas/faad2 that referenced this issue Jun 2, 2023
"intensity" and "noise" scale_factors have different meaning.
Removed checks at parsing time and added capping at processing.
eustas added a commit to eustas/faad2 that referenced this issue Jun 5, 2023
In earlier changelist, following the comments on scale_factor
field I've "unified" checking of scale_factor for all 3 major cases.
That was a mistake. Some files stopped decoding failing exactly
at point where scale_factor is checked.

There are 3 types of scale_factor: "quant", "intensity" and "noise".

"intensity" and "noise" scale_factors have different meaning.
Removed checks at parsing time for them and added capping at processing.

"noise" scale_factor stands for magnitude of generated signal.
Large negative factor means inaudible noise. On encoder side
(e.g. in FAAC) it is even replaced with "silence" after some threshold
(MSE < 0.4, it renders to exp ~= -6).
Large positive factor means "loud" noise. Again too-big values simply
does not fit output format.
Same reasoning applies to floating point calculations.
For floating point noise scale factor is capped with [-120,120] range,
i.e. scale is (9.3e-10,1.7e+9)
For fixed poind noise scale factor is capped with [-60,60].

"intensity" stands for "joint stereo". In FAAC encoder if
the difference between scale_factor is 30 or more, the quieter channel
is encoded as silence. I.e. if difference in power more than 180
that feels like there is only one audio source.
Given that same cap is applied to "intensity" scale_factor.

Moreover, for "quant" scale_factor limit is 0..255 with an offset of 100,
i.e. it is -100..155; close enough to the new limits for other two
scale_factor.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant