annotate liba52/test.c @ 3484:72e299c83b4f

compile remez.c
author steve
date Thu, 13 Dec 2001 23:36:36 +0000
parents 098634f41331
children a57fce4ac936
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
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
7 #include <stdio.h>
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
8 #include <stdlib.h>
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
9 #include <inttypes.h>
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
10
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
11 #include "a52.h"
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
12
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
13 static sample_t * samples;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
14 static a52_state_t state;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
15 static uint8_t buf[3840];
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
16 static int buf_size=0;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
17
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
18 static int16_t out_buf[6*256*6];
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
19
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
20 static inline int16_t convert (int32_t i)
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
21 {
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
22 if (i > 0x43c07fff)
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
23 return 32767;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
24 else if (i < 0x43bf8000)
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
25 return -32768;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
26 else
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
27 return i - 0x43c00000;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
28 }
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
29
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
30 static inline void float_to_int (float * _f, int16_t * s16, int flags)
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
31 {
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
32 int i;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
33 int32_t * f = (int32_t *) _f;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
34
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
35 switch (flags) {
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
36 case A52_MONO:
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
37 for (i = 0; i < 256; i++) {
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
38 s16[5*i] = s16[5*i+1] = s16[5*i+2] = s16[5*i+3] = 0;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
39 s16[5*i+4] = convert (f[i]);
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
40 }
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
41 break;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
42 case A52_CHANNEL:
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
43 case A52_STEREO:
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
44 case A52_DOLBY:
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
45 for (i = 0; i < 256; i++) {
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
46 s16[2*i] = convert (f[i]);
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
47 s16[2*i+1] = convert (f[i+256]);
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
48 }
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
49 break;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
50 case A52_3F:
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
51 for (i = 0; i < 256; i++) {
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
52 s16[5*i] = convert (f[i]);
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
53 s16[5*i+1] = convert (f[i+512]);
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
54 s16[5*i+2] = s16[5*i+3] = 0;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
55 s16[5*i+4] = convert (f[i+256]);
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
56 }
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
57 break;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
58 case A52_2F2R:
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
59 for (i = 0; i < 256; i++) {
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
60 s16[4*i] = convert (f[i]);
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
61 s16[4*i+1] = convert (f[i+256]);
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
62 s16[4*i+2] = convert (f[i+512]);
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
63 s16[4*i+3] = convert (f[i+768]);
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
64 }
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
65 break;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
66 case A52_3F2R:
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
67 for (i = 0; i < 256; i++) {
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
68 s16[5*i] = convert (f[i]);
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
69 s16[5*i+1] = convert (f[i+512]);
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
70 s16[5*i+2] = convert (f[i+768]);
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
71 s16[5*i+3] = convert (f[i+1024]);
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
72 s16[5*i+4] = convert (f[i+256]);
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
73 }
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
74 break;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
75 case A52_MONO | A52_LFE:
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
76 for (i = 0; i < 256; i++) {
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
77 s16[6*i] = s16[6*i+1] = s16[6*i+2] = s16[6*i+3] = 0;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
78 s16[6*i+4] = convert (f[i+256]);
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
79 s16[6*i+5] = convert (f[i]);
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
80 }
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
81 break;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
82 case A52_CHANNEL | A52_LFE:
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
83 case A52_STEREO | A52_LFE:
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
84 case A52_DOLBY | A52_LFE:
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
85 for (i = 0; i < 256; i++) {
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
86 s16[6*i] = convert (f[i+256]);
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
87 s16[6*i+1] = convert (f[i+512]);
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
88 s16[6*i+2] = s16[6*i+3] = s16[6*i+4] = 0;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
89 s16[6*i+5] = convert (f[i]);
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
90 }
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
91 break;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
92 case A52_3F | A52_LFE:
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
93 for (i = 0; i < 256; i++) {
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
94 s16[6*i] = convert (f[i+256]);
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
95 s16[6*i+1] = convert (f[i+768]);
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
96 s16[6*i+2] = s16[6*i+3] = 0;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
97 s16[6*i+4] = convert (f[i+512]);
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
98 s16[6*i+5] = convert (f[i]);
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
99 }
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
100 break;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
101 case A52_2F2R | A52_LFE:
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
102 for (i = 0; i < 256; i++) {
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
103 s16[6*i] = convert (f[i+256]);
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
104 s16[6*i+1] = convert (f[i+512]);
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
105 s16[6*i+2] = convert (f[i+768]);
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
106 s16[6*i+3] = convert (f[i+1024]);
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
107 s16[6*i+4] = 0;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
108 s16[6*i+5] = convert (f[i]);
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
109 }
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
110 break;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
111 case A52_3F2R | A52_LFE:
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
112 for (i = 0; i < 256; i++) {
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
113 s16[6*i] = convert (f[i+256]);
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
114 s16[6*i+1] = convert (f[i+768]);
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
115 s16[6*i+2] = convert (f[i+1024]);
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
116 s16[6*i+3] = convert (f[i+1280]);
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
117 s16[6*i+4] = convert (f[i+512]);
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
118 s16[6*i+5] = convert (f[i]);
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
119 }
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
120 break;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
121 }
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
122 }
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
123
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
124
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
125 int main(){
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
126 int accel=0;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
127 int sample_rate=0;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
128 int bit_rate=0;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
129
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
130 samples = a52_init (accel);
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
131 if (samples == NULL) {
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
132 fprintf (stderr, "A52 init failed\n");
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
133 return 1;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
134 }
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
135
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
136 while(1){
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
137 int length,i;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
138 int16_t *s16;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
139 sample_t level=1, bias=384;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
140 int flags=0;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
141
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
142 while(buf_size<7){
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
143 int c=getchar();
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
144 if(c<0) goto eof;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
145 buf[buf_size++]=c;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
146 }
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
147 length = a52_syncinfo (buf, &flags, &sample_rate, &bit_rate);
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
148 if(!length){
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
149 // bad file => resync
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
150 memcpy(buf,buf+1,6);
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
151 --buf_size;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
152 continue;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
153 }
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
154 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
155 while(buf_size<length){
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
156 buf[buf_size++]=getchar();
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
157 }
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
158
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
159 buf_size=0;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
160
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
161 // decode:
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
162 flags=A52_STEREO; // A52_DOLBY // A52_2F2R // A52_3F2R | A52_LFE
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
163 flags |= A52_ADJUST_LEVEL;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
164 if (a52_frame (&state, buf, &flags, &level, bias))
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
165 { fprintf(stderr,"error at decoding\n"); continue; }
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
166
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
167 // a52_dynrng (&state, NULL, NULL); // disable dynamic range compensation
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
168
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
169 s16 = out_buf;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
170 for (i = 0; i < 6; i++) {
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
171 int32_t * f = (int32_t *) samples;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
172 int i;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
173 if (a52_block (&state, samples))
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
174 { fprintf(stderr,"error at sampling\n"); break; }
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
175 // resample to STEREO/DOLBY:
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
176 for (i = 0; i < 256; i++) {
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
177 s16[2*i] = convert (f[i]);
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
178 s16[2*i+1] = convert (f[i+256]);
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
179 }
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
180 s16+=2*i;
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
181 }
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
182 fwrite(out_buf,6*256*2*2,1,stdout);
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
183
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
184 }
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
185
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
186 eof:
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
187
098634f41331 sample program for testing liba52
arpi
parents:
diff changeset
188 }