Mercurial > libavcodec.hg
annotate adpcm.c @ 1743:fa06a4a448f7 libavcodec
Fix for older version of zlib
author | rtognimp |
---|---|
date | Tue, 13 Jan 2004 19:46:37 +0000 |
parents | d39bb6945761 |
children | 45e99aa10395 |
rev | line source |
---|---|
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
1 /* |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
2 * ADPCM codecs |
1443
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
3 * Copyright (c) 2001-2003 The ffmpeg Project |
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
4 * |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
5 * This library is free software; you can redistribute it and/or |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
6 * modify it under the terms of the GNU Lesser General Public |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
7 * License as published by the Free Software Foundation; either |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
8 * version 2 of the License, or (at your option) any later version. |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
9 * |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
10 * This library is distributed in the hope that it will be useful, |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
13 * Lesser General Public License for more details. |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
14 * |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
15 * You should have received a copy of the GNU Lesser General Public |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
16 * License along with this library; if not, write to the Free Software |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
18 */ |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
19 #include "avcodec.h" |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
20 |
1106 | 21 /** |
22 * @file adpcm.c | |
23 * ADPCM codecs. | |
1535 | 24 * First version by Francois Revol (revol@free.fr) |
1491
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
1443
diff
changeset
|
25 * Fringe ADPCM codecs (e.g., DK3, DK4, Westwood) |
1443
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
26 * by Mike Melanson (melanson@pcisys.net) |
1535 | 27 * CD-ROM XA ADPCM codec by BERO |
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
28 * |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
29 * Features and limitations: |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
30 * |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
31 * Reference documents: |
1443
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
32 * http://www.pcisys.net/~melanson/codecs/simpleaudio.html |
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
33 * http://www.geocities.com/SiliconValley/8682/aud3.txt |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
34 * http://openquicktime.sourceforge.net/plugins.htm |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
35 * XAnim sources (xa_codec.c) http://www.rasnaimaging.com/people/lapus/download.html |
577
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
36 * http://www.cs.ucla.edu/~leec/mediabench/applications.html |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
37 * SoX source code http://home.sprynet.com/~cbagwell/sox.html |
1535 | 38 * |
39 * CD-ROM XA: | |
40 * http://ku-www.ss.titech.ac.jp/~yatsushi/xaadpcm.html | |
41 * vagpack & depack http://homepages.compuserve.de/bITmASTER32/psx-index.html | |
42 * readstr http://www.geocities.co.jp/Playtown/2004/ | |
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
43 */ |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
44 |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
45 #define BLKSIZE 1024 |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
46 |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
47 #define CLAMP_TO_SHORT(value) \ |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
48 if (value > 32767) \ |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
49 value = 32767; \ |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
50 else if (value < -32768) \ |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
51 value = -32768; \ |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
52 |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
53 /* step_table[] and index_table[] are from the ADPCM reference source */ |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
54 /* This is the index table: */ |
1081
18157900b434
* fixed IMA WAV decoding (though still might not be fully correct)
kabi
parents:
1064
diff
changeset
|
55 static const int index_table[16] = { |
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
56 -1, -1, -1, -1, 2, 4, 6, 8, |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
57 -1, -1, -1, -1, 2, 4, 6, 8, |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
58 }; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
59 |
1106 | 60 /** |
61 * This is the step table. Note that many programs use slight deviations from | |
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
62 * this table, but such deviations are negligible: |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
63 */ |
1081
18157900b434
* fixed IMA WAV decoding (though still might not be fully correct)
kabi
parents:
1064
diff
changeset
|
64 static const int step_table[89] = { |
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
65 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
66 19, 21, 23, 25, 28, 31, 34, 37, 41, 45, |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
67 50, 55, 60, 66, 73, 80, 88, 97, 107, 118, |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
68 130, 143, 157, 173, 190, 209, 230, 253, 279, 307, |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
69 337, 371, 408, 449, 494, 544, 598, 658, 724, 796, |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
70 876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066, |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
71 2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358, |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
72 5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899, |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
73 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767 |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
74 }; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
75 |
1535 | 76 /* These are for MS-ADPCM */ |
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
77 /* AdaptationTable[], AdaptCoeff1[], and AdaptCoeff2[] are from libsndfile */ |
1081
18157900b434
* fixed IMA WAV decoding (though still might not be fully correct)
kabi
parents:
1064
diff
changeset
|
78 static const int AdaptationTable[] = { |
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
79 230, 230, 230, 230, 307, 409, 512, 614, |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
80 768, 614, 512, 409, 307, 230, 230, 230 |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
81 }; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
82 |
1081
18157900b434
* fixed IMA WAV decoding (though still might not be fully correct)
kabi
parents:
1064
diff
changeset
|
83 static const int AdaptCoeff1[] = { |
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
84 256, 512, 0, 192, 240, 460, 392 |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
85 }; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
86 |
1081
18157900b434
* fixed IMA WAV decoding (though still might not be fully correct)
kabi
parents:
1064
diff
changeset
|
87 static const int AdaptCoeff2[] = { |
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
88 0, -256, 0, 64, 0, -208, -232 |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
89 }; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
90 |
1535 | 91 /* These are for CD-ROM XA ADPCM */ |
1559 | 92 static const int xa_adpcm_table[5][2] = { |
1535 | 93 { 0, 0 }, |
94 { 60, 0 }, | |
95 { 115, -52 }, | |
96 { 98, -55 }, | |
97 { 122, -60 } | |
98 }; | |
99 | |
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
100 /* end of tables */ |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
101 |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
102 typedef struct ADPCMChannelStatus { |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
103 int predictor; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
104 short int step_index; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
105 int step; |
577
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
106 /* for encoding */ |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
107 int prev_sample; |
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
108 |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
109 /* MS version */ |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
110 short sample1; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
111 short sample2; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
112 int coeff1; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
113 int coeff2; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
114 int idelta; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
115 } ADPCMChannelStatus; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
116 |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
117 typedef struct ADPCMContext { |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
118 int channel; /* for stereo MOVs, decode left, then decode right, then tell it's decoded */ |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
119 ADPCMChannelStatus status[2]; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
120 short sample_buffer[32]; /* hold left samples while waiting for right samples */ |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
121 } ADPCMContext; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
122 |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
123 /* XXX: implement encoding */ |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
124 |
1530
3b31998fe22f
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
1491
diff
changeset
|
125 #ifdef CONFIG_ENCODERS |
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
126 static int adpcm_encode_init(AVCodecContext *avctx) |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
127 { |
577
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
128 if (avctx->channels > 2) |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
129 return -1; /* only stereo or mono =) */ |
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
130 switch(avctx->codec->id) { |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
131 case CODEC_ID_ADPCM_IMA_QT: |
1611 | 132 av_log(avctx, AV_LOG_ERROR, "ADPCM: codec adpcm_ima_qt unsupported for encoding !\n"); |
577
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
133 avctx->frame_size = 64; /* XXX: can multiple of avctx->channels * 64 (left and right blocks are interleaved) */ |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
134 return -1; |
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
135 break; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
136 case CODEC_ID_ADPCM_IMA_WAV: |
577
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
137 avctx->frame_size = (BLKSIZE - 4 * avctx->channels) * 8 / (4 * avctx->channels) + 1; /* each 16 bits sample gives one nibble */ |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
138 /* and we have 4 bytes per channel overhead */ |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
139 avctx->block_align = BLKSIZE; |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
140 /* seems frame_size isn't taken into account... have to buffer the samples :-( */ |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
141 break; |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
142 case CODEC_ID_ADPCM_MS: |
1611 | 143 av_log(avctx, AV_LOG_ERROR, "ADPCM: codec adpcm_ms unsupported for encoding !\n"); |
577
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
144 return -1; |
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
145 break; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
146 default: |
577
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
147 return -1; |
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
148 break; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
149 } |
925 | 150 |
151 avctx->coded_frame= avcodec_alloc_frame(); | |
152 avctx->coded_frame->key_frame= 1; | |
153 | |
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
154 return 0; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
155 } |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
156 |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
157 static int adpcm_encode_close(AVCodecContext *avctx) |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
158 { |
925 | 159 av_freep(&avctx->coded_frame); |
160 | |
577
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
161 return 0; |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
162 } |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
163 |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
164 |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
165 static inline unsigned char adpcm_ima_compress_sample(ADPCMChannelStatus *c, short sample) |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
166 { |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
167 int step_index; |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
168 unsigned char nibble; |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
169 |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
170 int sign = 0; /* sign bit of the nibble (MSB) */ |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
171 int delta, predicted_delta; |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
172 |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
173 delta = sample - c->prev_sample; |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
174 |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
175 if (delta < 0) { |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
176 sign = 1; |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
177 delta = -delta; |
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
178 } |
577
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
179 |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
180 step_index = c->step_index; |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
181 |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
182 /* nibble = 4 * delta / step_table[step_index]; */ |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
183 nibble = (delta << 2) / step_table[step_index]; |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
184 |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
185 if (nibble > 7) |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
186 nibble = 7; |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
187 |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
188 step_index += index_table[nibble]; |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
189 if (step_index < 0) |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
190 step_index = 0; |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
191 if (step_index > 88) |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
192 step_index = 88; |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
193 |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
194 /* what the decoder will find */ |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
195 predicted_delta = ((step_table[step_index] * nibble) / 4) + (step_table[step_index] / 8); |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
196 |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
197 if (sign) |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
198 c->prev_sample -= predicted_delta; |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
199 else |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
200 c->prev_sample += predicted_delta; |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
201 |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
202 CLAMP_TO_SHORT(c->prev_sample); |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
203 |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
204 |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
205 nibble += sign << 3; /* sign * 8 */ |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
206 |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
207 /* save back */ |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
208 c->step_index = step_index; |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
209 |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
210 return nibble; |
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
211 } |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
212 |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
213 static int adpcm_encode_frame(AVCodecContext *avctx, |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
214 unsigned char *frame, int buf_size, void *data) |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
215 { |
577
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
216 int n; |
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
217 short *samples; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
218 unsigned char *dst; |
577
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
219 ADPCMContext *c = avctx->priv_data; |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
220 |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
221 dst = frame; |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
222 samples = (short *)data; |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
223 /* n = (BLKSIZE - 4 * avctx->channels) / (2 * 8 * avctx->channels); */ |
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
224 |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
225 switch(avctx->codec->id) { |
577
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
226 case CODEC_ID_ADPCM_IMA_QT: /* XXX: can't test until we get .mov writer */ |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
227 break; |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
228 case CODEC_ID_ADPCM_IMA_WAV: |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
229 n = avctx->frame_size / 8; |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
230 c->status[0].prev_sample = (signed short)samples[0]; /* XXX */ |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
231 /* c->status[0].step_index = 0; *//* XXX: not sure how to init the state machine */ |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
232 *dst++ = (c->status[0].prev_sample) & 0xFF; /* little endian */ |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
233 *dst++ = (c->status[0].prev_sample >> 8) & 0xFF; |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
234 *dst++ = (unsigned char)c->status[0].step_index; |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
235 *dst++ = 0; /* unknown */ |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
236 samples++; |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
237 if (avctx->channels == 2) { |
1559 | 238 c->status[1].prev_sample = (signed short)samples[1]; |
577
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
239 /* c->status[1].step_index = 0; */ |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
240 *dst++ = (c->status[1].prev_sample) & 0xFF; |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
241 *dst++ = (c->status[1].prev_sample >> 8) & 0xFF; |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
242 *dst++ = (unsigned char)c->status[1].step_index; |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
243 *dst++ = 0; |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
244 samples++; |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
245 } |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
246 |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
247 /* stereo: 4 bytes (8 samples) for left, 4 bytes for right, 4 bytes left, ... */ |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
248 for (; n>0; n--) { |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
249 *dst = adpcm_ima_compress_sample(&c->status[0], samples[0]) & 0x0F; |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
250 *dst |= (adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels]) << 4) & 0xF0; |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
251 dst++; |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
252 *dst = adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 2]) & 0x0F; |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
253 *dst |= (adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 3]) << 4) & 0xF0; |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
254 dst++; |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
255 *dst = adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 4]) & 0x0F; |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
256 *dst |= (adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 5]) << 4) & 0xF0; |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
257 dst++; |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
258 *dst = adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 6]) & 0x0F; |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
259 *dst |= (adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 7]) << 4) & 0xF0; |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
260 dst++; |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
261 /* right channel */ |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
262 if (avctx->channels == 2) { |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
263 *dst = adpcm_ima_compress_sample(&c->status[1], samples[1]); |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
264 *dst |= adpcm_ima_compress_sample(&c->status[1], samples[3]) << 4; |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
265 dst++; |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
266 *dst = adpcm_ima_compress_sample(&c->status[1], samples[5]); |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
267 *dst |= adpcm_ima_compress_sample(&c->status[1], samples[7]) << 4; |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
268 dst++; |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
269 *dst = adpcm_ima_compress_sample(&c->status[1], samples[9]); |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
270 *dst |= adpcm_ima_compress_sample(&c->status[1], samples[11]) << 4; |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
271 dst++; |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
272 *dst = adpcm_ima_compress_sample(&c->status[1], samples[13]); |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
273 *dst |= adpcm_ima_compress_sample(&c->status[1], samples[15]) << 4; |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
274 dst++; |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
275 } |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
276 samples += 8 * avctx->channels; |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
277 } |
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
278 break; |
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
279 default: |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
280 return -1; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
281 } |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
282 return dst - frame; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
283 } |
1530
3b31998fe22f
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
1491
diff
changeset
|
284 #endif //CONFIG_ENCODERS |
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
285 |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
286 static int adpcm_decode_init(AVCodecContext * avctx) |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
287 { |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
288 ADPCMContext *c = avctx->priv_data; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
289 |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
290 c->channel = 0; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
291 c->status[0].predictor = c->status[1].predictor = 0; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
292 c->status[0].step_index = c->status[1].step_index = 0; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
293 c->status[0].step = c->status[1].step = 0; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
294 |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
295 switch(avctx->codec->id) { |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
296 default: |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
297 break; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
298 } |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
299 return 0; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
300 } |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
301 |
1737 | 302 static inline short adpcm_ima_expand_nibble(ADPCMChannelStatus *c, char nibble, int shift) |
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
303 { |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
304 int step_index; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
305 int predictor; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
306 int sign, delta, diff, step; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
307 |
1081
18157900b434
* fixed IMA WAV decoding (though still might not be fully correct)
kabi
parents:
1064
diff
changeset
|
308 step = step_table[c->step_index]; |
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
309 step_index = c->step_index + index_table[(unsigned)nibble]; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
310 if (step_index < 0) step_index = 0; |
1081
18157900b434
* fixed IMA WAV decoding (though still might not be fully correct)
kabi
parents:
1064
diff
changeset
|
311 else if (step_index > 88) step_index = 88; |
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
312 |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
313 sign = nibble & 8; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
314 delta = nibble & 7; |
1443
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
315 /* perform direct multiplication instead of series of jumps proposed by |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
316 * the reference ADPCM implementation since modern CPUs can do the mults |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
317 * quickly enough */ |
1737 | 318 diff = ((2 * delta + 1) * step) >> shift; |
1296 | 319 predictor = c->predictor; |
320 if (sign) predictor -= diff; | |
321 else predictor += diff; | |
322 | |
323 CLAMP_TO_SHORT(predictor); | |
324 c->predictor = predictor; | |
325 c->step_index = step_index; | |
326 | |
327 return (short)predictor; | |
328 } | |
329 | |
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
330 static inline short adpcm_ms_expand_nibble(ADPCMChannelStatus *c, char nibble) |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
331 { |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
332 int predictor; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
333 |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
334 predictor = (((c->sample1) * (c->coeff1)) + ((c->sample2) * (c->coeff2))) / 256; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
335 predictor += (signed)((nibble & 0x08)?(nibble - 0x10):(nibble)) * c->idelta; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
336 CLAMP_TO_SHORT(predictor); |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
337 |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
338 c->sample2 = c->sample1; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
339 c->sample1 = predictor; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
340 c->idelta = (AdaptationTable[(int)nibble] * c->idelta) / 256; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
341 if (c->idelta < 16) c->idelta = 16; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
342 |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
343 return (short)predictor; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
344 } |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
345 |
1535 | 346 static void xa_decode(short *out, const unsigned char *in, |
347 ADPCMChannelStatus *left, ADPCMChannelStatus *right, int inc) | |
348 { | |
349 int i, j; | |
350 int shift,filter,f0,f1; | |
351 int s_1,s_2; | |
352 int d,s,t; | |
353 | |
354 for(i=0;i<4;i++) { | |
355 | |
356 shift = 12 - (in[4+i*2] & 15); | |
357 filter = in[4+i*2] >> 4; | |
358 f0 = xa_adpcm_table[filter][0]; | |
359 f1 = xa_adpcm_table[filter][1]; | |
360 | |
361 s_1 = left->sample1; | |
362 s_2 = left->sample2; | |
363 | |
364 for(j=0;j<28;j++) { | |
365 d = in[16+i+j*4]; | |
366 | |
367 t = (signed char)(d<<4)>>4; | |
368 s = ( t<<shift ) + ((s_1*f0 + s_2*f1+32)>>6); | |
369 CLAMP_TO_SHORT(s); | |
370 *out = s; | |
371 out += inc; | |
372 s_2 = s_1; | |
373 s_1 = s; | |
374 } | |
375 | |
376 if (inc==2) { /* stereo */ | |
377 left->sample1 = s_1; | |
378 left->sample2 = s_2; | |
379 s_1 = right->sample1; | |
380 s_2 = right->sample2; | |
381 out = out + 1 - 28*2; | |
382 } | |
383 | |
384 shift = 12 - (in[5+i*2] & 15); | |
385 filter = in[5+i*2] >> 4; | |
386 | |
387 f0 = xa_adpcm_table[filter][0]; | |
388 f1 = xa_adpcm_table[filter][1]; | |
389 | |
390 for(j=0;j<28;j++) { | |
391 d = in[16+i+j*4]; | |
392 | |
393 t = (signed char)d >> 4; | |
394 s = ( t<<shift ) + ((s_1*f0 + s_2*f1+32)>>6); | |
395 CLAMP_TO_SHORT(s); | |
396 *out = s; | |
397 out += inc; | |
398 s_2 = s_1; | |
399 s_1 = s; | |
400 } | |
401 | |
402 if (inc==2) { /* stereo */ | |
403 right->sample1 = s_1; | |
404 right->sample2 = s_2; | |
405 out -= 1; | |
406 } else { | |
407 left->sample1 = s_1; | |
408 left->sample2 = s_2; | |
409 } | |
410 } | |
411 } | |
412 | |
413 | |
1443
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
414 /* DK3 ADPCM support macro */ |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
415 #define DK3_GET_NEXT_NIBBLE() \ |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
416 if (decode_top_nibble_next) \ |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
417 { \ |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
418 nibble = (last_byte >> 4) & 0x0F; \ |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
419 decode_top_nibble_next = 0; \ |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
420 } \ |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
421 else \ |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
422 { \ |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
423 last_byte = *src++; \ |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
424 if (src >= buf + buf_size) break; \ |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
425 nibble = last_byte & 0x0F; \ |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
426 decode_top_nibble_next = 1; \ |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
427 } |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
428 |
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
429 static int adpcm_decode_frame(AVCodecContext *avctx, |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
430 void *data, int *data_size, |
1064 | 431 uint8_t *buf, int buf_size) |
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
432 { |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
433 ADPCMContext *c = avctx->priv_data; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
434 ADPCMChannelStatus *cs; |
1296 | 435 int n, m, channel, i; |
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
436 int block_predictor[2]; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
437 short *samples; |
1064 | 438 uint8_t *src; |
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
439 int st; /* stereo */ |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
440 |
1443
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
441 /* DK3 ADPCM accounting variables */ |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
442 unsigned char last_byte = 0; |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
443 unsigned char nibble; |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
444 int decode_top_nibble_next = 0; |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
445 int diff_channel; |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
446 |
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
447 samples = data; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
448 src = buf; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
449 |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
450 st = avctx->channels == 2; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
451 |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
452 switch(avctx->codec->id) { |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
453 case CODEC_ID_ADPCM_IMA_QT: |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
454 n = (buf_size - 2);/* >> 2*avctx->channels;*/ |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
455 channel = c->channel; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
456 cs = &(c->status[channel]); |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
457 /* (pppppp) (piiiiiii) */ |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
458 |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
459 /* Bits 15-7 are the _top_ 9 bits of the 16-bit initial predictor value */ |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
460 cs->predictor = (*src++) << 8; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
461 cs->predictor |= (*src & 0x80); |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
462 cs->predictor &= 0xFF80; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
463 |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
464 /* sign extension */ |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
465 if(cs->predictor & 0x8000) |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
466 cs->predictor -= 0x10000; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
467 |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
468 CLAMP_TO_SHORT(cs->predictor); |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
469 |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
470 cs->step_index = (*src++) & 0x7F; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
471 |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1577
diff
changeset
|
472 if (cs->step_index > 88) av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\n", cs->step_index); |
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
473 if (cs->step_index > 88) cs->step_index = 88; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
474 |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
475 cs->step = step_table[cs->step_index]; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
476 |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
477 if (st && channel) |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
478 samples++; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
479 |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
480 for(m=32; n>0 && m>0; n--, m--) { /* in QuickTime, IMA is encoded by chuncks of 34 bytes (=64 samples) */ |
1737 | 481 *samples = adpcm_ima_expand_nibble(cs, src[0] & 0x0F, 3); |
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
482 samples += avctx->channels; |
1737 | 483 *samples = adpcm_ima_expand_nibble(cs, (src[0] >> 4) & 0x0F, 3); |
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
484 samples += avctx->channels; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
485 src ++; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
486 } |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
487 |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
488 if(st) { /* handle stereo interlacing */ |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
489 c->channel = (channel + 1) % 2; /* we get one packet for left, then one for right data */ |
1695
2d11403fde4e
initial predictors are not sent to the output in QT IMA; fix stereo QT
melanson
parents:
1611
diff
changeset
|
490 if(channel == 1) { /* wait for the other packet before outputing anything */ |
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
491 *data_size = 0; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
492 return src - buf; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
493 } |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
494 } |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
495 break; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
496 case CODEC_ID_ADPCM_IMA_WAV: |
1576
bc4b13ca74de
block algn patch by ("Assaf Yaari" <assafy at mobixell dot com>)
michael
parents:
1559
diff
changeset
|
497 if (avctx->block_align != 0 && buf_size > avctx->block_align) |
bc4b13ca74de
block algn patch by ("Assaf Yaari" <assafy at mobixell dot com>)
michael
parents:
1559
diff
changeset
|
498 buf_size = avctx->block_align; |
bc4b13ca74de
block algn patch by ("Assaf Yaari" <assafy at mobixell dot com>)
michael
parents:
1559
diff
changeset
|
499 |
1737 | 500 for(i=0; i<avctx->channels; i++){ |
501 cs = &(c->status[i]); | |
502 cs->predictor = *src++; | |
503 cs->predictor |= (*src++) << 8; | |
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
504 if(cs->predictor & 0x8000) |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
505 cs->predictor -= 0x10000; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
506 CLAMP_TO_SHORT(cs->predictor); |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
507 |
1737 | 508 // XXX: is this correct ??: *samples++ = cs->predictor; |
577
babaca0899f1
adpcm encoding patch by Franois Revol <revol at free dot fr>
michaelni
parents:
573
diff
changeset
|
509 |
1737 | 510 cs->step_index = *src++; |
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
511 if (cs->step_index < 0) cs->step_index = 0; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
512 if (cs->step_index > 88) cs->step_index = 88; |
1737 | 513 if (*src++) av_log(avctx, AV_LOG_ERROR, "unused byte should be null !!\n"); /* unused */ |
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
514 } |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
515 |
1093 | 516 for(m=4; src < (buf + buf_size);) { |
1737 | 517 *samples++ = adpcm_ima_expand_nibble(&c->status[0], src[0] & 0x0F, 3); |
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
518 if (st) |
1737 | 519 *samples++ = adpcm_ima_expand_nibble(&c->status[1], src[4] & 0x0F, 3); |
520 *samples++ = adpcm_ima_expand_nibble(&c->status[0], (src[0] >> 4) & 0x0F, 3); | |
1093 | 521 if (st) { |
1737 | 522 *samples++ = adpcm_ima_expand_nibble(&c->status[1], (src[4] >> 4) & 0x0F, 3); |
1093 | 523 if (!--m) { |
524 m=4; | |
525 src+=4; | |
526 } | |
527 } | |
528 src++; | |
1081
18157900b434
* fixed IMA WAV decoding (though still might not be fully correct)
kabi
parents:
1064
diff
changeset
|
529 } |
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
530 break; |
1296 | 531 case CODEC_ID_ADPCM_4XM: |
532 cs = &(c->status[0]); | |
533 c->status[0].predictor= (int16_t)(src[0] + (src[1]<<8)); src+=2; | |
534 if(st){ | |
535 c->status[1].predictor= (int16_t)(src[0] + (src[1]<<8)); src+=2; | |
536 } | |
537 c->status[0].step_index= (int16_t)(src[0] + (src[1]<<8)); src+=2; | |
538 if(st){ | |
539 c->status[1].step_index= (int16_t)(src[0] + (src[1]<<8)); src+=2; | |
540 } | |
1695
2d11403fde4e
initial predictors are not sent to the output in QT IMA; fix stereo QT
melanson
parents:
1611
diff
changeset
|
541 if (cs->step_index < 0) cs->step_index = 0; |
2d11403fde4e
initial predictors are not sent to the output in QT IMA; fix stereo QT
melanson
parents:
1611
diff
changeset
|
542 if (cs->step_index > 88) cs->step_index = 88; |
1296 | 543 |
544 m= (buf_size - (src - buf))>>st; | |
545 for(i=0; i<m; i++) { | |
1737 | 546 *samples++ = adpcm_ima_expand_nibble(&c->status[0], src[i] & 0x0F, 4); |
1296 | 547 if (st) |
1737 | 548 *samples++ = adpcm_ima_expand_nibble(&c->status[1], src[i+m] & 0x0F, 4); |
549 *samples++ = adpcm_ima_expand_nibble(&c->status[0], src[i] >> 4, 4); | |
1296 | 550 if (st) |
1737 | 551 *samples++ = adpcm_ima_expand_nibble(&c->status[1], src[i+m] >> 4, 4); |
1296 | 552 } |
553 | |
554 src += m<<st; | |
555 | |
556 break; | |
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
557 case CODEC_ID_ADPCM_MS: |
1576
bc4b13ca74de
block algn patch by ("Assaf Yaari" <assafy at mobixell dot com>)
michael
parents:
1559
diff
changeset
|
558 if (avctx->block_align != 0 && buf_size > avctx->block_align) |
bc4b13ca74de
block algn patch by ("Assaf Yaari" <assafy at mobixell dot com>)
michael
parents:
1559
diff
changeset
|
559 buf_size = avctx->block_align; |
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
560 n = buf_size - 7 * avctx->channels; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
561 if (n < 0) |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
562 return -1; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
563 block_predictor[0] = (*src++); /* should be bound */ |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
564 block_predictor[0] = (block_predictor[0] < 0)?(0):((block_predictor[0] > 7)?(7):(block_predictor[0])); |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
565 block_predictor[1] = 0; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
566 if (st) |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
567 block_predictor[1] = (*src++); |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
568 block_predictor[1] = (block_predictor[1] < 0)?(0):((block_predictor[1] > 7)?(7):(block_predictor[1])); |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
569 c->status[0].idelta = ((*src & 0xFF) | ((src[1] << 8) & 0xFF00)); |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
570 if (c->status[0].idelta & 0x08000) |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
571 c->status[0].idelta -= 0x10000; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
572 src+=2; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
573 if (st) |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
574 c->status[1].idelta = ((*src & 0xFF) | ((src[1] << 8) & 0xFF00)); |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
575 if (st && c->status[1].idelta & 0x08000) |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
576 c->status[1].idelta |= 0xFFFF0000; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
577 if (st) |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
578 src+=2; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
579 c->status[0].coeff1 = AdaptCoeff1[block_predictor[0]]; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
580 c->status[0].coeff2 = AdaptCoeff2[block_predictor[0]]; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
581 c->status[1].coeff1 = AdaptCoeff1[block_predictor[1]]; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
582 c->status[1].coeff2 = AdaptCoeff2[block_predictor[1]]; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
583 |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
584 c->status[0].sample1 = ((*src & 0xFF) | ((src[1] << 8) & 0xFF00)); |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
585 src+=2; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
586 if (st) c->status[1].sample1 = ((*src & 0xFF) | ((src[1] << 8) & 0xFF00)); |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
587 if (st) src+=2; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
588 c->status[0].sample2 = ((*src & 0xFF) | ((src[1] << 8) & 0xFF00)); |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
589 src+=2; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
590 if (st) c->status[1].sample2 = ((*src & 0xFF) | ((src[1] << 8) & 0xFF00)); |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
591 if (st) src+=2; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
592 |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
593 *samples++ = c->status[0].sample1; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
594 if (st) *samples++ = c->status[1].sample1; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
595 *samples++ = c->status[0].sample2; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
596 if (st) *samples++ = c->status[1].sample2; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
597 for(;n>0;n--) { |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
598 *samples++ = adpcm_ms_expand_nibble(&c->status[0], (src[0] >> 4) & 0x0F); |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
599 *samples++ = adpcm_ms_expand_nibble(&c->status[st], src[0] & 0x0F); |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
600 src ++; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
601 } |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
602 break; |
1443
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
603 case CODEC_ID_ADPCM_IMA_DK4: |
1577 | 604 if (avctx->block_align != 0 && buf_size > avctx->block_align) |
605 buf_size = avctx->block_align; | |
606 | |
1443
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
607 c->status[0].predictor = (src[0] | (src[1] << 8)); |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
608 c->status[0].step_index = src[2]; |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
609 src += 4; |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
610 if(c->status[0].predictor & 0x8000) |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
611 c->status[0].predictor -= 0x10000; |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
612 *samples++ = c->status[0].predictor; |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
613 if (st) { |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
614 c->status[1].predictor = (src[0] | (src[1] << 8)); |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
615 c->status[1].step_index = src[2]; |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
616 src += 4; |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
617 if(c->status[1].predictor & 0x8000) |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
618 c->status[1].predictor -= 0x10000; |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
619 *samples++ = c->status[1].predictor; |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
620 } |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
621 while (src < buf + buf_size) { |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
622 |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
623 /* take care of the top nibble (always left or mono channel) */ |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
624 *samples++ = adpcm_ima_expand_nibble(&c->status[0], |
1737 | 625 (src[0] >> 4) & 0x0F, 3); |
1443
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
626 |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
627 /* take care of the bottom nibble, which is right sample for |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
628 * stereo, or another mono sample */ |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
629 if (st) |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
630 *samples++ = adpcm_ima_expand_nibble(&c->status[1], |
1737 | 631 src[0] & 0x0F, 3); |
1443
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
632 else |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
633 *samples++ = adpcm_ima_expand_nibble(&c->status[0], |
1737 | 634 src[0] & 0x0F, 3); |
1443
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
635 |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
636 src++; |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
637 } |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
638 break; |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
639 case CODEC_ID_ADPCM_IMA_DK3: |
1577 | 640 if (avctx->block_align != 0 && buf_size > avctx->block_align) |
641 buf_size = avctx->block_align; | |
642 | |
1443
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
643 c->status[0].predictor = (src[10] | (src[11] << 8)); |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
644 c->status[1].predictor = (src[12] | (src[13] << 8)); |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
645 c->status[0].step_index = src[14]; |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
646 c->status[1].step_index = src[15]; |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
647 /* sign extend the predictors */ |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
648 if(c->status[0].predictor & 0x8000) |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
649 c->status[0].predictor -= 0x10000; |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
650 if(c->status[1].predictor & 0x8000) |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
651 c->status[1].predictor -= 0x10000; |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
652 src += 16; |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
653 diff_channel = c->status[1].predictor; |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
654 |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
655 /* the DK3_GET_NEXT_NIBBLE macro issues the break statement when |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
656 * the buffer is consumed */ |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
657 while (1) { |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
658 |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
659 /* for this algorithm, c->status[0] is the sum channel and |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
660 * c->status[1] is the diff channel */ |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
661 |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
662 /* process the first predictor of the sum channel */ |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
663 DK3_GET_NEXT_NIBBLE(); |
1737 | 664 adpcm_ima_expand_nibble(&c->status[0], nibble, 3); |
1443
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
665 |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
666 /* process the diff channel predictor */ |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
667 DK3_GET_NEXT_NIBBLE(); |
1737 | 668 adpcm_ima_expand_nibble(&c->status[1], nibble, 3); |
1443
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
669 |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
670 /* process the first pair of stereo PCM samples */ |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
671 diff_channel = (diff_channel + c->status[1].predictor) / 2; |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
672 *samples++ = c->status[0].predictor + c->status[1].predictor; |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
673 *samples++ = c->status[0].predictor - c->status[1].predictor; |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
674 |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
675 /* process the second predictor of the sum channel */ |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
676 DK3_GET_NEXT_NIBBLE(); |
1737 | 677 adpcm_ima_expand_nibble(&c->status[0], nibble, 3); |
1443
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
678 |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
679 /* process the second pair of stereo PCM samples */ |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
680 diff_channel = (diff_channel + c->status[1].predictor) / 2; |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
681 *samples++ = c->status[0].predictor + c->status[1].predictor; |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
682 *samples++ = c->status[0].predictor - c->status[1].predictor; |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
683 } |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
684 break; |
1491
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
1443
diff
changeset
|
685 case CODEC_ID_ADPCM_IMA_WS: |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
1443
diff
changeset
|
686 /* no per-block initialization; just start decoding the data */ |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
1443
diff
changeset
|
687 while (src < buf + buf_size) { |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
1443
diff
changeset
|
688 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
1443
diff
changeset
|
689 if (st) { |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
1443
diff
changeset
|
690 *samples++ = adpcm_ima_expand_nibble(&c->status[0], |
1737 | 691 (src[0] >> 4) & 0x0F, 3); |
1491
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
1443
diff
changeset
|
692 *samples++ = adpcm_ima_expand_nibble(&c->status[1], |
1737 | 693 src[0] & 0x0F, 3); |
1491
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
1443
diff
changeset
|
694 } else { |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
1443
diff
changeset
|
695 *samples++ = adpcm_ima_expand_nibble(&c->status[0], |
1737 | 696 (src[0] >> 4) & 0x0F, 3); |
1491
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
1443
diff
changeset
|
697 *samples++ = adpcm_ima_expand_nibble(&c->status[0], |
1737 | 698 src[0] & 0x0F, 3); |
1491
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
1443
diff
changeset
|
699 } |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
1443
diff
changeset
|
700 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
1443
diff
changeset
|
701 src++; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
1443
diff
changeset
|
702 } |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
1443
diff
changeset
|
703 break; |
1535 | 704 case CODEC_ID_ADPCM_XA: |
705 c->status[0].sample1 = c->status[0].sample2 = | |
706 c->status[1].sample1 = c->status[1].sample2 = 0; | |
707 while (buf_size >= 128) { | |
708 xa_decode(samples, src, &c->status[0], &c->status[1], | |
709 avctx->channels); | |
710 src += 128; | |
711 samples += 28 * 8; | |
712 buf_size -= 128; | |
713 } | |
714 break; | |
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
715 default: |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
716 *data_size = 0; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
717 return -1; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
718 } |
1064 | 719 *data_size = (uint8_t *)samples - (uint8_t *)data; |
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
720 return src - buf; |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
721 } |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
722 |
1530
3b31998fe22f
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
1491
diff
changeset
|
723 |
3b31998fe22f
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
1491
diff
changeset
|
724 |
3b31998fe22f
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
1491
diff
changeset
|
725 #ifdef CONFIG_ENCODERS |
3b31998fe22f
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
1491
diff
changeset
|
726 #define ADPCM_ENCODER(id,name) \ |
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
727 AVCodec name ## _encoder = { \ |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
728 #name, \ |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
729 CODEC_TYPE_AUDIO, \ |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
730 id, \ |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
731 sizeof(ADPCMContext), \ |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
732 adpcm_encode_init, \ |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
733 adpcm_encode_frame, \ |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
734 adpcm_encode_close, \ |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
735 NULL, \ |
1530
3b31998fe22f
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
1491
diff
changeset
|
736 }; |
3b31998fe22f
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
1491
diff
changeset
|
737 #else |
3b31998fe22f
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
1491
diff
changeset
|
738 #define ADPCM_ENCODER(id,name) |
3b31998fe22f
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
1491
diff
changeset
|
739 #endif |
3b31998fe22f
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
1491
diff
changeset
|
740 |
3b31998fe22f
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
1491
diff
changeset
|
741 #ifdef CONFIG_DECODERS |
3b31998fe22f
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
1491
diff
changeset
|
742 #define ADPCM_DECODER(id,name) \ |
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
743 AVCodec name ## _decoder = { \ |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
744 #name, \ |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
745 CODEC_TYPE_AUDIO, \ |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
746 id, \ |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
747 sizeof(ADPCMContext), \ |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
748 adpcm_decode_init, \ |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
749 NULL, \ |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
750 NULL, \ |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
751 adpcm_decode_frame, \ |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
752 }; |
1530
3b31998fe22f
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
1491
diff
changeset
|
753 #else |
3b31998fe22f
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
1491
diff
changeset
|
754 #define ADPCM_DECODER(id,name) |
3b31998fe22f
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
1491
diff
changeset
|
755 #endif |
3b31998fe22f
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
1491
diff
changeset
|
756 |
3b31998fe22f
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
1491
diff
changeset
|
757 #define ADPCM_CODEC(id, name) \ |
3b31998fe22f
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
1491
diff
changeset
|
758 ADPCM_ENCODER(id,name) ADPCM_DECODER(id,name) |
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
759 |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
760 ADPCM_CODEC(CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt); |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
761 ADPCM_CODEC(CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav); |
1443
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
762 ADPCM_CODEC(CODEC_ID_ADPCM_IMA_DK3, adpcm_ima_dk3); |
47f4c8a5a7fc
New fringe codecs: WC3/Xan video, Xan DPCM, DK3 & DK4 ADPCM
tmmm
parents:
1296
diff
changeset
|
763 ADPCM_CODEC(CODEC_ID_ADPCM_IMA_DK4, adpcm_ima_dk4); |
1491
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
1443
diff
changeset
|
764 ADPCM_CODEC(CODEC_ID_ADPCM_IMA_WS, adpcm_ima_ws); |
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
765 ADPCM_CODEC(CODEC_ID_ADPCM_MS, adpcm_ms); |
1296 | 766 ADPCM_CODEC(CODEC_ID_ADPCM_4XM, adpcm_4xm); |
1535 | 767 ADPCM_CODEC(CODEC_ID_ADPCM_XA, adpcm_xa); |
768 ADPCM_CODEC(CODEC_ID_ADPCM_ADX, adpcm_adx); | |
573
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
769 |
b0f52172f4c5
beos/mov/adpcm patch by Franois Revol <revol at free dot fr>
michaelni
parents:
diff
changeset
|
770 #undef ADPCM_CODEC |