diff --git a/libavcodec/aac_tablegen.c b/libavcodec/aac_tablegen.c index de1c9578a7..33a179f51e 100644 --- a/libavcodec/aac_tablegen.c +++ b/libavcodec/aac_tablegen.c @@ -31,9 +31,7 @@ int main(void) write_fileheader(); - printf("const float ff_aac_pow2sf_tab[428] = {\n"); - write_float_array(ff_aac_pow2sf_tab, 428); - printf("};\n"); + WRITE_ARRAY("const", float, ff_aac_pow2sf_tab); return 0; } diff --git a/libavcodec/cbrt_tablegen.c b/libavcodec/cbrt_tablegen.c index 5cbceb247c..e0a8e63a8b 100644 --- a/libavcodec/cbrt_tablegen.c +++ b/libavcodec/cbrt_tablegen.c @@ -31,9 +31,7 @@ int main(void) write_fileheader(); - printf("static const uint32_t cbrt_tab[1<<13] = {\n"); - write_uint32_t_array(cbrt_tab, 1 << 13); - printf("};\n"); + WRITE_ARRAY("static const", uint32_t, cbrt_tab); return 0; } diff --git a/libavcodec/mpegaudio_tablegen.c b/libavcodec/mpegaudio_tablegen.c index 57e239c166..0888e78620 100644 --- a/libavcodec/mpegaudio_tablegen.c +++ b/libavcodec/mpegaudio_tablegen.c @@ -31,29 +31,12 @@ int main(void) write_fileheader(); - printf("static const int8_t table_4_3_exp[TABLE_4_3_SIZE] = {\n"); - write_int8_t_array(table_4_3_exp, TABLE_4_3_SIZE); - printf("};\n"); - - printf("static const uint32_t table_4_3_value[TABLE_4_3_SIZE] = {\n"); - write_uint32_t_array(table_4_3_value, TABLE_4_3_SIZE); - printf("};\n"); - - printf("static const uint32_t exp_table[512] = {\n"); - write_uint32_t_array(exp_table, 512); - printf("};\n"); - - printf("static const float exp_table_float[512] = {\n"); - write_float_array(exp_table_float, 512); - printf("};\n"); - - printf("static const uint32_t expval_table[512][16] = {\n"); - write_uint32_t_2d_array(expval_table, 512, 16); - printf("};\n"); - - printf("static const float expval_table_float[512][16] = {\n"); - write_float_2d_array(expval_table_float, 512, 16); - printf("};\n"); + WRITE_ARRAY("static const", int8_t, table_4_3_exp); + WRITE_ARRAY("static const", uint32_t, table_4_3_value); + WRITE_ARRAY("static const", uint32_t, exp_table); + WRITE_ARRAY("static const", float, exp_table_float); + WRITE_2D_ARRAY("static const", uint32_t, expval_table); + WRITE_2D_ARRAY("static const", float, expval_table_float); return 0; } diff --git a/libavcodec/pcm_tablegen.c b/libavcodec/pcm_tablegen.c index 13b33ddefc..b0fde936c7 100644 --- a/libavcodec/pcm_tablegen.c +++ b/libavcodec/pcm_tablegen.c @@ -32,13 +32,8 @@ int main(void) write_fileheader(); - printf("static const uint8_t linear_to_alaw[1 << 14] = {\n"); - write_uint8_t_array(linear_to_alaw, 1 << 14); - printf("};\n"); - - printf("static const uint8_t linear_to_ulaw[1 << 14] = {\n"); - write_uint8_t_array(linear_to_ulaw, 1 << 14); - printf("};\n"); + WRITE_ARRAY("static const", uint8_t, linear_to_alaw); + WRITE_ARRAY("static const", uint8_t, linear_to_ulaw); return 0; } diff --git a/libavcodec/qdm2_tablegen.c b/libavcodec/qdm2_tablegen.c index d11599b6dd..a7a9fb6643 100644 --- a/libavcodec/qdm2_tablegen.c +++ b/libavcodec/qdm2_tablegen.c @@ -33,25 +33,12 @@ int main(void) write_fileheader(); - printf("static const uint16_t softclip_table[HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD + 1] = {\n"); - write_uint16_t_array(softclip_table, HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD + 1); - printf("};\n"); + WRITE_ARRAY("static const", uint16_t, softclip_table); + WRITE_ARRAY("static const", float, noise_table); + WRITE_ARRAY("static const", float, noise_samples); - printf("static const float noise_table[4096] = {\n"); - write_float_array(noise_table, 4096); - printf("};\n"); - - printf("static const uint8_t random_dequant_index[256][5] = {\n"); - write_uint8_t_2d_array(random_dequant_index, 256, 5); - printf("};\n"); - - printf("static const uint8_t random_dequant_type24[128][3] = {\n"); - write_uint8_t_2d_array(random_dequant_type24, 128, 3); - printf("};\n"); - - printf("static const float noise_samples[128] = {\n"); - write_float_array(noise_samples, 128); - printf("};\n"); + WRITE_2D_ARRAY("static const", uint8_t, random_dequant_index); + WRITE_2D_ARRAY("static const", uint8_t, random_dequant_type24); return 0; } diff --git a/libavcodec/tableprint.h b/libavcodec/tableprint.h index 849bccf78e..97a667db33 100644 --- a/libavcodec/tableprint.h +++ b/libavcodec/tableprint.h @@ -25,6 +25,7 @@ #include #include +#include "libavutil/common.h" #define WRITE_1D_FUNC_ARGV(type, linebrk, fmtstr, ...)\ void write_##type##_array(const type *data, int len)\ @@ -72,4 +73,23 @@ void write_float_2d_array (const void *, int, int); /** Write a standard file header */ void write_fileheader(void); +#define WRITE_ARRAY(prefix, type, name) \ + do { \ + const size_t array_size = FF_ARRAY_ELEMS(name); \ + printf(prefix" "#type" "#name"[%zu] = {\n", \ + array_size); \ + write_##type##_array(name, array_size); \ + printf("};\n"); \ + } while(0) + +#define WRITE_2D_ARRAY(prefix, type, name) \ + do { \ + const size_t array_size1 = FF_ARRAY_ELEMS(name); \ + const size_t array_size2 = FF_ARRAY_ELEMS(name[0]); \ + printf(prefix" "#type" "#name"[%zu][%zu] = {\n", \ + array_size1, array_size2 ); \ + write_##type##_2d_array(name, array_size1, array_size2); \ + printf("};\n"); \ + } while(0) + #endif /* AVCODEC_TABLEPRINT_H */