1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2010 Yoshihisa Uchida
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
23 #include "codecs/libtta/ttalib.h"
28 * TTA (True Audio) codec:
31 * [1] TRUE AUDIO CODEC SOFTWARE http://true-audio.com/
34 static int32_t samples
[PCM_BUFFER_LENGTH
* 2] IBSS_ATTR
;
36 /* this is the codec entry point */
37 enum codec_status
codec_main(enum codec_entry_call_reason reason
)
39 if (reason
== CODEC_LOAD
) {
40 /* Generic codec initialisation */
41 ci
->configure(DSP_SET_SAMPLE_DEPTH
, TTA_OUTPUT_DEPTH
- 1);
47 /* this is called for each file to process */
48 enum codec_status
codec_run(void)
51 unsigned int decodedsamples
;
59 DEBUGF("codec_init() error\n");
65 if (set_tta_info(&info
) < 0 || player_init(&info
) < 0)
68 codec_set_replaygain(ci
->id3
);
70 ci
->configure(DSP_SWITCH_FREQUENCY
, ci
->id3
->frequency
);
72 ci
->configure(DSP_SET_STEREO_MODE
, STEREO_INTERLEAVED
);
73 } else if (info
.NCH
== 1) {
74 ci
->configure(DSP_SET_STEREO_MODE
, STEREO_MONO
);
76 DEBUGF("CODEC_ERROR: more than 2 channels\n");
81 /* The main decoder loop */
85 if (ci
->id3
->offset
> 0)
87 /* Need to save offset for later use (cleared indirectly by advance_buffer) */
88 new_pos
= set_position(ci
->id3
->offset
, TTA_SEEK_POS
);
90 decodedsamples
= new_pos
;
95 enum codec_command_action action
= ci
->get_command(¶m
);
97 if (action
== CODEC_ACTION_HALT
)
100 if (action
== CODEC_ACTION_SEEK_TIME
)
102 new_pos
= set_position(param
/ SEEK_STEP
, TTA_SEEK_TIME
);
105 decodedsamples
= new_pos
;
108 ci
->set_elapsed((uint64_t)info
.LENGTH
* 1000 * decodedsamples
/ info
.DATALENGTH
);
112 sample_count
= get_samples(samples
);
113 if (sample_count
< 0)
116 ci
->pcmbuf_insert(samples
, NULL
, sample_count
);
117 decodedsamples
+= sample_count
;
118 if (decodedsamples
>= info
.DATALENGTH
)
120 ci
->set_elapsed((uint64_t)info
.LENGTH
* 1000 * decodedsamples
/ info
.DATALENGTH
);