diff options
author | Sean Bartell <wingedtachikoma@gmail.com> | 2011-06-25 21:32:25 -0400 |
---|---|---|
committer | Nils Wallménius <nils@rockbox.org> | 2012-04-25 22:13:20 +0200 |
commit | f40bfc9267b13b54e6379dfe7539447662879d24 (patch) | |
tree | 9b20069d5e62809ff434061ad730096836f916f2 /lib/rbcodec/codecs/libtta | |
parent | a0009907de7a0107d49040d8a180f140e2eff299 (diff) | |
download | rockbox-f40bfc9267b13b54e6379dfe7539447662879d24.tar.gz rockbox-f40bfc9267b13b54e6379dfe7539447662879d24.zip |
Add codecs to librbcodec.
Change-Id: Id7f4717d51ed02d67cb9f9cb3c0ada4a81843f97
Reviewed-on: http://gerrit.rockbox.org/137
Reviewed-by: Nils Wallménius <nils@rockbox.org>
Tested-by: Nils Wallménius <nils@rockbox.org>
Diffstat (limited to 'lib/rbcodec/codecs/libtta')
-rw-r--r-- | lib/rbcodec/codecs/libtta/README | 72 | ||||
-rw-r--r-- | lib/rbcodec/codecs/libtta/README.rockbox | 33 | ||||
-rw-r--r-- | lib/rbcodec/codecs/libtta/SOURCES | 7 | ||||
-rw-r--r-- | lib/rbcodec/codecs/libtta/filter.h | 136 | ||||
-rw-r--r-- | lib/rbcodec/codecs/libtta/filter_arm.S | 198 | ||||
-rw-r--r-- | lib/rbcodec/codecs/libtta/filter_coldfire.S | 164 | ||||
-rw-r--r-- | lib/rbcodec/codecs/libtta/libtta.make | 18 | ||||
-rw-r--r-- | lib/rbcodec/codecs/libtta/ttadec.c | 582 | ||||
-rw-r--r-- | lib/rbcodec/codecs/libtta/ttadec.h | 203 | ||||
-rw-r--r-- | lib/rbcodec/codecs/libtta/ttalib.h | 157 |
10 files changed, 1570 insertions, 0 deletions
diff --git a/lib/rbcodec/codecs/libtta/README b/lib/rbcodec/codecs/libtta/README new file mode 100644 index 0000000000..8b1a1b23c0 --- /dev/null +++ b/lib/rbcodec/codecs/libtta/README | |||
@@ -0,0 +1,72 @@ | |||
1 | TTA Hardware Players Library | ||
2 | ============================ | ||
3 | |||
4 | Version 1.2, (c) 2004 Alexander Djourik. All rights reserved. | ||
5 | |||
6 | * Introduction | ||
7 | |||
8 | This library provides to decode a multichannel 8,16 and 24 | ||
9 | bits TTA audio files. TTA is a lossless audio format. Being | ||
10 | "lossless" means that no data/quality is lost in the compression | ||
11 | - when uncompressed, the data will be identical to the original. | ||
12 | The compression ratios of TTA depend on the type of music file | ||
13 | being compressed, but the compression size will generally range | ||
14 | between 30% - 70% of the original. | ||
15 | |||
16 | TTA format supports both of ID3v1/v2 tags. Detailed format | ||
17 | description is available at http://www.true-audio.com. | ||
18 | |||
19 | The decoder process has a minimal system requirements and does | ||
20 | not required to create a big additional memory pools. As the | ||
21 | TTA algorithms has a same system requirements both for decoding | ||
22 | and for encoding processes - the TTA recorder can be easily | ||
23 | realized also. | ||
24 | |||
25 | * Changes | ||
26 | |||
27 | 14/04/2004 1.0 Initial release | ||
28 | 16/04/2004 1.1 Code optimization | ||
29 | Code clean-up | ||
30 | 29/10/2004 1.2 ID3 tags support | ||
31 | Code clean-up | ||
32 | |||
33 | * To Do | ||
34 | |||
35 | - TTA recorder functions. | ||
36 | |||
37 | * Developers | ||
38 | |||
39 | Alexander Djourik <ald@true-audio.com> | ||
40 | Pavel Zhilin <pzh@true-audio.com> | ||
41 | |||
42 | * Copying | ||
43 | |||
44 | Redistribution and use in source and binary forms, with or without | ||
45 | modification, are permitted provided that the following conditions | ||
46 | are met: | ||
47 | |||
48 | 1. Redistributions of source code must retain the above copyright | ||
49 | notice, this list of conditions and the following disclaimer. | ||
50 | 2. Redistributions in binary form must reproduce the above copyright | ||
51 | notice, this list of conditions and the following disclaimer in the | ||
52 | documentation and/or other materials provided with the distribution. | ||
53 | 3. Neither the name of the True Audio Software nor the names of its | ||
54 | contributors may be used to endorse or promote products derived | ||
55 | from this software without specific prior written permission. | ||
56 | |||
57 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
58 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
59 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
60 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
61 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
62 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
63 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
64 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
65 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
66 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
67 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
68 | |||
69 | * See also | ||
70 | |||
71 | Please visit the TTA homepage at http://tta.sourceforge.net for the | ||
72 | latest in news and downloads. | ||
diff --git a/lib/rbcodec/codecs/libtta/README.rockbox b/lib/rbcodec/codecs/libtta/README.rockbox new file mode 100644 index 0000000000..549aa4e097 --- /dev/null +++ b/lib/rbcodec/codecs/libtta/README.rockbox | |||
@@ -0,0 +1,33 @@ | |||
1 | Library: True Audio | ||
2 | Imported by : Yoshihisa Uchida | ||
3 | Import date : 2010-03-05 | ||
4 | Baseed by : TTA library version 1.2 for hardware players (ttalib-hwplayer-1.2.tgz) | ||
5 | from http://true-audio.com/Free_Downloads | ||
6 | |||
7 | This directory contains a decoder version of True Auido. | ||
8 | |||
9 | LICENSING INFORMATION | ||
10 | |||
11 | True Audio license is described in the README file or each source file in this directory. | ||
12 | |||
13 | Limitation | ||
14 | |||
15 | - Decoding is not real time on some targets. | ||
16 | - Max duration is 4095 seconds (about 1 hours 8 minutes). | ||
17 | |||
18 | IMPORT DETAILS | ||
19 | |||
20 | The .[ch] files from ttalib-hwplayer-1.2.tgz were imported into Rockbox. | ||
21 | But the following files do not include. | ||
22 | Makefile | ||
23 | tta.vcproj | ||
24 | samples/* | ||
25 | |||
26 | |||
27 | When source files import in Rockbox, I changed below. | ||
28 | |||
29 | all files | ||
30 | - TAB => 4 spaces. | ||
31 | - // style comments changes to /* */ style. | ||
32 | |||
33 | Moreover, I modify to optimize the decoding speed. | ||
diff --git a/lib/rbcodec/codecs/libtta/SOURCES b/lib/rbcodec/codecs/libtta/SOURCES new file mode 100644 index 0000000000..0a8f1171eb --- /dev/null +++ b/lib/rbcodec/codecs/libtta/SOURCES | |||
@@ -0,0 +1,7 @@ | |||
1 | ttadec.c | ||
2 | #ifdef CPU_ARM | ||
3 | filter_arm.S | ||
4 | #endif | ||
5 | #ifdef CPU_COLDFIRE | ||
6 | filter_coldfire.S | ||
7 | #endif | ||
diff --git a/lib/rbcodec/codecs/libtta/filter.h b/lib/rbcodec/codecs/libtta/filter.h new file mode 100644 index 0000000000..228757b9a0 --- /dev/null +++ b/lib/rbcodec/codecs/libtta/filter.h | |||
@@ -0,0 +1,136 @@ | |||
1 | /* | ||
2 | * filter.h | ||
3 | * | ||
4 | * Description: TTAv1 filter functions | ||
5 | * Developed by: Alexander Djourik <ald@true-audio.com> | ||
6 | * Pavel Zhilin <pzh@true-audio.com> | ||
7 | * | ||
8 | * Copyright (c) 2004 True Audio Software. All rights reserved. | ||
9 | * | ||
10 | */ | ||
11 | |||
12 | /* | ||
13 | * Redistribution and use in source and binary forms, with or without | ||
14 | * modification, are permitted provided that the following conditions | ||
15 | * are met: | ||
16 | * | ||
17 | * 1. Redistributions of source code must retain the above copyright | ||
18 | * notice, this list of conditions and the following disclaimer. | ||
19 | * 2. Redistributions in binary form must reproduce the above copyright | ||
20 | * notice, this list of conditions and the following disclaimer in the | ||
21 | * documentation and/or other materials provided with the distribution. | ||
22 | * 3. Neither the name of the True Audio Software nor the names of its | ||
23 | * contributors may be used to endorse or promote products derived | ||
24 | * from this software without specific prior written permission. | ||
25 | * | ||
26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
27 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
28 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
29 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
30 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
31 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
32 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
33 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
34 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
35 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
36 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
37 | */ | ||
38 | |||
39 | #ifndef FILTER_H | ||
40 | #define FILTER_H | ||
41 | |||
42 | ///////// Filter Settings ////////// | ||
43 | static int flt_set[3] = {10, 9, 10}; | ||
44 | |||
45 | #if defined(CPU_ARM) || defined(CPU_COLDFIRE) | ||
46 | int hybrid_filter(fltst *fs, int *in); /* implements in filter_arm.S */ | ||
47 | |||
48 | #else | ||
49 | |||
50 | static inline void | ||
51 | memshl (register int *pA) { | ||
52 | register int *pB = pA + 16; | ||
53 | |||
54 | *pA++ = *pB++; | ||
55 | *pA++ = *pB++; | ||
56 | *pA++ = *pB++; | ||
57 | *pA++ = *pB++; | ||
58 | *pA++ = *pB++; | ||
59 | *pA++ = *pB++; | ||
60 | *pA++ = *pB++; | ||
61 | *pA = *pB; | ||
62 | } | ||
63 | |||
64 | static inline void | ||
65 | hybrid_filter (fltst *fs, int *in) { | ||
66 | register int *pA = fs->dl + fs->index; | ||
67 | register int *pB = fs->qm; | ||
68 | register int *pM = fs->dx + fs->index; | ||
69 | register int sum = fs->round; | ||
70 | |||
71 | if (!fs->error) { | ||
72 | sum += *pA++ * *pB++; | ||
73 | sum += *pA++ * *pB++; | ||
74 | sum += *pA++ * *pB++; | ||
75 | sum += *pA++ * *pB++; | ||
76 | sum += *pA++ * *pB++; | ||
77 | sum += *pA++ * *pB++; | ||
78 | sum += *pA++ * *pB++; | ||
79 | sum += *pA * *pB; | ||
80 | pM += 8; | ||
81 | } else if (fs->error < 0) { | ||
82 | sum += *pA++ * (*pB++ -= *pM++); | ||
83 | sum += *pA++ * (*pB++ -= *pM++); | ||
84 | sum += *pA++ * (*pB++ -= *pM++); | ||
85 | sum += *pA++ * (*pB++ -= *pM++); | ||
86 | sum += *pA++ * (*pB++ -= *pM++); | ||
87 | sum += *pA++ * (*pB++ -= *pM++); | ||
88 | sum += *pA++ * (*pB++ -= *pM++); | ||
89 | sum += *pA * (*pB -= *pM++); | ||
90 | } else { | ||
91 | sum += *pA++ * (*pB++ += *pM++); | ||
92 | sum += *pA++ * (*pB++ += *pM++); | ||
93 | sum += *pA++ * (*pB++ += *pM++); | ||
94 | sum += *pA++ * (*pB++ += *pM++); | ||
95 | sum += *pA++ * (*pB++ += *pM++); | ||
96 | sum += *pA++ * (*pB++ += *pM++); | ||
97 | sum += *pA++ * (*pB++ += *pM++); | ||
98 | sum += *pA * (*pB += *pM++); | ||
99 | } | ||
100 | |||
101 | pB = pA++; | ||
102 | fs->error = *in; | ||
103 | *in += (sum >> fs->shift); | ||
104 | *pA = *in; | ||
105 | |||
106 | *pM-- = ((*pB-- >> 30) | 1) << 2; | ||
107 | *pM-- = ((*pB-- >> 30) | 1) << 1; | ||
108 | *pM-- = ((*pB-- >> 30) | 1) << 1; | ||
109 | *pM = ((*pB >> 30) | 1); | ||
110 | |||
111 | *(pA-1) = *(pA-0) - *(pA-1); | ||
112 | *(pA-2) = *(pA-1) - *(pA-2); | ||
113 | *(pA-3) = *(pA-2) - *(pA-3); | ||
114 | |||
115 | /* | ||
116 | * Rockbox speciffic | ||
117 | * in order to make speed up, memshl() is executed at the rate once every 16 times. | ||
118 | */ | ||
119 | if (++fs->index == 16) | ||
120 | { | ||
121 | memshl (fs->dl); | ||
122 | memshl (fs->dx); | ||
123 | fs->index = 0; | ||
124 | } | ||
125 | } | ||
126 | #endif | ||
127 | |||
128 | static inline void | ||
129 | filter_init (fltst *fs, int shift) { | ||
130 | ci->memset (fs, 0, sizeof(fltst)); | ||
131 | fs->shift = shift; | ||
132 | fs->round = 1 << (shift - 1); | ||
133 | fs->index = 0; | ||
134 | } | ||
135 | |||
136 | #endif /* FILTER_H */ | ||
diff --git a/lib/rbcodec/codecs/libtta/filter_arm.S b/lib/rbcodec/codecs/libtta/filter_arm.S new file mode 100644 index 0000000000..f3959b83ca --- /dev/null +++ b/lib/rbcodec/codecs/libtta/filter_arm.S | |||
@@ -0,0 +1,198 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2010 Yoshihisa Uchida | ||
11 | * | ||
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. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include "config.h" | ||
23 | |||
24 | /* | ||
25 | * The following are assembler optimised version of | ||
26 | * void hybrid_filter(fltst *fs, int *in) | ||
27 | */ | ||
28 | |||
29 | #ifdef USE_IRAM | ||
30 | .section .icode, "ax", %progbits | ||
31 | #else | ||
32 | .text | ||
33 | #endif | ||
34 | .align | ||
35 | .global hybrid_filter | ||
36 | .type hybrid_filter, %function | ||
37 | |||
38 | hybrid_filter: | ||
39 | @ input: r0 = fs, r1 = in | ||
40 | stmdb sp!, {r4 - r12, lr} | ||
41 | |||
42 | @ get fs members | ||
43 | @ r2 pA := fs->dl + fs->index | ||
44 | @ r3 pM := fs->dx + fs->index | ||
45 | @ r4 pB := fs->qm | ||
46 | @ r5 fs->index | ||
47 | @ r6 fs->error | ||
48 | @ lr sum := fs->round | ||
49 | |||
50 | ldmia r0, {r5, r6, lr} @ r5 = fs->index | ||
51 | @ r6 = fs->error | ||
52 | @ lr = fs->round | ||
53 | add r2, r0, #148 @ r2 = fs->dl | ||
54 | add r3, r0, #52 @ r3 = fs->dx | ||
55 | add r4, r0, #20 @ r4 = fs->qm | ||
56 | add r2, r2, r5 @ r2 = (unsigned char*)fs->dl + fs->index | ||
57 | add r3, r3, r5 @ r3 = (unsigned char*)fs->dx + fs->index | ||
58 | |||
59 | cmp r6, #0 | ||
60 | bmi .hf_negative | ||
61 | bne .hf_positive | ||
62 | |||
63 | @ case fs->error == 0 | ||
64 | |||
65 | add r3, r3, #32 | ||
66 | ldmia r4!, {r5, r6, r7, r8 } | ||
67 | ldmia r2!, {r9, r10, r11, r12} | ||
68 | mla lr, r5, r9, lr | ||
69 | mla lr, r6, r10, lr | ||
70 | mla lr, r7, r11, lr | ||
71 | mla lr, r8, r12, lr | ||
72 | ldmia r4!, {r5, r6, r7, r8 } | ||
73 | b .hf2 | ||
74 | |||
75 | .hf_negative: | ||
76 | @ case fs->error < 0 | ||
77 | |||
78 | ldmia r4, {r5, r6, r7, r8 } | ||
79 | ldmia r3!, {r9, r10, r11, r12} | ||
80 | sub r5, r5, r9 | ||
81 | sub r6, r6, r10 | ||
82 | sub r7, r7, r11 | ||
83 | sub r8, r8, r12 | ||
84 | stmia r4!, {r5, r6, r7, r8 } @ update fs->qm[0], ..., fs->qm[3] | ||
85 | ldmia r2!, {r9, r10, r11, r12} | ||
86 | mla lr, r5, r9, lr | ||
87 | mla lr, r6, r10, lr | ||
88 | mla lr, r7, r11, lr | ||
89 | mla lr, r8, r12, lr | ||
90 | ldmia r4, {r5, r6, r7, r8 } | ||
91 | ldmia r3!, {r9, r10, r11, r12} | ||
92 | sub r5, r5, r9 | ||
93 | sub r6, r6, r10 | ||
94 | sub r7, r7, r11 | ||
95 | sub r8, r8, r12 | ||
96 | stmia r4!, {r5, r6, r7, r8 } @ update fs->qm[4], ..., fs->qm[7] | ||
97 | b .hf2 | ||
98 | |||
99 | .hf_positive: | ||
100 | @ case fs->error > 0 | ||
101 | |||
102 | ldmia r4, {r5, r6, r7, r8 } | ||
103 | ldmia r3!, {r9, r10, r11, r12} | ||
104 | add r5, r5, r9 | ||
105 | add r6, r6, r10 | ||
106 | add r7, r7, r11 | ||
107 | add r8, r8, r12 | ||
108 | stmia r4!, {r5, r6, r7, r8 } @ update fs->qm[0], ..., fs->qm[3] | ||
109 | ldmia r2!, {r9, r10, r11, r12} | ||
110 | mla lr, r5, r9, lr | ||
111 | mla lr, r6, r10, lr | ||
112 | mla lr, r7, r11, lr | ||
113 | mla lr, r8, r12, lr | ||
114 | ldmia r4, {r5, r6, r7, r8 } | ||
115 | ldmia r3!, {r9, r10, r11, r12} | ||
116 | add r5, r5, r9 | ||
117 | add r6, r6, r10 | ||
118 | add r7, r7, r11 | ||
119 | add r8, r8, r12 | ||
120 | stmia r4!, {r5, r6, r7, r8 } @ update fs->qm[4], ..., fs->qm[7] | ||
121 | |||
122 | .hf2: | ||
123 | ldmia r2!, {r9, r10, r11, r12} | ||
124 | mla lr, r5, r9, lr | ||
125 | mla lr, r6, r10, lr | ||
126 | mla lr, r7, r11, lr | ||
127 | mla lr, r8, r12, lr | ||
128 | |||
129 | @ fs->error = *in; | ||
130 | @ *in += (sum >> fs->shift) | ||
131 | @ *pA = *in | ||
132 | |||
133 | ldr r5, [r1] @ r5 = *in | ||
134 | ldr r6, [r0, #12] @ r6 = fs->shift | ||
135 | add lr, r5, lr, asr r6 | ||
136 | str lr, [r1] @ *in += (sum >> fs->shift) | ||
137 | |||
138 | @ update fs->index | ||
139 | |||
140 | ldr r1, [r0] @ r1 = fs->index | ||
141 | add r1, r1, #4 | ||
142 | ands r1, r1, #63 @ set Z flag (after this, CPSR must keep !!) | ||
143 | stmia r0, {r1, r5} @ fs->index = (fs->index + 4) & 63 | ||
144 | @ fs->error = (original) *in | ||
145 | |||
146 | @ change *pM, *(pM-1), *(pM-2), *(pM-3) | ||
147 | @ r9 = *(pA-4), r5 = *(pM-3) | ||
148 | @ r10 = *(pA-3), r6 = *(pM-2) | ||
149 | @ r11 = *(pA-2), r7 = *(pM-1) | ||
150 | @ r12 = *(pA-1), r8 = *(pM-0) | ||
151 | @ lr = *(pA-0) | ||
152 | |||
153 | mov r4, #1 | ||
154 | orr r5, r4, r9, asr #30 | ||
155 | orr r6, r4, r10, asr #30 | ||
156 | orr r7, r4, r11, asr #30 | ||
157 | orr r8, r4, r12, asr #30 | ||
158 | mov r6, r6, lsl #1 | ||
159 | mov r7, r7, lsl #1 | ||
160 | mov r8, r8, lsl #2 | ||
161 | |||
162 | @ change *(pA-1), *(pA-2), *(pA-3) | ||
163 | sub r12, lr, r12 | ||
164 | sub r11, r12, r11 | ||
165 | sub r10, r11, r10 | ||
166 | |||
167 | @ set to the memory: *pA, *(pA-1), *(pA-2), *(pA-3), *pM, *(pM-1), *(pM-2), *(pM-3) | ||
168 | stmneda r2, {r10, r11, r12, lr} | ||
169 | stmneda r3, {r5, r6, r7, r8} | ||
170 | ldmpc cond=ne regs=r4-r12 @ hybrid_filter end (when fs->index != 0) | ||
171 | |||
172 | .hf_memshl: | ||
173 | @ memshl (fs->dl) | ||
174 | @ r9 = fs->dl[16 + 3] | ||
175 | @ r10 = fs->dl[16 + 4] | ||
176 | @ r11 = fs->dl[16 + 5] | ||
177 | @ r12 = fs->dl[16 + 6] | ||
178 | @ lr = fs->dl[16 + 7] | ||
179 | |||
180 | add r2, r0, #212 @ r2 = fs->dl + 16 | ||
181 | ldmia r2, {r1, r3, r4} | ||
182 | sub r2, r2, #64 @ r2 = fs->dl | ||
183 | stmia r2, {r1, r3, r4, r9 - r12, lr} | ||
184 | |||
185 | @ memshl (fs->dx) | ||
186 | @ r5 = fs->dx[16 + 4] | ||
187 | @ r6 = fs->dx[16 + 5] | ||
188 | @ r7 = fs->dx[16 + 6] | ||
189 | @ r8 = fs->dx[16 + 7] | ||
190 | |||
191 | add r9, r0, #116 @ r9 = fs->dx + 16 | ||
192 | ldmia r9, {r1, r2, r3, r4} | ||
193 | sub r9, r9, #64 @ r9 = fs->dx | ||
194 | stmia r9, {r1 - r8} | ||
195 | ldmpc regs=r4-r12 @ hybrid_filter end (when fs->index == 0) | ||
196 | |||
197 | hybrid_filter_end: | ||
198 | .size hybrid_filter, hybrid_filter_end - hybrid_filter | ||
diff --git a/lib/rbcodec/codecs/libtta/filter_coldfire.S b/lib/rbcodec/codecs/libtta/filter_coldfire.S new file mode 100644 index 0000000000..3950eb52e6 --- /dev/null +++ b/lib/rbcodec/codecs/libtta/filter_coldfire.S | |||
@@ -0,0 +1,164 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2010 Nils Wallménius | ||
11 | * | ||
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. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include "config.h" | ||
23 | |||
24 | /* | ||
25 | * The following is an assembler optimised version of | ||
26 | * void hybrid_filter(fltst *fs, int *in) | ||
27 | */ | ||
28 | |||
29 | #if defined(USE_IRAM) | ||
30 | .section .icode | ||
31 | #else | ||
32 | .text | ||
33 | #endif | ||
34 | .align 2 | ||
35 | .global hybrid_filter | ||
36 | .type hybrid_filter, @function | ||
37 | |||
38 | hybrid_filter: | ||
39 | lea.l (-8*4, %sp), %sp | ||
40 | movem.l %d2-%d7/%a2-%a3, (%sp) | save some registers | ||
41 | move.l (8*4+4, %sp), %a0 | a0 = fs | ||
42 | movem.l (%a0), %d4-%d5 | d4 = fs->index, d5 = fs->error | ||
43 | |||
44 | lea.l (%a0, %d4.l*4), %a2 | ||
45 | lea.l (148, %a2), %a1 | a1 = fs->dl + fs->index (*pA) | ||
46 | lea.l (52, %a2), %a2 | a2 = fs->dx + fs->index (*pM) | ||
47 | |||
48 | move.l (%a1)+, %a3 | load one value from *pA (needed in every case) | ||
49 | movem.l (20, %a0), %d0-%d3 | load 4 values from *pB | ||
50 | |||
51 | tst.l %d5 | ||
52 | blt .hf_negative | ||
53 | bgt .hf_positive | ||
54 | |||
55 | | fs->error == 0 | ||
56 | mac.l %d0, %a3, (%a1)+, %a3, %acc0 | ||
57 | mac.l %d1, %a3, (%a1)+, %a3, %acc0 | ||
58 | mac.l %d2, %a3, (%a1)+, %a3, %acc0 | ||
59 | mac.l %d3, %a3, (%a1)+, %d4, %acc0 | ||
60 | movem.l (4*4+20, %a0), %d0-%d3 | load 4 values from *pB | ||
61 | bra 0f | ||
62 | |||
63 | .hf_negative: | fs->error < 0 | ||
64 | movem.l (%a2), %d4-%d7 | load 4 values from *pM | ||
65 | sub.l %d4, %d0 | ||
66 | sub.l %d5, %d1 | ||
67 | sub.l %d6, %d2 | ||
68 | sub.l %d7, %d3 | ||
69 | movem.l %d0-%d3, (20, %a0) | ||
70 | mac.l %d0, %a3, (%a1)+, %a3, %acc0 | ||
71 | mac.l %d1, %a3, (%a1)+, %a3, %acc0 | ||
72 | mac.l %d2, %a3, (%a1)+, %a3, %acc0 | ||
73 | mac.l %d3, %a3, (%a1)+, %d4, %acc0 | ||
74 | |||
75 | movem.l (4*4+20, %a0), %d0-%d3 | load 4 values from *pB | ||
76 | movem.l (4*4, %a2), %d5-%d7/%a3 | load 4 values from *pM | ||
77 | sub.l %d5, %d0 | ||
78 | sub.l %d6, %d1 | ||
79 | sub.l %d7, %d2 | ||
80 | sub.l %a3, %d3 | ||
81 | movem.l %d0-%d3, (4*4+20, %a0) | ||
82 | bra 0f | ||
83 | |||
84 | .hf_positive: | fs->error > 0 | ||
85 | movem.l (%a2), %d4-%d7 | load 4 values from *pM | ||
86 | add.l %d4, %d0 | ||
87 | add.l %d5, %d1 | ||
88 | add.l %d6, %d2 | ||
89 | add.l %d7, %d3 | ||
90 | movem.l %d0-%d3, (20, %a0) | ||
91 | mac.l %d0, %a3, (%a1)+, %a3, %acc0 | ||
92 | mac.l %d1, %a3, (%a1)+, %a3, %acc0 | ||
93 | mac.l %d2, %a3, (%a1)+, %a3, %acc0 | ||
94 | mac.l %d3, %a3, (%a1)+, %d4, %acc0 | ||
95 | |||
96 | movem.l (4*4+20, %a0), %d0-%d3 | load 4 values from *pB | ||
97 | movem.l (4*4, %a2), %d5-%d7/%a3 | load 4 values from *pM | ||
98 | add.l %d5, %d0 | ||
99 | add.l %d6, %d1 | ||
100 | add.l %d7, %d2 | ||
101 | add.l %a3, %d3 | ||
102 | movem.l %d0-%d3, (4*4+20, %a0) | ||
103 | |||
104 | 0: | ||
105 | |||
106 | mac.l %d0, %d4, (%a1)+, %d5, %acc0 | common macro block | ||
107 | mac.l %d1, %d5, (%a1)+, %d6, %acc0 | ||
108 | mac.l %d2, %d6, (%a1), %d7, %acc0 | ||
109 | mac.l %d3, %d7, %acc0 | ||
110 | |||
111 | move.l (8*4+8, %sp), %a3 | a3 = in | ||
112 | move.l (%a3), %d3 | ||
113 | move.l %d3, (4, %a0) | fs->error = *in | ||
114 | movclr.l %acc0, %d0 | d0 = sum | ||
115 | movem.l (8, %a0), %d1-%d2 | ||
116 | add.l %d1, %d0 | sum += fs->round | ||
117 | asr.l %d2, %d0 | sum >>= fs->shift | ||
118 | |||
119 | add.l %d0, %d3 | ||
120 | move.l %d3, (%a3) | *in += (sum >> fs->shift) | ||
121 | |||
122 | move.l %d3, ( 1*4, %a1) | ||
123 | sub.l %d7, %d3 | ||
124 | move.l %d3, ( 0*4, %a1) | ||
125 | sub.l %d6, %d3 | ||
126 | move.l %d3, (-1*4, %a1) | ||
127 | sub.l %d5, %d3 | ||
128 | move.l %d3, (-2*4, %a1) | ||
129 | |||
130 | moveq #30,%d0 | ||
131 | asr.l %d0,%d7 | ||
132 | asr.l %d0,%d6 | ||
133 | asr.l %d0,%d5 | ||
134 | asr.l %d0,%d4 | ||
135 | |||
136 | moveq #1,%d0 | ||
137 | or.l %d0,%d7 | ||
138 | or.l %d0,%d6 | ||
139 | or.l %d0,%d5 | ||
140 | or.l %d0,%d4 | ||
141 | |||
142 | lsl.l #2,%d7 | ||
143 | lsl.l #1,%d6 | ||
144 | lsl.l #1,%d5 | ||
145 | movem.l %d4-%d7, (8*4-3*4,%a2) | store to *pM | ||
146 | |||
147 | move.l (%a0), %d0 | ||
148 | addq.l #1, %d0 | ||
149 | cmp.l #16, %d0 | ++fs->index == 16 ? | ||
150 | bne 1f | ||
151 | |||
152 | movem.l (16*4+148, %a0), %d0-%d7 | ||
153 | movem.l %d0-%d7, (148, %a0) | ||
154 | movem.l (16*4+52, %a0), %d0-%d7 | ||
155 | movem.l %d0-%d7, (52, %a0) | ||
156 | clr.l %d0 | fs->index = 0 | ||
157 | 1: | ||
158 | |||
159 | move.l %d0, (%a0) | ||
160 | |||
161 | movem.l (%sp), %d2-%d7/%a2-%a3 | restore stacked regs | ||
162 | lea.l (8*4, %sp), %sp | ||
163 | rts | ||
164 | |||
diff --git a/lib/rbcodec/codecs/libtta/libtta.make b/lib/rbcodec/codecs/libtta/libtta.make new file mode 100644 index 0000000000..3fe3db1989 --- /dev/null +++ b/lib/rbcodec/codecs/libtta/libtta.make | |||
@@ -0,0 +1,18 @@ | |||
1 | # __________ __ ___. | ||
2 | # Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
3 | # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
4 | # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
5 | # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
6 | # \/ \/ \/ \/ \/ | ||
7 | # $Id$ | ||
8 | # | ||
9 | |||
10 | # libtta | ||
11 | TTALIB := $(CODECDIR)/libtta.a | ||
12 | TTALIB_SRC := $(call preprocess, $(RBCODECLIB_DIR)/codecs/libtta/SOURCES) | ||
13 | TTALIB_OBJ := $(call c2obj, $(TTALIB_SRC)) | ||
14 | OTHER_SRC += $(TTALIB_SRC) | ||
15 | |||
16 | $(TTALIB): $(TTALIB_OBJ) | ||
17 | $(SILENT)$(shell rm -f $@) | ||
18 | $(call PRINTS,AR $(@F))$(AR) rcs $@ $^ >/dev/null | ||
diff --git a/lib/rbcodec/codecs/libtta/ttadec.c b/lib/rbcodec/codecs/libtta/ttadec.c new file mode 100644 index 0000000000..06ca431084 --- /dev/null +++ b/lib/rbcodec/codecs/libtta/ttadec.c | |||
@@ -0,0 +1,582 @@ | |||
1 | /* | ||
2 | * ttadec.c | ||
3 | * | ||
4 | * Description: TTAv1 decoder library for HW players | ||
5 | * Developed by: Alexander Djourik <ald@true-audio.com> | ||
6 | * Pavel Zhilin <pzh@true-audio.com> | ||
7 | * | ||
8 | * Copyright (c) 2004 True Audio Software. All rights reserved. | ||
9 | * | ||
10 | */ | ||
11 | |||
12 | /* | ||
13 | * Redistribution and use in source and binary forms, with or without | ||
14 | * modification, are permitted provided that the following conditions | ||
15 | * are met: | ||
16 | * | ||
17 | * 1. Redistributions of source code must retain the above copyright | ||
18 | * notice, this list of conditions and the following disclaimer. | ||
19 | * 2. Redistributions in binary form must reproduce the above copyright | ||
20 | * notice, this list of conditions and the following disclaimer in the | ||
21 | * documentation and/or other materials provided with the distribution. | ||
22 | * 3. Neither the name of the True Audio Software nor the names of its | ||
23 | * contributors may be used to endorse or promote products derived | ||
24 | * from this software without specific prior written permission. | ||
25 | * | ||
26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
27 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
28 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
29 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
30 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
31 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
32 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
33 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
34 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
35 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
36 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
37 | */ | ||
38 | |||
39 | #include <stdio.h> | ||
40 | #include "codeclib.h" | ||
41 | |||
42 | #include "ttalib.h" | ||
43 | #include "ttadec.h" | ||
44 | #include "filter.h" | ||
45 | |||
46 | /******************* static variables and structures *******************/ | ||
47 | |||
48 | static unsigned char isobuffers[ISO_BUFFERS_SIZE + 4] IBSS_ATTR; | ||
49 | static unsigned char * const iso_buffers_end ICONST_ATTR = isobuffers + ISO_BUFFERS_SIZE; | ||
50 | static unsigned int pcm_buffer_size IBSS_ATTR; | ||
51 | |||
52 | static decoder tta[MAX_NCH] IBSS_ATTR; /* decoder state */ | ||
53 | /* Rockbox speciffic: cache is defined in get_samples() (non static value) */ | ||
54 | /* static int cache[MAX_NCH]; // decoder cache */ | ||
55 | |||
56 | static tta_info *ttainfo IBSS_ATTR; /* currently playing file info */ | ||
57 | |||
58 | static unsigned int fframes IBSS_ATTR; /* number of frames in file */ | ||
59 | static unsigned int framelen IBSS_ATTR; /* the frame length in samples */ | ||
60 | static unsigned int lastlen IBSS_ATTR; /* the length of the last frame in samples */ | ||
61 | static unsigned int data_pos IBSS_ATTR; /* currently playing frame index */ | ||
62 | static unsigned int data_cur IBSS_ATTR; /* the playing position in frame */ | ||
63 | |||
64 | static int maxvalue IBSS_ATTR; /* output data max value */ | ||
65 | |||
66 | /* Rockbox speciffic: seek_table is static size */ | ||
67 | static unsigned int seek_table[MAX_SEEK_TABLE_SIZE]; /* the playing position table */ | ||
68 | static unsigned int st_state; /* seek table status */ | ||
69 | |||
70 | static unsigned int frame_crc32 IBSS_ATTR; | ||
71 | static unsigned int bit_count IBSS_ATTR; | ||
72 | static unsigned int bit_cache IBSS_ATTR; | ||
73 | static unsigned char *bitpos IBSS_ATTR; | ||
74 | |||
75 | /* Rockbox speciffic: deletes read_id3_tags(). */ | ||
76 | /* static int read_id3_tags (tta_info *info); */ | ||
77 | |||
78 | /********************* rockbox helper functions *************************/ | ||
79 | |||
80 | /* emulate stdio functions */ | ||
81 | static size_t tta_fread(void *ptr, size_t size, size_t nobj) | ||
82 | { | ||
83 | size_t read_size; | ||
84 | unsigned char *buffer = ci->request_buffer(&read_size, size * nobj); | ||
85 | |||
86 | if (read_size > 0) | ||
87 | { | ||
88 | ci->memcpy(ptr, buffer, read_size); | ||
89 | ci->advance_buffer(read_size); | ||
90 | } | ||
91 | return read_size; | ||
92 | } | ||
93 | |||
94 | static int tta_fseek(long offset, int origin) | ||
95 | { | ||
96 | switch (origin) | ||
97 | { | ||
98 | case SEEK_CUR: | ||
99 | ci->advance_buffer(offset); | ||
100 | break; | ||
101 | case SEEK_SET: | ||
102 | ci->seek_buffer(offset); | ||
103 | break; | ||
104 | case SEEK_END: | ||
105 | ci->seek_buffer(offset + ci->id3->filesize); | ||
106 | break; | ||
107 | default: | ||
108 | return -1; | ||
109 | } | ||
110 | return 0; | ||
111 | } | ||
112 | |||
113 | /************************* crc32 functions *****************************/ | ||
114 | |||
115 | #define UPDATE_CRC32(x, crc) crc = \ | ||
116 | (((crc>>8) & 0x00FFFFFF) ^ crc32_table[(crc^x) & 0xFF]) | ||
117 | |||
118 | static unsigned int | ||
119 | crc32 (unsigned char *buffer, unsigned int len) { | ||
120 | unsigned int i; | ||
121 | unsigned int crc = 0xFFFFFFFF; | ||
122 | |||
123 | for (i = 0; i < len; i++) UPDATE_CRC32(buffer[i], crc); | ||
124 | |||
125 | return (crc ^ 0xFFFFFFFF); | ||
126 | } | ||
127 | |||
128 | /************************* bit operations ******************************/ | ||
129 | |||
130 | #define GET_BINARY(value, bits) \ | ||
131 | while (bit_count < bits) { \ | ||
132 | if (bitpos == iso_buffers_end) { \ | ||
133 | if (!tta_fread(isobuffers, 1, ISO_BUFFERS_SIZE)) { \ | ||
134 | ttainfo->STATE = READ_ERROR; \ | ||
135 | return -1; \ | ||
136 | } \ | ||
137 | bitpos = isobuffers; \ | ||
138 | } \ | ||
139 | UPDATE_CRC32(*bitpos, frame_crc32); \ | ||
140 | bit_cache |= *bitpos << bit_count; \ | ||
141 | bit_count += 8; \ | ||
142 | bitpos++; \ | ||
143 | } \ | ||
144 | value = bit_cache & bit_mask[bits]; \ | ||
145 | bit_cache >>= bits; \ | ||
146 | bit_count -= bits; \ | ||
147 | bit_cache &= bit_mask[bit_count]; | ||
148 | |||
149 | #define GET_UNARY(value) \ | ||
150 | value = 0; \ | ||
151 | while (!(bit_cache ^ bit_mask[bit_count])) { \ | ||
152 | if (bitpos == iso_buffers_end) { \ | ||
153 | if (!tta_fread(isobuffers, 1, ISO_BUFFERS_SIZE)) { \ | ||
154 | ttainfo->STATE = READ_ERROR; \ | ||
155 | return -1; \ | ||
156 | } \ | ||
157 | bitpos = isobuffers; \ | ||
158 | } \ | ||
159 | value += bit_count; \ | ||
160 | bit_cache = *bitpos++; \ | ||
161 | UPDATE_CRC32(bit_cache, frame_crc32); \ | ||
162 | bit_count = 8; \ | ||
163 | } \ | ||
164 | while (bit_cache & 1) { \ | ||
165 | value++; \ | ||
166 | bit_cache >>= 1; \ | ||
167 | bit_count--; \ | ||
168 | } \ | ||
169 | bit_cache >>= 1; \ | ||
170 | bit_count--; | ||
171 | |||
172 | /************************* rice operations ******************************/ | ||
173 | |||
174 | static inline int update_rice(int value, adapt *rice, int depth, | ||
175 | const unsigned int *shift_table) | ||
176 | { | ||
177 | if (depth > 0) | ||
178 | { | ||
179 | rice->sum1 += value - (rice->sum1 >> 4); | ||
180 | if (rice->k1 > 0 && rice->sum1 < shift_table[rice->k1]) | ||
181 | rice->k1--; | ||
182 | else if (rice->sum1 > shift_table[rice->k1 + 1]) | ||
183 | rice->k1++; | ||
184 | value += *(shift_table + rice->k0 - 4); | ||
185 | } | ||
186 | rice->sum0 += value - (rice->sum0 >> 4); | ||
187 | if (rice->k0 > 0 && rice->sum0 < shift_table[rice->k0]) | ||
188 | rice->k0--; | ||
189 | else if (rice->sum0 > shift_table[rice->k0 + 1]) | ||
190 | rice->k0++; | ||
191 | |||
192 | return DEC(value); | ||
193 | } | ||
194 | |||
195 | /************************* buffer functions ******************************/ | ||
196 | |||
197 | static void init_buffer_read(void) { | ||
198 | frame_crc32 = 0xFFFFFFFFUL; | ||
199 | bit_count = bit_cache = 0; | ||
200 | bitpos = iso_buffers_end; | ||
201 | } | ||
202 | |||
203 | static int done_buffer_read(void) { | ||
204 | unsigned int crc32, rbytes; | ||
205 | |||
206 | frame_crc32 ^= 0xFFFFFFFFUL; | ||
207 | rbytes = iso_buffers_end - bitpos; | ||
208 | |||
209 | if (rbytes < sizeof(int)) { | ||
210 | ci->memcpy(isobuffers, bitpos, 4); | ||
211 | if (!tta_fread(isobuffers + rbytes, 1, ISO_BUFFERS_SIZE - rbytes)) | ||
212 | return -1; | ||
213 | bitpos = isobuffers; | ||
214 | } | ||
215 | |||
216 | ci->memcpy(&crc32, bitpos, 4); | ||
217 | crc32 = ENDSWAP_INT32(crc32); | ||
218 | bitpos += sizeof(int); | ||
219 | |||
220 | if (crc32 != frame_crc32) return -1; | ||
221 | |||
222 | bit_cache = bit_count = 0; | ||
223 | frame_crc32 = 0xFFFFFFFFUL; | ||
224 | |||
225 | return 0; | ||
226 | } | ||
227 | |||
228 | /************************* decoder functions ****************************/ | ||
229 | |||
230 | /* rockbox: not used | ||
231 | const char *get_error_str (int error) { | ||
232 | switch (error) { | ||
233 | case NO_ERROR: return "No errors found"; | ||
234 | case OPEN_ERROR: return "Can't open file"; | ||
235 | case FORMAT_ERROR: return "Not supported file format"; | ||
236 | case FILE_ERROR: return "File is corrupted"; | ||
237 | case READ_ERROR: return "Can't read from file"; | ||
238 | case MEMORY_ERROR: return "Insufficient memory available"; | ||
239 | default: return "Unknown error code"; | ||
240 | } | ||
241 | } */ | ||
242 | |||
243 | int set_tta_info (tta_info *info) | ||
244 | { | ||
245 | unsigned int checksum; | ||
246 | unsigned int datasize; | ||
247 | unsigned int origsize; | ||
248 | tta_hdr ttahdr; | ||
249 | |||
250 | /* clear the memory */ | ||
251 | ci->memset (info, 0, sizeof(tta_info)); | ||
252 | |||
253 | /* skip id3v2 tags */ | ||
254 | tta_fseek(ci->id3->id3v2len, SEEK_SET); | ||
255 | |||
256 | /* read TTA header */ | ||
257 | if (tta_fread (&ttahdr, 1, sizeof (ttahdr)) == 0) { | ||
258 | info->STATE = READ_ERROR; | ||
259 | return -1; | ||
260 | } | ||
261 | |||
262 | /* check for TTA3 signature */ | ||
263 | if (ENDSWAP_INT32(ttahdr.TTAid) != TTA1_SIGN) { | ||
264 | DEBUGF("ID error: %x\n", ENDSWAP_INT32(ttahdr.TTAid)); | ||
265 | info->STATE = FORMAT_ERROR; | ||
266 | return -1; | ||
267 | } | ||
268 | |||
269 | ttahdr.CRC32 = ENDSWAP_INT32(ttahdr.CRC32); | ||
270 | checksum = crc32((unsigned char *) &ttahdr, | ||
271 | sizeof(tta_hdr) - sizeof(int)); | ||
272 | if (checksum != ttahdr.CRC32) { | ||
273 | DEBUGF("CRC error: %x != %x\n", ttahdr.CRC32, checksum); | ||
274 | info->STATE = FILE_ERROR; | ||
275 | return -1; | ||
276 | } | ||
277 | |||
278 | ttahdr.AudioFormat = ENDSWAP_INT16(ttahdr.AudioFormat); | ||
279 | ttahdr.NumChannels = ENDSWAP_INT16(ttahdr.NumChannels); | ||
280 | ttahdr.BitsPerSample = ENDSWAP_INT16(ttahdr.BitsPerSample); | ||
281 | ttahdr.SampleRate = ENDSWAP_INT32(ttahdr.SampleRate); | ||
282 | ttahdr.DataLength = ENDSWAP_INT32(ttahdr.DataLength); | ||
283 | |||
284 | /* check for player supported formats */ | ||
285 | if (ttahdr.AudioFormat != WAVE_FORMAT_PCM || | ||
286 | ttahdr.NumChannels > MAX_NCH || | ||
287 | ttahdr.BitsPerSample > MAX_BPS ||( | ||
288 | ttahdr.SampleRate != 16000 && | ||
289 | ttahdr.SampleRate != 22050 && | ||
290 | ttahdr.SampleRate != 24000 && | ||
291 | ttahdr.SampleRate != 32000 && | ||
292 | ttahdr.SampleRate != 44100 && | ||
293 | ttahdr.SampleRate != 48000 && | ||
294 | ttahdr.SampleRate != 64000 && | ||
295 | ttahdr.SampleRate != 88200 && | ||
296 | ttahdr.SampleRate != 96000)) { | ||
297 | info->STATE = FORMAT_ERROR; | ||
298 | DEBUGF("illegal audio format: %d channels: %d samplerate: %d\n", | ||
299 | ttahdr.AudioFormat, ttahdr.NumChannels, ttahdr.SampleRate); | ||
300 | return -1; | ||
301 | } | ||
302 | |||
303 | /* fill the File Info */ | ||
304 | info->NCH = ttahdr.NumChannels; | ||
305 | info->BPS = ttahdr.BitsPerSample; | ||
306 | info->BSIZE = (ttahdr.BitsPerSample + 7)/8; | ||
307 | info->FORMAT = ttahdr.AudioFormat; | ||
308 | info->SAMPLERATE = ttahdr.SampleRate; | ||
309 | info->DATALENGTH = ttahdr.DataLength; | ||
310 | info->FRAMELEN = (int) MULTIPLY_FRAME_TIME(ttahdr.SampleRate); | ||
311 | info->LENGTH = ttahdr.DataLength / ttahdr.SampleRate; | ||
312 | info->DATAPOS = ci->id3->id3v2len; | ||
313 | info->FILESIZE = ci->id3->filesize; | ||
314 | |||
315 | datasize = info->FILESIZE - info->DATAPOS; | ||
316 | origsize = info->DATALENGTH * info->BSIZE * info->NCH; | ||
317 | |||
318 | /* info->COMPRESS = (double) datasize / origsize; */ | ||
319 | info->BITRATE = (int) ((uint64_t) datasize * info->SAMPLERATE * info->NCH * info->BPS | ||
320 | / (origsize * 1000LL)); | ||
321 | |||
322 | return 0; | ||
323 | } | ||
324 | |||
325 | static void rice_init(adapt *rice, unsigned int k0, unsigned int k1) { | ||
326 | rice->k0 = k0; | ||
327 | rice->k1 = k1; | ||
328 | rice->sum0 = shift_16[k0]; | ||
329 | rice->sum1 = shift_16[k1]; | ||
330 | } | ||
331 | |||
332 | static void decoder_init(decoder *tta, int nch, int byte_size) { | ||
333 | int shift = flt_set[byte_size - 1]; | ||
334 | int i; | ||
335 | |||
336 | for (i = 0; i < nch; i++) { | ||
337 | filter_init(&tta[i].fst, shift); | ||
338 | rice_init(&tta[i].rice, 10, 10); | ||
339 | tta[i].last = 0; | ||
340 | } | ||
341 | } | ||
342 | |||
343 | static void seek_table_init (unsigned int *seek_table, | ||
344 | unsigned int len, unsigned int data_offset) { | ||
345 | unsigned int *st, frame_len; | ||
346 | |||
347 | for (st = seek_table; st < (seek_table + len); st++) { | ||
348 | frame_len = ENDSWAP_INT32(*st); | ||
349 | *st = data_offset; | ||
350 | data_offset += frame_len; | ||
351 | } | ||
352 | } | ||
353 | |||
354 | int set_position (unsigned int pos, enum tta_seek_type type) | ||
355 | { | ||
356 | unsigned int i; | ||
357 | unsigned int seek_pos; | ||
358 | |||
359 | if (type == TTA_SEEK_TIME) | ||
360 | { | ||
361 | if (pos >= fframes) | ||
362 | pos = fframes -1; | ||
363 | } | ||
364 | else | ||
365 | { | ||
366 | pos -= ttainfo->DATAPOS; | ||
367 | for (i = 1; i < fframes; i++) | ||
368 | { | ||
369 | if (seek_table[i] > pos) | ||
370 | break; | ||
371 | } | ||
372 | pos = i - 1; | ||
373 | } | ||
374 | if (!st_state) { | ||
375 | ttainfo->STATE = FILE_ERROR; | ||
376 | return -1; | ||
377 | } | ||
378 | seek_pos = ttainfo->DATAPOS + seek_table[data_pos = pos]; | ||
379 | if (tta_fseek(seek_pos, SEEK_SET) < 0) { | ||
380 | ttainfo->STATE = READ_ERROR; | ||
381 | return -1; | ||
382 | } | ||
383 | |||
384 | data_cur = 0; | ||
385 | framelen = 0; | ||
386 | |||
387 | /* init bit reader */ | ||
388 | init_buffer_read(); | ||
389 | return data_pos * ttainfo->FRAMELEN; | ||
390 | } | ||
391 | |||
392 | int player_init (tta_info *info) { | ||
393 | unsigned int checksum; | ||
394 | unsigned int data_offset; | ||
395 | unsigned int st_size; | ||
396 | |||
397 | #ifdef CPU_COLDFIRE | ||
398 | coldfire_set_macsr(0); /* signed integer mode */ | ||
399 | #endif | ||
400 | |||
401 | ttainfo = info; | ||
402 | |||
403 | framelen = 0; | ||
404 | data_pos = 0; | ||
405 | data_cur = 0; | ||
406 | |||
407 | lastlen = ttainfo->DATALENGTH % ttainfo->FRAMELEN; | ||
408 | fframes = ttainfo->DATALENGTH / ttainfo->FRAMELEN + (lastlen ? 1 : 0); | ||
409 | st_size = (fframes + 1) * sizeof(int); | ||
410 | |||
411 | /* | ||
412 | * Rockbox speciffic | ||
413 | * playable tta file is to MAX_SEEK_TABLE_SIZE frames | ||
414 | * about 1:08:15 (frequency 44.1 kHz) | ||
415 | */ | ||
416 | if (fframes > MAX_SEEK_TABLE_SIZE) | ||
417 | { | ||
418 | LOGF("frame is too many: %d > %d", fframes, MAX_SEEK_TABLE_SIZE); | ||
419 | return -1; | ||
420 | } | ||
421 | |||
422 | /* read seek table */ | ||
423 | if (!tta_fread(seek_table, st_size, 1)) { | ||
424 | ttainfo->STATE = READ_ERROR; | ||
425 | return -1; | ||
426 | } | ||
427 | |||
428 | checksum = crc32((unsigned char *) seek_table, st_size - sizeof(int)); | ||
429 | st_state = (checksum == ENDSWAP_INT32(seek_table[fframes])); | ||
430 | data_offset = sizeof(tta_hdr) + st_size; | ||
431 | |||
432 | /* init seek table */ | ||
433 | seek_table_init(seek_table, fframes, data_offset); | ||
434 | |||
435 | /* init bit reader */ | ||
436 | init_buffer_read(); | ||
437 | |||
438 | /* | ||
439 | * Rockbox speciffic | ||
440 | * because pcm data is int32_t, does not multiply ttainfo->BSIZE. | ||
441 | */ | ||
442 | pcm_buffer_size = PCM_BUFFER_LENGTH * ttainfo->NCH; | ||
443 | maxvalue = (1UL << ttainfo->BPS) - 1; | ||
444 | |||
445 | return 0; | ||
446 | } | ||
447 | |||
448 | /* | ||
449 | * Rockbox specffic | ||
450 | * because the seek table is static size buffer, player_stop() is nooperation function. | ||
451 | */ | ||
452 | void player_stop (void) { | ||
453 | /* | ||
454 | if (seek_table) { | ||
455 | free(seek_table); | ||
456 | seek_table = NULL; | ||
457 | } | ||
458 | */ | ||
459 | } | ||
460 | |||
461 | /* | ||
462 | * Rockbox speciffic | ||
463 | * with the optimization, the decoding logic is modify a little. | ||
464 | */ | ||
465 | int get_samples (int32_t *buffer) { | ||
466 | unsigned int k, depth, unary, binary; | ||
467 | int32_t *p = buffer; | ||
468 | decoder *dec = tta; | ||
469 | int value, res; | ||
470 | int cur_pos = pcm_buffer_size; | ||
471 | int pcm_shift_bits = TTA_OUTPUT_DEPTH - ttainfo->BPS; | ||
472 | int pr_bits = (ttainfo->BSIZE == 1)? 4 : 5; | ||
473 | int cache = 0; /* decoder cache */ | ||
474 | |||
475 | fltst *fst; | ||
476 | adapt *rice; | ||
477 | |||
478 | for (res = 0; --cur_pos >= 0;) { | ||
479 | fst = &dec->fst; | ||
480 | rice = &dec->rice; | ||
481 | |||
482 | if (data_cur == framelen) { | ||
483 | if (data_pos == fframes) break; | ||
484 | if (framelen && done_buffer_read()) { | ||
485 | if (set_position(data_pos, TTA_SEEK_TIME) < 0) return -1; | ||
486 | if (res) break; | ||
487 | } | ||
488 | |||
489 | if (data_pos == fframes - 1 && lastlen) | ||
490 | framelen = lastlen; | ||
491 | else framelen = ttainfo->FRAMELEN; | ||
492 | |||
493 | decoder_init(tta, ttainfo->NCH, ttainfo->BSIZE); | ||
494 | data_pos++; data_cur = 0; | ||
495 | } | ||
496 | |||
497 | /* decode Rice unsigned */ | ||
498 | GET_UNARY(unary); | ||
499 | |||
500 | switch (unary) { | ||
501 | case 0: depth = 0; k = rice->k0; break; | ||
502 | default: | ||
503 | depth = 1; k = rice->k1; | ||
504 | unary--; | ||
505 | } | ||
506 | |||
507 | if (k) { | ||
508 | GET_BINARY(binary, k); | ||
509 | value = (unary << k) + binary; | ||
510 | } else value = unary; | ||
511 | |||
512 | value = update_rice(value, rice, depth, shift_16); | ||
513 | |||
514 | /* Rockbox specific: the following logic move to update_rice() */ | ||
515 | #if 0 | ||
516 | if (depth > 0) | ||
517 | { | ||
518 | rice->sum1 += value - (rice->sum1 >> 4); | ||
519 | if (rice->k1 > 0 && rice->sum1 < shift_16[rice->k1]) | ||
520 | rice->k1--; | ||
521 | else if (rice->sum1 > shift_16[rice->k1 + 1]) | ||
522 | rice->k1++; | ||
523 | value += bit_shift[rice->k0]; | ||
524 | } | ||
525 | rice->sum0 += value - (rice->sum0 >> 4); | ||
526 | if (rice->k0 > 0 && rice->sum0 < shift_16[rice->k0]) | ||
527 | rice->k0--; | ||
528 | else if (rice->sum0 > shift_16[rice->k0 + 1]) | ||
529 | rice->k0++; | ||
530 | |||
531 | value = DEC(value); | ||
532 | #endif | ||
533 | |||
534 | /* decompress stage 1: adaptive hybrid filter */ | ||
535 | hybrid_filter(fst, &value); | ||
536 | |||
537 | /* decompress stage 2: fixed order 1 prediction */ | ||
538 | value += PREDICTOR1(dec->last, pr_bits); | ||
539 | dec->last = value; | ||
540 | |||
541 | /* check for errors */ | ||
542 | if (abs(value) > maxvalue) { | ||
543 | unsigned int tail = | ||
544 | pcm_buffer_size / (ttainfo->BSIZE * ttainfo->NCH) - res; | ||
545 | ci->memset(buffer, 0, pcm_buffer_size * sizeof(int32_t)); | ||
546 | data_cur += tail; res += tail; | ||
547 | break; | ||
548 | } | ||
549 | |||
550 | /* Rockbox speciffic: Rockbox supports max 2channels */ | ||
551 | if (ttainfo->NCH == 1) | ||
552 | { | ||
553 | *p++ = value << pcm_shift_bits; | ||
554 | data_cur++; | ||
555 | res++; | ||
556 | } | ||
557 | else | ||
558 | { | ||
559 | if (dec == tta) | ||
560 | { | ||
561 | cache = value; | ||
562 | dec++; | ||
563 | } | ||
564 | else | ||
565 | { | ||
566 | value += cache / 2; | ||
567 | cache = value - cache; | ||
568 | dec = tta; | ||
569 | *p++ = cache << pcm_shift_bits; | ||
570 | *p++ = value << pcm_shift_bits; | ||
571 | data_cur++; | ||
572 | res++; | ||
573 | } | ||
574 | } | ||
575 | } | ||
576 | |||
577 | return res; | ||
578 | } | ||
579 | |||
580 | /* Rockbox speciffic: id3 tags functions delete. */ | ||
581 | |||
582 | /* eof */ | ||
diff --git a/lib/rbcodec/codecs/libtta/ttadec.h b/lib/rbcodec/codecs/libtta/ttadec.h new file mode 100644 index 0000000000..c185e5c858 --- /dev/null +++ b/lib/rbcodec/codecs/libtta/ttadec.h | |||
@@ -0,0 +1,203 @@ | |||
1 | /* | ||
2 | * ttadec.h | ||
3 | * | ||
4 | * Description: TTAv1 decoder definitions and prototypes | ||
5 | * Developed by: Alexander Djourik <ald@true-audio.com> | ||
6 | * Pavel Zhilin <pzh@true-audio.com> | ||
7 | * | ||
8 | * Copyright (c) 2004 True Audio Software. All rights reserved. | ||
9 | * | ||
10 | */ | ||
11 | |||
12 | /* | ||
13 | * Redistribution and use in source and binary forms, with or without | ||
14 | * modification, are permitted provided that the following conditions | ||
15 | * are met: | ||
16 | * | ||
17 | * 1. Redistributions of source code must retain the above copyright | ||
18 | * notice, this list of conditions and the following disclaimer. | ||
19 | * 2. Redistributions in binary form must reproduce the above copyright | ||
20 | * notice, this list of conditions and the following disclaimer in the | ||
21 | * documentation and/or other materials provided with the distribution. | ||
22 | * 3. Neither the name of the True Audio Software nor the names of its | ||
23 | * contributors may be used to endorse or promote products derived | ||
24 | * from this software without specific prior written permission. | ||
25 | * | ||
26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
27 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
28 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
29 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
30 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
31 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
32 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
33 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
34 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
35 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
36 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
37 | */ | ||
38 | |||
39 | #ifndef TTADEC_H_ | ||
40 | #define TTADEC_H_ | ||
41 | |||
42 | #define __ATTRIBUTE_PACKED__ __attribute__((packed)) | ||
43 | |||
44 | #define TTA1_SIGN 0x31415454 | ||
45 | #define MAX_ORDER 8 | ||
46 | |||
47 | #ifndef WAVE_FORMAT_PCM | ||
48 | #define WAVE_FORMAT_PCM 1 | ||
49 | #endif | ||
50 | |||
51 | typedef unsigned long long uint64; | ||
52 | |||
53 | static const unsigned int crc32_table[256] ICONST_ATTR = { | ||
54 | 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, | ||
55 | 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, | ||
56 | 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, | ||
57 | 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, | ||
58 | 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, | ||
59 | 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, | ||
60 | 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, | ||
61 | 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, | ||
62 | 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, | ||
63 | 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, | ||
64 | 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, | ||
65 | 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, | ||
66 | 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, | ||
67 | 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, | ||
68 | 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, | ||
69 | 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, | ||
70 | 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, | ||
71 | 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, | ||
72 | 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, | ||
73 | 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, | ||
74 | 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, | ||
75 | 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, | ||
76 | 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, | ||
77 | 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, | ||
78 | 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, | ||
79 | 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, | ||
80 | 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, | ||
81 | 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, | ||
82 | 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, | ||
83 | 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, | ||
84 | 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, | ||
85 | 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, | ||
86 | 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, | ||
87 | 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, | ||
88 | 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, | ||
89 | 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, | ||
90 | 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, | ||
91 | 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, | ||
92 | 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, | ||
93 | 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, | ||
94 | 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, | ||
95 | 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, | ||
96 | 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, | ||
97 | 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, | ||
98 | 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, | ||
99 | 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, | ||
100 | 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, | ||
101 | 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, | ||
102 | 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, | ||
103 | 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, | ||
104 | 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, | ||
105 | 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, | ||
106 | 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, | ||
107 | 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, | ||
108 | 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, | ||
109 | 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, | ||
110 | 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, | ||
111 | 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, | ||
112 | 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, | ||
113 | 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, | ||
114 | 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, | ||
115 | 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, | ||
116 | 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, | ||
117 | 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d | ||
118 | }; | ||
119 | |||
120 | static const unsigned int bit_mask[] ICONST_ATTR = { | ||
121 | 0x00000000, 0x00000001, 0x00000003, 0x00000007, | ||
122 | 0x0000000f, 0x0000001f, 0x0000003f, 0x0000007f, | ||
123 | 0x000000ff, 0x000001ff, 0x000003ff, 0x000007ff, | ||
124 | 0x00000fff, 0x00001fff, 0x00003fff, 0x00007fff, | ||
125 | 0x0000ffff, 0x0001ffff, 0x0003ffff, 0x0007ffff, | ||
126 | 0x000fffff, 0x001fffff, 0x003fffff, 0x007fffff, | ||
127 | 0x00ffffff, 0x01ffffff, 0x03ffffff, 0x07ffffff, | ||
128 | 0x0fffffff, 0x1fffffff, 0x3fffffff, 0x7fffffff, | ||
129 | 0xffffffff | ||
130 | }; | ||
131 | |||
132 | static const unsigned int bit_shift[] ICONST_ATTR = { | ||
133 | 0x00000001, 0x00000002, 0x00000004, 0x00000008, | ||
134 | 0x00000010, 0x00000020, 0x00000040, 0x00000080, | ||
135 | 0x00000100, 0x00000200, 0x00000400, 0x00000800, | ||
136 | 0x00001000, 0x00002000, 0x00004000, 0x00008000, | ||
137 | 0x00010000, 0x00020000, 0x00040000, 0x00080000, | ||
138 | 0x00100000, 0x00200000, 0x00400000, 0x00800000, | ||
139 | 0x01000000, 0x02000000, 0x04000000, 0x08000000, | ||
140 | 0x10000000, 0x20000000, 0x40000000, 0x80000000, | ||
141 | 0x80000000, 0x80000000, 0x80000000, 0x80000000, | ||
142 | 0x80000000, 0x80000000, 0x80000000, 0x80000000 | ||
143 | }; | ||
144 | |||
145 | static const unsigned int * const shift_16 ICONST_ATTR = bit_shift + 4; | ||
146 | |||
147 | typedef unsigned char byte; | ||
148 | |||
149 | #ifndef ROCKBOX_LITTLE_ENDIAN | ||
150 | #define ENDSWAP_INT16(x) (((((x)>>8)&0xFF)|(((x)&0xFF)<<8))) | ||
151 | #define ENDSWAP_INT32(x) (((((x)>>24)&0xFF)|(((x)>>8)&0xFF00)|(((x)&0xFF00)<<8)|(((x)&0xFF)<<24))) | ||
152 | #define WRITE_BUFFER(x, bsize, out) { \ | ||
153 | if (bsize > 2) *out++ = (byte)(*x >> 16)); \ | ||
154 | if (bsize > 1) *out++ = (byte)(*x >> 8); \ | ||
155 | *out++ = (byte) *x; } | ||
156 | #else | ||
157 | #define ENDSWAP_INT16(x) (x) | ||
158 | #define ENDSWAP_INT32(x) (x) | ||
159 | #define WRITE_BUFFER(x, bsize, out) { \ | ||
160 | *out++ = (byte) *x; \ | ||
161 | if (bsize > 1) *out++ = (byte)(*x >> 8); \ | ||
162 | if (bsize > 2) *out++ = (byte)(*x >> 16); } | ||
163 | #endif | ||
164 | |||
165 | #define PREDICTOR1(x, k) ((int)((((uint64)x << k) - x) >> k)) | ||
166 | #define DEC(x) (((x)&1)?(((x)+1)>>1):(-(x)>>1)) | ||
167 | |||
168 | typedef struct { | ||
169 | unsigned int TTAid; | ||
170 | unsigned short AudioFormat; | ||
171 | unsigned short NumChannels; | ||
172 | unsigned short BitsPerSample; | ||
173 | unsigned int SampleRate; | ||
174 | unsigned int DataLength; | ||
175 | unsigned int CRC32; | ||
176 | } __ATTRIBUTE_PACKED__ tta_hdr; | ||
177 | |||
178 | typedef struct { | ||
179 | unsigned int k0; | ||
180 | unsigned int k1; | ||
181 | unsigned int sum0; | ||
182 | unsigned int sum1; | ||
183 | } adapt; | ||
184 | |||
185 | typedef struct { | ||
186 | int index; /* Rockbox speciffic */ | ||
187 | int error; | ||
188 | int round; | ||
189 | int shift; | ||
190 | int mutex; | ||
191 | int qm[MAX_ORDER]; | ||
192 | int dx[MAX_ORDER * 3]; /* original: dx[MAX_ORDER + 1] */ | ||
193 | int dl[MAX_ORDER * 3]; /* original: dx[MAX_ORDER + 1] */ | ||
194 | } fltst; | ||
195 | |||
196 | typedef struct { | ||
197 | fltst fst; | ||
198 | adapt rice; | ||
199 | int last; | ||
200 | } decoder; | ||
201 | |||
202 | /* Rockbox speciffic: about id3 tags definitions delete. */ | ||
203 | #endif /* TTADEC_H_ */ | ||
diff --git a/lib/rbcodec/codecs/libtta/ttalib.h b/lib/rbcodec/codecs/libtta/ttalib.h new file mode 100644 index 0000000000..45da71813a --- /dev/null +++ b/lib/rbcodec/codecs/libtta/ttalib.h | |||
@@ -0,0 +1,157 @@ | |||
1 | /* | ||
2 | * ttalib.h | ||
3 | * | ||
4 | * Description: TTAv1 player library prototypes | ||
5 | * Developed by: Alexander Djourik <ald@true-audio.com> | ||
6 | * Pavel Zhilin <pzh@true-audio.com> | ||
7 | * | ||
8 | * Copyright (c) 2004 True Audio Software. All rights reserved. | ||
9 | * | ||
10 | */ | ||
11 | |||
12 | /* | ||
13 | * Redistribution and use in source and binary forms, with or without | ||
14 | * modification, are permitted provided that the following conditions | ||
15 | * are met: | ||
16 | * | ||
17 | * 1. Redistributions of source code must retain the above copyright | ||
18 | * notice, this list of conditions and the following disclaimer. | ||
19 | * 2. Redistributions in binary form must reproduce the above copyright | ||
20 | * notice, this list of conditions and the following disclaimer in the | ||
21 | * documentation and/or other materials provided with the distribution. | ||
22 | * 3. Neither the name of the True Audio Software nor the names of its | ||
23 | * contributors may be used to endorse or promote products derived | ||
24 | * from this software without specific prior written permission. | ||
25 | * | ||
26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
27 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
28 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
29 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
30 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
31 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
32 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
33 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
34 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
35 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
36 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
37 | */ | ||
38 | |||
39 | #ifndef TTALIB_H_ | ||
40 | #define TTALIB_H_ | ||
41 | |||
42 | #define MAX_BPS 24 /* Max supported Bit resolution */ | ||
43 | #define MAX_NCH 2 /* Max supported number of channels (Rockbox changes: 8 -> 2) */ | ||
44 | |||
45 | #ifndef MAXLINE | ||
46 | #define MAX_LINE 1024 | ||
47 | #endif | ||
48 | |||
49 | /* decoded pcm sample depth (sample 28bit + sign 1bit) */ | ||
50 | #define TTA_OUTPUT_DEPTH 29 | ||
51 | |||
52 | /* return codes */ | ||
53 | #define NO_ERROR 0 /* No errors found */ | ||
54 | #define OPEN_ERROR 1 /* Can't open file */ | ||
55 | #define FORMAT_ERROR 2 /* Unknown TTA format version */ | ||
56 | #define PLAYER_ERROR 3 /* Not supported file format */ | ||
57 | #define FILE_ERROR 4 /* File is corrupted */ | ||
58 | #define READ_ERROR 5 /* Can't read from file */ | ||
59 | #define MEMORY_ERROR 6 /* Insufficient memory available */ | ||
60 | |||
61 | /* Rockbox speciffic: does not use FRAME_TIME */ | ||
62 | /* #define FRAME_TIME 1.04489795918367346939 */ | ||
63 | #define MULTIPLY_FRAME_TIME(x) (256 * (x) / 245) /* = FRAME_TIME * x */ | ||
64 | #define SEEK_STEP (int)MULTIPLY_FRAME_TIME(1000) /* (FRAME_TIME * 1000) */ | ||
65 | |||
66 | #define ISO_BUFFER_LENGTH (1024*32) | ||
67 | #define ISO_NBUFFERS (8) | ||
68 | #define ISO_BUFFERS_SIZE (4096) /* (ISO_BUFFER_LENGTH*ISO_NBUFFERS) */ | ||
69 | #define PCM_BUFFER_LENGTH (4608) | ||
70 | #define MAX_SEEK_TABLE_SIZE (4096) | ||
71 | |||
72 | typedef struct { | ||
73 | /* FILE *HANDLE; // file handle (Rockbox does not use) */ | ||
74 | unsigned int FILESIZE; /* compressed size */ | ||
75 | unsigned short NCH; /* number of channels */ | ||
76 | unsigned short BPS; /* bits per sample */ | ||
77 | unsigned short BSIZE; /* byte size */ | ||
78 | unsigned short FORMAT; /* audio format */ | ||
79 | unsigned int SAMPLERATE; /* samplerate (sps) */ | ||
80 | unsigned int DATALENGTH; /* data length in samples */ | ||
81 | unsigned int FRAMELEN; /* frame length */ | ||
82 | unsigned int LENGTH; /* playback time (sec) */ | ||
83 | unsigned int STATE; /* return code */ | ||
84 | unsigned int DATAPOS; /* size of ID3v2 header */ | ||
85 | unsigned int BITRATE; /* average bitrate (kbps) */ | ||
86 | /* double COMPRESS; // compression ratio (Rockbox does not use) */ | ||
87 | /* id3_info ID3; // ID3 information (Rockbox does not use) */ | ||
88 | } tta_info; | ||
89 | |||
90 | enum tta_seek_type | ||
91 | { | ||
92 | TTA_SEEK_TIME, | ||
93 | TTA_SEEK_POS, | ||
94 | }; | ||
95 | |||
96 | /*********************** Library functions *************************/ | ||
97 | /* Rockbox speciffic: open_tta_file() does not use */ | ||
98 | |||
99 | /* Rockbox speciffic: It is used in place of open_tta_file(). */ | ||
100 | int set_tta_info( // FUNCTION: set tta file info structure | ||
101 | tta_info *info); // file info structure | ||
102 | /* | ||
103 | * RETURN VALUE | ||
104 | * This function returns 0 if success. Otherwise, -1 is returned | ||
105 | * and the variable STATE of the currently using info structure | ||
106 | * is set to indicate the error. | ||
107 | * | ||
108 | */ | ||
109 | |||
110 | /* Rockbox speciffic: close_tta_file() does not use */ | ||
111 | |||
112 | /* Rockbox speciffic: set_position() change arguments and return value. */ | ||
113 | /* | ||
114 | * FUNCTION: sets playback position | ||
115 | * pos: seek position | ||
116 | * seek_time_ms / SEEK_STEP (when type is TTA_SEEK_TIME) | ||
117 | * file position (when type is TTA_SEEK_POS) | ||
118 | */ | ||
119 | int set_position ( | ||
120 | unsigned int pos, | ||
121 | enum tta_seek_type type); | ||
122 | |||
123 | /* | ||
124 | * RETURN VALUE | ||
125 | * This function returns the seeked data position (>= 0) if success. Otherwise, -1 is returned | ||
126 | * and the variable STATE of the currently using info structure | ||
127 | * is set to indicate the error. | ||
128 | * | ||
129 | */ | ||
130 | |||
131 | int player_init ( // FUNCTION: initializes TTA player | ||
132 | tta_info *info); // file info structure | ||
133 | /* | ||
134 | * RETURN VALUE | ||
135 | * This function returns 0 if success. Otherwise, -1 is returned | ||
136 | * and the variable STATE of the currently using info structure | ||
137 | * is set to indicate the error. | ||
138 | * | ||
139 | */ | ||
140 | |||
141 | void player_stop (void); // FUNCTION: destroys memory pools | ||
142 | |||
143 | /* Rockbox speciffic: unsigned char -> int32_t */ | ||
144 | int get_samples ( // FUNCTION: decode PCM_BUFFER_LENGTH samples | ||
145 | int32_t *buffer) ICODE_ATTR; // into the current PCM buffer position | ||
146 | |||
147 | /* | ||
148 | * RETURN VALUE | ||
149 | * This function returns the number of samples successfully decoded. | ||
150 | * Otherwise, -1 is returned and the variable STATE of the currently | ||
151 | * using info structure is set to indicate the error. | ||
152 | * | ||
153 | */ | ||
154 | |||
155 | const char *get_error_str (int error); // FUNCTION: get error description | ||
156 | |||
157 | #endif /* TTALIB_H_ */ | ||