annotate src/tta/ttadec.c @ 1978:fa9f85cebade

s/vfs_/aud_vfs_/g
author William Pitcock <nenolod@atheme.org>
date Sun, 07 Oct 2007 00:25:33 -0500
parents 0d5b0f861bf0
children cb9802386cda
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
1 /*
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
2 * ttadec.c
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
3 *
1012
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
4 * Description: TTAv1 decoder library
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
5 * Developed by: Alexander Djourik <ald@true-audio.com>
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
6 *
1012
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
7 * Copyright (c) 1999-2007 Alexander Djourik. All rights reserved.
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
8 *
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
9 */
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
10
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
11 /*
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
12 * This library is free software; you can redistribute it and/or
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
13 * modify it under the terms of the GNU Lesser General Public
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
14 * License as published by the Free Software Foundation; either
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
15 * version 2.1 of the License, or (at your option) any later version.
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
16 *
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
17 * This library is distributed in the hope that it will be useful,
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
20 * Lesser General Public License for more details.
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
21 *
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
22 * You should have received a copy of the GNU Lesser General Public
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
23 * License along with this library; if not, write to the Free Software
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
25 *
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
26 * Please see the file COPYING in this directory for full copyright
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
27 * information.
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
28 */
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
29
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
30 #include <stdlib.h>
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
31 #include <stdio.h>
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
32 #include <string.h>
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
33
912
5bd17596c7e9 [svn] - patches from upstream TTA author. see http://boards.nenolod.net/viewtopic.php?t=375
nenolod
parents: 551
diff changeset
34 #include "ttadec.h"
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
35 #include "ttalib.h"
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
36
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
37 /******************* static variables and structures *******************/
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
38
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
39 static unsigned char isobuffers[ISO_BUFFERS_SIZE + 4];
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
40 static unsigned char *iso_buffers_end = isobuffers + ISO_BUFFERS_SIZE;
551
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
41 static unsigned int pcm_buffer_size;
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
42
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
43 static decoder tta[MAX_NCH]; // decoder state
551
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
44 static int cache[MAX_NCH]; // decoder cache
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
45
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
46 tta_info *ttainfo; // currently playing file info
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
47
551
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
48 static unsigned int fframes; // number of frames in file
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
49 static unsigned int framelen; // the frame length in samples
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
50 static unsigned int lastlen; // the length of the last frame in samples
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
51 static unsigned int data_pos; // currently playing frame index
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
52 static unsigned int data_cur; // the playing position in frame
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
53
551
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
54 static int maxvalue; // output data max value
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
55 static unsigned int *seek_table; // the playing position table
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
56 static unsigned int st_state; //seek table status
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
57
912
5bd17596c7e9 [svn] - patches from upstream TTA author. see http://boards.nenolod.net/viewtopic.php?t=375
nenolod
parents: 551
diff changeset
58 static __uint32_t frame_crc32;
5bd17596c7e9 [svn] - patches from upstream TTA author. see http://boards.nenolod.net/viewtopic.php?t=375
nenolod
parents: 551
diff changeset
59 static __uint32_t bit_count;
5bd17596c7e9 [svn] - patches from upstream TTA author. see http://boards.nenolod.net/viewtopic.php?t=375
nenolod
parents: 551
diff changeset
60 static __uint32_t bit_cache;
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
61 static unsigned char *bitpos;
551
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
62 static unsigned int bitrate;
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
63
1012
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
64 /************************* crc32 functions *****************************/
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
65
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
66 #define UPDATE_CRC32(x, crc) crc = \
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
67 (((crc>>8) & 0x00FFFFFF) ^ crc32_table[(crc^x) & 0xFF])
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
68
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
69 static __uint32_t
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
70 crc32 (unsigned char *buffer, unsigned int len) {
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
71 unsigned int i;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
72 unsigned int crc = 0xFFFFFFFF;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
73
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
74 for (i = 0; i < len; i++) UPDATE_CRC32(buffer[i], crc);
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
75
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
76 return (crc ^ 0xFFFFFFFF);
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
77 }
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
78
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
79 /************************* bit operations ******************************/
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
80
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
81 static void init_buffer_read() {
1012
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
82 frame_crc32 = 0xFFFFFFFFUL;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
83 bit_count = bit_cache = 0;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
84 bitpos = iso_buffers_end;
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
85 }
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
86
551
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
87 __inline void get_binary(unsigned int *value, unsigned int bits) {
1012
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
88 while (bit_count < bits) {
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
89 if (bitpos == iso_buffers_end) {
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1237
diff changeset
90 int res = aud_vfs_fread(isobuffers, 1,
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
91 ISO_BUFFERS_SIZE, ttainfo->HANDLE);
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
92 if (!res) {
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
93 ttainfo->STATE = READ_ERROR;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
94 return;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
95 }
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
96 bitpos = isobuffers;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
97 }
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
98
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
99 UPDATE_CRC32(*bitpos, frame_crc32);
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
100 bit_cache |= *bitpos << bit_count;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
101 bit_count += 8;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
102 bitpos++;
1012
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
103 }
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
104
1012
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
105 *value = bit_cache & bit_mask[bits];
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
106 bit_cache >>= bits;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
107 bit_count -= bits;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
108 bit_cache &= bit_mask[bit_count];
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
109 }
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
110
551
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
111 __inline void get_unary(unsigned int *value) {
1012
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
112 *value = 0;
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
113
1012
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
114 while (!(bit_cache ^ bit_mask[bit_count])) {
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
115 if (bitpos == iso_buffers_end) {
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1237
diff changeset
116 int res = aud_vfs_fread(isobuffers, 1,
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
117 ISO_BUFFERS_SIZE, ttainfo->HANDLE);
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
118 if (!res) {
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
119 ttainfo->STATE = READ_ERROR;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
120 return;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
121 }
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
122 bitpos = isobuffers;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
123 }
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
124
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
125 *value += bit_count;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
126 bit_cache = *bitpos++;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
127 UPDATE_CRC32(bit_cache, frame_crc32);
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
128 bit_count = 8;
1012
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
129 }
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
130
1012
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
131 while (bit_cache & 1) {
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
132 (*value)++;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
133 bit_cache >>= 1;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
134 bit_count--;
1012
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
135 }
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
136
1012
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
137 bit_cache >>= 1;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
138 bit_count--;
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
139 }
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
140
551
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
141 static int done_buffer_read() {
1012
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
142 unsigned int crc32, rbytes, res;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
143 frame_crc32 ^= 0xFFFFFFFFUL;
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
144
1012
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
145 rbytes = iso_buffers_end - bitpos;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
146 if (rbytes < sizeof(int)) {
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
147 memcpy(isobuffers, bitpos, 4);
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1237
diff changeset
148 res = aud_vfs_fread(isobuffers + rbytes, 1,
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
149 ISO_BUFFERS_SIZE - rbytes, ttainfo->HANDLE);
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
150 if (!res) {
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
151 ttainfo->STATE = READ_ERROR;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
152 return 0;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
153 }
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
154 bitpos = isobuffers;
1012
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
155 }
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
156
1012
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
157 memcpy(&crc32, bitpos, 4);
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
158 crc32 = ENDSWAP_INT32(crc32);
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
159 bitpos += sizeof(int);
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
160 res = (crc32 != frame_crc32);
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
161
1012
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
162 bit_cache = bit_count = 0;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
163 frame_crc32 = 0xFFFFFFFFUL;
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
164
1012
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
165 // calculate dynamic bitrate
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
166 if (data_pos < fframes) {
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
167 rbytes = seek_table[data_pos] -
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
168 seek_table[data_pos - 1];
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
169 bitrate = (rbytes << 3) / 1070;
1012
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
170 }
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
171
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
172 return res;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
173 }
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
174
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
175 /************************** filter functions ****************************/
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
176
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
177 ///////// Filter Settings //////////
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
178 static int flt_set[3] = {10, 9, 10};
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
179
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
180 __inline void
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
181 memshl (register int *pA, register int *pB) {
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
182 *pA++ = *pB++;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
183 *pA++ = *pB++;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
184 *pA++ = *pB++;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
185 *pA++ = *pB++;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
186 *pA++ = *pB++;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
187 *pA++ = *pB++;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
188 *pA++ = *pB++;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
189 *pA = *pB;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
190 }
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
191
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
192 __inline void
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
193 hybrid_filter (fltst *fs, int *in) {
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
194 register int *pA = fs->dl;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
195 register int *pB = fs->qm;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
196 register int *pM = fs->dx;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
197 register int sum = fs->round;
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
198
1012
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
199 if (!fs->error) {
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
200 sum += *pA++ * *pB, pB++;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
201 sum += *pA++ * *pB, pB++;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
202 sum += *pA++ * *pB, pB++;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
203 sum += *pA++ * *pB, pB++;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
204 sum += *pA++ * *pB, pB++;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
205 sum += *pA++ * *pB, pB++;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
206 sum += *pA++ * *pB, pB++;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
207 sum += *pA++ * *pB, pB++; pM += 8;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
208 } else if (fs->error < 0) {
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
209 sum += *pA++ * (*pB -= *pM++), pB++;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
210 sum += *pA++ * (*pB -= *pM++), pB++;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
211 sum += *pA++ * (*pB -= *pM++), pB++;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
212 sum += *pA++ * (*pB -= *pM++), pB++;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
213 sum += *pA++ * (*pB -= *pM++), pB++;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
214 sum += *pA++ * (*pB -= *pM++), pB++;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
215 sum += *pA++ * (*pB -= *pM++), pB++;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
216 sum += *pA++ * (*pB -= *pM++), pB++;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
217 } else {
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
218 sum += *pA++ * (*pB += *pM++), pB++;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
219 sum += *pA++ * (*pB += *pM++), pB++;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
220 sum += *pA++ * (*pB += *pM++), pB++;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
221 sum += *pA++ * (*pB += *pM++), pB++;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
222 sum += *pA++ * (*pB += *pM++), pB++;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
223 sum += *pA++ * (*pB += *pM++), pB++;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
224 sum += *pA++ * (*pB += *pM++), pB++;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
225 sum += *pA++ * (*pB += *pM++), pB++;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
226 }
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
227
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
228 *(pM-0) = ((*(pA-1) >> 30) | 1) << 2;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
229 *(pM-1) = ((*(pA-2) >> 30) | 1) << 1;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
230 *(pM-2) = ((*(pA-3) >> 30) | 1) << 1;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
231 *(pM-3) = ((*(pA-4) >> 30) | 1);
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
232
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
233 fs->error = *in;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
234 *in += (sum >> fs->shift);
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
235 *pA = *in;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
236
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
237 *(pA-1) = *(pA-0) - *(pA-1);
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
238 *(pA-2) = *(pA-1) - *(pA-2);
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
239 *(pA-3) = *(pA-2) - *(pA-3);
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
240
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
241 memshl (fs->dl, fs->dl + 1);
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
242 memshl (fs->dx, fs->dx + 1);
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
243 }
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
244
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
245 void
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
246 filter_init (fltst *fs, int shift) {
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
247 memset (fs, 0, sizeof(fltst));
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
248 fs->shift = shift;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
249 fs->round = 1 << (shift - 1);
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
250 }
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
251
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
252 /************************* decoder functions ****************************/
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
253
1012
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
254 int id3v2_header_length (tta_info *ttainfo) {
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
255 struct {
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
256 unsigned char id[3];
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
257 unsigned short version;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
258 unsigned char flags;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
259 unsigned char size[4];
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
260 } __ATTRIBUTE_PACKED__ id3v2;
551
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
261 unsigned int len = 0;
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
262
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1237
diff changeset
263 if (!aud_vfs_fread(&id3v2, sizeof(id3v2), 1, ttainfo->HANDLE) ||
1012
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
264 memcmp(id3v2.id, "ID3", 3) ||
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
265 id3v2.size[0] & 0x80)
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
266 {
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
267 fseek (ttainfo->HANDLE, 0, SEEK_SET);
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
268 return 0;
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
269 }
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
270
1012
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
271 len = (id3v2.size[0] & 0x7f);
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
272 len = (len << 7) | (id3v2.size[1] & 0x7f);
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
273 len = (len << 7) | (id3v2.size[2] & 0x7f);
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
274 len = (len << 7) | (id3v2.size[3] & 0x7f);
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
275 len += 10;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
276 if (id3v2.flags & (1 << 4)) len += 10;
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
277
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
278 return len;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
279 }
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
280
551
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
281 int open_tta_file (const char *filename, tta_info *info, unsigned int data_offset) {
1237
0d5b0f861bf0 - quick fix for link breakage to libaudid3tag.so when --prefix is specified.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 1190
diff changeset
282 VFSFile *infile;
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
283 tta_hdr ttahdr;
551
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
284 unsigned int checksum;
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
285
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
286 // clear the memory
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
287 memset (info, 0, sizeof(tta_info));
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
288
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1237
diff changeset
289 info->HANDLE = infile = aud_vfs_fopen(filename, "rb");
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
290 if (!infile) return OPEN_ERROR;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
291
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
292 // read id3v2 header
1012
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
293 // if (!data_offset)
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
294 // data_offset = id3v2_header_length(info);
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
295
1012
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
296 data_offset = get_id3_tags (filename, info);
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1237
diff changeset
297 aud_vfs_fseek (infile, data_offset, SEEK_SET);
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
298
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
299 // read TTA header
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1237
diff changeset
300 if (aud_vfs_fread (&ttahdr, 1, sizeof (ttahdr), infile) == 0) {
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1237
diff changeset
301 aud_vfs_fclose (infile);
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
302 info->STATE = READ_ERROR;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
303 return -1;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
304 }
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
305
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
306 // check for TTA3 signature
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
307 if (ENDSWAP_INT32(ttahdr.TTAid) != TTA1_SIGN) {
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1237
diff changeset
308 aud_vfs_fclose (infile);
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
309 info->STATE = FORMAT_ERROR;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
310 return -1;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
311 }
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
312
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
313 ttahdr.CRC32 = ENDSWAP_INT32(ttahdr.CRC32);
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
314 checksum = crc32((unsigned char *) &ttahdr,
551
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
315 sizeof(tta_hdr) - sizeof(int));
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
316 if (checksum != ttahdr.CRC32) {
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1237
diff changeset
317 aud_vfs_fclose (infile);
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
318 info->STATE = FILE_ERROR;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
319 return -1;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
320 }
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
321
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
322 ttahdr.AudioFormat = ENDSWAP_INT16(ttahdr.AudioFormat);
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
323 ttahdr.NumChannels = ENDSWAP_INT16(ttahdr.NumChannels);
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
324 ttahdr.BitsPerSample = ENDSWAP_INT16(ttahdr.BitsPerSample);
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
325 ttahdr.SampleRate = ENDSWAP_INT32(ttahdr.SampleRate);
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
326 ttahdr.DataLength = ENDSWAP_INT32(ttahdr.DataLength);
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
327
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
328 // check for player supported formats
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
329 if (ttahdr.AudioFormat != WAVE_FORMAT_PCM ||
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
330 ttahdr.NumChannels > MAX_NCH ||
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
331 ttahdr.BitsPerSample > MAX_BPS ||(
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
332 ttahdr.SampleRate != 16000 &&
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
333 ttahdr.SampleRate != 22050 &&
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
334 ttahdr.SampleRate != 24000 &&
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
335 ttahdr.SampleRate != 32000 &&
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
336 ttahdr.SampleRate != 44100 &&
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
337 ttahdr.SampleRate != 48000 &&
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
338 ttahdr.SampleRate != 64000 &&
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
339 ttahdr.SampleRate != 88200 &&
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
340 ttahdr.SampleRate != 96000)) {
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1237
diff changeset
341 aud_vfs_fclose (infile);
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
342 info->STATE = FORMAT_ERROR;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
343 return FORMAT_ERROR;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
344 }
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
345
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
346 // fill the File Info
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
347 info->HANDLE = infile;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
348 info->NCH = ttahdr.NumChannels;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
349 info->BPS = ttahdr.BitsPerSample;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
350 info->BSIZE = (ttahdr.BitsPerSample + 7)/8;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
351 info->FORMAT = ttahdr.AudioFormat;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
352 info->SAMPLERATE = ttahdr.SampleRate;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
353 info->DATALENGTH = ttahdr.DataLength;
551
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
354 info->FRAMELEN = (int) (FRAME_TIME * ttahdr.SampleRate);
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
355 info->LENGTH = ttahdr.DataLength / ttahdr.SampleRate;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
356 info->DATAPOS = data_offset;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
357
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
358
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
359 return 0;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
360 }
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
361
551
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
362 static void rice_init(adapt *rice, unsigned int k0, unsigned int k1) {
1012
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
363 rice->k0 = k0;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
364 rice->k1 = k1;
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
365 rice->sum0 = shift_16[k0];
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
366 rice->sum1 = shift_16[k1];
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
367 }
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
368
551
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
369 static void decoder_init(decoder *tta, int nch, int byte_size) {
1012
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
370 int shift = flt_set[byte_size - 1];
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
371 int i;
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
372
1012
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
373 for (i = 0; i < nch; i++) {
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
374 filter_init(&tta[i].fst, shift);
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
375 rice_init(&tta[i].rice, 10, 10);
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
376 tta[i].last = 0;
1012
d0d99b22e393 [svn] import major update by Aleksander Djuric (the original author).
yaz
parents: 912
diff changeset
377 }
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
378 }
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
379
551
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
380 static void seek_table_init (unsigned int *seek_table,
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
381 unsigned int len, unsigned int data_offset) {
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
382 unsigned int *st, frame_len;
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
383
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
384 for (st = seek_table; st < (seek_table + len); st++) {
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
385 frame_len = ENDSWAP_INT32(*st);
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
386 *st = data_offset;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
387 data_offset += frame_len;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
388 }
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
389 }
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
390
551
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
391 int set_position (unsigned int pos) {
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
392 unsigned int seek_pos;
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
393
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
394 if (pos >= fframes) return 0;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
395 if (!st_state) {
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
396 ttainfo->STATE = FILE_ERROR;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
397 return -1;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
398 }
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
399
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
400 seek_pos = ttainfo->DATAPOS + seek_table[data_pos = pos];
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1237
diff changeset
401 aud_vfs_fseek(ttainfo->HANDLE, seek_pos, SEEK_SET);
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
402
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
403 data_cur = 0;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
404 framelen = 0;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
405
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
406 // init bit reader
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
407 init_buffer_read();
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
408
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
409 return 0;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
410 }
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
411
551
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
412 int player_init (tta_info *info) {
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
413 unsigned int checksum;
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
414 unsigned int data_offset;
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
415 unsigned int st_size;
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
416
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
417 ttainfo = info;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
418
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
419 framelen = 0;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
420 data_pos = 0;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
421 data_cur = 0;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
422 bitrate = 0;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
423
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
424 lastlen = ttainfo->DATALENGTH % ttainfo->FRAMELEN;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
425 fframes = ttainfo->DATALENGTH / ttainfo->FRAMELEN + (lastlen ? 1:0);
551
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
426 st_size = (fframes + 1) * sizeof(int);
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
427
551
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
428 seek_table = (unsigned int *) malloc(st_size);
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
429 if (!seek_table) {
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
430 ttainfo->STATE = MEMORY_ERROR;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
431 return -1;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
432 }
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
433
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
434 // read seek table
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1237
diff changeset
435 if (!aud_vfs_fread(seek_table, st_size, 1, ttainfo->HANDLE)) {
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
436 ttainfo->STATE = READ_ERROR;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
437 return -1;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
438 }
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
439
551
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
440 checksum = crc32((unsigned char *) seek_table, st_size - sizeof(int));
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
441 st_state = (checksum == ENDSWAP_INT32(seek_table[fframes]));
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
442 data_offset = sizeof(tta_hdr) + st_size;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
443
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
444 // init seek table
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
445 seek_table_init(seek_table, fframes, data_offset);
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
446
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
447 // init bit reader
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
448 init_buffer_read();
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
449
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
450 pcm_buffer_size = PCM_BUFFER_LENGTH * ttainfo->BSIZE * ttainfo->NCH;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
451 maxvalue = (1UL << ttainfo->BPS) - 1;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
452
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
453 return 0;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
454 }
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
455
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
456 void close_tta_file (tta_info *info) {
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
457 if (info->HANDLE) {
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1237
diff changeset
458 aud_vfs_fclose (info->HANDLE);
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
459 info->HANDLE = NULL;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
460 }
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
461 }
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
462
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
463 void player_stop () {
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
464 if (seek_table) {
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
465 free(seek_table);
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
466 seek_table = NULL;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
467 }
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
468 }
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
469
551
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
470 int get_bitrate () {
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
471 return bitrate;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
472 }
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
473
551
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
474 int get_samples (byte *buffer) {
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
475 unsigned int k, depth, unary, binary;
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
476 byte *p = buffer;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
477 decoder *dec = tta;
551
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
478 int *prev = cache;
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
479 int value, res;
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
480
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
481 for (res = 0; p < buffer + pcm_buffer_size;) {
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
482 fltst *fst = &dec->fst;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
483 adapt *rice = &dec->rice;
551
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
484 int *last = &dec->last;
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
485
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
486 if (data_cur == framelen) {
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
487 if (data_pos == fframes) break;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
488 if (framelen && done_buffer_read()) {
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
489 if (set_position(data_pos) < 0)
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
490 return -1;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
491 if (res) break;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
492 }
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
493
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
494 if (data_pos == fframes - 1 && lastlen)
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
495 framelen = lastlen;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
496 else framelen = ttainfo->FRAMELEN;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
497
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
498 decoder_init(tta, ttainfo->NCH, ttainfo->BSIZE);
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
499 data_pos++; data_cur = 0;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
500 }
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
501
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
502 // decode Rice unsigned
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
503 get_unary(&unary);
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
504
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
505 switch (unary) {
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
506 case 0: depth = 0; k = rice->k0; break;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
507 default:
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
508 depth = 1; k = rice->k1;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
509 unary--;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
510 }
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
511
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
512 if (k) {
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
513 get_binary(&binary, k);
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
514 value = (unary << k) + binary;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
515 } else value = unary;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
516
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
517 switch (depth) {
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
518 case 1:
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
519 rice->sum1 += value - (rice->sum1 >> 4);
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
520 if (rice->k1 > 0 && rice->sum1 < shift_16[rice->k1])
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
521 rice->k1--;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
522 else if (rice->sum1 > shift_16[rice->k1 + 1])
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
523 rice->k1++;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
524 value += bit_shift[rice->k0];
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
525 default:
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
526 rice->sum0 += value - (rice->sum0 >> 4);
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
527 if (rice->k0 > 0 && rice->sum0 < shift_16[rice->k0])
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
528 rice->k0--;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
529 else if (rice->sum0 > shift_16[rice->k0 + 1])
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
530 rice->k0++;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
531 }
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
532
1237
0d5b0f861bf0 - quick fix for link breakage to libaudid3tag.so when --prefix is specified.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 1190
diff changeset
533 value = DEC(value);
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
534
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
535 // decompress stage 1: adaptive hybrid filter
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
536 hybrid_filter(fst, &value);
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
537
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
538 // decompress stage 2: fixed order 1 prediction
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
539 switch (ttainfo->BSIZE) {
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
540 case 1: value += PREDICTOR1(*last, 4); break; // bps 8
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
541 case 2: value += PREDICTOR1(*last, 5); break; // bps 16
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
542 case 3: value += PREDICTOR1(*last, 5); break; // bps 24
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
543 case 4: value += *last; break; // bps 32
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
544 } *last = value;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
545
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
546 // check for errors
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
547 if (abs(value) > maxvalue) {
551
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
548 unsigned int tail =
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
549 pcm_buffer_size / (ttainfo->BSIZE * ttainfo->NCH) - res;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
550 memset(buffer, 0, pcm_buffer_size);
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
551 data_cur += tail; res += tail;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
552 break;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
553 }
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
554
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
555 if (dec < tta + (ttainfo->NCH - 1)) {
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
556 *prev++ = value; dec++;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
557 } else {
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
558 *prev = value;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
559 if (ttainfo->NCH > 1) {
551
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
560 int *r = prev - 1;
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
561 for (*prev += *r/2; r >= cache; r--)
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
562 *r = *(r + 1) - *r;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
563 for (r = cache; r < prev; r++)
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
564 WRITE_BUFFER(r, ttainfo->BSIZE, p)
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
565 }
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
566 WRITE_BUFFER(prev, ttainfo->BSIZE, p)
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
567 prev = cache;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
568 data_cur++; res++;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
569 dec = tta;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
570 }
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
571 }
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
572
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
573 return res;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
574 }
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
575
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
576 /* end */