annotate liba52/test.c @ 3767:a498c4b93d5d

rawi420 added
author alex
date Wed, 26 Dec 2001 14:24:57 +0000
parents 831860fada69
children 0cc94b1eec0f
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
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
2 // liba52 sample by A'rpi/ESP-team
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
3 // reads ac3 stream form stdin, decodes and downmix to s16 stereo pcm and
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
4 // writes it to stdout. resulting stream playbackable with sox:
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
5 // play -c 2 -r 48000 out.sw
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
6
3507
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
7 //#define TIMING //needs Pentium or newer
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
8
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
9 #include <stdio.h>
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
10 #include <stdlib.h>
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
11 #include <inttypes.h>
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"
3579
831860fada69 runtime cpu detection for the idct
michael
parents: 3565
diff changeset
14 #include "../cpudetect.h"
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
15
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
16 static sample_t * samples;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
17 static a52_state_t state;
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
3507
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
23 #ifdef TIMING
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
24 static inline long long rdtsc()
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
25 {
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
26 long long l;
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
27 asm volatile( "rdtsc\n\t"
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
28 : "=A" (l)
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
29 );
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
30 // printf("%d\n", int(l/1000));
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
31 return l;
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
32 }
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
33
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
34 #define STARTTIMING t=rdtsc();
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
35 #define ENDTIMING sum+=rdtsc()-t; t=rdtsc();
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
36 #else
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
37 #define STARTTIMING ;
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
38 #define ENDTIMING ;
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
39 #endif
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
40
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
41
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
42 int main(){
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
43 int accel=0;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
44 int sample_rate=0;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
45 int bit_rate=0;
3507
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
46 #ifdef TIMING
3511
70a686041bbe better benchmarking
michael
parents: 3507
diff changeset
47 long long t, sum=0, min=256*256*256*64;
3507
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
48 #endif
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
49
3579
831860fada69 runtime cpu detection for the idct
michael
parents: 3565
diff changeset
50 FILE *temp= stdout;
831860fada69 runtime cpu detection for the idct
michael
parents: 3565
diff changeset
51 stdout= stderr; //EVIL HACK FIXME
831860fada69 runtime cpu detection for the idct
michael
parents: 3565
diff changeset
52 GetCpuCaps(&gCpuCaps);
831860fada69 runtime cpu detection for the idct
michael
parents: 3565
diff changeset
53 stdout= temp;
831860fada69 runtime cpu detection for the idct
michael
parents: 3565
diff changeset
54
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
55 samples = a52_init (accel);
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
56 if (samples == NULL) {
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
57 fprintf (stderr, "A52 init failed\n");
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
58 return 1;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
59 }
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
60
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
61 while(1){
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
62 int length,i;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
63 int16_t *s16;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
64 sample_t level=1, bias=384;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
65 int flags=0;
3565
7f7991864b96 use resample.c functions
arpi
parents: 3511
diff changeset
66 int channels=0;
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
67
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
68 while(buf_size<7){
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
69 int c=getchar();
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
70 if(c<0) goto eof;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
71 buf[buf_size++]=c;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
72 }
3507
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
73 STARTTIMING
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
74 length = a52_syncinfo (buf, &flags, &sample_rate, &bit_rate);
3507
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
75 ENDTIMING
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
76 if(!length){
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
77 // bad file => resync
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
78 memcpy(buf,buf+1,6);
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
79 --buf_size;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
80 continue;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
81 }
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
82 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
83 while(buf_size<length){
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
84 buf[buf_size++]=getchar();
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
85 }
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
86
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
87 buf_size=0;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
88
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
89 // decode:
3579
831860fada69 runtime cpu detection for the idct
michael
parents: 3565
diff changeset
90 flags=A52_STEREO; //A52_STEREO; // A52_DOLBY // A52_2F2R // A52_3F2R | A52_LFE
3565
7f7991864b96 use resample.c functions
arpi
parents: 3511
diff changeset
91 channels=2;
7f7991864b96 use resample.c functions
arpi
parents: 3511
diff changeset
92
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
93 flags |= A52_ADJUST_LEVEL;
3507
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
94 STARTTIMING
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
95 if (a52_frame (&state, buf, &flags, &level, bias))
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
96 { fprintf(stderr,"error at decoding\n"); continue; }
3507
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
97 ENDTIMING
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
98
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
99 // a52_dynrng (&state, NULL, NULL); // disable dynamic range compensation
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
100
3579
831860fada69 runtime cpu detection for the idct
michael
parents: 3565
diff changeset
101 STARTTIMING
3565
7f7991864b96 use resample.c functions
arpi
parents: 3511
diff changeset
102 a52_resample_init(flags,channels);
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
103 s16 = out_buf;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
104 for (i = 0; i < 6; i++) {
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
105 if (a52_block (&state, samples))
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
106 { fprintf(stderr,"error at sampling\n"); break; }
3565
7f7991864b96 use resample.c functions
arpi
parents: 3511
diff changeset
107 // float->int + channels interleaving:
7f7991864b96 use resample.c functions
arpi
parents: 3511
diff changeset
108 s16+=a52_resample(samples,s16);
3579
831860fada69 runtime cpu detection for the idct
michael
parents: 3565
diff changeset
109 ENDTIMING
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
110 }
3511
70a686041bbe better benchmarking
michael
parents: 3507
diff changeset
111 #ifdef TIMING
70a686041bbe better benchmarking
michael
parents: 3507
diff changeset
112 if(sum<min) min=sum;
70a686041bbe better benchmarking
michael
parents: 3507
diff changeset
113 sum=0;
70a686041bbe better benchmarking
michael
parents: 3507
diff changeset
114 #endif
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
115 fwrite(out_buf,6*256*2*2,1,stdout);
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
116
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
117 }
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
118
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
119 eof:
3507
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
120 #ifdef TIMING
3511
70a686041bbe better benchmarking
michael
parents: 3507
diff changeset
121 fprintf(stderr, "%4.4fk cycles ",min/1000.0);
70a686041bbe better benchmarking
michael
parents: 3507
diff changeset
122 sum=0;
3507
a57fce4ac936 benchmarking code (#define TIMING)
michael
parents: 3396
diff changeset
123 #endif
3396
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
124 }