diff options
author | Christian Gmeiner <christian.gmeiner@gmail.com> | 2005-02-25 17:58:10 +0000 |
---|---|---|
committer | Christian Gmeiner <christian.gmeiner@gmail.com> | 2005-02-25 17:58:10 +0000 |
commit | 0eeb92f11c88c83254352c85cb1bb6a45da6c30a (patch) | |
tree | d03dc74a65e9cf2d43191d370c7e34e38a798683 /apps/plugins/wv2wav.c | |
parent | fe94a7aa8e3cc328e0dc417ae1041d57f9128d31 (diff) | |
download | rockbox-0eeb92f11c88c83254352c85cb1bb6a45da6c30a.tar.gz rockbox-0eeb92f11c88c83254352c85cb1bb6a45da6c30a.zip |
add wv2wav
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6063 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/wv2wav.c')
-rw-r--r-- | apps/plugins/wv2wav.c | 196 |
1 files changed, 196 insertions, 0 deletions
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 | |||
30 | static struct plugin_api* rb; | ||
31 | static file_info_struct file_info; | ||
32 | static 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. */ | ||
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 | *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 */ | ||
83 | void 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 | ||
108 | Maybe we do this at a lower level, but the | ||
109 | first thing is to get all working */ | ||
110 | long 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 */ | ||
129 | enum 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 */ | ||