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
|
|
|
|
2006-01-18 00:05:14 +00:00
|
|
|
CODEC_HEADER
|
|
|
|
|
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
|
|
|
/* this is the codec entry point */
|
2006-11-26 18:31:41 +00:00
|
|
|
enum codec_status codec_main(void)
|
2005-09-22 21:55:37 +00:00
|
|
|
{
|
|
|
|
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;
|
2006-01-18 20:22:03 +00:00
|
|
|
int retval;
|
2005-09-22 21:55:37 +00:00
|
|
|
|
|
|
|
/* Generic codec initialisation */
|
2007-02-10 16:34:16 +00:00
|
|
|
ci->configure(CODEC_SET_FILEBUF_WATERMARK, 1024*512);
|
|
|
|
ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, 1024*128);
|
2005-09-22 21:55:37 +00:00
|
|
|
|
2007-02-10 16:34:16 +00:00
|
|
|
ci->configure(DSP_SET_STEREO_MODE, STEREO_NONINTERLEAVED);
|
|
|
|
ci->configure(DSP_SET_SAMPLE_DEPTH, ALAC_OUTPUT_DEPTH-1);
|
2005-10-30 22:06:42 +00:00
|
|
|
|
2005-09-22 21:55:37 +00:00
|
|
|
next_track:
|
|
|
|
|
2006-11-26 18:31:41 +00:00
|
|
|
if (codec_init()) {
|
2005-09-22 21:55:37 +00:00
|
|
|
LOGF("ALAC: Error initialising codec\n");
|
2006-01-18 20:22:03 +00:00
|
|
|
retval = CODEC_ERROR;
|
|
|
|
goto exit;
|
2005-09-22 21:55:37 +00:00
|
|
|
}
|
|
|
|
|
2006-11-23 20:05:14 +00:00
|
|
|
while (!*ci->taginfo_ready && !ci->stop_codec)
|
|
|
|
ci->sleep(1);
|
2005-09-22 21:55:37 +00:00
|
|
|
|
2007-02-10 16:34:16 +00:00
|
|
|
ci->configure(DSP_SWITCH_FREQUENCY, ci->id3->frequency);
|
2006-11-26 18:31:41 +00:00
|
|
|
codec_set_replaygain(ci->id3);
|
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");
|
2006-01-18 20:22:03 +00:00
|
|
|
retval = CODEC_ERROR;
|
2006-04-22 14:40:13 +00:00
|
|
|
goto done;
|
2005-09-22 21:55:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* initialise the sound converter */
|
2006-10-11 17:12:29 +00:00
|
|
|
create_alac(demux_res.sound_sample_size, demux_res.num_channels,&alac);
|
2005-09-22 21:55:37 +00:00
|
|
|
alac_set_info(&alac, demux_res.codecdata);
|
|
|
|
|
|
|
|
i=0;
|
|
|
|
samplesdone=0;
|
|
|
|
/* The main decoding loop */
|
|
|
|
while (i < demux_res.num_sample_byte_sizes) {
|
2006-11-26 18:31:41 +00:00
|
|
|
ci->yield();
|
2006-04-15 02:03:11 +00:00
|
|
|
if (ci->stop_codec || ci->new_track) {
|
2005-09-22 21:55:37 +00:00
|
|
|
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");
|
2006-01-18 20:22:03 +00:00
|
|
|
retval = CODEC_ERROR;
|
2006-04-22 14:40:13 +00:00
|
|
|
goto done;
|
2005-09-22 21:55:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Request the required number of bytes from the input buffer */
|
|
|
|
|
2006-03-24 14:02:27 +00:00
|
|
|
buffer=ci->request_buffer(&n,sample_byte_size);
|
2005-09-22 21:55:37 +00:00
|
|
|
if (n!=sample_byte_size) {
|
2006-01-18 20:22:03 +00:00
|
|
|
retval = CODEC_ERROR;
|
2006-04-22 14:40:13 +00:00
|
|
|
goto done;
|
2005-09-22 21:55:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Decode one block - returned samples will be host-endian */
|
2006-11-26 18:31:41 +00:00
|
|
|
ci->yield();
|
|
|
|
samplesdecoded=alac_decode_frame(&alac, buffer, outputbuffer, ci->yield);
|
2005-09-22 21:55:37 +00:00
|
|
|
|
2006-04-13 17:04:53 +00:00
|
|
|
/* Advance codec buffer n bytes */
|
2005-10-30 21:04:32 +00:00
|
|
|
ci->advance_buffer(n);
|
2005-09-22 21:55:37 +00:00
|
|
|
|
|
|
|
/* Output the audio */
|
2006-11-26 18:31:41 +00:00
|
|
|
ci->yield();
|
2007-02-07 00:51:50 +00:00
|
|
|
ci->pcmbuf_insert(outputbuffer[0], outputbuffer[1], samplesdecoded);
|
2005-09-22 21:55:37 +00:00
|
|
|
|
|
|
|
/* 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++;
|
|
|
|
}
|
2006-04-22 14:40:13 +00:00
|
|
|
retval = CODEC_OK;
|
2005-09-22 21:55:37 +00:00
|
|
|
|
2006-04-22 14:40:13 +00:00
|
|
|
done:
|
2005-09-22 21:55:37 +00:00
|
|
|
LOGF("ALAC: Decoded %d samples\n",samplesdone);
|
|
|
|
|
|
|
|
if (ci->request_next_track())
|
|
|
|
goto next_track;
|
|
|
|
|
2006-01-18 20:22:03 +00:00
|
|
|
exit:
|
|
|
|
return retval;
|
2005-09-22 21:55:37 +00:00
|
|
|
}
|