annotate libmpcodecs/ad_imaadpcm.c @ 30754:dff9ee89b7c1

Move stream_read_line implementation from stream.h to stream.c, it is not speed critical and the function call overhead is not relevant for its overall speed anyway.
author reimar
date Sun, 28 Feb 2010 13:54:55 +0000
parents cc27da5d7286
children b40d593a463f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
1 /*
30421
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29297
diff changeset
2 * IMA ADPCM decoder
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29297
diff changeset
3 *
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29297
diff changeset
4 * This file is in charge of decoding all of the various IMA ADPCM data
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29297
diff changeset
5 * formats that various entities have created. Details about the data
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29297
diff changeset
6 * formats can be found here:
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29297
diff changeset
7 * http://www.pcisys.net/~melanson/codecs/
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29297
diff changeset
8 *
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29297
diff changeset
9 * So far, this file handles these formats:
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29297
diff changeset
10 * 'ima4': IMA ADPCM found in QT files
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29297
diff changeset
11 * 0x11: IMA ADPCM found in MS AVI/ASF/WAV files
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29297
diff changeset
12 * 0x61: DK4 ADPCM found in certain AVI files on Sega Saturn CD-ROMs;
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29297
diff changeset
13 * note that this is a 'rogue' format number in that it was
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29297
diff changeset
14 * never officially registered with Microsoft
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29297
diff changeset
15 * 0x1100736d: IMA ADPCM coded like in MS AVI/ASF/WAV found in QT files
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29297
diff changeset
16 *
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29297
diff changeset
17 * Copyright (c) 2002 Mike Melanson
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29297
diff changeset
18 *
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29297
diff changeset
19 * This file is part of MPlayer.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29297
diff changeset
20 *
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29297
diff changeset
21 * MPlayer is free software; you can redistribute it and/or modify
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29297
diff changeset
22 * it under the terms of the GNU General Public License as published by
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29297
diff changeset
23 * the Free Software Foundation; either version 2 of the License, or
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29297
diff changeset
24 * (at your option) any later version.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29297
diff changeset
25 *
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29297
diff changeset
26 * MPlayer is distributed in the hope that it will be useful,
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29297
diff changeset
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29297
diff changeset
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29297
diff changeset
29 * GNU General Public License for more details.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29297
diff changeset
30 *
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29297
diff changeset
31 * You should have received a copy of the GNU General Public License along
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29297
diff changeset
32 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29297
diff changeset
33 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29297
diff changeset
34 */
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
35
5340
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
36 #include <stdio.h>
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
37 #include <stdlib.h>
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
38 #include <unistd.h>
27220
3d94f70003e9 Explicitly include inttypes.h in ad_imaadpcm
reimar
parents: 27153
diff changeset
39 #include <inttypes.h>
5340
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
40
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
41 #include "config.h"
21372
1767c271d710 Remove bswap.h, use libavutil/bswap.h instead.
diego
parents: 15786
diff changeset
42 #include "libavutil/common.h"
21507
fa99b3d31d13 Hack around libavutil/bswap.h compilation problems due to always_inline undefined.
reimar
parents: 21372
diff changeset
43 #include "mpbswap.h"
5340
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
44 #include "ad_internal.h"
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
45
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
46 #define MS_IMA_ADPCM_PREAMBLE_SIZE 4
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
47
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
48 #define QT_IMA_ADPCM_PREAMBLE_SIZE 2
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
49 #define QT_IMA_ADPCM_BLOCK_SIZE 0x22
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
50 #define QT_IMA_ADPCM_SAMPLES_PER_BLOCK 64
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
51
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
52 #define BE_16(x) (be2me_16(*(unsigned short *)(x)))
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
53 #define LE_16(x) (le2me_16(*(unsigned short *)(x)))
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
54
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
55 // pertinent tables for IMA ADPCM
27116
a8a6a38cd86b Use smaller types for tables
reimar
parents: 27115
diff changeset
56 static const int16_t adpcm_step[89] =
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
57 {
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
58 7, 8, 9, 10, 11, 12, 13, 14, 16, 17,
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
59 19, 21, 23, 25, 28, 31, 34, 37, 41, 45,
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
60 50, 55, 60, 66, 73, 80, 88, 97, 107, 118,
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
61 130, 143, 157, 173, 190, 209, 230, 253, 279, 307,
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
62 337, 371, 408, 449, 494, 544, 598, 658, 724, 796,
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
63 876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066,
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
64 2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358,
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
65 5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899,
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
66 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
67 };
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
68
27121
237e683b7480 Half size for adpcm_index
reimar
parents: 27120
diff changeset
69 static const int8_t adpcm_index[8] =
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
70 {
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
71 -1, -1, -1, -1, 2, 4, 6, 8,
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
72 };
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
73
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
74 // useful macros
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
75 // clamp a number between 0 and 88
27118
5798fb7fceb6 Simplify some imaadpcm macros
reimar
parents: 27117
diff changeset
76 #define CLAMP_0_TO_88(x) x = av_clip(x, 0, 88);
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
77 // clamp a number within a signed 16-bit range
27118
5798fb7fceb6 Simplify some imaadpcm macros
reimar
parents: 27117
diff changeset
78 #define CLAMP_S16(x) x = av_clip_int16(x);
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
79 // clamp a number above 16
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
80 #define CLAMP_ABOVE_16(x) if (x < 16) x = 16;
5340
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
81
30504
cc27da5d7286 Mark all ad_info_t/vd_info_t structure declarations as const.
diego
parents: 30421
diff changeset
82 static const ad_info_t info =
5340
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
83 {
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
84 "IMA ADPCM audio decoder",
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
85 "imaadpcm",
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
86 "Nick Kurshev",
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
87 "Mike Melanson",
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
88 ""
5340
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
89 };
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
90
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
91 LIBAD_EXTERN(imaadpcm)
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
92
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
93 static int preinit(sh_audio_t *sh_audio)
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
94 {
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
95 // not exactly sure what this field is for
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
96 sh_audio->audio_out_minsize = 8192;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
97
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
98 // if format is "ima4", assume the audio is coming from a QT file which
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
99 // indicates constant block size, whereas an AVI/ASF/WAV file will fill
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
100 // in this field with 0x11
8103
d2d2e01343ca ms\0x00\x11 support
alex
parents: 7180
diff changeset
101 if ((sh_audio->format == 0x11) || (sh_audio->format == 0x61) ||
d2d2e01343ca ms\0x00\x11 support
alex
parents: 7180
diff changeset
102 (sh_audio->format == 0x1100736d))
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
103 {
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 27230
diff changeset
104 sh_audio->ds->ss_div = (sh_audio->wf->nBlockAlign -
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
105 (MS_IMA_ADPCM_PREAMBLE_SIZE * sh_audio->wf->nChannels)) * 2;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
106 sh_audio->ds->ss_mul = sh_audio->wf->nBlockAlign;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
107 }
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
108 else
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
109 {
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
110 sh_audio->ds->ss_div = QT_IMA_ADPCM_SAMPLES_PER_BLOCK;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
111 sh_audio->ds->ss_mul = QT_IMA_ADPCM_BLOCK_SIZE * sh_audio->wf->nChannels;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
112 }
5458
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5408
diff changeset
113 sh_audio->audio_in_minsize=sh_audio->ds->ss_mul;
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
114 return 1;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
115 }
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
116
5340
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
117 static int init(sh_audio_t *sh_audio)
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
118 {
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
119 /* IMA-ADPCM 4:1 audio codec:*/
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
120 sh_audio->channels=sh_audio->wf->nChannels;
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
121 sh_audio->samplerate=sh_audio->wf->nSamplesPerSec;
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
122 /* decodes 34 byte -> 64 short*/
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 27230
diff changeset
123 sh_audio->i_bps =
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
124 (sh_audio->ds->ss_mul * sh_audio->samplerate) / sh_audio->ds->ss_div;
13427
9d0b052c4f74 setting samplesize to 2 in decoders where neccessary.
reimar
parents: 10808
diff changeset
125 sh_audio->samplesize=2;
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
126
5340
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
127 return 1;
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
128 }
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
129
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
130 static void uninit(sh_audio_t *sh_audio)
5340
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
131 {
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
132 }
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
133
5481
8ae2bf330ad5 control() done
arpi
parents: 5458
diff changeset
134 static int control(sh_audio_t *sh_audio,int cmd,void* arg, ...)
5340
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
135 {
5481
8ae2bf330ad5 control() done
arpi
parents: 5458
diff changeset
136 if(cmd==ADCTRL_SKIP_FRAME){
8ae2bf330ad5 control() done
arpi
parents: 5458
diff changeset
137 demux_read_data(sh_audio->ds, sh_audio->a_in_buffer,sh_audio->ds->ss_mul);
8ae2bf330ad5 control() done
arpi
parents: 5458
diff changeset
138 return CONTROL_TRUE;
8ae2bf330ad5 control() done
arpi
parents: 5458
diff changeset
139 }
5340
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
140 return CONTROL_UNKNOWN;
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
141 }
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
142
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
143 static void decode_nibbles(unsigned short *output,
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
144 int output_size, int channels,
27117
95495e636ba8 Directly pass arrays into decode_nibbles
reimar
parents: 27116
diff changeset
145 int predictor[2], int index[2])
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
146 {
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
147 int step[2];
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
148 int i;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
149 int sign;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
150 int delta;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
151 int channel_number = 0;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
152
27117
95495e636ba8 Directly pass arrays into decode_nibbles
reimar
parents: 27116
diff changeset
153 step[0] = adpcm_step[index[0]];
95495e636ba8 Directly pass arrays into decode_nibbles
reimar
parents: 27116
diff changeset
154 step[1] = adpcm_step[index[1]];
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
155
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
156 for (i = 0; i < output_size; i++)
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
157 {
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
158 delta = output[i];
27121
237e683b7480 Half size for adpcm_index
reimar
parents: 27120
diff changeset
159 sign = delta & 8;
237e683b7480 Half size for adpcm_index
reimar
parents: 27120
diff changeset
160 delta = delta & 7;
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
161
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
162 index[channel_number] += adpcm_index[delta];
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
163 CLAMP_0_TO_88(index[channel_number]);
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
164
27120
ea18c012330a Simplify predictor updates
reimar
parents: 27119
diff changeset
165 delta = 2 * delta + 1;
ea18c012330a Simplify predictor updates
reimar
parents: 27119
diff changeset
166 if (sign) delta = -delta;
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
167
27120
ea18c012330a Simplify predictor updates
reimar
parents: 27119
diff changeset
168 predictor[channel_number] += (delta * step[channel_number]) >> 3;
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
169
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
170 CLAMP_S16(predictor[channel_number]);
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
171 output[i] = predictor[channel_number];
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
172 step[channel_number] = adpcm_step[index[channel_number]];
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
173
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
174 // toggle channel
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
175 channel_number ^= channels - 1;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
176
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
177 }
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
178 }
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
179
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
180 static int qt_ima_adpcm_decode_block(unsigned short *output,
27112
cd61e85bb657 Simplify ad_imaadpcm decode_audio function
reimar
parents: 21507
diff changeset
181 unsigned char *input, int channels, int block_size)
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
182 {
29297
dbc412fcde45 Initialize local variable, avoids a possible crash due to using an
reimar
parents: 29263
diff changeset
183 int initial_predictor[2] = {0};
dbc412fcde45 Initialize local variable, avoids a possible crash due to using an
reimar
parents: 29263
diff changeset
184 int initial_index[2] = {0};
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
185 int i;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
186
27230
48b793612e37 Make really sure channels can only be 1 or 2 for imaadpcm
reimar
parents: 27229
diff changeset
187 if (channels != 1) channels = 2;
27113
680301b96149 Add a few size checks to IMA decoder. The code is still a mess though,
reimar
parents: 27112
diff changeset
188 if (block_size < channels * QT_IMA_ADPCM_BLOCK_SIZE)
680301b96149 Add a few size checks to IMA decoder. The code is still a mess though,
reimar
parents: 27112
diff changeset
189 return -1;
680301b96149 Add a few size checks to IMA decoder. The code is still a mess though,
reimar
parents: 27112
diff changeset
190
27114
6a0bcac0335c Simplify code to read index/predictor
reimar
parents: 27113
diff changeset
191 for (i = 0; i < channels; i++) {
27119
7c07e13eeae3 Get rid of 16-bit sign extension macro
reimar
parents: 27118
diff changeset
192 initial_index[i] = initial_predictor[i] = (int16_t)BE_16(&input[i * QT_IMA_ADPCM_BLOCK_SIZE]);
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
193
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
194 // mask, sign-extend, and clamp the predictor portion
27119
7c07e13eeae3 Get rid of 16-bit sign extension macro
reimar
parents: 27118
diff changeset
195 initial_predictor[i] &= ~0x7F;
27114
6a0bcac0335c Simplify code to read index/predictor
reimar
parents: 27113
diff changeset
196 CLAMP_S16(initial_predictor[i]);
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
197
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
198 // mask and clamp the index portion
27114
6a0bcac0335c Simplify code to read index/predictor
reimar
parents: 27113
diff changeset
199 initial_index[i] &= 0x7F;
6a0bcac0335c Simplify code to read index/predictor
reimar
parents: 27113
diff changeset
200 CLAMP_0_TO_88(initial_index[i]);
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
201 }
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
202
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
203 // break apart all of the nibbles in the block
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
204 if (channels == 1)
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
205 for (i = 0; i < QT_IMA_ADPCM_SAMPLES_PER_BLOCK / 2; i++)
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
206 {
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
207 output[i * 2 + 0] = input[2 + i] & 0x0F;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
208 output[i * 2 + 1] = input[2 + i] >> 4;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
209 }
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
210 else
15786
99df5428882f fix illegal read
reimar
parents: 13427
diff changeset
211 for (i = 0; i < QT_IMA_ADPCM_SAMPLES_PER_BLOCK / 2; i++)
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
212 {
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
213 output[i * 4 + 0] = input[2 + i] & 0x0F;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
214 output[i * 4 + 1] = input[2 + QT_IMA_ADPCM_BLOCK_SIZE + i] & 0x0F;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
215 output[i * 4 + 2] = input[2 + i] >> 4;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
216 output[i * 4 + 3] = input[2 + QT_IMA_ADPCM_BLOCK_SIZE + i] >> 4;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
217 }
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
218
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
219 decode_nibbles(output,
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
220 QT_IMA_ADPCM_SAMPLES_PER_BLOCK * channels, channels,
27117
95495e636ba8 Directly pass arrays into decode_nibbles
reimar
parents: 27116
diff changeset
221 initial_predictor, initial_index);
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
222
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
223 return QT_IMA_ADPCM_SAMPLES_PER_BLOCK * channels;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
224 }
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
225
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
226 static int ms_ima_adpcm_decode_block(unsigned short *output,
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
227 unsigned char *input, int channels, int block_size)
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
228 {
27114
6a0bcac0335c Simplify code to read index/predictor
reimar
parents: 27113
diff changeset
229 int predictor[2];
6a0bcac0335c Simplify code to read index/predictor
reimar
parents: 27113
diff changeset
230 int index[2];
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
231 int i;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
232 int channel_counter;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
233 int channel_index;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
234 int channel_index_l;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
235 int channel_index_r;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
236
27230
48b793612e37 Make really sure channels can only be 1 or 2 for imaadpcm
reimar
parents: 27229
diff changeset
237 if (channels != 1) channels = 2;
27113
680301b96149 Add a few size checks to IMA decoder. The code is still a mess though,
reimar
parents: 27112
diff changeset
238 if (block_size < MS_IMA_ADPCM_PREAMBLE_SIZE * channels)
680301b96149 Add a few size checks to IMA decoder. The code is still a mess though,
reimar
parents: 27112
diff changeset
239 return -1;
680301b96149 Add a few size checks to IMA decoder. The code is still a mess though,
reimar
parents: 27112
diff changeset
240
27114
6a0bcac0335c Simplify code to read index/predictor
reimar
parents: 27113
diff changeset
241 for (i = 0; i < channels; i++) {
27119
7c07e13eeae3 Get rid of 16-bit sign extension macro
reimar
parents: 27118
diff changeset
242 predictor[i] = (int16_t)LE_16(&input[i * 4]);
27114
6a0bcac0335c Simplify code to read index/predictor
reimar
parents: 27113
diff changeset
243 index[i] = input[i * 4 + 2];
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
244 }
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
245
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
246 if (channels == 1)
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
247 for (i = 0;
10808
9883dfced49c 100l: you have 2 nibbles per byte, don't divide byte count by 2
rtognimp
parents: 8103
diff changeset
248 i < (block_size - MS_IMA_ADPCM_PREAMBLE_SIZE * channels); i++)
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
249 {
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
250 output[i * 2 + 0] = input[MS_IMA_ADPCM_PREAMBLE_SIZE + i] & 0x0F;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
251 output[i * 2 + 1] = input[MS_IMA_ADPCM_PREAMBLE_SIZE + i] >> 4;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
252 }
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
253 else
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
254 {
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
255 // encoded as 8 nibbles (4 bytes) per channel; switch channel every
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
256 // 4th byte
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
257 channel_counter = 0;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
258 channel_index_l = 0;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
259 channel_index_r = 1;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
260 channel_index = channel_index_l;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
261 for (i = 0;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
262 i < (block_size - MS_IMA_ADPCM_PREAMBLE_SIZE * channels); i++)
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
263 {
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
264 output[channel_index + 0] =
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
265 input[MS_IMA_ADPCM_PREAMBLE_SIZE * 2 + i] & 0x0F;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
266 output[channel_index + 2] =
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
267 input[MS_IMA_ADPCM_PREAMBLE_SIZE * 2 + i] >> 4;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
268 channel_index += 4;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
269 channel_counter++;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
270 if (channel_counter == 4)
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
271 {
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
272 channel_index_l = channel_index;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
273 channel_index = channel_index_r;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
274 }
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
275 else if (channel_counter == 8)
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
276 {
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
277 channel_index_r = channel_index;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
278 channel_index = channel_index_l;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
279 channel_counter = 0;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
280 }
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
281 }
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
282 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 27230
diff changeset
283
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
284 decode_nibbles(output,
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
285 (block_size - MS_IMA_ADPCM_PREAMBLE_SIZE * channels) * 2,
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
286 channels,
27117
95495e636ba8 Directly pass arrays into decode_nibbles
reimar
parents: 27116
diff changeset
287 predictor, index);
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
288
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
289 return (block_size - MS_IMA_ADPCM_PREAMBLE_SIZE * channels) * 2;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
290 }
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
291
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
292 static int dk4_ima_adpcm_decode_block(unsigned short *output,
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
293 unsigned char *input, int channels, int block_size)
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
294 {
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
295 int i;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
296 int output_ptr;
27114
6a0bcac0335c Simplify code to read index/predictor
reimar
parents: 27113
diff changeset
297 int predictor[2];
6a0bcac0335c Simplify code to read index/predictor
reimar
parents: 27113
diff changeset
298 int index[2];
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
299
27230
48b793612e37 Make really sure channels can only be 1 or 2 for imaadpcm
reimar
parents: 27229
diff changeset
300 if (channels != 1) channels = 2;
27113
680301b96149 Add a few size checks to IMA decoder. The code is still a mess though,
reimar
parents: 27112
diff changeset
301 if (block_size < MS_IMA_ADPCM_PREAMBLE_SIZE * channels)
680301b96149 Add a few size checks to IMA decoder. The code is still a mess though,
reimar
parents: 27112
diff changeset
302 return -1;
680301b96149 Add a few size checks to IMA decoder. The code is still a mess though,
reimar
parents: 27112
diff changeset
303
27114
6a0bcac0335c Simplify code to read index/predictor
reimar
parents: 27113
diff changeset
304 for (i = 0; i < channels; i++) {
6a0bcac0335c Simplify code to read index/predictor
reimar
parents: 27113
diff changeset
305 // the first predictor value goes straight to the output
27119
7c07e13eeae3 Get rid of 16-bit sign extension macro
reimar
parents: 27118
diff changeset
306 predictor[i] = output[i] = (int16_t)LE_16(&input[i * 4]);
27114
6a0bcac0335c Simplify code to read index/predictor
reimar
parents: 27113
diff changeset
307 index[i] = input[i * 4 + 2];
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
308 }
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
309
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
310 output_ptr = channels;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
311 for (i = MS_IMA_ADPCM_PREAMBLE_SIZE * channels; i < block_size; i++)
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
312 {
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
313 output[output_ptr++] = input[i] >> 4;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
314 output[output_ptr++] = input[i] & 0x0F;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
315 }
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
316
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
317 decode_nibbles(&output[channels],
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
318 (block_size - MS_IMA_ADPCM_PREAMBLE_SIZE * channels) * 2 - channels,
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
319 channels,
27117
95495e636ba8 Directly pass arrays into decode_nibbles
reimar
parents: 27116
diff changeset
320 predictor, index);
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
321
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
322 return (block_size - MS_IMA_ADPCM_PREAMBLE_SIZE * channels) * 2 - channels;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
323 }
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
324
5340
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
325 static int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen)
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
326 {
27112
cd61e85bb657 Simplify ad_imaadpcm decode_audio function
reimar
parents: 21507
diff changeset
327 int res = -1;
cd61e85bb657 Simplify ad_imaadpcm decode_audio function
reimar
parents: 21507
diff changeset
328 int (*decode_func)(unsigned short *output, unsigned char *input, int channels, int block_size) = qt_ima_adpcm_decode_block;
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
329 if (demux_read_data(sh_audio->ds, sh_audio->a_in_buffer,
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 27230
diff changeset
330 sh_audio->ds->ss_mul) !=
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 27230
diff changeset
331 sh_audio->ds->ss_mul)
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
332 return -1;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
333
8103
d2d2e01343ca ms\0x00\x11 support
alex
parents: 7180
diff changeset
334 if ((sh_audio->format == 0x11) || (sh_audio->format == 0x1100736d))
27112
cd61e85bb657 Simplify ad_imaadpcm decode_audio function
reimar
parents: 21507
diff changeset
335 decode_func = ms_ima_adpcm_decode_block;
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
336 else if (sh_audio->format == 0x61)
27112
cd61e85bb657 Simplify ad_imaadpcm decode_audio function
reimar
parents: 21507
diff changeset
337 decode_func = dk4_ima_adpcm_decode_block;
cd61e85bb657 Simplify ad_imaadpcm decode_audio function
reimar
parents: 21507
diff changeset
338
cd61e85bb657 Simplify ad_imaadpcm decode_audio function
reimar
parents: 21507
diff changeset
339 res = decode_func((unsigned short*)buf, sh_audio->a_in_buffer,
cd61e85bb657 Simplify ad_imaadpcm decode_audio function
reimar
parents: 21507
diff changeset
340 sh_audio->wf->nChannels, sh_audio->ds->ss_mul);
27229
e6de9712a5e5 Simplify imaadpcm return statement
reimar
parents: 27221
diff changeset
341 return res < 0 ? res : 2 * res;
5340
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
342 }