annotate liba52/test.c @ 25503:9f8f66eca56e

Remove unused static variable pass, fixes the warning: ae_lame.c:72: warning: 'pass' defined but not used
author diego
date Thu, 27 Dec 2007 11:19:54 +0000
parents 853622d14aa4
children 8b013fe0f842
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
1 // liba52 sample by A'rpi/ESP-team
25479
98658dfa6a9d cosmetics: grammar/spelling
diego
parents: 25100
diff changeset
2 // Reads an AC-3 stream from stdin, decodes and downmixes to s16 stereo PCM
98658dfa6a9d cosmetics: grammar/spelling
diego
parents: 25100
diff changeset
3 // and writes it to stdout. The resulting stream is playable with sox:
25486
853622d14aa4 Fix compilation of liba52/test.c testing and benchmarking application.
iive
parents: 25479
diff changeset
4 // play -c2 -r48000 -sw -fs out.sw
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
5
3507
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
6 //#define TIMING //needs Pentium or newer
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
7
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
8 #include <stdio.h>
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
9 #include <stdlib.h>
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
10 #include <inttypes.h>
12966
4e7d8679d6d8 compilation fix for test program
reimar
parents: 3908
diff changeset
11 #include <string.h>
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
12
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
13 #include "a52.h"
3908
0cc94b1eec0f runtime cpudetect in liba52 way
michael
parents: 3579
diff changeset
14 #include "mm_accel.h"
3579
831860fada69 runtime cpu detection for the idct
michael
parents: 3565
diff changeset
15 #include "../cpudetect.h"
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
16
25486
853622d14aa4 Fix compilation of liba52/test.c testing and benchmarking application.
iive
parents: 25479
diff changeset
17 static a52_state_t *state;
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
18 static uint8_t buf[3840];
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
19 static int buf_size=0;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
20
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
21 static int16_t out_buf[6*256*6];
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
22
25486
853622d14aa4 Fix compilation of liba52/test.c testing and benchmarking application.
iive
parents: 25479
diff changeset
23 void mp_msg( int x, const char *format, ... ) // stub for cpudetect.c
12966
4e7d8679d6d8 compilation fix for test program
reimar
parents: 3908
diff changeset
24 {
4e7d8679d6d8 compilation fix for test program
reimar
parents: 3908
diff changeset
25 }
4e7d8679d6d8 compilation fix for test program
reimar
parents: 3908
diff changeset
26
3507
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
27 #ifdef TIMING
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
28 static inline long long rdtsc()
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
29 {
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
30 long long l;
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
31 asm volatile( "rdtsc\n\t"
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
32 : "=A" (l)
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
33 );
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
34 // printf("%d\n", int(l/1000));
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
35 return l;
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
36 }
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
37
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
38 #define STARTTIMING t=rdtsc();
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
39 #define ENDTIMING sum+=rdtsc()-t; t=rdtsc();
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
40 #else
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
41 #define STARTTIMING ;
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
42 #define ENDTIMING ;
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
43 #endif
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
44
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
45
25100
531116b7693d main() --> main(void)
diego
parents: 12966
diff changeset
46 int main(void){
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
47 int accel=0;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
48 int sample_rate=0;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
49 int bit_rate=0;
3507
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
50 #ifdef TIMING
3511
70a686041bbe better benchmarking
michael
parents: 3507
diff changeset
51 long long t, sum=0, min=256*256*256*64;
3507
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
52 #endif
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
53
3579
831860fada69 runtime cpu detection for the idct
michael
parents: 3565
diff changeset
54 FILE *temp= stdout;
831860fada69 runtime cpu detection for the idct
michael
parents: 3565
diff changeset
55 stdout= stderr; //EVIL HACK FIXME
831860fada69 runtime cpu detection for the idct
michael
parents: 3565
diff changeset
56 GetCpuCaps(&gCpuCaps);
831860fada69 runtime cpu detection for the idct
michael
parents: 3565
diff changeset
57 stdout= temp;
3908
0cc94b1eec0f runtime cpudetect in liba52 way
michael
parents: 3579
diff changeset
58 // gCpuCaps.hasMMX=0;
0cc94b1eec0f runtime cpudetect in liba52 way
michael
parents: 3579
diff changeset
59 // gCpuCaps.hasSSE=0;
0cc94b1eec0f runtime cpudetect in liba52 way
michael
parents: 3579
diff changeset
60 if(gCpuCaps.hasMMX) accel |= MM_ACCEL_X86_MMX;
0cc94b1eec0f runtime cpudetect in liba52 way
michael
parents: 3579
diff changeset
61 if(gCpuCaps.hasMMX2) accel |= MM_ACCEL_X86_MMXEXT;
0cc94b1eec0f runtime cpudetect in liba52 way
michael
parents: 3579
diff changeset
62 if(gCpuCaps.hasSSE) accel |= MM_ACCEL_X86_SSE;
0cc94b1eec0f runtime cpudetect in liba52 way
michael
parents: 3579
diff changeset
63 if(gCpuCaps.has3DNow) accel |= MM_ACCEL_X86_3DNOW;
0cc94b1eec0f runtime cpudetect in liba52 way
michael
parents: 3579
diff changeset
64 // if(gCpuCaps.has3DNowExt) accel |= MM_ACCEL_X86_3DNOWEXT;
3579
831860fada69 runtime cpu detection for the idct
michael
parents: 3565
diff changeset
65
25486
853622d14aa4 Fix compilation of liba52/test.c testing and benchmarking application.
iive
parents: 25479
diff changeset
66 state = a52_init (accel);
853622d14aa4 Fix compilation of liba52/test.c testing and benchmarking application.
iive
parents: 25479
diff changeset
67 if (state == NULL) {
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
68 fprintf (stderr, "A52 init failed\n");
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
69 return 1;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
70 }
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
71
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
72 while(1){
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
73 int length,i;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
74 int16_t *s16;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
75 sample_t level=1, bias=384;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
76 int flags=0;
3565
7f7991864b96 use resample.c functions
arpi
parents: 3511
diff changeset
77 int channels=0;
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
78
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
79 while(buf_size<7){
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
80 int c=getchar();
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
81 if(c<0) goto eof;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
82 buf[buf_size++]=c;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
83 }
3507
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
84 STARTTIMING
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
85 length = a52_syncinfo (buf, &flags, &sample_rate, &bit_rate);
3507
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
86 ENDTIMING
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
87 if(!length){
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
88 // bad file => resync
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
89 memcpy(buf,buf+1,6);
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
90 --buf_size;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
91 continue;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
92 }
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
93 fprintf(stderr,"sync. %d bytes 0x%X %d Hz %d kbit\n",length,flags,sample_rate,bit_rate);
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
94 while(buf_size<length){
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
95 buf[buf_size++]=getchar();
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
96 }
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
97
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
98 buf_size=0;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
99
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
100 // decode:
3908
0cc94b1eec0f runtime cpudetect in liba52 way
michael
parents: 3579
diff changeset
101 flags=A52_STEREO; //A52_STEREO; //A52_DOLBY; //A52_STEREO; // A52_DOLBY // A52_2F2R // A52_3F2R | A52_LFE
3565
7f7991864b96 use resample.c functions
arpi
parents: 3511
diff changeset
102 channels=2;
7f7991864b96 use resample.c functions
arpi
parents: 3511
diff changeset
103
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
104 flags |= A52_ADJUST_LEVEL;
3507
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
105 STARTTIMING
25486
853622d14aa4 Fix compilation of liba52/test.c testing and benchmarking application.
iive
parents: 25479
diff changeset
106 if (a52_frame (state, buf, &flags, &level, bias))
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
107 { fprintf(stderr,"error at decoding\n"); continue; }
3507
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
108 ENDTIMING
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
109
25486
853622d14aa4 Fix compilation of liba52/test.c testing and benchmarking application.
iive
parents: 25479
diff changeset
110 // a52_dynrng (state, NULL, NULL); // disable dynamic range compensation
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
111
3579
831860fada69 runtime cpu detection for the idct
michael
parents: 3565
diff changeset
112 STARTTIMING
3908
0cc94b1eec0f runtime cpudetect in liba52 way
michael
parents: 3579
diff changeset
113 a52_resample_init(accel,flags,channels);
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
114 s16 = out_buf;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
115 for (i = 0; i < 6; i++) {
25486
853622d14aa4 Fix compilation of liba52/test.c testing and benchmarking application.
iive
parents: 25479
diff changeset
116 if (a52_block (state))
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
117 { fprintf(stderr,"error at sampling\n"); break; }
3565
7f7991864b96 use resample.c functions
arpi
parents: 3511
diff changeset
118 // float->int + channels interleaving:
25486
853622d14aa4 Fix compilation of liba52/test.c testing and benchmarking application.
iive
parents: 25479
diff changeset
119 s16+=a52_resample(a52_samples(state),s16);
3579
831860fada69 runtime cpu detection for the idct
michael
parents: 3565
diff changeset
120 ENDTIMING
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
121 }
3511
70a686041bbe better benchmarking
michael
parents: 3507
diff changeset
122 #ifdef TIMING
70a686041bbe better benchmarking
michael
parents: 3507
diff changeset
123 if(sum<min) min=sum;
70a686041bbe better benchmarking
michael
parents: 3507
diff changeset
124 sum=0;
70a686041bbe better benchmarking
michael
parents: 3507
diff changeset
125 #endif
3908
0cc94b1eec0f runtime cpudetect in liba52 way
michael
parents: 3579
diff changeset
126 fwrite(out_buf,6*256*2*channels,1,stdout);
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
127
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
128 }
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
129
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
130 eof:
3507
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
131 #ifdef TIMING
25486
853622d14aa4 Fix compilation of liba52/test.c testing and benchmarking application.
iive
parents: 25479
diff changeset
132 fprintf(stderr, "%4.4fk cycles\n",min/1000.0);
3511
70a686041bbe better benchmarking
michael
parents: 3507
diff changeset
133 sum=0;
3507
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
134 #endif
25486
853622d14aa4 Fix compilation of liba52/test.c testing and benchmarking application.
iive
parents: 25479
diff changeset
135 return 0;
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
136 }