2010-05-13 12:40:09 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Yoshihisa Uchida
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "codeclib.h"
|
|
|
|
#include "codecs/libtta/ttalib.h"
|
|
|
|
|
|
|
|
CODEC_HEADER
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TTA (True Audio) codec:
|
|
|
|
*
|
|
|
|
* References
|
|
|
|
* [1] TRUE AUDIO CODEC SOFTWARE http://true-audio.com/
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int32_t samples[PCM_BUFFER_LENGTH * 2] IBSS_ATTR;
|
|
|
|
|
|
|
|
/* this is the codec entry point */
|
2011-04-27 03:08:23 +00:00
|
|
|
enum codec_status codec_main(enum codec_entry_call_reason reason)
|
|
|
|
{
|
|
|
|
if (reason == CODEC_LOAD) {
|
|
|
|
/* Generic codec initialisation */
|
|
|
|
ci->configure(DSP_SET_SAMPLE_DEPTH, TTA_OUTPUT_DEPTH - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return CODEC_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* this is called for each file to process */
|
|
|
|
enum codec_status codec_run(void)
|
2010-05-13 12:40:09 +00:00
|
|
|
{
|
|
|
|
tta_info info;
|
2010-05-14 11:08:56 +00:00
|
|
|
unsigned int decodedsamples;
|
2010-05-13 12:40:09 +00:00
|
|
|
int endofstream;
|
|
|
|
int new_pos = 0;
|
|
|
|
int sample_count;
|
2011-04-27 03:08:23 +00:00
|
|
|
intptr_t param;
|
2010-05-13 12:40:09 +00:00
|
|
|
|
|
|
|
if (codec_init())
|
|
|
|
{
|
|
|
|
DEBUGF("codec_init() error\n");
|
2011-04-27 03:08:23 +00:00
|
|
|
return CODEC_ERROR;
|
2010-05-13 12:40:09 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
ci->seek_buffer(0);
|
2010-05-13 12:40:09 +00:00
|
|
|
|
2010-05-14 11:08:56 +00:00
|
|
|
if (set_tta_info(&info) < 0 || player_init(&info) < 0)
|
2011-04-27 03:08:23 +00:00
|
|
|
return CODEC_ERROR;
|
2010-05-13 12:40:09 +00:00
|
|
|
|
|
|
|
codec_set_replaygain(ci->id3);
|
|
|
|
|
2013-05-05 04:48:40 +00:00
|
|
|
ci->configure(DSP_SET_FREQUENCY, ci->id3->frequency);
|
2010-05-13 12:40:09 +00:00
|
|
|
if (info.NCH == 2) {
|
|
|
|
ci->configure(DSP_SET_STEREO_MODE, STEREO_INTERLEAVED);
|
|
|
|
} else if (info.NCH == 1) {
|
|
|
|
ci->configure(DSP_SET_STEREO_MODE, STEREO_MONO);
|
|
|
|
} else {
|
|
|
|
DEBUGF("CODEC_ERROR: more than 2 channels\n");
|
2011-04-27 03:08:23 +00:00
|
|
|
player_stop();
|
|
|
|
return CODEC_ERROR;
|
2010-05-13 12:40:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* The main decoder loop */
|
2010-05-14 11:08:56 +00:00
|
|
|
decodedsamples = 0;
|
2010-05-13 12:40:09 +00:00
|
|
|
endofstream = 0;
|
|
|
|
|
|
|
|
if (ci->id3->offset > 0)
|
|
|
|
{
|
|
|
|
/* Need to save offset for later use (cleared indirectly by advance_buffer) */
|
|
|
|
new_pos = set_position(ci->id3->offset, TTA_SEEK_POS);
|
|
|
|
if (new_pos >= 0)
|
|
|
|
decodedsamples = new_pos;
|
|
|
|
}
|
|
|
|
|
2011-08-28 07:45:35 +00:00
|
|
|
ci->set_elapsed((uint64_t)info.LENGTH * 1000 * decodedsamples / info.DATALENGTH);
|
|
|
|
|
2010-05-13 12:40:09 +00:00
|
|
|
while (!endofstream)
|
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
enum codec_command_action action = ci->get_command(¶m);
|
|
|
|
|
|
|
|
if (action == CODEC_ACTION_HALT)
|
2010-05-13 12:40:09 +00:00
|
|
|
break;
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
if (action == CODEC_ACTION_SEEK_TIME)
|
2010-05-13 12:40:09 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
new_pos = set_position(param / SEEK_STEP, TTA_SEEK_TIME);
|
2010-05-13 12:40:09 +00:00
|
|
|
if (new_pos >= 0)
|
|
|
|
{
|
|
|
|
decodedsamples = new_pos;
|
|
|
|
}
|
2011-04-27 03:08:23 +00:00
|
|
|
|
|
|
|
ci->set_elapsed((uint64_t)info.LENGTH * 1000 * decodedsamples / info.DATALENGTH);
|
|
|
|
ci->seek_complete();
|
2010-05-13 12:40:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sample_count = get_samples(samples);
|
|
|
|
if (sample_count < 0)
|
|
|
|
break;
|
2011-04-27 03:08:23 +00:00
|
|
|
|
2010-05-13 12:40:09 +00:00
|
|
|
ci->pcmbuf_insert(samples, NULL, sample_count);
|
|
|
|
decodedsamples += sample_count;
|
|
|
|
if (decodedsamples >= info.DATALENGTH)
|
|
|
|
endofstream = 1;
|
|
|
|
ci->set_elapsed((uint64_t)info.LENGTH * 1000 * decodedsamples / info.DATALENGTH);
|
|
|
|
}
|
2011-02-20 15:27:10 +00:00
|
|
|
|
2010-05-13 12:40:09 +00:00
|
|
|
player_stop();
|
2011-04-27 03:08:23 +00:00
|
|
|
return CODEC_OK;
|
2010-05-13 12:40:09 +00:00
|
|
|
}
|