diff options
Diffstat (limited to 'apps/codecs/libcook/cook.c')
-rw-r--r-- | apps/codecs/libcook/cook.c | 185 |
1 files changed, 4 insertions, 181 deletions
diff --git a/apps/codecs/libcook/cook.c b/apps/codecs/libcook/cook.c index 856004f31b..e3a919ddec 100644 --- a/apps/codecs/libcook/cook.c +++ b/apps/codecs/libcook/cook.c | |||
@@ -45,18 +45,9 @@ | |||
45 | #include <math.h> | 45 | #include <math.h> |
46 | #include <stddef.h> | 46 | #include <stddef.h> |
47 | #include <stdio.h> | 47 | #include <stdio.h> |
48 | #include <sys/types.h> | ||
49 | #include <sys/stat.h> | ||
50 | #include <fcntl.h> | ||
51 | #include <unistd.h> | ||
52 | |||
53 | #include "libavutil/lfg.h" | ||
54 | #include "bitstream.h" | ||
55 | #include "dsputil.h" | ||
56 | #include "bytestream.h" | ||
57 | 48 | ||
49 | #include "cook.h" | ||
58 | #include "cookdata.h" | 50 | #include "cookdata.h" |
59 | #include "rm2wav.h" | ||
60 | 51 | ||
61 | /* The following table is taken from libavutil/mathematics.c */ | 52 | /* The following table is taken from libavutil/mathematics.c */ |
62 | const uint8_t ff_log2_tab[256]={ | 53 | const uint8_t ff_log2_tab[256]={ |
@@ -82,90 +73,6 @@ const uint8_t ff_log2_tab[256]={ | |||
82 | //#define DUMP_RAW_FRAMES | 73 | //#define DUMP_RAW_FRAMES |
83 | #define DEBUGF(message,args ...) av_log(NULL,AV_LOG_ERROR,message,## args) | 74 | #define DEBUGF(message,args ...) av_log(NULL,AV_LOG_ERROR,message,## args) |
84 | 75 | ||
85 | typedef struct { | ||
86 | int *now; | ||
87 | int *previous; | ||
88 | } cook_gains; | ||
89 | |||
90 | typedef struct cook { | ||
91 | /* | ||
92 | * The following 5 functions provide the lowlevel arithmetic on | ||
93 | * the internal audio buffers. | ||
94 | */ | ||
95 | void (* scalar_dequant)(struct cook *q, int index, int quant_index, | ||
96 | int* subband_coef_index, int* subband_coef_sign, | ||
97 | float* mlt_p); | ||
98 | |||
99 | void (* decouple) (struct cook *q, | ||
100 | int subband, | ||
101 | float f1, float f2, | ||
102 | float *decode_buffer, | ||
103 | float *mlt_buffer1, float *mlt_buffer2); | ||
104 | |||
105 | void (* imlt_window) (struct cook *q, float *buffer1, | ||
106 | cook_gains *gains_ptr, float *previous_buffer); | ||
107 | |||
108 | void (* interpolate) (struct cook *q, float* buffer, | ||
109 | int gain_index, int gain_index_next); | ||
110 | |||
111 | void (* saturate_output) (struct cook *q, int chan, int16_t *out); | ||
112 | |||
113 | GetBitContext gb; | ||
114 | int frame_number; | ||
115 | int block_align; | ||
116 | int extradata_size; | ||
117 | /* stream data */ | ||
118 | int nb_channels; | ||
119 | int joint_stereo; | ||
120 | int bit_rate; | ||
121 | int sample_rate; | ||
122 | int samples_per_channel; | ||
123 | int samples_per_frame; | ||
124 | int subbands; | ||
125 | int log2_numvector_size; | ||
126 | int numvector_size; //1 << log2_numvector_size; | ||
127 | int js_subband_start; | ||
128 | int total_subbands; | ||
129 | int num_vectors; | ||
130 | int bits_per_subpacket; | ||
131 | int cookversion; | ||
132 | /* states */ | ||
133 | AVLFG random_state; | ||
134 | /* transform data */ | ||
135 | MDCTContext mdct_ctx; | ||
136 | float* mlt_window; | ||
137 | |||
138 | /* gain buffers */ | ||
139 | cook_gains gains1; | ||
140 | cook_gains gains2; | ||
141 | int gain_1[9]; | ||
142 | int gain_2[9]; | ||
143 | int gain_3[9]; | ||
144 | int gain_4[9]; | ||
145 | |||
146 | /* VLC data */ | ||
147 | int js_vlc_bits; | ||
148 | VLC envelope_quant_index[13]; | ||
149 | VLC sqvh[7]; //scalar quantization | ||
150 | VLC ccpl; //channel coupling | ||
151 | |||
152 | /* generatable tables and related variables */ | ||
153 | int gain_size_factor; | ||
154 | float gain_table[23]; | ||
155 | |||
156 | /* data buffers */ | ||
157 | |||
158 | uint8_t* decoded_bytes_buffer; | ||
159 | float mono_mdct_output[2048] __attribute__ ((aligned(16))); //DECLARE_ALIGNED_16(float,mono_mdct_output[2048]); | ||
160 | float mono_previous_buffer1[1024]; | ||
161 | float mono_previous_buffer2[1024]; | ||
162 | float decode_buffer_1[1024]; | ||
163 | float decode_buffer_2[1024]; | ||
164 | float decode_buffer_0[1060]; /* static allocation for joint decode */ | ||
165 | |||
166 | const float *cplscales[5]; | ||
167 | } COOKContext; | ||
168 | |||
169 | static float pow2tab[127]; | 76 | static float pow2tab[127]; |
170 | static float rootpow2tab[127]; | 77 | static float rootpow2tab[127]; |
171 | 78 | ||
@@ -335,7 +242,7 @@ static inline int decode_bytes(const uint8_t* inbuffer, uint8_t* out, int bytes) | |||
335 | * Cook uninit | 242 | * Cook uninit |
336 | */ | 243 | */ |
337 | 244 | ||
338 | static av_cold int cook_decode_close(COOKContext *q) | 245 | av_cold int cook_decode_close(COOKContext *q) |
339 | { | 246 | { |
340 | int i; | 247 | int i; |
341 | //COOKContext *q = avctx->priv_data; | 248 | //COOKContext *q = avctx->priv_data; |
@@ -997,7 +904,7 @@ static int decode_subpacket(COOKContext *q, const uint8_t *inbuffer, | |||
997 | * @param rmctx pointer to the RMContext | 904 | * @param rmctx pointer to the RMContext |
998 | */ | 905 | */ |
999 | 906 | ||
1000 | static int cook_decode_frame(RMContext *rmctx,COOKContext *q, | 907 | int cook_decode_frame(RMContext *rmctx,COOKContext *q, |
1001 | int16_t *outbuffer, int *data_size, | 908 | int16_t *outbuffer, int *data_size, |
1002 | const uint8_t *inbuffer, int buf_size) { | 909 | const uint8_t *inbuffer, int buf_size) { |
1003 | //COOKContext *q = avctx->priv_data; | 910 | //COOKContext *q = avctx->priv_data; |
@@ -1053,7 +960,7 @@ static av_cold int cook_count_channels(unsigned int mask){ | |||
1053 | * Cook initialization | 960 | * Cook initialization |
1054 | */ | 961 | */ |
1055 | 962 | ||
1056 | static av_cold int cook_decode_init(RMContext *rmctx, COOKContext *q) | 963 | av_cold int cook_decode_init(RMContext *rmctx, COOKContext *q) |
1057 | { | 964 | { |
1058 | /* cook extradata */ | 965 | /* cook extradata */ |
1059 | q->cookversion = rmctx->cook_version; | 966 | q->cookversion = rmctx->cook_version; |
@@ -1203,87 +1110,3 @@ static av_cold int cook_decode_init(RMContext *rmctx, COOKContext *q) | |||
1203 | return 0; | 1110 | return 0; |
1204 | } | 1111 | } |
1205 | 1112 | ||
1206 | |||
1207 | int main(int argc, char *argv[]) | ||
1208 | { | ||
1209 | int fd, fd_dec; | ||
1210 | int res, datasize,x,i; | ||
1211 | int nb_frames = 0; | ||
1212 | #ifdef DUMP_RAW_FRAMES | ||
1213 | char filename[15]; | ||
1214 | int fd_out; | ||
1215 | #endif | ||
1216 | int16_t outbuf[2048]; | ||
1217 | uint8_t inbuf[1024]; | ||
1218 | uint16_t fs,sps,h; | ||
1219 | uint32_t packet_count; | ||
1220 | COOKContext q; | ||
1221 | RMContext rmctx; | ||
1222 | RMPacket pkt; | ||
1223 | |||
1224 | memset(&q,0,sizeof(COOKContext)); | ||
1225 | memset(&rmctx,0,sizeof(RMContext)); | ||
1226 | memset(&pkt,0,sizeof(RMPacket)); | ||
1227 | |||
1228 | if (argc != 2) { | ||
1229 | av_log(NULL,AV_LOG_ERROR,"Incorrect number of arguments\n"); | ||
1230 | return -1; | ||
1231 | } | ||
1232 | |||
1233 | fd = open(argv[1],O_RDONLY); | ||
1234 | if (fd < 0) { | ||
1235 | av_log(NULL,AV_LOG_ERROR,"Error opening file %s\n", argv[1]); | ||
1236 | return -1; | ||
1237 | } | ||
1238 | |||
1239 | fd_dec = open_wav("output.wav"); | ||
1240 | if (fd_dec < 0) { | ||
1241 | av_log(NULL,AV_LOG_ERROR,"Error creating output file\n"); | ||
1242 | return -1; | ||
1243 | } | ||
1244 | res = real_parse_header(fd, &rmctx); | ||
1245 | packet_count = rmctx.nb_packets; | ||
1246 | rmctx.audio_framesize = rmctx.block_align; | ||
1247 | rmctx.block_align = rmctx.sub_packet_size; | ||
1248 | fs = rmctx.audio_framesize; | ||
1249 | sps= rmctx.block_align; | ||
1250 | h = rmctx.sub_packet_h; | ||
1251 | cook_decode_init(&rmctx,&q); | ||
1252 | av_log(NULL,AV_LOG_ERROR,"nb_frames = %d\n",nb_frames); | ||
1253 | x = 0; | ||
1254 | if(packet_count % h) | ||
1255 | { | ||
1256 | packet_count += h - (packet_count % h); | ||
1257 | rmctx.nb_packets = packet_count; | ||
1258 | } | ||
1259 | while(packet_count) | ||
1260 | { | ||
1261 | |||
1262 | memset(pkt.data,0,sizeof(pkt.data)); | ||
1263 | rm_get_packet(fd, &rmctx, &pkt); | ||
1264 | DEBUGF("total frames = %d packet count = %d output counter = %d \n",rmctx.audio_pkt_cnt*(fs/sps), packet_count,rmctx.audio_pkt_cnt); | ||
1265 | for(i = 0; i < rmctx.audio_pkt_cnt*(fs/sps) ; i++) | ||
1266 | { | ||
1267 | /* output raw audio frames that are sent to the decoder into separate files */ | ||
1268 | #ifdef DUMP_RAW_FRAMES | ||
1269 | snprintf(filename,sizeof(filename),"dump%d.raw",++x); | ||
1270 | fd_out = open(filename,O_WRONLY|O_CREAT|O_APPEND); | ||
1271 | write(fd_out,pkt.data+i*sps,sps); | ||
1272 | close(fd_out); | ||
1273 | #endif | ||
1274 | |||
1275 | memcpy(inbuf,pkt.data+i*sps,sps); | ||
1276 | nb_frames = cook_decode_frame(&rmctx,&q, outbuf, &datasize, inbuf , rmctx.block_align); | ||
1277 | rmctx.frame_number++; | ||
1278 | write(fd_dec,outbuf,datasize); | ||
1279 | } | ||
1280 | packet_count -= rmctx.audio_pkt_cnt; | ||
1281 | rmctx.audio_pkt_cnt = 0; | ||
1282 | } | ||
1283 | cook_decode_close(&q); | ||
1284 | close_wav(fd_dec,&rmctx); | ||
1285 | close(fd); | ||
1286 | |||
1287 | |||
1288 | return 0; | ||
1289 | } | ||