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
61float ff_ac3_heavy_dynamic_range_tab[256];61float ff_ac3_heavy_dynamic_range_tab[256];
62#endif62#endif
63 63
64/** Adjustments in dB gain */
65static 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};
76 64
77/** Adjustments in dB gain (LFE, +10 to -21 dB) */65/** Adjustments in dB gain (LFE, +10 to -21 dB) */
78static const float gain_levels_lfe[32] = {66static const float gain_levels_lfe[32] = {
@@ -346,8 +334,8 @@ static int parse_frame_header(AC3DecodeContext *s) · 267 unmodified lines
346static int set_downmix_coeffs(AC3DecodeContext *s)334static int set_downmix_coeffs(AC3DecodeContext *s)
347{335{
348 int i;336 int i;
349 float cmix = gain_levels[s-> center_mix_level];337 float cmix = ff_ac3_gain_levels[s-> center_mix_level];
350 float smix = gain_levels[s->surround_mix_level];338 float smix = ff_ac3_gain_levels[s->surround_mix_level];
351 float norm0, norm1;339 float norm0, norm1;
352 float downmix_coeffs[2][AC3_MAX_CHANNELS];340 float downmix_coeffs[2][AC3_MAX_CHANNELS];
353 341
@@ -360,8 +348,8 @@ static int set_downmix_coeffs(AC3DecodeContext *s) · 6 unmodified lines
360 }348 }
361 349
362 for (i = 0; i < s->fbw_channels; i++) {350 for (i = 0; i < s->fbw_channels; i++) {
363 downmix_coeffs[0][i] = gain_levels[ac3_default_coeffs[s->channel_mode][i][0]];351 downmix_coeffs[0][i] = ff_ac3_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]];352 downmix_coeffs[1][i] = ff_ac3_gain_levels[ac3_default_coeffs[s->channel_mode][i][1]];
365 }353 }
366 if (s->channel_mode > 1 && s->channel_mode & 1) {354 if (s->channel_mode > 1 && s->channel_mode & 1) {
367 downmix_coeffs[0][1] = downmix_coeffs[1][1] = cmix;355 downmix_coeffs[0][1] = downmix_coeffs[1][1] = cmix;
@@ -1562,10 +1550,10 @@ dependent_frame: · 1194 unmodified lines
1562 s->output_mode = AC3_CHMODE_STEREO;1550 s->output_mode = AC3_CHMODE_STEREO;
1563 }1551 }
1564 1552
1565 s->loro_center_mix_level = gain_levels[s-> center_mix_level];1553 s->loro_center_mix_level = ff_ac3_gain_levels[s-> center_mix_level];
1566 s->loro_surround_mix_level = gain_levels[s->surround_mix_level];1554 s->loro_surround_mix_level = ff_ac3_gain_levels[s->surround_mix_level];
1567 s->ltrt_center_mix_level = gain_levels[s-> center_mix_level_ltrt];1555 s->ltrt_center_mix_level = ff_ac3_gain_levels[s-> center_mix_level_ltrt];
1568 s->ltrt_surround_mix_level = gain_levels[s->surround_mix_level_ltrt];1556 s->ltrt_surround_mix_level = ff_ac3_gain_levels[s->surround_mix_level_ltrt];
1569 switch (s->preferred_downmix) {1557 switch (s->preferred_downmix) {
1570 case AC3_DMIXMOD_LTRT:1558 case AC3_DMIXMOD_LTRT:
1571 s->preferred_stereo_downmix = AV_DOWNMIX_TYPE_LTRT;1559 s->preferred_stereo_downmix = AV_DOWNMIX_TYPE_LTRT;
@@ -1804,10 +1792,10 @@ skip: · 232 unmodified lines
1804 downmix_info->preferred_downmix_type = AV_DOWNMIX_TYPE_UNKNOWN;1792 downmix_info->preferred_downmix_type = AV_DOWNMIX_TYPE_UNKNOWN;
1805 break;1793 break;
1806 }1794 }
1807 downmix_info->center_mix_level = gain_levels[s-> center_mix_level];1795 downmix_info->center_mix_level = ff_ac3_gain_levels[s-> center_mix_level];
1808 downmix_info->center_mix_level_ltrt = gain_levels[s-> center_mix_level_ltrt];1796 downmix_info->center_mix_level_ltrt = ff_ac3_gain_levels[s-> center_mix_level_ltrt];
1809 downmix_info->surround_mix_level = gain_levels[s-> surround_mix_level];1797 downmix_info->surround_mix_level = ff_ac3_gain_levels[s-> surround_mix_level];
1810 downmix_info->surround_mix_level_ltrt = gain_levels[s->surround_mix_level_ltrt];1798 downmix_info->surround_mix_level_ltrt = ff_ac3_gain_levels[s->surround_mix_level_ltrt];
1811 if (s->lfe_mix_level_exists)1799 if (s->lfe_mix_level_exists)
1812 downmix_info->lfe_mix_level = gain_levels_lfe[s->lfe_mix_level];1800 downmix_info->lfe_mix_level = gain_levels_lfe[s->lfe_mix_level];
1813 else1801 else
libavcodec/ac3enc.c+1−4
@@ -71,10 +71,7 @@ static const float surmixlev_options[SURMIXLEV_NUM_OPTIONS] = { · 70 unmodified lines
71};71};
72 72
73#define EXTMIXLEV_NUM_OPTIONS 873#define EXTMIXLEV_NUM_OPTIONS 8
74static const float extmixlev_options[EXTMIXLEV_NUM_OPTIONS] = {74#define extmixlev_options ff_ac3_gain_levels
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};
78 75
79/* The first two options apply only to the AC-3 encoders;76/* The first two options apply only to the AC-3 encoders;
80 * the rest is also valid for EAC-3. When modifying it,77 * the rest is also valid for EAC-3. When modifying it,
libavcodec/ac3tab.c+14−0
@@ -25,6 +25,7 @@ · 24 unmodified lines
25 */25 */
26 26
27#include "libavutil/channel_layout.h"27#include "libavutil/channel_layout.h"
28#include "libavutil/mathematics.h"
28 29
29#include "ac3tab.h"30#include "ac3tab.h"
30 31
@@ -147,6 +148,19 @@ const uint16_t ff_ac3_fast_gain_tab[8]= { · 116 unmodified lines
147 0x080, 0x100, 0x180, 0x200, 0x280, 0x300, 0x380, 0x400,148 0x080, 0x100, 0x180, 0x200, 0x280, 0x300, 0x380, 0x400,
148};149};
149 150
151/** Adjustments in dB gain */
152const 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
150const uint64_t ff_eac3_custom_channel_map_locations[16][2] = {164const uint64_t ff_eac3_custom_channel_map_locations[16][2] = {
151 { 1, AV_CH_FRONT_LEFT },165 { 1, AV_CH_FRONT_LEFT },
152 { 1, AV_CH_FRONT_CENTER },166 { 1, AV_CH_FRONT_CENTER },
libavcodec/ac3tab.h+5−0
@@ -26,6 +26,9 @@ · 25 unmodified lines
26 26
27#include "ac3defs.h"27#include "ac3defs.h"
28 28
29#include "libavutil/attributes_internal.h"
30
31FF_VISIBILITY_PUSH_HIDDEN
29extern const uint16_t ff_ac3_frame_size_tab[38][3];32extern const uint16_t ff_ac3_frame_size_tab[38][3];
30extern const uint8_t ff_ac3_channels_tab[8];33extern const uint8_t ff_ac3_channels_tab[8];
31extern const uint16_t ff_ac3_channel_layout_tab[8];34extern 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
43extern const uint16_t ff_ac3_fast_gain_tab[8];46extern const uint16_t ff_ac3_fast_gain_tab[8];
44extern const uint8_t ff_ac3_band_start_tab[AC3_CRITICAL_BANDS+1];47extern const uint8_t ff_ac3_band_start_tab[AC3_CRITICAL_BANDS+1];
45extern const uint8_t ff_ac3_bin_to_band_tab[253];48extern const uint8_t ff_ac3_bin_to_band_tab[253];
49extern const float ff_ac3_gain_levels[9];
46extern const uint64_t ff_eac3_custom_channel_map_locations[16][2];50extern const uint64_t ff_eac3_custom_channel_map_locations[16][2];
51FF_VISIBILITY_POP_HIDDEN
47 52
48#define COMMON_CHANNEL_MAP \53#define COMMON_CHANNEL_MAP \
49 { { 0, 1, }, { 0, 1, 2, } },\54 { { 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