comparison liba52/test.c @ 3507:a57fce4ac936

benchmarking code (#define TIMING)
author michael
date Sat, 15 Dec 2001 22:32:14 +0000
parents 098634f41331
children 70a686041bbe
comparison
equal deleted inserted replaced
3506:3d906972dafd 3507:a57fce4ac936
2 // liba52 sample by A'rpi/ESP-team 2 // liba52 sample by A'rpi/ESP-team
3 // reads ac3 stream form stdin, decodes and downmix to s16 stereo pcm and 3 // reads ac3 stream form stdin, decodes and downmix to s16 stereo pcm and
4 // writes it to stdout. resulting stream playbackable with sox: 4 // writes it to stdout. resulting stream playbackable with sox:
5 // play -c 2 -r 48000 out.sw 5 // play -c 2 -r 48000 out.sw
6 6
7 //#define TIMING //needs Pentium or newer
8
7 #include <stdio.h> 9 #include <stdio.h>
8 #include <stdlib.h> 10 #include <stdlib.h>
9 #include <inttypes.h> 11 #include <inttypes.h>
10 12
11 #include "a52.h" 13 #include "a52.h"
14 static a52_state_t state; 16 static a52_state_t state;
15 static uint8_t buf[3840]; 17 static uint8_t buf[3840];
16 static int buf_size=0; 18 static int buf_size=0;
17 19
18 static int16_t out_buf[6*256*6]; 20 static int16_t out_buf[6*256*6];
21
22 #ifdef TIMING
23 static inline long long rdtsc()
24 {
25 long long l;
26 asm volatile( "rdtsc\n\t"
27 : "=A" (l)
28 );
29 // printf("%d\n", int(l/1000));
30 return l;
31 }
32
33 #define STARTTIMING t=rdtsc();
34 #define ENDTIMING sum+=rdtsc()-t; t=rdtsc();
35 #else
36 #define STARTTIMING ;
37 #define ENDTIMING ;
38 #endif
39
19 40
20 static inline int16_t convert (int32_t i) 41 static inline int16_t convert (int32_t i)
21 { 42 {
22 if (i > 0x43c07fff) 43 if (i > 0x43c07fff)
23 return 32767; 44 return 32767;
124 145
125 int main(){ 146 int main(){
126 int accel=0; 147 int accel=0;
127 int sample_rate=0; 148 int sample_rate=0;
128 int bit_rate=0; 149 int bit_rate=0;
150 #ifdef TIMING
151 long long t, sum=0;
152 #endif
129 153
130 samples = a52_init (accel); 154 samples = a52_init (accel);
131 if (samples == NULL) { 155 if (samples == NULL) {
132 fprintf (stderr, "A52 init failed\n"); 156 fprintf (stderr, "A52 init failed\n");
133 return 1; 157 return 1;
142 while(buf_size<7){ 166 while(buf_size<7){
143 int c=getchar(); 167 int c=getchar();
144 if(c<0) goto eof; 168 if(c<0) goto eof;
145 buf[buf_size++]=c; 169 buf[buf_size++]=c;
146 } 170 }
171 STARTTIMING
147 length = a52_syncinfo (buf, &flags, &sample_rate, &bit_rate); 172 length = a52_syncinfo (buf, &flags, &sample_rate, &bit_rate);
173 ENDTIMING
148 if(!length){ 174 if(!length){
149 // bad file => resync 175 // bad file => resync
150 memcpy(buf,buf+1,6); 176 memcpy(buf,buf+1,6);
151 --buf_size; 177 --buf_size;
152 continue; 178 continue;
159 buf_size=0; 185 buf_size=0;
160 186
161 // decode: 187 // decode:
162 flags=A52_STEREO; // A52_DOLBY // A52_2F2R // A52_3F2R | A52_LFE 188 flags=A52_STEREO; // A52_DOLBY // A52_2F2R // A52_3F2R | A52_LFE
163 flags |= A52_ADJUST_LEVEL; 189 flags |= A52_ADJUST_LEVEL;
190 STARTTIMING
164 if (a52_frame (&state, buf, &flags, &level, bias)) 191 if (a52_frame (&state, buf, &flags, &level, bias))
165 { fprintf(stderr,"error at decoding\n"); continue; } 192 { fprintf(stderr,"error at decoding\n"); continue; }
193 ENDTIMING
166 194
167 // a52_dynrng (&state, NULL, NULL); // disable dynamic range compensation 195 // a52_dynrng (&state, NULL, NULL); // disable dynamic range compensation
168 196
169 s16 = out_buf; 197 s16 = out_buf;
170 for (i = 0; i < 6; i++) { 198 for (i = 0; i < 6; i++) {
171 int32_t * f = (int32_t *) samples; 199 int32_t * f = (int32_t *) samples;
172 int i; 200 int i;
201 STARTTIMING
173 if (a52_block (&state, samples)) 202 if (a52_block (&state, samples))
174 { fprintf(stderr,"error at sampling\n"); break; } 203 { fprintf(stderr,"error at sampling\n"); break; }
204 ENDTIMING
175 // resample to STEREO/DOLBY: 205 // resample to STEREO/DOLBY:
176 for (i = 0; i < 256; i++) { 206 for (i = 0; i < 256; i++) {
177 s16[2*i] = convert (f[i]); 207 s16[2*i] = convert (f[i]);
178 s16[2*i+1] = convert (f[i+256]); 208 s16[2*i+1] = convert (f[i+256]);
179 } 209 }
183 213
184 } 214 }
185 215
186 eof: 216 eof:
187 217
188 } 218 #ifdef TIMING
219 fprintf(stderr, "%4.4fm cycles\n",sum/1000000.0);
220 #endif
221
222 }