FFmpeg
Loading...
Searching...
No Matches
ac3.c
Go to the documentation of this file.
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#include <inttypes.h>
20#include <stdio.h>
21#include <string.h>
22
23#include "libavutil/crc.h"
25#include "libavutil/lfg.h"
26#include "libavutil/macros.h"
27#include "libavcodec/ac3.h"
28#include "libavcodec/ac3dsp.h"
29#include "libavcodec/ac3tab.h"
30
31static uint32_t hash_int16(const AVCRC *crc, uint32_t hash,
32 const int16_t *data, int count)
33{
34 uint8_t bytes[2 * AC3_MAX_COEFS];
35
36 for (int i = 0; i < count; i++)
37 AV_WL16(bytes + 2 * i, data[i]);
38 return av_crc(crc, hash, bytes, 2 * count);
39}
40
41int main(void)
42{
43 static const int ends[] = { 7, 27, 28, 29, 37, 73, 133, 229, 253 };
44 static const int offsets[] = { -960, -959, 0, 1024, 3132 };
46 int8_t exp[AC3_MAX_COEFS];
47 int16_t psd[AC3_MAX_COEFS], band_psd[AC3_CRITICAL_BANDS];
48 int16_t mask[AC3_CRITICAL_BANDS];
49 uint8_t bap[AC3_MAX_COEFS];
50 AC3DSPContext dsp;
51 AVLFG lfg;
52
53 ff_ac3dsp_init(&dsp);
54 av_lfg_init(&lfg, 1);
55 for (int i = 0; i < AC3_CRITICAL_BANDS; i++)
56 mask[i] = av_lfg_get(&lfg) % 3073;
57
58 for (int pattern = 0; pattern < 4; pattern++) {
59 uint32_t psd_hash = 0, bap_hash = 0;
60
61 for (int i = 0; i < AC3_MAX_COEFS; i++)
62 exp[i] = pattern == 0 ? 0 : pattern == 1 ? 24 :
63 pattern == 2 ? (i & 1) * 24 : av_lfg_get(&lfg) % 25;
64
65 for (int start = 0; start < 253; start++) {
66 for (int j = 0; j <= FF_ARRAY_ELEMS(ends); j++) {
67 int end = j ? ends[j - 1] : start + 1;
68
69 if (start >= end)
70 continue;
71 memset(psd, 0x5a, sizeof(psd));
72 memset(band_psd, 0x5a, sizeof(band_psd));
73 ff_ac3_bit_alloc_calc_psd(exp, start, end, psd, band_psd);
74 psd_hash = hash_int16(crc, psd_hash, psd, AC3_MAX_COEFS);
75 psd_hash = hash_int16(crc, psd_hash, band_psd, AC3_CRITICAL_BANDS);
76
77 for (int floor = 0; floor < 8; floor++) {
78 for (int k = 0; k < FF_ARRAY_ELEMS(offsets); k++) {
79 memset(bap, 0x5a, sizeof(bap));
80 dsp.bit_alloc_calc_bap(mask, psd, start, end,
82 ff_ac3_bap_tab, bap);
83 bap_hash = av_crc(crc, bap_hash, bap, sizeof(bap));
84 }
85 }
86 }
87 }
88 printf("pattern %d: psd %08"PRIx32" bap %08"PRIx32"\n",
89 pattern, psd_hash, bap_hash);
90 }
91 return 0;
92}
void ff_ac3_bit_alloc_calc_psd(int8_t *exp, int start, int end, int16_t *psd, int16_t *band_psd)
Calculate the log power-spectral density of the input signal.
Definition ac3.c:175
Common code between the AC-3 encoder and decoder.
#define AC3_CRITICAL_BANDS
Definition ac3defs.h:34
#define AC3_MAX_COEFS
Definition ac3defs.h:29
const int16_t ff_ac3_floor_tab[8]
Definition ac3tab.c:143
const uint8_t ff_ac3_bap_tab[64]
Definition ac3tab.c:117
static uint8_t hash[HASH_SIZE]
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
Public header for CRC hash function implementation.
__device__ int printf(const char *,...)
static __device__ float floor(float a)
int8_t exp
Definition eval.c:76
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
Definition crc.c:389
uint32_t AVCRC
Definition crc.h:46
uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length)
Calculate the CRC of a block.
Definition crc.c:421
@ AV_CRC_32_IEEE
Definition crc.h:52
static const int offsets[]
Definition hevc_pel.c:34
#define AV_WL16(p, v)
av_cold void av_lfg_init(AVLFG *c, unsigned int seed)
Definition lfg.c:32
static unsigned int av_lfg_get(AVLFG *c)
Get the next random unsigned 32-bit number using an ALFG.
Definition lfg.h:53
av_cold void ff_ac3dsp_init(AC3DSPContext *c)
Definition ac3dsp.c:385
static const uint16_t mask[17]
Definition lzw.c:38
Utility Preprocessor macros.
const char data[16]
Definition mxf.c:149
#define FF_ARRAY_ELEMS(a)
void(* bit_alloc_calc_bap)(int16_t *mask, int16_t *psd, int start, int end, int snr_offset, int floor, const uint8_t *bap_tab, uint8_t *bap)
Calculate bit allocation pointers.
Definition ac3dsp.h:74
Context structure for the Lagged Fibonacci PRNG.
Definition lfg.h:33
int main(void)
Definition ac3.c:41
static uint32_t hash_int16(const AVCRC *crc, uint32_t hash, const int16_t *data, int count)
Definition ac3.c:31