summaryrefslogtreecommitdiff
path: root/apps/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins')
-rw-r--r--apps/plugins/Makefile2
-rw-r--r--apps/plugins/SOURCES1
-rw-r--r--apps/plugins/viewers.config1
-rw-r--r--apps/plugins/wv2wav.c196
4 files changed, 199 insertions, 1 deletions
diff --git a/apps/plugins/Makefile b/apps/plugins/Makefile
index 50b5ab9c67..3e56510f53 100644
--- a/apps/plugins/Makefile
+++ b/apps/plugins/Makefile
@@ -17,7 +17,7 @@ ifdef APPEXTRA
17endif 17endif
18 18
19ifdef SOFTWARECODECS 19ifdef SOFTWARECODECS
20 CODECLIBS = -lmad -la52 -lFLAC -lTremor 20 CODECLIBS = -lmad -la52 -lFLAC -lTremor -lwavpack
21endif 21endif
22 22
23LDS := plugin.lds 23LDS := plugin.lds
diff --git a/apps/plugins/SOURCES b/apps/plugins/SOURCES
index d29bd3cb32..643fc0c5c1 100644
--- a/apps/plugins/SOURCES
+++ b/apps/plugins/SOURCES
@@ -68,4 +68,5 @@ mpa2wav.c
68a52towav.c 68a52towav.c
69flac2wav.c 69flac2wav.c
70vorbis2wav.c 70vorbis2wav.c
71wv2wav.c
71#endif 72#endif
diff --git a/apps/plugins/viewers.config b/apps/plugins/viewers.config
index aa25d6fe81..2290a8e635 100644
--- a/apps/plugins/viewers.config
+++ b/apps/plugins/viewers.config
@@ -12,3 +12,4 @@ ac3,a52towav.rock, 00 00 00 00 00 00
12a52,a52towav.rock, 00 00 00 00 00 00 12a52,a52towav.rock, 00 00 00 00 00 00
13flac,flac2wav.rock, 00 00 00 00 00 00 13flac,flac2wav.rock, 00 00 00 00 00 00
14ogg,vorbis2wav.rock, 00 00 00 00 00 00 14ogg,vorbis2wav.rock, 00 00 00 00 00 00
15wv,wv2wav.rock, 00 00 00 00 00 00
diff --git a/apps/plugins/wv2wav.c b/apps/plugins/wv2wav.c
new file mode 100644
index 0000000000..73f71cd962
--- /dev/null
+++ b/apps/plugins/wv2wav.c
@@ -0,0 +1,196 @@
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
30static struct plugin_api* rb;
31static file_info_struct file_info;
32static long temp_buffer [BUFFER_SIZE];
33
34/* Reformat samples from longs in processor's native endian mode to
35 little-endian data with (possibly) less than 4 bytes / sample. */
36uchar* 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 *dst++ = *src++ + 128;
45
46 break;
47
48 case 2:
49 while (samcnt--)
50 {
51 *dst++ = (uchar)(temp = *src++);
52 *dst++ = (uchar)(temp >> 8);
53 }
54
55 break;
56
57 case 3:
58 while (samcnt--)
59 {
60 *dst++ = (uchar)(temp = *src++);
61 *dst++ = (uchar)(temp >> 8);
62 *dst++ = (uchar)(temp >> 16);
63 }
64
65 break;
66
67 case 4:
68 while (samcnt--)
69 {
70 *dst++ = (uchar)(temp = *src++);
71 *dst++ = (uchar)(temp >> 8);
72 *dst++ = (uchar)(temp >> 16);
73 *dst++ = (uchar)(temp >> 24);
74 }
75
76 break;
77 }
78
79 return dst;
80}
81
82/* this is our function to decode a memory block from a file */
83void wvpack_decode_data(file_info_struct* file_info, int samples_to_decode, WavpackContext **wpc)
84{
85 int bps = WavpackGetBytesPerSample(*wpc);
86
87 /* nothing to decode */
88 if (!samples_to_decode)
89 {
90 return;
91 }
92
93 /* decode now */
94 ulong samples_unpacked = WavpackUnpackSamples(*wpc, temp_buffer, samples_to_decode);
95
96 if (samples_unpacked)
97 {
98 /* update some infos */
99 file_info->current_sample += samples_unpacked;
100
101 format_samples (bps, (uchar *) temp_buffer, temp_buffer, samples_unpacked *= file_info->channels);
102
103 rb->write(file_info->outfile, temp_buffer, samples_unpacked * bps);
104 }
105}
106
107/* callback function for wavpack
108Maybe we do this at a lower level, but the
109first thing is to get all working */
110long Read(void* buffer, long size)
111{
112 long oldpos = file_info.curpos;
113
114 if ((file_info.curpos + size) < file_info.filesize)
115 {
116 memcpy(buffer, &filebuf[file_info.curpos], size);
117 file_info.curpos += size;
118 }
119 else
120 {
121 memcpy(buffer, &filebuf[file_info.curpos], (file_info.filesize-1-file_info.curpos));
122 file_info.curpos = file_info.filesize;
123 }
124
125 return (file_info.curpos - oldpos);
126}
127
128/* this is the plugin entry point */
129enum plugin_status plugin_start(struct plugin_api* api, void* file)
130{
131 WavpackContext *wpc;
132 char error[80];
133
134 /* generic plugin initialisation */
135 TEST_PLUGIN_API(api);
136 rb = api;
137
138 /* this function sets up the buffers and reads the file into RAM */
139 if (local_init(file,"/wvtest.wav",&file_info,api))
140 {
141 return PLUGIN_ERROR;
142 }
143
144 /* setup wavpack */
145 wpc = WavpackOpenFileInput(Read, error);
146
147 /* was there an error? */
148 if (!wpc)
149 {
150 rb->splash(HZ*2, true, error);
151 return PLUGIN_ERROR;
152 }
153
154 /* grap/set some infos */
155 file_info.channels = WavpackGetReducedChannels(wpc);
156 file_info.total_samples = WavpackGetNumSamples(wpc);
157 file_info.bitspersample = WavpackGetBitsPerSample(wpc);
158 file_info.samplerate = WavpackGetSampleRate(wpc);
159 file_info.current_sample = 0;
160
161 /* deciding loop */
162 file_info.start_tick=*(rb->current_tick);
163 rb->button_clear_queue();
164
165 while (file_info.current_sample < file_info.total_samples)
166 {
167 wvpack_decode_data(&file_info, BUFFER_SIZE / file_info.channels, &wpc);
168
169 display_status(&file_info);
170
171 if (rb->button_get(false)!=BUTTON_NONE)
172 {
173 close_wav(&file_info);
174 return PLUGIN_OK;
175 }
176 }
177
178 /* do some last checks */
179 if ((WavpackGetNumSamples (wpc) != (ulong) -1) && (file_info.total_samples != WavpackGetNumSamples (wpc)))
180 {
181 rb->splash(HZ*2, true, "incorrect number of samples!");
182 return PLUGIN_ERROR;
183 }
184
185 if (WavpackGetNumErrors (wpc)) {
186 rb->splash(HZ*2, true, "crc errors detected!");
187 return PLUGIN_ERROR;
188 }
189
190 close_wav(&file_info);
191 rb->splash(HZ*2, true, "FINISHED!");
192
193 return PLUGIN_OK;
194}
195
196#endif /* CONFIG_HWCODEC == MASNONE */