diff options
Diffstat (limited to 'apps/plugins/flac2wav.c')
-rw-r--r-- | apps/plugins/flac2wav.c | 237 |
1 files changed, 0 insertions, 237 deletions
diff --git a/apps/plugins/flac2wav.c b/apps/plugins/flac2wav.c deleted file mode 100644 index 84b5ed15b2..0000000000 --- a/apps/plugins/flac2wav.c +++ /dev/null | |||
@@ -1,237 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 Björn Stenberg | ||
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 <codecs/libFLAC/include/FLAC/seekable_stream_decoder.h> | ||
26 | |||
27 | #include "lib/xxx2wav.h" /* Helper functions common to test decoders */ | ||
28 | |||
29 | #define FLAC_MAX_SUPPORTED_BLOCKSIZE 4608 | ||
30 | #define FLAC_MAX_SUPPORTED_CHANNELS 2 | ||
31 | |||
32 | static struct plugin_api* rb; | ||
33 | |||
34 | /* Called when the FLAC decoder needs some FLAC data to decode */ | ||
35 | FLAC__SeekableStreamDecoderReadStatus flac_read_handler(const FLAC__SeekableStreamDecoder *dec, | ||
36 | FLAC__byte buffer[], unsigned *bytes, void *data) | ||
37 | { (void)dec; | ||
38 | |||
39 | file_info_struct *p = (file_info_struct *) data; | ||
40 | |||
41 | if (p->curpos >= p->filesize) { | ||
42 | return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM; | ||
43 | } | ||
44 | |||
45 | rb->memcpy(buffer,&filebuf[p->curpos],*bytes); | ||
46 | p->curpos+=*bytes; | ||
47 | |||
48 | return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE; | ||
49 | } | ||
50 | |||
51 | /* Called when the FLAC decoder has some decoded PCM data to write */ | ||
52 | FLAC__StreamDecoderWriteStatus flac_write_handler(const FLAC__SeekableStreamDecoder *dec, | ||
53 | const FLAC__Frame *frame, | ||
54 | const FLAC__int32 * const buf[], | ||
55 | void *data) | ||
56 | { | ||
57 | unsigned int c_samp, c_chan, d_samp; | ||
58 | file_info_struct *p = (file_info_struct *) data; | ||
59 | uint32_t data_size = frame->header.blocksize * frame->header.channels * (p->bitspersample / 8); | ||
60 | uint32_t samples = frame->header.blocksize; | ||
61 | |||
62 | // FIXME: This should not be on the stack! | ||
63 | static unsigned char ldb[FLAC_MAX_SUPPORTED_BLOCKSIZE*FLAC_MAX_SUPPORTED_CHANNELS*2]; | ||
64 | |||
65 | if (samples*frame->header.channels > (FLAC_MAX_SUPPORTED_BLOCKSIZE*FLAC_MAX_SUPPORTED_CHANNELS)) { | ||
66 | // ERROR!!! | ||
67 | DEBUGF("ERROR: samples*frame->header.channels=%d\n",samples*frame->header.channels); | ||
68 | return(FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE); | ||
69 | } | ||
70 | |||
71 | (void)dec; | ||
72 | (void)data_size; | ||
73 | for(c_samp = d_samp = 0; c_samp < samples; c_samp++) { | ||
74 | for(c_chan = 0; c_chan < frame->header.channels; c_chan++, d_samp++) { | ||
75 | ldb[d_samp*2] = buf[c_chan][c_samp]&0xff; | ||
76 | ldb[(d_samp*2)+1] = (buf[c_chan][c_samp]&0xff00)>>8; | ||
77 | } | ||
78 | } | ||
79 | |||
80 | rb->write(p->outfile,ldb,data_size); | ||
81 | |||
82 | p->current_sample += samples; | ||
83 | |||
84 | return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; | ||
85 | } | ||
86 | |||
87 | void flac_metadata_handler(const FLAC__SeekableStreamDecoder *dec, | ||
88 | const FLAC__StreamMetadata *meta, void *data) | ||
89 | { | ||
90 | file_info_struct *p = (file_info_struct *) data; | ||
91 | (void)dec; | ||
92 | |||
93 | if(meta->type == FLAC__METADATA_TYPE_STREAMINFO) { | ||
94 | p->bitspersample = meta->data.stream_info.bits_per_sample; | ||
95 | p->samplerate = meta->data.stream_info.sample_rate; | ||
96 | p->channels = meta->data.stream_info.channels; | ||
97 | // FLAC__ASSERT(meta->data.stream_info.total_samples < 0x100000000); /* we can handle < 4 gigasamples */ | ||
98 | p->total_samples = (unsigned) | ||
99 | (meta->data.stream_info.total_samples & 0xffffffff); | ||
100 | p->current_sample = 0; | ||
101 | } | ||
102 | } | ||
103 | |||
104 | |||
105 | void flac_error_handler(const FLAC__SeekableStreamDecoder *dec, | ||
106 | FLAC__StreamDecoderErrorStatus status, void *data) | ||
107 | { | ||
108 | (void)dec; | ||
109 | (void)status; | ||
110 | (void)data; | ||
111 | } | ||
112 | |||
113 | FLAC__SeekableStreamDecoderSeekStatus flac_seek_handler (const FLAC__SeekableStreamDecoder *decoder, | ||
114 | FLAC__uint64 absolute_byte_offset, | ||
115 | void *client_data) | ||
116 | { | ||
117 | (void)decoder; | ||
118 | file_info_struct *p = (file_info_struct *) client_data; | ||
119 | rb->lseek(p->infile,SEEK_SET,absolute_byte_offset); | ||
120 | return(FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_OK); | ||
121 | } | ||
122 | |||
123 | FLAC__SeekableStreamDecoderTellStatus flac_tell_handler (const FLAC__SeekableStreamDecoder *decoder, | ||
124 | FLAC__uint64 *absolute_byte_offset, void *client_data) | ||
125 | { | ||
126 | file_info_struct *p = (file_info_struct *) client_data; | ||
127 | |||
128 | (void)decoder; | ||
129 | *absolute_byte_offset=rb->lseek(p->infile,SEEK_CUR,0); | ||
130 | return(FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_OK); | ||
131 | } | ||
132 | |||
133 | FLAC__SeekableStreamDecoderLengthStatus flac_length_handler (const FLAC__SeekableStreamDecoder *decoder, | ||
134 | FLAC__uint64 *stream_length, void *client_data) | ||
135 | { | ||
136 | file_info_struct *p = (file_info_struct *) client_data; | ||
137 | |||
138 | (void)decoder; | ||
139 | *stream_length=p->filesize; | ||
140 | return(FLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_OK); | ||
141 | } | ||
142 | |||
143 | FLAC__bool flac_eof_handler (const FLAC__SeekableStreamDecoder *decoder, | ||
144 | void *client_data) | ||
145 | { | ||
146 | file_info_struct *p = (file_info_struct *) client_data; | ||
147 | |||
148 | (void)decoder; | ||
149 | if (p->curpos >= p->filesize) { | ||
150 | return(true); | ||
151 | } else { | ||
152 | return(false); | ||
153 | } | ||
154 | } | ||
155 | |||
156 | #ifndef SIMULATOR | ||
157 | extern char iramcopy[]; | ||
158 | extern char iramstart[]; | ||
159 | extern char iramend[]; | ||
160 | #endif | ||
161 | |||
162 | /* this is the plugin entry point */ | ||
163 | enum plugin_status plugin_start(struct plugin_api* api, void* file) | ||
164 | { | ||
165 | FLAC__SeekableStreamDecoder* flacDecoder; | ||
166 | file_info_struct file_info; | ||
167 | |||
168 | TEST_PLUGIN_API(api); | ||
169 | |||
170 | /* if you are using a global api pointer, don't forget to copy it! | ||
171 | otherwise you will get lovely "I04: IllInstr" errors... :-) */ | ||
172 | rb = api; | ||
173 | |||
174 | #ifndef SIMULATOR | ||
175 | rb->memcpy(iramstart, iramcopy, iramend-iramstart); | ||
176 | #endif | ||
177 | |||
178 | /* This function sets up the buffers and reads the file into RAM */ | ||
179 | |||
180 | if (local_init(file,"/flactest.wav",&file_info,api)) { | ||
181 | return PLUGIN_ERROR; | ||
182 | } | ||
183 | |||
184 | /* Create a decoder instance */ | ||
185 | |||
186 | flacDecoder=FLAC__seekable_stream_decoder_new(); | ||
187 | |||
188 | /* Set up the decoder and the callback functions - this must be done before init */ | ||
189 | |||
190 | /* The following are required for stream_decoder and higher */ | ||
191 | FLAC__seekable_stream_decoder_set_client_data(flacDecoder,&file_info); | ||
192 | FLAC__seekable_stream_decoder_set_write_callback(flacDecoder, flac_write_handler); | ||
193 | FLAC__seekable_stream_decoder_set_read_callback(flacDecoder, flac_read_handler); | ||
194 | FLAC__seekable_stream_decoder_set_metadata_callback(flacDecoder, flac_metadata_handler); | ||
195 | FLAC__seekable_stream_decoder_set_error_callback(flacDecoder, flac_error_handler); | ||
196 | FLAC__seekable_stream_decoder_set_metadata_respond(flacDecoder, FLAC__METADATA_TYPE_STREAMINFO); | ||
197 | |||
198 | /* The following are only for the seekable_stream_decoder */ | ||
199 | FLAC__seekable_stream_decoder_set_seek_callback(flacDecoder, flac_seek_handler); | ||
200 | FLAC__seekable_stream_decoder_set_tell_callback(flacDecoder, flac_tell_handler); | ||
201 | FLAC__seekable_stream_decoder_set_length_callback(flacDecoder, flac_length_handler); | ||
202 | FLAC__seekable_stream_decoder_set_eof_callback(flacDecoder, flac_eof_handler); | ||
203 | |||
204 | if (FLAC__seekable_stream_decoder_init(flacDecoder)) { | ||
205 | return PLUGIN_ERROR; | ||
206 | } | ||
207 | |||
208 | /* The first thing to do is to parse the metadata */ | ||
209 | FLAC__seekable_stream_decoder_process_until_end_of_metadata(flacDecoder); | ||
210 | |||
211 | file_info.frames_decoded=0; | ||
212 | file_info.start_tick=*(rb->current_tick); | ||
213 | rb->button_clear_queue(); | ||
214 | |||
215 | while (FLAC__seekable_stream_decoder_get_state(flacDecoder)!=2) { | ||
216 | FLAC__seekable_stream_decoder_process_single(flacDecoder); | ||
217 | file_info.frames_decoded++; | ||
218 | |||
219 | display_status(&file_info); | ||
220 | |||
221 | if (rb->button_get(false)!=BUTTON_NONE) { | ||
222 | close_wav(&file_info); | ||
223 | return PLUGIN_OK; | ||
224 | } | ||
225 | } | ||
226 | |||
227 | close_wav(&file_info); | ||
228 | rb->splash(HZ*2, true, "FINISHED!"); | ||
229 | |||
230 | /* Flush internal buffers etc */ | ||
231 | //No need for this. flacResult=FLAC__seekable_stream_decoder_reset(flacDecoder); | ||
232 | |||
233 | // audio_close(); | ||
234 | |||
235 | return PLUGIN_OK; | ||
236 | } | ||
237 | #endif /* CONFIG_HWCODEC == MASNONE */ | ||