diff options
Diffstat (limited to 'apps/plugins/wv2wav.c')
-rw-r--r-- | apps/plugins/wv2wav.c | 217 |
1 files changed, 0 insertions, 217 deletions
diff --git a/apps/plugins/wv2wav.c b/apps/plugins/wv2wav.c deleted file mode 100644 index 909a0c3c63..0000000000 --- a/apps/plugins/wv2wav.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 Christian Gmeiner | ||
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 "lib/xxx2wav.h" /* Helper functions common to test decoders */ | ||
26 | #include <codecs/libwavpack/wavpack.h> | ||
27 | |||
28 | #define BUFFER_SIZE 4096 | ||
29 | |||
30 | static struct plugin_api* rb; | ||
31 | static file_info_struct file_info; | ||
32 | static long temp_buffer [BUFFER_SIZE] IDATA_ATTR; | ||
33 | |||
34 | /* Reformat samples from longs in processor's native endian mode to | ||
35 | little-endian data with 2 bytes / sample. */ | ||
36 | uchar* format_samples (int bps, uchar *dst, long *src, ulong samcnt) | ||
37 | { | ||
38 | long temp; | ||
39 | |||
40 | switch (bps) | ||
41 | { | ||
42 | case 1: | ||
43 | while (samcnt--) | ||
44 | { | ||
45 | *dst++ = (uchar)(temp = (*src++ << 8)); | ||
46 | *dst++ = (uchar)(temp >> 8); | ||
47 | } | ||
48 | |||
49 | break; | ||
50 | |||
51 | case 2: | ||
52 | while (samcnt--) | ||
53 | { | ||
54 | *dst++ = (uchar)(temp = *src++); | ||
55 | *dst++ = (uchar)(temp >> 8); | ||
56 | } | ||
57 | |||
58 | break; | ||
59 | |||
60 | case 3: | ||
61 | while (samcnt--) | ||
62 | { | ||
63 | *dst++ = (uchar)(temp = (*src++ >> 8)); | ||
64 | *dst++ = (uchar)(temp >> 8); | ||
65 | } | ||
66 | |||
67 | break; | ||
68 | |||
69 | case 4: | ||
70 | while (samcnt--) | ||
71 | { | ||
72 | *dst++ = (uchar)(temp = (*src++ >> 16)); | ||
73 | *dst++ = (uchar)(temp >> 8); | ||
74 | } | ||
75 | |||
76 | break; | ||
77 | } | ||
78 | |||
79 | return dst; | ||
80 | } | ||
81 | |||
82 | /* this is our function to decode a memory block from a file */ | ||
83 | void wvpack_decode_data(file_info_struct* file_info, int samples_to_decode, WavpackContext **wpc) | ||
84 | { | ||
85 | int bps = WavpackGetBytesPerSample(*wpc); | ||
86 | /* nothing to decode */ | ||
87 | if (!samples_to_decode) | ||
88 | { | ||
89 | return; | ||
90 | } | ||
91 | |||
92 | /* decode now */ | ||
93 | ulong samples_unpacked = WavpackUnpackSamples(*wpc, temp_buffer, samples_to_decode); | ||
94 | |||
95 | if (samples_unpacked) | ||
96 | { | ||
97 | /* update some infos */ | ||
98 | file_info->current_sample += samples_unpacked; | ||
99 | |||
100 | /* for now, convert mono to stereo here, in place */ | ||
101 | if (WavpackGetReducedChannels (*wpc) == 1) { | ||
102 | long *dst = temp_buffer + (samples_unpacked * 2); | ||
103 | long *src = temp_buffer + samples_unpacked; | ||
104 | long count = samples_unpacked; | ||
105 | |||
106 | while (count--) { | ||
107 | *--dst = *--src; | ||
108 | *--dst = *src; | ||
109 | } | ||
110 | } | ||
111 | |||
112 | format_samples (bps, (uchar *) temp_buffer, temp_buffer, samples_unpacked * file_info->channels); | ||
113 | rb->write(file_info->outfile, temp_buffer, samples_unpacked * 4); | ||
114 | } | ||
115 | } | ||
116 | |||
117 | /* callback function for wavpack | ||
118 | Maybe we do this at a lower level, but the | ||
119 | first thing is to get all working */ | ||
120 | long Read(void* buffer, long size) | ||
121 | { | ||
122 | long oldpos = file_info.curpos; | ||
123 | |||
124 | if ((file_info.curpos + size) < file_info.filesize) | ||
125 | { | ||
126 | memcpy(buffer, &filebuf[file_info.curpos], size); | ||
127 | file_info.curpos += size; | ||
128 | } | ||
129 | else | ||
130 | { | ||
131 | memcpy(buffer, &filebuf[file_info.curpos], file_info.filesize-file_info.curpos); | ||
132 | file_info.curpos = file_info.filesize; | ||
133 | } | ||
134 | |||
135 | return (file_info.curpos - oldpos); | ||
136 | } | ||
137 | |||
138 | #ifdef USE_IRAM | ||
139 | extern char iramcopy[]; | ||
140 | extern char iramstart[]; | ||
141 | extern char iramend[]; | ||
142 | #endif | ||
143 | |||
144 | /* this is the plugin entry point */ | ||
145 | enum plugin_status plugin_start(struct plugin_api* api, void* file) | ||
146 | { | ||
147 | WavpackContext *wpc; | ||
148 | char error[80]; | ||
149 | |||
150 | /* generic plugin initialisation */ | ||
151 | TEST_PLUGIN_API(api); | ||
152 | rb = api; | ||
153 | |||
154 | #ifdef USE_IRAM | ||
155 | rb->memcpy(iramstart, iramcopy, iramend-iramstart); | ||
156 | #endif | ||
157 | |||
158 | /* this function sets up the buffers and reads the file into RAM */ | ||
159 | if (local_init(file,"/wvtest.wav",&file_info,api)) | ||
160 | { | ||
161 | return PLUGIN_ERROR; | ||
162 | } | ||
163 | |||
164 | /* setup wavpack */ | ||
165 | wpc = WavpackOpenFileInput(Read, error); | ||
166 | |||
167 | /* was there an error? */ | ||
168 | if (!wpc) | ||
169 | { | ||
170 | rb->splash(HZ*2, true, error); | ||
171 | return PLUGIN_ERROR; | ||
172 | } | ||
173 | |||
174 | /* grap/set some infos (forcing some to temp values) */ | ||
175 | file_info.channels = 2; | ||
176 | file_info.total_samples = WavpackGetNumSamples(wpc); | ||
177 | file_info.bitspersample = 16; | ||
178 | file_info.samplerate = WavpackGetSampleRate(wpc); | ||
179 | file_info.current_sample = 0; | ||
180 | |||
181 | /* deciding loop */ | ||
182 | file_info.start_tick=*(rb->current_tick); | ||
183 | rb->button_clear_queue(); | ||
184 | |||
185 | while (file_info.current_sample < file_info.total_samples) | ||
186 | { | ||
187 | wvpack_decode_data(&file_info, BUFFER_SIZE / file_info.channels, &wpc); | ||
188 | |||
189 | display_status(&file_info); | ||
190 | |||
191 | if (rb->button_get(false)!=BUTTON_NONE) | ||
192 | { | ||
193 | close_wav(&file_info); | ||
194 | return PLUGIN_OK; | ||
195 | } | ||
196 | } | ||
197 | |||
198 | close_wav(&file_info); | ||
199 | |||
200 | /* do some last checks */ | ||
201 | if ((WavpackGetNumSamples (wpc) != (ulong) -1) && (file_info.current_sample != WavpackGetNumSamples (wpc))) | ||
202 | { | ||
203 | rb->splash(HZ*2, true, "incorrect number of samples!"); | ||
204 | return PLUGIN_ERROR; | ||
205 | } | ||
206 | |||
207 | if (WavpackGetNumErrors (wpc)) { | ||
208 | rb->splash(HZ*2, true, "crc errors detected!"); | ||
209 | return PLUGIN_ERROR; | ||
210 | } | ||
211 | |||
212 | rb->splash(HZ*2, true, "FINISHED!"); | ||
213 | |||
214 | return PLUGIN_OK; | ||
215 | } | ||
216 | |||
217 | #endif /* CONFIG_HWCODEC == MASNONE */ | ||