2005-09-22 21:55:37 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005 Dave Chapman
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2005-10-13 11:32:52 +00:00
|
|
|
#include "codeclib.h"
|
2005-10-29 17:12:52 +00:00
|
|
|
#include "libm4a/m4a.h"
|
|
|
|
#include "libalac/decomp.h"
|
2005-09-22 21:55:37 +00:00
|
|
|
|
|
|
|
#ifndef SIMULATOR
|
|
|
|
extern char iramcopy[];
|
|
|
|
extern char iramstart[];
|
|
|
|
extern char iramend[];
|
|
|
|
#endif
|
|
|
|
|
2005-10-28 00:11:28 +00:00
|
|
|
int32_t outputbuffer[ALAC_MAX_CHANNELS][ALAC_BLOCKSIZE] IBSS_ATTR;
|
2005-10-29 17:12:52 +00:00
|
|
|
|
2005-09-22 21:55:37 +00:00
|
|
|
struct codec_api* rb;
|
|
|
|
struct codec_api* ci;
|
|
|
|
|
|
|
|
/* this is the codec entry point */
|
|
|
|
enum codec_status codec_start(struct codec_api* api)
|
|
|
|
{
|
|
|
|
size_t n;
|
|
|
|
demux_res_t demux_res;
|
2005-10-29 17:12:52 +00:00
|
|
|
stream_t input_stream;
|
2005-09-22 21:55:37 +00:00
|
|
|
uint32_t samplesdone;
|
|
|
|
uint32_t elapsedtime;
|
|
|
|
uint32_t sample_duration;
|
|
|
|
uint32_t sample_byte_size;
|
2005-10-28 00:11:28 +00:00
|
|
|
int samplesdecoded;
|
2005-09-22 21:55:37 +00:00
|
|
|
unsigned int i;
|
|
|
|
unsigned char* buffer;
|
|
|
|
alac_file alac;
|
|
|
|
|
|
|
|
/* Generic codec initialisation */
|
|
|
|
TEST_CODEC_API(api);
|
|
|
|
|
|
|
|
rb = api;
|
|
|
|
ci = (struct codec_api*)api;
|
|
|
|
|
|
|
|
#ifndef SIMULATOR
|
|
|
|
rb->memcpy(iramstart, iramcopy, iramend-iramstart);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ci->configure(CODEC_SET_FILEBUF_WATERMARK, (int *)(1024*512));
|
|
|
|
ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*128));
|
|
|
|
|
2005-10-28 00:11:28 +00:00
|
|
|
ci->configure(CODEC_DSP_ENABLE, (bool *)true);
|
2005-09-22 21:55:37 +00:00
|
|
|
ci->configure(DSP_DITHER, (bool *)false);
|
2005-10-28 00:11:28 +00:00
|
|
|
ci->configure(DSP_SET_STEREO_MODE, (int *)STEREO_NONINTERLEAVED);
|
2005-10-30 22:06:42 +00:00
|
|
|
ci->configure(DSP_SET_SAMPLE_DEPTH, (int *)(ALAC_OUTPUT_DEPTH-1));
|
|
|
|
|
2005-09-22 21:55:37 +00:00
|
|
|
next_track:
|
|
|
|
|
|
|
|
if (codec_init(api)) {
|
|
|
|
LOGF("ALAC: Error initialising codec\n");
|
|
|
|
return CODEC_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (!rb->taginfo_ready)
|
|
|
|
rb->yield();
|
|
|
|
|
2005-10-28 00:11:28 +00:00
|
|
|
ci->configure(DSP_SET_FREQUENCY, (long *)(rb->id3->frequency));
|
2005-09-22 21:55:37 +00:00
|
|
|
|
2005-10-29 17:12:52 +00:00
|
|
|
stream_create(&input_stream,ci);
|
2005-09-22 21:55:37 +00:00
|
|
|
|
|
|
|
/* if qtmovie_read returns successfully, the stream is up to
|
|
|
|
* the movie data, which can be used directly by the decoder */
|
|
|
|
if (!qtmovie_read(&input_stream, &demux_res)) {
|
|
|
|
LOGF("ALAC: Error initialising file\n");
|
|
|
|
return CODEC_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* initialise the sound converter */
|
|
|
|
create_alac(demux_res.sample_size, demux_res.num_channels,&alac);
|
|
|
|
alac_set_info(&alac, demux_res.codecdata);
|
|
|
|
|
|
|
|
i=0;
|
|
|
|
samplesdone=0;
|
|
|
|
/* The main decoding loop */
|
|
|
|
while (i < demux_res.num_sample_byte_sizes) {
|
|
|
|
rb->yield();
|
|
|
|
if (ci->stop_codec || ci->reload_codec) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Deal with any pending seek requests */
|
|
|
|
if (ci->seek_time) {
|
2005-12-02 08:42:48 +00:00
|
|
|
if (alac_seek(&demux_res, &input_stream,
|
2005-11-06 19:18:04 +00:00
|
|
|
((ci->seek_time-1)/10) * (ci->id3->frequency/100),
|
2005-12-02 08:42:48 +00:00
|
|
|
&samplesdone, (int *)&i)) {
|
2005-09-22 21:55:37 +00:00
|
|
|
elapsedtime=(samplesdone*10)/(ci->id3->frequency/100);
|
|
|
|
ci->set_elapsed(elapsedtime);
|
|
|
|
}
|
2005-11-02 00:09:42 +00:00
|
|
|
ci->seek_complete();
|
2005-09-22 21:55:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Lookup the length (in samples and bytes) of block i */
|
|
|
|
if (!get_sample_info(&demux_res, i, &sample_duration,
|
|
|
|
&sample_byte_size)) {
|
|
|
|
LOGF("ALAC: Error in get_sample_info\n");
|
|
|
|
return CODEC_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Request the required number of bytes from the input buffer */
|
|
|
|
|
2005-10-15 09:40:56 +00:00
|
|
|
buffer=ci->request_buffer((long*)&n,sample_byte_size);
|
2005-09-22 21:55:37 +00:00
|
|
|
if (n!=sample_byte_size) {
|
|
|
|
return CODEC_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Decode one block - returned samples will be host-endian */
|
|
|
|
rb->yield();
|
2005-10-28 00:11:28 +00:00
|
|
|
samplesdecoded=alac_decode_frame(&alac, buffer, outputbuffer, rb->yield);
|
2005-09-22 21:55:37 +00:00
|
|
|
|
|
|
|
/* Advance codec buffer - unless we did a read */
|
2005-10-30 21:04:32 +00:00
|
|
|
ci->advance_buffer(n);
|
2005-09-22 21:55:37 +00:00
|
|
|
|
|
|
|
/* Output the audio */
|
|
|
|
rb->yield();
|
2005-10-28 00:11:28 +00:00
|
|
|
while(!ci->pcmbuf_insert_split(outputbuffer[0],
|
|
|
|
outputbuffer[1],
|
|
|
|
samplesdecoded*sizeof(int32_t)))
|
2005-09-22 21:55:37 +00:00
|
|
|
rb->yield();
|
|
|
|
|
|
|
|
/* Update the elapsed-time indicator */
|
|
|
|
samplesdone+=sample_duration;
|
|
|
|
elapsedtime=(samplesdone*10)/(ci->id3->frequency/100);
|
|
|
|
ci->set_elapsed(elapsedtime);
|
|
|
|
|
|
|
|
/* Keep track of current position - for resuming */
|
|
|
|
ci->set_offset(elapsedtime);
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOGF("ALAC: Decoded %d samples\n",samplesdone);
|
|
|
|
|
|
|
|
if (ci->request_next_track())
|
|
|
|
goto next_track;
|
|
|
|
|
|
|
|
return CODEC_OK;
|
|
|
|
}
|