diff options
Diffstat (limited to 'apps/plugins/a52towav.c')
-rw-r--r-- | apps/plugins/a52towav.c | 217 |
1 files changed, 0 insertions, 217 deletions
diff --git a/apps/plugins/a52towav.c b/apps/plugins/a52towav.c deleted file mode 100644 index f6769abd2b..0000000000 --- a/apps/plugins/a52towav.c +++ /dev/null | |||
@@ -1,217 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2005 Dave Chapman | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | #include "plugin.h" | ||
21 | |||
22 | #if (CONFIG_HWCODEC == MASNONE) | ||
23 | /* software codec platforms */ | ||
24 | |||
25 | #include <inttypes.h> /* Needed by a52.h */ | ||
26 | |||
27 | #include <codecs/liba52/config-a52.h> | ||
28 | #include <codecs/liba52/a52.h> | ||
29 | |||
30 | #include "lib/xxx2wav.h" /* Helper functions common to test decoders */ | ||
31 | |||
32 | static struct plugin_api* rb; | ||
33 | |||
34 | #ifdef WORDS_BIGENDIAN | ||
35 | #define LE_S16(x) ( (uint16_t) ( ((uint16_t)(x) >> 8) | ((uint16_t)(x) << 8) ) ) | ||
36 | #else | ||
37 | #define LE_S16(x) (x) | ||
38 | #endif | ||
39 | |||
40 | |||
41 | static float gain = 1; | ||
42 | static a52_state_t * state; | ||
43 | |||
44 | static inline int16_t convert (int32_t i) | ||
45 | { | ||
46 | i >>= 15; | ||
47 | return (i > 32767) ? 32767 : ((i < -32768) ? -32768 : i); | ||
48 | } | ||
49 | |||
50 | void ao_play(file_info_struct* file_info,sample_t* samples,int flags) { | ||
51 | int i; | ||
52 | static int16_t int16_samples[256*2]; | ||
53 | |||
54 | flags &= A52_CHANNEL_MASK | A52_LFE; | ||
55 | |||
56 | if (flags==A52_STEREO) { | ||
57 | for (i = 0; i < 256; i++) { | ||
58 | int16_samples[2*i] = LE_S16(convert (samples[i])); | ||
59 | int16_samples[2*i+1] = LE_S16(convert (samples[i+256])); | ||
60 | } | ||
61 | } else { | ||
62 | DEBUGF("ERROR: unsupported format: %d\n",flags); | ||
63 | } | ||
64 | |||
65 | /* FIX: Buffer the disk write to write larger amounts at one */ | ||
66 | i=rb->write(file_info->outfile,int16_samples,256*2*2); | ||
67 | } | ||
68 | |||
69 | |||
70 | void a52_decode_data (file_info_struct* file_info, uint8_t * start, uint8_t * end) | ||
71 | { | ||
72 | static uint8_t buf[3840]; | ||
73 | static uint8_t * bufptr = buf; | ||
74 | static uint8_t * bufpos = buf + 7; | ||
75 | |||
76 | /* | ||
77 | * sample_rate and flags are static because this routine could | ||
78 | * exit between the a52_syncinfo() and the ao_setup(), and we want | ||
79 | * to have the same values when we get back ! | ||
80 | */ | ||
81 | |||
82 | static int sample_rate; | ||
83 | static int flags; | ||
84 | int bit_rate; | ||
85 | int len; | ||
86 | |||
87 | while (1) { | ||
88 | len = end - start; | ||
89 | if (!len) | ||
90 | break; | ||
91 | if (len > bufpos - bufptr) | ||
92 | len = bufpos - bufptr; | ||
93 | memcpy (bufptr, start, len); | ||
94 | bufptr += len; | ||
95 | start += len; | ||
96 | if (bufptr == bufpos) { | ||
97 | if (bufpos == buf + 7) { | ||
98 | int length; | ||
99 | |||
100 | length = a52_syncinfo (buf, &flags, &sample_rate, &bit_rate); | ||
101 | if (!length) { | ||
102 | DEBUGF("skip\n"); | ||
103 | for (bufptr = buf; bufptr < buf + 6; bufptr++) | ||
104 | bufptr[0] = bufptr[1]; | ||
105 | continue; | ||
106 | } | ||
107 | bufpos = buf + length; | ||
108 | } else { | ||
109 | // The following two defaults are taken from audio_out_oss.c: | ||
110 | level_t level; | ||
111 | sample_t bias; | ||
112 | int i; | ||
113 | |||
114 | /* This is the configuration for the downmixing: */ | ||
115 | flags=A52_STEREO|A52_ADJUST_LEVEL|A52_LFE; | ||
116 | level=(1 << 26); | ||
117 | bias=0; | ||
118 | |||
119 | level = (level_t) (level * gain); | ||
120 | |||
121 | if (a52_frame (state, buf, &flags, &level, bias)) | ||
122 | goto error; | ||
123 | file_info->frames_decoded++; | ||
124 | |||
125 | /* We assume this never changes */ | ||
126 | file_info->samplerate=sample_rate; | ||
127 | |||
128 | // An A52 frame consists of 6 blocks of 256 samples | ||
129 | // So we decode and output them one block at a time | ||
130 | for (i = 0; i < 6; i++) { | ||
131 | if (a52_block (state)) { | ||
132 | goto error; | ||
133 | } | ||
134 | ao_play (file_info, a52_samples (state),flags); | ||
135 | file_info->current_sample+=256; | ||
136 | } | ||
137 | bufptr = buf; | ||
138 | bufpos = buf + 7; | ||
139 | continue; | ||
140 | error: | ||
141 | DEBUGF("error\n"); | ||
142 | bufptr = buf; | ||
143 | bufpos = buf + 7; | ||
144 | } | ||
145 | } | ||
146 | } | ||
147 | } | ||
148 | |||
149 | |||
150 | #define BUFFER_SIZE 4096 | ||
151 | |||
152 | #ifdef USE_IRAM | ||
153 | extern char iramcopy[]; | ||
154 | extern char iramstart[]; | ||
155 | extern char iramend[]; | ||
156 | #endif | ||
157 | |||
158 | /* this is the plugin entry point */ | ||
159 | enum plugin_status plugin_start(struct plugin_api* api, void* file) | ||
160 | { | ||
161 | file_info_struct file_info; | ||
162 | |||
163 | /* Generic plugin initialisation */ | ||
164 | |||
165 | TEST_PLUGIN_API(api); | ||
166 | rb = api; | ||
167 | |||
168 | #ifdef USE_IRAM | ||
169 | rb->memcpy(iramstart, iramcopy, iramend-iramstart); | ||
170 | #endif | ||
171 | |||
172 | /* This function sets up the buffers and reads the file into RAM */ | ||
173 | |||
174 | if (local_init(file,"/ac3test.wav",&file_info,api)) { | ||
175 | return PLUGIN_ERROR; | ||
176 | } | ||
177 | |||
178 | /* Intialise the A52 decoder and check for success */ | ||
179 | state = a52_init (0); // Parameter is "accel" | ||
180 | |||
181 | if (state == NULL) { | ||
182 | rb->splash(HZ*2, true, "a52_init failed"); | ||
183 | return PLUGIN_ERROR; | ||
184 | } | ||
185 | |||
186 | /* The main decoding loop */ | ||
187 | |||
188 | file_info.start_tick=*(rb->current_tick); | ||
189 | rb->button_clear_queue(); | ||
190 | |||
191 | while (file_info.curpos < file_info.filesize) { | ||
192 | |||
193 | if ((file_info.curpos+BUFFER_SIZE) < file_info.filesize) { | ||
194 | a52_decode_data(&file_info,&filebuf[file_info.curpos],&filebuf[file_info.curpos+BUFFER_SIZE]); | ||
195 | file_info.curpos+=BUFFER_SIZE; | ||
196 | } else { | ||
197 | a52_decode_data(&file_info,&filebuf[file_info.curpos],&filebuf[file_info.filesize-1]); | ||
198 | file_info.curpos=file_info.filesize; | ||
199 | } | ||
200 | |||
201 | display_status(&file_info); | ||
202 | |||
203 | if (rb->button_get(false)!=BUTTON_NONE) { | ||
204 | close_wav(&file_info); | ||
205 | return PLUGIN_OK; | ||
206 | } | ||
207 | } | ||
208 | close_wav(&file_info); | ||
209 | |||
210 | /* Cleanly close and exit */ | ||
211 | |||
212 | //NOT NEEDED: a52_free (state); | ||
213 | |||
214 | rb->splash(HZ*2, true, "FINISHED!"); | ||
215 | return PLUGIN_OK; | ||
216 | } | ||
217 | #endif /* CONFIG_HWCODEC == MASNONE */ | ||