History

avcodec/ac3{dec,enc}: Deduplicate gain levels table

(I don't know why the encoder only uses eight of the nine values.)

Andreas Rheinhardt committed 1 year ago

Commit dbd2ca31 parent 11723b34 files · +32 −28Browse files

Unified · Split

4 files
  1. libavcodec/ac3dec.c +12 −24
  2. libavcodec/ac3enc.c +1 −4
  3. libavcodec/ac3tab.c +14 −0
  4. libavcodec/ac3tab.h +5 −0
libavcodec/ac3dec.c+12−24
@@ -61,18 +61,6 @@ static float dynamic_range_tab[256]; · 60 unmodified lines
6161 float ff_ac3_heavy_dynamic_range_tab[256];
6262 #endif
6363
64−/** Adjustments in dB gain */
65−static const float gain_levels[9] = {
66− LEVEL_PLUS_3DB,
67− LEVEL_PLUS_1POINT5DB,
68− LEVEL_ONE,
69− LEVEL_MINUS_1POINT5DB,
70− LEVEL_MINUS_3DB,
71− LEVEL_MINUS_4POINT5DB,
72− LEVEL_MINUS_6DB,
73− LEVEL_ZERO,
74− LEVEL_MINUS_9DB
75−};
7664
7765 /** Adjustments in dB gain (LFE, +10 to -21 dB) */
7866 static const float gain_levels_lfe[32] = {
@@ -346,8 +334,8 @@ static int parse_frame_header(AC3DecodeContext *s) · 267 unmodified lines
346334 static int set_downmix_coeffs(AC3DecodeContext *s)
347335 {
348336 int i;
349− float cmix = gain_levels[s-> center_mix_level];
350− float smix = gain_levels[s->surround_mix_level];
337+ float cmix = ff_ac3_gain_levels[s-> center_mix_level];
338+ float smix = ff_ac3_gain_levels[s->surround_mix_level];
351339 float norm0, norm1;
352340 float downmix_coeffs[2][AC3_MAX_CHANNELS];
353341
@@ -360,8 +348,8 @@ static int set_downmix_coeffs(AC3DecodeContext *s) · 6 unmodified lines
360348 }
361349
362350 for (i = 0; i < s->fbw_channels; i++) {
363− downmix_coeffs[0][i] = gain_levels[ac3_default_coeffs[s->channel_mode][i][0]];
364− downmix_coeffs[1][i] = gain_levels[ac3_default_coeffs[s->channel_mode][i][1]];
351+ downmix_coeffs[0][i] = ff_ac3_gain_levels[ac3_default_coeffs[s->channel_mode][i][0]];
352+ downmix_coeffs[1][i] = ff_ac3_gain_levels[ac3_default_coeffs[s->channel_mode][i][1]];
365353 }
366354 if (s->channel_mode > 1 && s->channel_mode & 1) {
367355 downmix_coeffs[0][1] = downmix_coeffs[1][1] = cmix;
@@ -1562,10 +1550,10 @@ dependent_frame: · 1194 unmodified lines
15621550 s->output_mode = AC3_CHMODE_STEREO;
15631551 }
15641552
1565− s->loro_center_mix_level = gain_levels[s-> center_mix_level];
1566− s->loro_surround_mix_level = gain_levels[s->surround_mix_level];
1567− s->ltrt_center_mix_level = gain_levels[s-> center_mix_level_ltrt];
1568− s->ltrt_surround_mix_level = gain_levels[s->surround_mix_level_ltrt];
1553+ s->loro_center_mix_level = ff_ac3_gain_levels[s-> center_mix_level];
1554+ s->loro_surround_mix_level = ff_ac3_gain_levels[s->surround_mix_level];
1555+ s->ltrt_center_mix_level = ff_ac3_gain_levels[s-> center_mix_level_ltrt];
1556+ s->ltrt_surround_mix_level = ff_ac3_gain_levels[s->surround_mix_level_ltrt];
15691557 switch (s->preferred_downmix) {
15701558 case AC3_DMIXMOD_LTRT:
15711559 s->preferred_stereo_downmix = AV_DOWNMIX_TYPE_LTRT;
@@ -1804,10 +1792,10 @@ skip: · 232 unmodified lines
18041792 downmix_info->preferred_downmix_type = AV_DOWNMIX_TYPE_UNKNOWN;
18051793 break;
18061794 }
1807− downmix_info->center_mix_level = gain_levels[s-> center_mix_level];
1808− downmix_info->center_mix_level_ltrt = gain_levels[s-> center_mix_level_ltrt];
1809− downmix_info->surround_mix_level = gain_levels[s-> surround_mix_level];
1810− downmix_info->surround_mix_level_ltrt = gain_levels[s->surround_mix_level_ltrt];
1795+ downmix_info->center_mix_level = ff_ac3_gain_levels[s-> center_mix_level];
1796+ downmix_info->center_mix_level_ltrt = ff_ac3_gain_levels[s-> center_mix_level_ltrt];
1797+ downmix_info->surround_mix_level = ff_ac3_gain_levels[s-> surround_mix_level];
1798+ downmix_info->surround_mix_level_ltrt = ff_ac3_gain_levels[s->surround_mix_level_ltrt];
18111799 if (s->lfe_mix_level_exists)
18121800 downmix_info->lfe_mix_level = gain_levels_lfe[s->lfe_mix_level];
18131801 else
libavcodec/ac3enc.c+1−4
@@ -71,10 +71,7 @@ static const float surmixlev_options[SURMIXLEV_NUM_OPTIONS] = { · 70 unmodified lines
7171 };
7272
7373 #define EXTMIXLEV_NUM_OPTIONS 8
74−static const float extmixlev_options[EXTMIXLEV_NUM_OPTIONS] = {
75− LEVEL_PLUS_3DB, LEVEL_PLUS_1POINT5DB, LEVEL_ONE, LEVEL_MINUS_1POINT5DB,
76− LEVEL_MINUS_3DB, LEVEL_MINUS_4POINT5DB, LEVEL_MINUS_6DB, LEVEL_ZERO
77−};
74+#define extmixlev_options ff_ac3_gain_levels
7875
7976 /* The first two options apply only to the AC-3 encoders;
8077 * the rest is also valid for EAC-3. When modifying it,
libavcodec/ac3tab.c+14−0
@@ -25,6 +25,7 @@ · 24 unmodified lines
2525 */
2626
2727 #include "libavutil/channel_layout.h"
28+#include "libavutil/mathematics.h"
2829
2930 #include "ac3tab.h"
3031
@@ -147,6 +148,19 @@ const uint16_t ff_ac3_fast_gain_tab[8]= { · 116 unmodified lines
147148 0x080, 0x100, 0x180, 0x200, 0x280, 0x300, 0x380, 0x400,
148149 };
149150
151+/** Adjustments in dB gain */
152+const float ff_ac3_gain_levels[9] = {
153+ LEVEL_PLUS_3DB,
154+ LEVEL_PLUS_1POINT5DB,
155+ LEVEL_ONE,
156+ LEVEL_MINUS_1POINT5DB,
157+ LEVEL_MINUS_3DB,
158+ LEVEL_MINUS_4POINT5DB,
159+ LEVEL_MINUS_6DB,
160+ LEVEL_ZERO,
161+ LEVEL_MINUS_9DB
162+};
163+
150164 const uint64_t ff_eac3_custom_channel_map_locations[16][2] = {
151165 { 1, AV_CH_FRONT_LEFT },
152166 { 1, AV_CH_FRONT_CENTER },
libavcodec/ac3tab.h+5−0
@@ -26,6 +26,9 @@ · 25 unmodified lines
2626
2727 #include "ac3defs.h"
2828
29+#include "libavutil/attributes_internal.h"
30+
31+FF_VISIBILITY_PUSH_HIDDEN
2932 extern const uint16_t ff_ac3_frame_size_tab[38][3];
3033 extern const uint8_t ff_ac3_channels_tab[8];
3134 extern const uint16_t ff_ac3_channel_layout_tab[8];
@@ -43,7 +46,9 @@ extern const int16_t ff_ac3_floor_tab[8]; · 11 unmodified lines
4346 extern const uint16_t ff_ac3_fast_gain_tab[8];
4447 extern const uint8_t ff_ac3_band_start_tab[AC3_CRITICAL_BANDS+1];
4548 extern const uint8_t ff_ac3_bin_to_band_tab[253];
49+extern const float ff_ac3_gain_levels[9];
4650 extern const uint64_t ff_eac3_custom_channel_map_locations[16][2];
51+FF_VISIBILITY_POP_HIDDEN
4752
4853 #define COMMON_CHANNEL_MAP \
4954 { { 0, 1, }, { 0, 1, 2, } },\

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t