Mercurial > libavcodec.hg
annotate adx.c @ 3690:35aae593db08 libavcodec
[Cosmetics] Remove some done TODOs/FIXMEs from comments
author | kostya |
---|---|
date | Sat, 09 Sep 2006 11:23:44 +0000 |
parents | 2d042ed9dd2c |
children | c8c591fe26f8 |
rev | line source |
---|---|
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
1 /* |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
2 * ADX ADPCM codecs |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
3 * Copyright (c) 2001,2003 BERO |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
4 * |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
5 * This library is free software; you can redistribute it and/or |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
6 * modify it under the terms of the GNU Lesser General Public |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
7 * License as published by the Free Software Foundation; either |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
8 * version 2 of the License, or (at your option) any later version. |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
9 * |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
10 * This library is distributed in the hope that it will be useful, |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
13 * Lesser General Public License for more details. |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
14 * |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
15 * You should have received a copy of the GNU Lesser General Public |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
16 * License along with this library; if not, write to the Free Software |
3036
0b546eab515d
Update licensing information: The FSF changed postal address.
diego
parents:
2967
diff
changeset
|
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
18 */ |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
19 #include "avcodec.h" |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
20 |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
21 /** |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
22 * @file adx.c |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
23 * SEGA CRI adx codecs. |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
24 * |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
25 * Reference documents: |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
26 * http://ku-www.ss.titech.ac.jp/~yatsushi/adx.html |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
27 * adx2wav & wav2adx http://www.geocities.co.jp/Playtown/2004/ |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
28 */ |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
29 |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
30 typedef struct { |
1534
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
31 int s1,s2; |
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
32 } PREV; |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
33 |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
34 typedef struct { |
1534
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
35 PREV prev[2]; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
36 int header_parsed; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
37 unsigned char dec_temp[18*2]; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
38 unsigned short enc_temp[32*2]; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
39 int in_temp; |
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
40 } ADXContext; |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
41 |
1534
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
42 //#define BASEVOL 0x11e0 |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
43 #define BASEVOL 0x4000 |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
44 #define SCALE1 0x7298 |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
45 #define SCALE2 0x3350 |
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
46 |
1534
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
47 #define CLIP(s) if (s>32767) s=32767; else if (s<-32768) s=-32768 |
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
48 |
1534
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
49 /* 18 bytes <-> 32 samples */ |
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
50 |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
51 #ifdef CONFIG_ENCODERS |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
52 static void adx_encode(unsigned char *adx,const short *wav,PREV *prev) |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
53 { |
1534
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
54 int scale; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
55 int i; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
56 int s0,s1,s2,d; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
57 int max=0; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
58 int min=0; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
59 int data[32]; |
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
60 |
1534
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
61 s1 = prev->s1; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
62 s2 = prev->s2; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
63 for(i=0;i<32;i++) { |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
64 s0 = wav[i]; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
65 d = ((s0<<14) - SCALE1*s1 + SCALE2*s2)/BASEVOL; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
66 data[i]=d; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
67 if (max<d) max=d; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
68 if (min>d) min=d; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
69 s2 = s1; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
70 s1 = s0; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
71 } |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
72 prev->s1 = s1; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
73 prev->s2 = s2; |
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
74 |
1534
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
75 /* -8..+7 */ |
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
76 |
1534
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
77 if (max==0 && min==0) { |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
78 memset(adx,0,18); |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
79 return; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
80 } |
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
81 |
1534
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
82 if (max/7>-min/8) scale = max/7; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
83 else scale = -min/8; |
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
84 |
1534
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
85 if (scale==0) scale=1; |
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
86 |
1534
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
87 adx[0] = scale>>8; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
88 adx[1] = scale; |
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
89 |
1534
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
90 for(i=0;i<16;i++) { |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
91 adx[i+2] = ((data[i*2]/scale)<<4) | ((data[i*2+1]/scale)&0xf); |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
92 } |
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
93 } |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
94 #endif //CONFIG_ENCODERS |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
95 |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
96 static void adx_decode(short *out,const unsigned char *in,PREV *prev) |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
97 { |
1534
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
98 int scale = ((in[0]<<8)|(in[1])); |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
99 int i; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
100 int s0,s1,s2,d; |
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
101 |
1534
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
102 // printf("%x ",scale); |
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
103 |
1534
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
104 in+=2; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
105 s1 = prev->s1; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
106 s2 = prev->s2; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
107 for(i=0;i<16;i++) { |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
108 d = in[i]; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
109 // d>>=4; if (d&8) d-=16; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
110 d = ((signed char)d >> 4); |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
111 s0 = (BASEVOL*d*scale + SCALE1*s1 - SCALE2*s2)>>14; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
112 CLIP(s0); |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
113 *out++=s0; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
114 s2 = s1; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
115 s1 = s0; |
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
116 |
1534
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
117 d = in[i]; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
118 //d&=15; if (d&8) d-=16; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
119 d = ((signed char)(d<<4) >> 4); |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
120 s0 = (BASEVOL*d*scale + SCALE1*s1 - SCALE2*s2)>>14; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
121 CLIP(s0); |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
122 *out++=s0; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
123 s2 = s1; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
124 s1 = s0; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
125 } |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
126 prev->s1 = s1; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
127 prev->s2 = s2; |
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
128 |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
129 } |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
130 |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
131 static void adx_decode_stereo(short *out,const unsigned char *in,PREV *prev) |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
132 { |
1534
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
133 short tmp[32*2]; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
134 int i; |
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
135 |
1534
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
136 adx_decode(tmp ,in ,prev); |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
137 adx_decode(tmp+32,in+18,prev+1); |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
138 for(i=0;i<32;i++) { |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
139 out[i*2] = tmp[i]; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
140 out[i*2+1] = tmp[i+32]; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
141 } |
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
142 } |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
143 |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
144 #ifdef CONFIG_ENCODERS |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
145 |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
146 static void write_long(unsigned char *p,uint32_t v) |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
147 { |
1534
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
148 p[0] = v>>24; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
149 p[1] = v>>16; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
150 p[2] = v>>8; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
151 p[3] = v; |
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
152 } |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
153 |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
154 static int adx_encode_header(AVCodecContext *avctx,unsigned char *buf,size_t bufsize) |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
155 { |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
156 #if 0 |
1534
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
157 struct { |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
158 uint32_t offset; /* 0x80000000 + sample start - 4 */ |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
159 unsigned char unknown1[3]; /* 03 12 04 */ |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
160 unsigned char channel; /* 1 or 2 */ |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
161 uint32_t freq; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
162 uint32_t size; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
163 uint32_t unknown2; /* 01 f4 03 00 */ |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
164 uint32_t unknown3; /* 00 00 00 00 */ |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
165 uint32_t unknown4; /* 00 00 00 00 */ |
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
166 |
1534
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
167 /* if loop |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
168 unknown3 00 15 00 01 |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
169 unknown4 00 00 00 01 |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
170 long loop_start_sample; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
171 long loop_start_byte; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
172 long loop_end_sample; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
173 long loop_end_byte; |
2967 | 174 long |
1534
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
175 */ |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
176 } adxhdr; /* big endian */ |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
177 /* offset-6 "(c)CRI" */ |
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
178 #endif |
1534
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
179 write_long(buf+0x00,0x80000000|0x20); |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
180 write_long(buf+0x04,0x03120400|avctx->channels); |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
181 write_long(buf+0x08,avctx->sample_rate); |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
182 write_long(buf+0x0c,0); /* FIXME: set after */ |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
183 write_long(buf+0x10,0x01040300); |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
184 write_long(buf+0x14,0x00000000); |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
185 write_long(buf+0x18,0x00000000); |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
186 memcpy(buf+0x1c,"\0\0(c)CRI",8); |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
187 return 0x20+4; |
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
188 } |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
189 |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
190 static int adx_decode_init(AVCodecContext *avctx); |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
191 static int adx_encode_init(AVCodecContext *avctx) |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
192 { |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
193 if (avctx->channels > 2) |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
194 return -1; /* only stereo or mono =) */ |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
195 avctx->frame_size = 32; |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
196 |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
197 avctx->coded_frame= avcodec_alloc_frame(); |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
198 avctx->coded_frame->key_frame= 1; |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
199 |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
200 // avctx->bit_rate = avctx->sample_rate*avctx->channels*18*8/32; |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
201 |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1569
diff
changeset
|
202 av_log(avctx, AV_LOG_DEBUG, "adx encode init\n"); |
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
203 adx_decode_init(avctx); |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
204 |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
205 return 0; |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
206 } |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
207 |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
208 static int adx_encode_close(AVCodecContext *avctx) |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
209 { |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
210 av_freep(&avctx->coded_frame); |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
211 |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
212 return 0; |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
213 } |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
214 |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
215 static int adx_encode_frame(AVCodecContext *avctx, |
1569
1f8d1e1173d8
Fixes GCC 3.3.2 warnings patch by (Panagiotis Issaris <takis at lumumba dot luc dot ac dot be>)
michael
parents:
1534
diff
changeset
|
216 uint8_t *frame, int buf_size, void *data) |
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
217 { |
1534
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
218 ADXContext *c = avctx->priv_data; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
219 const short *samples = data; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
220 unsigned char *dst = frame; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
221 int rest = avctx->frame_size; |
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
222 |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
223 /* |
1534
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
224 input data size = |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
225 ffmpeg.c: do_audio_out() |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
226 frame_bytes = enc->frame_size * 2 * enc->channels; |
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
227 */ |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
228 |
1534
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
229 // printf("sz=%d ",buf_size); fflush(stdout); |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
230 if (!c->header_parsed) { |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
231 int hdrsize = adx_encode_header(avctx,dst,buf_size); |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
232 dst+=hdrsize; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
233 c->header_parsed = 1; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
234 } |
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
235 |
1534
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
236 if (avctx->channels==1) { |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
237 while(rest>=32) { |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
238 adx_encode(dst,samples,c->prev); |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
239 dst+=18; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
240 samples+=32; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
241 rest-=32; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
242 } |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
243 } else { |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
244 while(rest>=32*2) { |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
245 short tmpbuf[32*2]; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
246 int i; |
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
247 |
1534
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
248 for(i=0;i<32;i++) { |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
249 tmpbuf[i] = samples[i*2]; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
250 tmpbuf[i+32] = samples[i*2+1]; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
251 } |
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
252 |
1534
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
253 adx_encode(dst,tmpbuf,c->prev); |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
254 adx_encode(dst+18,tmpbuf+32,c->prev+1); |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
255 dst+=18*2; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
256 samples+=32*2; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
257 rest-=32*2; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
258 } |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
259 } |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
260 return dst-frame; |
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
261 } |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
262 |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
263 #endif //CONFIG_ENCODERS |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
264 |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
265 static uint32_t read_long(const unsigned char *p) |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
266 { |
1534
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
267 return (p[0]<<24)|(p[1]<<16)|(p[2]<<8)|p[3]; |
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
268 } |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
269 |
3356
90344fa4a1d4
cleanup patch from Diego Petten <flameeyes@gentoo.org>
lu_zero
parents:
3036
diff
changeset
|
270 static int is_adx(const unsigned char *buf,size_t bufsize) |
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
271 { |
1534
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
272 int offset; |
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
273 |
1534
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
274 if (buf[0]!=0x80) return 0; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
275 offset = (read_long(buf)^0x80000000)+4; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
276 if (bufsize<offset || memcmp(buf+offset-6,"(c)CRI",6)) return 0; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
277 return offset; |
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
278 } |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
279 |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
280 /* return data offset or 6 */ |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
281 static int adx_decode_header(AVCodecContext *avctx,const unsigned char *buf,size_t bufsize) |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
282 { |
1534
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
283 int offset; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
284 int channels,freq,size; |
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
285 |
1534
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
286 offset = is_adx(buf,bufsize); |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
287 if (offset==0) return 0; |
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
288 |
1534
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
289 channels = buf[7]; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
290 freq = read_long(buf+8); |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
291 size = read_long(buf+12); |
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
292 |
1534
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
293 // printf("freq=%d ch=%d\n",freq,channels); |
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
294 |
1534
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
295 avctx->sample_rate = freq; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
296 avctx->channels = channels; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
297 avctx->bit_rate = freq*channels*18*8/32; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
298 // avctx->frame_size = 18*channels; |
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
299 |
1534
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
300 return offset; |
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
301 } |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
302 |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
303 static int adx_decode_init(AVCodecContext * avctx) |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
304 { |
1534
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
305 ADXContext *c = avctx->priv_data; |
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
306 |
1534
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
307 // printf("adx_decode_init\n"); fflush(stdout); |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
308 c->prev[0].s1 = 0; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
309 c->prev[0].s2 = 0; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
310 c->prev[1].s1 = 0; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
311 c->prev[1].s2 = 0; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
312 c->header_parsed = 0; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
313 c->in_temp = 0; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
314 return 0; |
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
315 } |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
316 |
2522
e25782262d7d
kill warnings patch by (Mns Rullgrd <mru inprovide com>)
michael
parents:
1598
diff
changeset
|
317 #if 0 |
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
318 static void dump(unsigned char *buf,size_t len) |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
319 { |
1534
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
320 int i; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
321 for(i=0;i<len;i++) { |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1569
diff
changeset
|
322 if ((i&15)==0) av_log(NULL, AV_LOG_DEBUG, "%04x ",i); |
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1569
diff
changeset
|
323 av_log(NULL, AV_LOG_DEBUG, "%02x ",buf[i]); |
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1569
diff
changeset
|
324 if ((i&15)==15) av_log(NULL, AV_LOG_DEBUG, "\n"); |
1534
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
325 } |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1569
diff
changeset
|
326 av_log(NULL, AV_LOG_ERROR, "\n"); |
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
327 } |
2522
e25782262d7d
kill warnings patch by (Mns Rullgrd <mru inprovide com>)
michael
parents:
1598
diff
changeset
|
328 #endif |
e25782262d7d
kill warnings patch by (Mns Rullgrd <mru inprovide com>)
michael
parents:
1598
diff
changeset
|
329 |
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
330 static int adx_decode_frame(AVCodecContext *avctx, |
1534
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
331 void *data, int *data_size, |
1569
1f8d1e1173d8
Fixes GCC 3.3.2 warnings patch by (Panagiotis Issaris <takis at lumumba dot luc dot ac dot be>)
michael
parents:
1534
diff
changeset
|
332 uint8_t *buf0, int buf_size) |
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
333 { |
1534
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
334 ADXContext *c = avctx->priv_data; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
335 short *samples = data; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
336 const uint8_t *buf = buf0; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
337 int rest = buf_size; |
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
338 |
1534
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
339 if (!c->header_parsed) { |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
340 int hdrsize = adx_decode_header(avctx,buf,rest); |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
341 if (hdrsize==0) return -1; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
342 c->header_parsed = 1; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
343 buf += hdrsize; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
344 rest -= hdrsize; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
345 } |
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
346 |
1534
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
347 if (c->in_temp) { |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
348 int copysize = 18*avctx->channels - c->in_temp; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
349 memcpy(c->dec_temp+c->in_temp,buf,copysize); |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
350 rest -= copysize; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
351 buf += copysize; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
352 if (avctx->channels==1) { |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
353 adx_decode(samples,c->dec_temp,c->prev); |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
354 samples += 32; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
355 } else { |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
356 adx_decode_stereo(samples,c->dec_temp,c->prev); |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
357 samples += 32*2; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
358 } |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
359 } |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
360 // |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
361 if (avctx->channels==1) { |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
362 while(rest>=18) { |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
363 adx_decode(samples,buf,c->prev); |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
364 rest-=18; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
365 buf+=18; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
366 samples+=32; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
367 } |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
368 } else { |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
369 while(rest>=18*2) { |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
370 adx_decode_stereo(samples,buf,c->prev); |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
371 rest-=18*2; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
372 buf+=18*2; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
373 samples+=32*2; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
374 } |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
375 } |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
376 // |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
377 c->in_temp = rest; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
378 if (rest) { |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
379 memcpy(c->dec_temp,buf,rest); |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
380 buf+=rest; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
381 } |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
382 *data_size = (uint8_t*)samples - (uint8_t*)data; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
383 // printf("%d:%d ",buf-buf0,*data_size); fflush(stdout); |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
384 return buf-buf0; |
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
385 } |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
386 |
1534
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
387 #ifdef CONFIG_ENCODERS |
3445 | 388 AVCodec adpcm_adx_encoder = { |
389 "adpcm_adx", | |
1534
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
390 CODEC_TYPE_AUDIO, |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
391 CODEC_ID_ADPCM_ADX, |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
392 sizeof(ADXContext), |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
393 adx_encode_init, |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
394 adx_encode_frame, |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
395 adx_encode_close, |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
396 NULL, |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
397 }; |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
398 #endif //CONFIG_ENCODERS |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
399 |
3445 | 400 AVCodec adpcm_adx_decoder = { |
401 "adpcm_adx", | |
1534
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
402 CODEC_TYPE_AUDIO, |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
403 CODEC_ID_ADPCM_ADX, |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
404 sizeof(ADXContext), |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
405 adx_decode_init, |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
406 NULL, |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
407 NULL, |
5bdf2017d854
replace file to remove nasty DOS CRs and hard tabs
melanson
parents:
1531
diff
changeset
|
408 adx_decode_frame, |
1531
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
409 }; |
a78de892cefd
added CRI ADX and XA ADPCM audio modules, courtesy of BERO
melanson
parents:
diff
changeset
|
410 |