annotate liba52/test.c @ 30936:50b51e6987bd

Replace some "m" constraints by MANGLE to avoid issues with some compilers not being able to compile it and deduplicate the code at the same time.
author reimar
date Wed, 31 Mar 2010 17:00:33 +0000
parents e83eef58b30a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
25526
8b013fe0f842 Add proper license header.
diego
parents: 25486
diff changeset
1 /*
8b013fe0f842 Add proper license header.
diego
parents: 25486
diff changeset
2 * liba52 sample by A'rpi/ESP-team
8b013fe0f842 Add proper license header.
diego
parents: 25486
diff changeset
3 * Reads an AC-3 stream from stdin, decodes and downmixes to s16 stereo PCM
8b013fe0f842 Add proper license header.
diego
parents: 25486
diff changeset
4 * and writes it to stdout. The resulting stream is playable with sox:
8b013fe0f842 Add proper license header.
diego
parents: 25486
diff changeset
5 * play -c2 -r48000 -sw -fs out.sw
8b013fe0f842 Add proper license header.
diego
parents: 25486
diff changeset
6 *
8b013fe0f842 Add proper license header.
diego
parents: 25486
diff changeset
7 * Copyright (C) 2001 Árpád Gereöffy
8b013fe0f842 Add proper license header.
diego
parents: 25486
diff changeset
8 *
8b013fe0f842 Add proper license header.
diego
parents: 25486
diff changeset
9 * This program is free software; you can redistribute it and/or modify
8b013fe0f842 Add proper license header.
diego
parents: 25486
diff changeset
10 * it under the terms of the GNU General Public License as published by
8b013fe0f842 Add proper license header.
diego
parents: 25486
diff changeset
11 * the Free Software Foundation; either version 2 of the License, or
8b013fe0f842 Add proper license header.
diego
parents: 25486
diff changeset
12 * (at your option) any later version.
8b013fe0f842 Add proper license header.
diego
parents: 25486
diff changeset
13 *
8b013fe0f842 Add proper license header.
diego
parents: 25486
diff changeset
14 * This program is distributed in the hope that it will be useful,
8b013fe0f842 Add proper license header.
diego
parents: 25486
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8b013fe0f842 Add proper license header.
diego
parents: 25486
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8b013fe0f842 Add proper license header.
diego
parents: 25486
diff changeset
17 * GNU General Public License for more details.
8b013fe0f842 Add proper license header.
diego
parents: 25486
diff changeset
18 *
8b013fe0f842 Add proper license header.
diego
parents: 25486
diff changeset
19 * You should have received a copy of the GNU General Public License
8b013fe0f842 Add proper license header.
diego
parents: 25486
diff changeset
20 * along with this program; if not, write to the Free Software
8b013fe0f842 Add proper license header.
diego
parents: 25486
diff changeset
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
8b013fe0f842 Add proper license header.
diego
parents: 25486
diff changeset
22 */
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
23
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 29212
diff changeset
24 //#define TIMING //needs Pentium or newer
3507
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
25
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
26 #include <stdio.h>
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
27 #include <stdlib.h>
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
28 #include <inttypes.h>
12966
4e7d8679d6d8 compilation fix for test program
reimar
parents: 3908
diff changeset
29 #include <string.h>
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
30
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
31 #include "a52.h"
3908
0cc94b1eec0f runtime cpudetect in liba52 way
michael
parents: 3579
diff changeset
32 #include "mm_accel.h"
26544
f20a11161e62 Use consistent #include paths without "../".
diego
parents: 25526
diff changeset
33 #include "cpudetect.h"
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
34
25486
853622d14aa4 Fix compilation of liba52/test.c testing and benchmarking application.
iive
parents: 25479
diff changeset
35 static a52_state_t *state;
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
36 static uint8_t buf[3840];
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
37 static int buf_size=0;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
38
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
39 static int16_t out_buf[6*256*6];
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
40
25486
853622d14aa4 Fix compilation of liba52/test.c testing and benchmarking application.
iive
parents: 25479
diff changeset
41 void mp_msg( int x, const char *format, ... ) // stub for cpudetect.c
12966
4e7d8679d6d8 compilation fix for test program
reimar
parents: 3908
diff changeset
42 {
4e7d8679d6d8 compilation fix for test program
reimar
parents: 3908
diff changeset
43 }
4e7d8679d6d8 compilation fix for test program
reimar
parents: 3908
diff changeset
44
3507
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
45 #ifdef TIMING
29212
eda346733b8c Add missing 'void' to parameterless function declarations.
diego
parents: 27754
diff changeset
46 static inline long long rdtsc(void)
3507
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
47 {
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
48 long long l;
27754
08d18fe9da52 Change all occurrences of asm and __asm to __asm__, same as was done for FFmpeg.
diego
parents: 26544
diff changeset
49 __asm__ volatile("rdtsc\n\t"
3507
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
50 : "=A" (l)
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
51 );
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
52 // printf("%d\n", int(l/1000));
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
53 return l;
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
54 }
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
55
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
56 #define STARTTIMING t=rdtsc();
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
57 #define ENDTIMING sum+=rdtsc()-t; t=rdtsc();
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
58 #else
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
59 #define STARTTIMING ;
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
60 #define ENDTIMING ;
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
61 #endif
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
62
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
63
25100
531116b7693d main() --> main(void)
diego
parents: 12966
diff changeset
64 int main(void){
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
65 int accel=0;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
66 int sample_rate=0;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
67 int bit_rate=0;
3507
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
68 #ifdef TIMING
3511
70a686041bbe better benchmarking
michael
parents: 3507
diff changeset
69 long long t, sum=0, min=256*256*256*64;
3507
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
70 #endif
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
71
3579
831860fada69 runtime cpu detection for the idct
michael
parents: 3565
diff changeset
72 FILE *temp= stdout;
831860fada69 runtime cpu detection for the idct
michael
parents: 3565
diff changeset
73 stdout= stderr; //EVIL HACK FIXME
831860fada69 runtime cpu detection for the idct
michael
parents: 3565
diff changeset
74 GetCpuCaps(&gCpuCaps);
831860fada69 runtime cpu detection for the idct
michael
parents: 3565
diff changeset
75 stdout= temp;
3908
0cc94b1eec0f runtime cpudetect in liba52 way
michael
parents: 3579
diff changeset
76 // gCpuCaps.hasMMX=0;
0cc94b1eec0f runtime cpudetect in liba52 way
michael
parents: 3579
diff changeset
77 // gCpuCaps.hasSSE=0;
0cc94b1eec0f runtime cpudetect in liba52 way
michael
parents: 3579
diff changeset
78 if(gCpuCaps.hasMMX) accel |= MM_ACCEL_X86_MMX;
0cc94b1eec0f runtime cpudetect in liba52 way
michael
parents: 3579
diff changeset
79 if(gCpuCaps.hasMMX2) accel |= MM_ACCEL_X86_MMXEXT;
0cc94b1eec0f runtime cpudetect in liba52 way
michael
parents: 3579
diff changeset
80 if(gCpuCaps.hasSSE) accel |= MM_ACCEL_X86_SSE;
0cc94b1eec0f runtime cpudetect in liba52 way
michael
parents: 3579
diff changeset
81 if(gCpuCaps.has3DNow) accel |= MM_ACCEL_X86_3DNOW;
0cc94b1eec0f runtime cpudetect in liba52 way
michael
parents: 3579
diff changeset
82 // if(gCpuCaps.has3DNowExt) accel |= MM_ACCEL_X86_3DNOWEXT;
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 29212
diff changeset
83
25486
853622d14aa4 Fix compilation of liba52/test.c testing and benchmarking application.
iive
parents: 25479
diff changeset
84 state = a52_init (accel);
853622d14aa4 Fix compilation of liba52/test.c testing and benchmarking application.
iive
parents: 25479
diff changeset
85 if (state == NULL) {
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
86 fprintf (stderr, "A52 init failed\n");
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
87 return 1;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
88 }
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
89
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
90 while(1){
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
91 int length,i;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
92 int16_t *s16;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
93 sample_t level=1, bias=384;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
94 int flags=0;
3565
7f7991864b96 use resample.c functions
arpi
parents: 3511
diff changeset
95 int channels=0;
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
96
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
97 while(buf_size<7){
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
98 int c=getchar();
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
99 if(c<0) goto eof;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
100 buf[buf_size++]=c;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
101 }
3507
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
102 STARTTIMING
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
103 length = a52_syncinfo (buf, &flags, &sample_rate, &bit_rate);
3507
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
104 ENDTIMING
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
105 if(!length){
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
106 // bad file => resync
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
107 memcpy(buf,buf+1,6);
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
108 --buf_size;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
109 continue;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
110 }
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
111 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
112 while(buf_size<length){
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
113 buf[buf_size++]=getchar();
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
114 }
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 29212
diff changeset
115
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
116 buf_size=0;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
117
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
118 // decode:
3908
0cc94b1eec0f runtime cpudetect in liba52 way
michael
parents: 3579
diff changeset
119 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
120 channels=2;
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 29212
diff changeset
121
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
122 flags |= A52_ADJUST_LEVEL;
3507
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
123 STARTTIMING
25486
853622d14aa4 Fix compilation of liba52/test.c testing and benchmarking application.
iive
parents: 25479
diff changeset
124 if (a52_frame (state, buf, &flags, &level, bias))
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
125 { fprintf(stderr,"error at decoding\n"); continue; }
3507
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
126 ENDTIMING
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
127
25486
853622d14aa4 Fix compilation of liba52/test.c testing and benchmarking application.
iive
parents: 25479
diff changeset
128 // a52_dynrng (state, NULL, NULL); // disable dynamic range compensation
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
129
3579
831860fada69 runtime cpu detection for the idct
michael
parents: 3565
diff changeset
130 STARTTIMING
3908
0cc94b1eec0f runtime cpudetect in liba52 way
michael
parents: 3579
diff changeset
131 a52_resample_init(accel,flags,channels);
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
132 s16 = out_buf;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
133 for (i = 0; i < 6; i++) {
25486
853622d14aa4 Fix compilation of liba52/test.c testing and benchmarking application.
iive
parents: 25479
diff changeset
134 if (a52_block (state))
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
135 { fprintf(stderr,"error at sampling\n"); break; }
3565
7f7991864b96 use resample.c functions
arpi
parents: 3511
diff changeset
136 // float->int + channels interleaving:
25486
853622d14aa4 Fix compilation of liba52/test.c testing and benchmarking application.
iive
parents: 25479
diff changeset
137 s16+=a52_resample(a52_samples(state),s16);
3579
831860fada69 runtime cpu detection for the idct
michael
parents: 3565
diff changeset
138 ENDTIMING
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
139 }
3511
70a686041bbe better benchmarking
michael
parents: 3507
diff changeset
140 #ifdef TIMING
70a686041bbe better benchmarking
michael
parents: 3507
diff changeset
141 if(sum<min) min=sum;
70a686041bbe better benchmarking
michael
parents: 3507
diff changeset
142 sum=0;
70a686041bbe better benchmarking
michael
parents: 3507
diff changeset
143 #endif
3908
0cc94b1eec0f runtime cpudetect in liba52 way
michael
parents: 3579
diff changeset
144 fwrite(out_buf,6*256*2*channels,1,stdout);
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
145
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
146 }
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
147
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
148 eof:
3507
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
149 #ifdef TIMING
25486
853622d14aa4 Fix compilation of liba52/test.c testing and benchmarking application.
iive
parents: 25479
diff changeset
150 fprintf(stderr, "%4.4fk cycles\n",min/1000.0);
3511
70a686041bbe better benchmarking
michael
parents: 3507
diff changeset
151 sum=0;
3507
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
152 #endif
25486
853622d14aa4 Fix compilation of liba52/test.c testing and benchmarking application.
iive
parents: 25479
diff changeset
153 return 0;
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
154 }