summaryrefslogtreecommitdiff
path: root/apps/plugins/mpc2wav.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/mpc2wav.c')
-rw-r--r--apps/plugins/mpc2wav.c208
1 files changed, 0 insertions, 208 deletions
diff --git a/apps/plugins/mpc2wav.c b/apps/plugins/mpc2wav.c
deleted file mode 100644
index b1478bac31..0000000000
--- a/apps/plugins/mpc2wav.c
+++ /dev/null
@@ -1,208 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2005 Thom Johansen
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/* This is a lovely mishmash of sample.c from libmusepack and mpa2wav.c,
21 * but happens to work, so no whining!
22 */
23
24#include "plugin.h"
25
26#if (CONFIG_HWCODEC == MASNONE)
27/* software codec platforms */
28
29#include <codecs/libmusepack/musepack.h>
30
31#include "lib/xxx2wav.h" /* Helper functions common to test decoders */
32
33static struct plugin_api* rb;
34mpc_decoder decoder;
35
36/*
37 Our implementations of the mpc_reader callback functions.
38*/
39mpc_int32_t
40read_impl(void *data, void *ptr, mpc_int32_t size)
41{
42 file_info_struct *f = (file_info_struct *)data;
43 mpc_int32_t num = f->filesize - f->curpos;
44 if (num > size)
45 num = size;
46 rb->memcpy(ptr, filebuf + f->curpos, num);
47 f->curpos += num;
48 return num;
49}
50
51bool
52seek_impl(void *data, mpc_int32_t offset)
53{
54 file_info_struct *f = (file_info_struct *)data;
55 if (offset > f->filesize) {
56 return 0;
57 } else {
58 f->curpos = offset;
59 return 1;
60 }
61}
62
63mpc_int32_t
64tell_impl(void *data)
65{
66 file_info_struct *f = (file_info_struct *)data;
67 return f->curpos;
68}
69
70mpc_int32_t
71get_size_impl(void *data)
72{
73 file_info_struct *f = (file_info_struct *)data;
74 return f->filesize;
75}
76
77bool
78canseek_impl(void *data)
79{
80 (void)data;
81 return true;
82}
83
84static int
85shift_signed(MPC_SAMPLE_FORMAT val, int shift)
86{
87 if (shift > 0)
88 val <<= shift;
89 else if (shift < 0)
90 val >>= -shift;
91 return (int)val;
92}
93
94#define OUTPUT_BUFFER_SIZE 65536 /* Must be an integer multiple of 4. */
95
96unsigned char OutputBuffer[OUTPUT_BUFFER_SIZE];
97MPC_SAMPLE_FORMAT sample_buffer[MPC_DECODER_BUFFER_LENGTH];
98unsigned char *OutputPtr=OutputBuffer;
99const unsigned char *OutputBufferEnd=OutputBuffer+OUTPUT_BUFFER_SIZE;
100
101#ifdef USE_IRAM
102extern char iramcopy[];
103extern char iramstart[];
104extern char iramend[];
105#endif
106
107/* this is the plugin entry point */
108enum plugin_status plugin_start(struct plugin_api* api, void* file)
109{
110 file_info_struct file_info;
111 unsigned short Sample;
112 unsigned status = 1;
113 unsigned int i;
114 mpc_reader reader;
115
116 /* Generic plugin inititialisation */
117
118 TEST_PLUGIN_API(api);
119 rb = api;
120
121#ifdef USE_IRAM
122 rb->memcpy(iramstart, iramcopy, iramend-iramstart);
123#endif
124
125 reader.read = read_impl;
126 reader.seek = seek_impl;
127 reader.tell = tell_impl;
128 reader.get_size = get_size_impl;
129 reader.canseek = canseek_impl;
130 reader.data = &file_info;
131
132 /* This function sets up the buffers and reads the file into RAM */
133
134 if (local_init(file, "/libmusepacktest.wav", &file_info, api)) {
135 return PLUGIN_ERROR;
136 }
137
138 /* read file's streaminfo data */
139 mpc_streaminfo info;
140 mpc_streaminfo_init(&info);
141 if (mpc_streaminfo_read(&info, &reader) != ERROR_CODE_OK) {
142 rb->splash(HZ, true, "Not an MPC file.");
143 return PLUGIN_ERROR;
144 }
145 file_info.samplerate=info.sample_freq;
146 /* instantiate a decoder with our file reader */
147 mpc_decoder_setup(&decoder, &reader);
148 if (!mpc_decoder_initialize(&decoder, &info)) {
149 rb->splash(HZ, true, "Error in init.");
150 return PLUGIN_ERROR;
151 }
152 file_info.frames_decoded = 0;
153 file_info.start_tick = *(rb->current_tick);
154
155 rb->button_clear_queue();
156
157 /* This is the decoding loop. */
158 while (status != 0) {
159 status = mpc_decoder_decode(&decoder, sample_buffer, 0, 0);
160 if (status == (unsigned)(-1)) {
161 //decode error
162 rb->splash(HZ, true, "Error decoding file.");
163 break;
164 }
165 else //status>0
166 {
167 file_info.current_sample += status;
168 file_info.frames_decoded++;
169 /* Convert musepack's numbers to an array of 16-bit LE signed integers */
170#if 1 /* uncomment to time without byte swapping and disk writing */
171 for(i = 0; i < status*info.channels; i += info.channels)
172 {
173 /* Left channel */
174 Sample=shift_signed(sample_buffer[i], 16 - MPC_FIXED_POINT_SCALE_SHIFT);
175 *(OutputPtr++)=Sample&0xff;
176 *(OutputPtr++)=Sample>>8;
177
178 /* Right channel. If the decoded stream is monophonic then
179 * the right output channel is the same as the left one.
180 */
181 if(info.channels==2)
182 Sample=shift_signed(sample_buffer[i + 1], 16 - MPC_FIXED_POINT_SCALE_SHIFT);
183 *(OutputPtr++)=Sample&0xff;
184 *(OutputPtr++)=Sample>>8;
185
186 /* Flush the buffer if it is full. */
187 if(OutputPtr==OutputBufferEnd)
188 {
189 rb->write(file_info.outfile,OutputBuffer,OUTPUT_BUFFER_SIZE);
190 OutputPtr=OutputBuffer;
191 }
192 }
193#endif
194
195 }
196 display_status(&file_info);
197
198 if (rb->button_get(false)!=BUTTON_NONE) {
199 close_wav(&file_info);
200 return PLUGIN_OK;
201 }
202 }
203 close_wav(&file_info);
204 rb->splash(HZ*2, true, "FINISHED!");
205
206 return PLUGIN_OK;
207}
208#endif /* CONFIG_HWCODEC == MASNONE */