cook_fix_all_new.c
来自「君正早期ucos系统(只有早期的才不没有打包成库),MPLAYER,文件系统,图」· C语言 代码 · 共 1,811 行 · 第 1/5 页
C
1,811 行
*/
static inline void
-mlt_compensate_output(COOKContext *q, float *decode_buffer,
- cook_gains *gains, float *previous_buffer,
+mlt_compensate_output(COOKContext *q, REAL_T *decode_buffer,
+ cook_gains *gains, REAL_T *previous_buffer,
int16_t *out, int chan)
{
- float *output = q->mono_mdct_output + q->samples_per_channel;
- int j;
-
imlt_gain(q, decode_buffer, gains, previous_buffer);
-
- /* Clip and convert floats to 16 bits.
- */
- for (j = 0; j < q->samples_per_channel; j++) {
- out[chan + q->nb_channels * j] =
- av_clip(lrintf(output[j]), -32768, 32767);
- }
+ output_math(q, out, chan);
}
@@ -1072,10 +934,6 @@
q->numvector_size = (1 << q->log2_numvector_size);
/* Generate tables */
- init_rootpow2table(q);
- init_pow2table(q);
- init_gain_table(q);
-
if (init_cook_vlc_tables(q) != 0)
return -1;
@@ -1105,8 +963,8 @@
q->gains2.now = q->gain_3;
q->gains2.previous = q->gain_4;
- /* Initialize transform. */
- if ( init_cook_mlt(q) != 0 )
+ /* Initialize fixed/floating point routines. */
+ if (init_cook_math(q) != 0)
return -1;
/* Try to catch some obviously faulty streams, othervise it might be exploitable */
diff -urN svn/libavcodec/cookdata_fixpoint.h fixpoint/libavcodec/cookdata_fixpoint.h
--- svn/libavcodec/cookdata_fixpoint.h 1970-01-01 01:00:00.000000000 +0100
+++ fixpoint/libavcodec/cookdata_fixpoint.h 2007-03-21 13:02:32.000000000 +0100
@@ -0,0 +1,82 @@
+/*
+ * COOK compatible decoder fixed point data types and constants
+ * Copyright (c) 2007 Ian Braithwaite
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+/**
+ * @file cookdata_fixpoint.h
+ * Cook AKA RealAudio G2 compatible decoder
+ * fixed point data types and constants
+ */
+
+#include <stdint.h>
+typedef int32_t FIXP; /* Fixed point variable type */
+typedef uint16_t FIXPU; /* Fixed point fraction 0<=x<1 */
+
+typedef FIXP REAL_T;
+
+
+/**
+ * Additional variables in COOKContext
+ * for fixed point routines
+ */
+typedef struct {
+ /* generatable tables */
+ /**
+ * Sine/cosine table.
+ * x_i = 2^16 sin(i 2pi/8192), 2^16 cos(i 2pi/8192); i=0..1024
+ */
+ FIXPU sincos_lookup[2050];
+} realvars_t;
+
+
+#define cPI1_8 0xec83 /* cos( pi/8) 2^16 */
+#define cPI2_8 0xb505 /* cos(2pi/8) 2^16 */
+#define cPI3_8 0x61f8 /* cos(3pi/8) 2^16 */
+
+
+static const FIXPU pow128_tab[128] = {
+ /* x_i = 2^(15+i/128) */
+ 0x8000, 0x80b2, 0x8165, 0x8219, 0x82ce, 0x8383, 0x843a, 0x84f2, 0x85ab,
+ 0x8665, 0x871f, 0x87db, 0x8898, 0x8956, 0x8a15, 0x8ad5, 0x8b96, 0x8c58,
+ 0x8d1b, 0x8ddf, 0x8ea4, 0x8f6b, 0x9032, 0x90fa, 0x91c4, 0x928e, 0x935a,
+ 0x9427, 0x94f5, 0x95c4, 0x9694, 0x9765, 0x9838, 0x990c, 0x99e0, 0x9ab6,
+ 0x9b8d, 0x9c65, 0x9d3f, 0x9e19, 0x9ef5, 0x9fd2, 0xa0b0, 0xa190, 0xa270,
+ 0xa352, 0xa435, 0xa519, 0xa5ff, 0xa6e6, 0xa7ce, 0xa8b7, 0xa9a1, 0xaa8d,
+ 0xab7a, 0xac69, 0xad58, 0xae49, 0xaf3b, 0xb02f, 0xb124, 0xb21a, 0xb312,
+ 0xb40b, 0xb505, 0xb601, 0xb6fe, 0xb7fc, 0xb8fc, 0xb9fd, 0xbaff, 0xbc03,
+ 0xbd09, 0xbe0f, 0xbf18, 0xc021, 0xc12c, 0xc239, 0xc347, 0xc456, 0xc567,
+ 0xc67a, 0xc78d, 0xc8a3, 0xc9ba, 0xcad2, 0xcbec, 0xcd08, 0xce25, 0xcf43,
+ 0xd063, 0xd185, 0xd2a8, 0xd3cd, 0xd4f3, 0xd61b, 0xd745, 0xd870, 0xd99d,
+ 0xdacc, 0xdbfc, 0xdd2e, 0xde61, 0xdf96, 0xe0cd, 0xe205, 0xe340, 0xe47b,
+ 0xe5b9, 0xe6f8, 0xe839, 0xe97c, 0xeac1, 0xec07, 0xed4f, 0xee99, 0xefe5,
+ 0xf132, 0xf281, 0xf3d3, 0xf525, 0xf67a, 0xf7d1, 0xf929, 0xfa84, 0xfbe0,
+ 0xfd3e, 0xfe9e
+};
+
+
+/* Set up types and include cook data.
+ */
+typedef FIXP Q_t[2];
+#define Q(x) {(FIXP)((float)(x) * (1<<28) + 0.5f), \
+ (FIXP)((float)(x) * (1<<28) * 0.707106781187f + 0.5f)}
+typedef FIXPU C_t;
+#define C(x) (FIXPU)((float)(x) * (1<<16) + 0.5f)
+#include "cookdata.h"
diff -urN svn/libavcodec/cookdata_float.h fixpoint/libavcodec/cookdata_float.h
--- svn/libavcodec/cookdata_float.h 2007-03-21 12:51:50.000000000 +0100
+++ fixpoint/libavcodec/cookdata_float.h 2007-03-21 11:01:58.000000000 +0100
@@ -1,5 +1,5 @@
/*
- * COOK compatible decoder
+ * COOK compatible decoder floating point data types and constants
* Copyright (c) 2003 Sascha Sommer
* Copyright (c) 2005 Benjamin Larsson
*
@@ -22,1126 +22,36 @@
*/
/**
- * @file cook.c
- * Cook compatible decoder.
- * This decoder handles RealNetworks, RealAudio G2 data.
- * Cook is identified by the codec name cook in RM files.
- *
- * To use this decoder, a calling application must supply the extradata
- * bytes provided from the RM container; 8+ bytes for mono streams and
- * 16+ for stereo streams (maybe more).
- *
- * Codec technicalities (all this assume a buffer length of 1024):
- * Cook works with several different techniques to achieve its compression.
- * In the timedomain the buffer is divided into 8 pieces and quantized. If
- * two neighboring pieces have different quantization index a smooth
- * quantization curve is used to get a smooth overlap between the different
- * pieces.
- * To get to the transformdomain Cook uses a modulated lapped transform.
- * The transform domain has 50 subbands with 20 elements each. This
- * means only a maximum of 50*20=1000 coefficients are used out of the 1024
- * available.
+ * @file cookdata_float.h
+ * Cook AKA RealAudio G2 compatible decoder
+ * floating point data types and constants
*/
#include <math.h>
-#include <stddef.h>
-#include <stdio.h>
-
-#include "avcodec.h"
-#include "bitstream.h"
-#include "dsputil.h"
-#include "common.h"
-#include "bytestream.h"
-#include "random.h"
-
-#include "cookdata.h"
-
-/* the different Cook versions */
-#define MONO 0x1000001
-#define STEREO 0x1000002
-#define JOINT_STEREO 0x1000003
-#define MC_COOK 0x2000000 //multichannel Cook, not supported
-
-#define SUBBAND_SIZE 20
-//#define COOKDEBUG
+typedef float REAL_T;
-typedef struct {
- int *now;
- int *previous;
-} cook_gains;
+/**
+ * Additional variables in COOKContext
+ * for floating point routines.
+ */
typedef struct {
- GetBitContext gb;
- /* stream data */
- int nb_channels;
- int joint_stereo;
- int bit_rate;
- int sample_rate;
- int samples_per_channel;
- int samples_per_frame;
- int subbands;
- int log2_numvector_size;
- int numvector_size; //1 << log2_numvector_size;
- int js_subband_start;
- int total_subbands;
- int num_vectors;
- int bits_per_subpacket;
- int cookversion;
- /* states */
- AVRandomState random_state;
-
/* transform data */
MDCTContext mdct_ctx;
DECLARE_ALIGNED_16(FFTSample, mdct_tmp[1024]); /* temporary storage for imlt */
float* mlt_window;
- /* gain buffers */
- cook_gains gains1;
- cook_gains gains2;
- int gain_1[9];
- int gain_2[9];
- int gain_3[9];
- int gain_4[9];
-
- /* VLC data */
- int js_vlc_bits;
- VLC envelope_quant_index[13];
- VLC sqvh[7]; //scalar quantization
- VLC ccpl; //channel coupling
-
- /* generatable tables and related variables */
- int gain_size_factor;
+ /* generatable tables */
float gain_table[23];
float pow2tab[127];
float rootpow2tab[127];
+} realvars_t;
- /* data buffers */
-
- uint8_t* decoded_bytes_buffer;
- DECLARE_ALIGNED_16(float,mono_mdct_output[2048]);
- float mono_previous_buffer1[1024];
- float mono_previous_buffer2[1024];
- float decode_buffer_1[1024];
- float decode_buffer_2[1024];
-} COOKContext;
-
-/* debug functions */
-
-#ifdef COOKDEBUG
-static void dump_float_table(float* table, int size, int delimiter) {
- int i=0;
- av_log(NULL,AV_LOG_ERROR,"\n[%d]: ",i);
- for (i=0 ; i<size ; i++) {
- av_log(NULL, AV_LOG_ERROR, "%5.1f, ", table[i]);
- if ((i+1)%delimiter == 0) av_log(NULL,AV_LOG_ERROR,"\n[%d]: ",i+1);
- }
-}
-
-static void dump_int_table(int* table, int size, int delimiter) {
- int i=0;
- av_log(NULL,AV_LOG_ERROR,"\n[%d]: ",i);
- for (i=0 ; i<size ; i++) {
- av_log(NULL, AV_LOG_ERROR, "%d, ", table[i]);
- if ((i+1)%delimiter == 0) av_log(NULL,AV_LOG_ERROR,"\n[%d]: ",i+1);
- }
-}
-
-static void dump_short_table(short* table, int size, int delimiter) {
- int i=0;
- av_log(NULL,AV_LOG_ERROR,"\n[%d]: ",i);
- for (i=0 ; i<size ; i++) {
- av_log(NULL, AV_LOG_ERROR, "%d, ", table[i]);
- if ((i+1)%delimiter == 0) av_log(NULL,AV_LOG_ERROR,"\n[%d]: ",i+1);
- }
-}
-
-#endif
-
-/*************** init functions ***************/
-
-/* table generator */
-static void init_pow2table(COOKContext *q){
- int i;
- q->pow2tab[63] = 1.0;
- for (i=1 ; i<64 ; i++){
- q->pow2tab[63+i]=(float)((uint64_t)1<<i);
- q->pow2tab[63-i]=1.0/(float)((uint64_t)1<<i);
- }
-}
-
-/* table generator */
-static void init_rootpow2table(COOKContext *q){
- int i;
- q->rootpow2tab[63] = 1.0;
- for (i=1 ; i<64 ; i++){
- q->rootpow2tab[63+i]=sqrt((float)((uint64_t)1<<i));
- q->rootpow2tab[63-i]=sqrt(1.0/(float)((uint64_t)1<<i));
- }
-}
-
-/* table generator */
-static void init_gain_table(COOKContext *q) {
- int i;
- q->gain_size_factor = q->samples_per_channel/8;
- for (i=0 ; i<23 ; i++) {
- q->gain_table[i] = pow((double)q->pow2tab[i+52] ,
- (1.0/(double)q->gain_size_factor));
- }
-}
-
-
-static int init_cook_vlc_tables(COOKContext *q) {
- int i, result;
-
- result = 0;
- for (i=0 ; i<13 ; i++) {
- result &= init_vlc (&q->envelope_quant_index[i], 9, 24,
- envelope_quant_index_huffbits[i], 1, 1,
- envelope_quant_index_huffcodes[i], 2, 2, 0);
- }
- av_log(NULL,AV_LOG_DEBUG,"sqvh VLC init\n");
- for (i=0 ; i<7 ; i++) {
- result &= init_vlc (&q->sqvh[i], vhvlcsize_tab[i], vhsize_tab[i],
- cvh_huffbits[i], 1, 1,
- cvh_huffcodes[i], 2, 2, 0);
- }
-
- if (q->nb_channels==2 && q->joint_stereo==1){
- result &= init_vlc (&q->ccpl, 6, (1<<q->js_vlc_bits)-1,
- ccpl_huffbits[q->js_vlc_bits-2], 1, 1,
- ccpl_huffcodes[q->js_vlc_bits-2], 2, 2, 0);
- av_log(NULL,AV_LOG_DEBUG,"Joint-stereo VLC used.\n");
- }
-
- av_log(NULL,AV_LOG_DEBUG,"VLC tables initialized.\n");
- return result;
-}
-
-static int init_cook_mlt(COOKContext *q) {
- int j;
- float alpha;
- int mlt_size = q->samples_per_channel;
-
- if ((q->mlt_window = av_malloc(sizeof(float)*mlt_size)) == 0)
- return -1;
-
- /* Initialize the MLT window: simple sine window. */
- alpha = M_PI / (2.0 * (float)mlt_size);
- for(j=0 ; j<mlt_size ; j++)
- q->mlt_window[j] = sin((j + 0.5) * alpha) * sqrt(2.0 / q->samples_per_channel);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?