annotate libmpcodecs/ad_imaadpcm.c @ 6139:3898967fcc96

some more output cosmetics, especially for vivo and mov demuxers
author arpi
date Mon, 20 May 2002 03:51:58 +0000
parents 8ae2bf330ad5
children 28677d779205
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 /*
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
2 IMA ADPCM Decoder for MPlayer
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
3 by Mike Melanson
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
4
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
5 This file is in charge of decoding all of the various IMA ADPCM data
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
6 formats that various entities have created. Details about the data
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
7 formats can be found here:
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
8 http://www.pcisys.net/~melanson/codecs/
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
9
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
10 So far, this file handles these formats:
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
11 'ima4': IMA ADPCM found in QT files
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
12 0x11: IMA ADPCM found in MS AVI/ASF/WAV files
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
13 0x61: DK4 ADPCM found in certain AVI files on Sega Saturn CD-ROMs;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
14 note that this is a 'rogue' format number in that it was
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
15 never officially registered with Microsoft
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
16 */
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
17
5340
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
18 #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
19 #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
20 #include <unistd.h>
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
21
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
22 #include "config.h"
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
23 #include "bswap.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
24 #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
25
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
26 #define MS_IMA_ADPCM_PREAMBLE_SIZE 4
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
27
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
28 #define QT_IMA_ADPCM_PREAMBLE_SIZE 2
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
29 #define QT_IMA_ADPCM_BLOCK_SIZE 0x22
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
30 #define QT_IMA_ADPCM_SAMPLES_PER_BLOCK 64
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
31
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
32 #define BE_16(x) (be2me_16(*(unsigned short *)(x)))
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
33 #define BE_32(x) (be2me_32(*(unsigned int *)(x)))
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
34 #define LE_16(x) (le2me_16(*(unsigned short *)(x)))
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
35 #define LE_32(x) (le2me_32(*(unsigned int *)(x)))
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
36
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
37 // pertinent tables for IMA ADPCM
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
38 static int adpcm_step[89] =
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
39 {
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
40 7, 8, 9, 10, 11, 12, 13, 14, 16, 17,
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
41 19, 21, 23, 25, 28, 31, 34, 37, 41, 45,
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
42 50, 55, 60, 66, 73, 80, 88, 97, 107, 118,
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
43 130, 143, 157, 173, 190, 209, 230, 253, 279, 307,
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
44 337, 371, 408, 449, 494, 544, 598, 658, 724, 796,
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
45 876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066,
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
46 2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358,
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
47 5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899,
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
48 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
49 };
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
50
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
51 static int adpcm_index[16] =
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
52 {
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
53 -1, -1, -1, -1, 2, 4, 6, 8,
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
54 -1, -1, -1, -1, 2, 4, 6, 8
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
55 };
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
56
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
57 // useful macros
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
58 // clamp a number between 0 and 88
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
59 #define CLAMP_0_TO_88(x) if (x < 0) x = 0; else if (x > 88) x = 88;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
60 // clamp a number within a signed 16-bit range
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
61 #define CLAMP_S16(x) if (x < -32768) x = -32768; \
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
62 else if (x > 32767) x = 32767;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
63 // clamp a number above 16
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
64 #define CLAMP_ABOVE_16(x) if (x < 16) x = 16;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
65 // sign extend a 16-bit value
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
66 #define SE_16BIT(x) if (x & 0x8000) x -= 0x10000;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
67 // sign extend a 4-bit value
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
68 #define SE_4BIT(x) if (x & 0x8) x -= 0x10;
5340
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
69
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
70 static ad_info_t info =
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
71 {
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
72 "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
73 "imaadpcm",
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
74 AFM_IMAADPCM,
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
75 "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
76 "Mike Melanson",
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
77 ""
5340
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
78 };
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
79
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
80 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
81
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
82 static int preinit(sh_audio_t *sh_audio)
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
83 {
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
84 // not exactly sure what this field is for
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
85 sh_audio->audio_out_minsize = 8192;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
86
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
87 // 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
88 // indicates constant block size, whereas an AVI/ASF/WAV file will fill
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
89 // in this field with 0x11
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
90 if ((sh_audio->format == 0x11) || (sh_audio->format == 0x61))
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
91 {
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
92 sh_audio->ds->ss_div = (sh_audio->wf->nBlockAlign -
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
93 (MS_IMA_ADPCM_PREAMBLE_SIZE * sh_audio->wf->nChannels)) * 2;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
94 sh_audio->ds->ss_mul = sh_audio->wf->nBlockAlign;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
95 }
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
96 else
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
97 {
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
98 sh_audio->ds->ss_div = QT_IMA_ADPCM_SAMPLES_PER_BLOCK;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
99 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
100 }
5458
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5408
diff changeset
101 sh_audio->audio_in_minsize=sh_audio->ds->ss_mul;
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
102 return 1;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
103 }
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
104
5340
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
105 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
106 {
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
107 /* 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
108 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
109 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
110 /* decodes 34 byte -> 64 short*/
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
111 sh_audio->i_bps =
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
112 (sh_audio->ds->ss_mul * sh_audio->samplerate) / sh_audio->ds->ss_div;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
113
5340
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
114 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
115 }
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
116
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
117 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
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 }
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
120
5481
8ae2bf330ad5 control() done
arpi
parents: 5458
diff changeset
121 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
122 {
5481
8ae2bf330ad5 control() done
arpi
parents: 5458
diff changeset
123 if(cmd==ADCTRL_SKIP_FRAME){
8ae2bf330ad5 control() done
arpi
parents: 5458
diff changeset
124 demux_read_data(sh_audio->ds, sh_audio->a_in_buffer,sh_audio->ds->ss_mul);
8ae2bf330ad5 control() done
arpi
parents: 5458
diff changeset
125 return CONTROL_TRUE;
8ae2bf330ad5 control() done
arpi
parents: 5458
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 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
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 decode_nibbles(unsigned short *output,
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
131 int output_size, int channels,
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
132 int predictor_l, int index_l,
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
133 int predictor_r, int index_r)
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
134 {
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
135 int step[2];
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
136 int predictor[2];
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
137 int index[2];
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
138 int diff;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
139 int i;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
140 int sign;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
141 int delta;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
142 int channel_number = 0;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
143
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
144 step[0] = adpcm_step[index_l];
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
145 step[1] = adpcm_step[index_r];
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
146 predictor[0] = predictor_l;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
147 predictor[1] = predictor_r;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
148 index[0] = index_l;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
149 index[1] = index_r;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
150
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
151 for (i = 0; i < output_size; i++)
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
152 {
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
153 delta = output[i];
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
154
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
155 index[channel_number] += adpcm_index[delta];
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
156 CLAMP_0_TO_88(index[channel_number]);
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
157
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
158 sign = delta & 8;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
159 delta = delta & 7;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
160
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
161 diff = step[channel_number] >> 3;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
162 if (delta & 4) diff += step[channel_number];
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
163 if (delta & 2) diff += step[channel_number] >> 1;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
164 if (delta & 1) diff += step[channel_number] >> 2;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
165
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
166 if (sign)
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
167 predictor[channel_number] -= diff;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
168 else
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
169 predictor[channel_number] += diff;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
170
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
171 CLAMP_S16(predictor[channel_number]);
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
172 output[i] = predictor[channel_number];
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
173 step[channel_number] = adpcm_step[index[channel_number]];
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
174
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
175 // toggle channel
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
176 channel_number ^= channels - 1;
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
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
181 static int qt_ima_adpcm_decode_block(unsigned short *output,
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
182 unsigned char *input, int channels)
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
183 {
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
184 int initial_predictor_l = 0;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
185 int initial_predictor_r = 0;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
186 int initial_index_l = 0;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
187 int initial_index_r = 0;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
188 int i;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
189
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
190 initial_predictor_l = BE_16(&input[0]);
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
191 initial_index_l = initial_predictor_l;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
192
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
193 // mask, sign-extend, and clamp the predictor portion
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
194 initial_predictor_l &= 0xFF80;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
195 SE_16BIT(initial_predictor_l);
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
196 CLAMP_S16(initial_predictor_l);
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
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
199 initial_index_l &= 0x7F;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
200 CLAMP_0_TO_88(initial_index_l);
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
201
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
202 // handle stereo
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
203 if (channels > 1)
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
204 {
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
205 initial_predictor_r = BE_16(&input[QT_IMA_ADPCM_BLOCK_SIZE]);
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
206 initial_index_r = initial_predictor_r;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
207
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
208 // mask, sign-extend, and clamp the predictor portion
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
209 initial_predictor_r &= 0xFF80;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
210 SE_16BIT(initial_predictor_r);
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
211 CLAMP_S16(initial_predictor_r);
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
212
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
213 // mask and clamp the index portion
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
214 initial_index_r &= 0x7F;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
215 CLAMP_0_TO_88(initial_index_r);
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
216 }
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
217
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
218 // break apart all of the nibbles in the block
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
219 if (channels == 1)
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
220 for (i = 0; i < QT_IMA_ADPCM_SAMPLES_PER_BLOCK / 2; i++)
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
221 {
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
222 output[i * 2 + 0] = input[2 + i] & 0x0F;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
223 output[i * 2 + 1] = input[2 + i] >> 4;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
224 }
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
225 else
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
226 for (i = 0; i < QT_IMA_ADPCM_SAMPLES_PER_BLOCK / 2 * 2; i++)
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
227 {
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
228 output[i * 4 + 0] = input[2 + i] & 0x0F;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
229 output[i * 4 + 1] = input[2 + QT_IMA_ADPCM_BLOCK_SIZE + i] & 0x0F;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
230 output[i * 4 + 2] = input[2 + i] >> 4;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
231 output[i * 4 + 3] = input[2 + QT_IMA_ADPCM_BLOCK_SIZE + i] >> 4;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
232 }
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
233
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
234 decode_nibbles(output,
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
235 QT_IMA_ADPCM_SAMPLES_PER_BLOCK * channels, channels,
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
236 initial_predictor_l, initial_index_l,
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
237 initial_predictor_r, initial_index_r);
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
238
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
239 return QT_IMA_ADPCM_SAMPLES_PER_BLOCK * channels;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
240 }
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
241
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
242 static int ms_ima_adpcm_decode_block(unsigned short *output,
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
243 unsigned char *input, int channels, int block_size)
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
244 {
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
245 int predictor_l = 0;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
246 int predictor_r = 0;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
247 int index_l = 0;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
248 int index_r = 0;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
249 int i;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
250 int channel_counter;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
251 int channel_index;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
252 int channel_index_l;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
253 int channel_index_r;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
254
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
255 predictor_l = LE_16(&input[0]);
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
256 SE_16BIT(predictor_l);
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
257 index_l = input[2];
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
258 if (channels == 2)
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
259 {
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
260 predictor_r = LE_16(&input[4]);
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
261 SE_16BIT(predictor_r);
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
262 index_r = input[6];
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
263 }
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
264
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
265 if (channels == 1)
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
266 for (i = 0;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
267 i < (block_size - MS_IMA_ADPCM_PREAMBLE_SIZE * channels) / 2; i++)
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
268 {
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
269 output[i * 2 + 0] = input[MS_IMA_ADPCM_PREAMBLE_SIZE + i] & 0x0F;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
270 output[i * 2 + 1] = input[MS_IMA_ADPCM_PREAMBLE_SIZE + i] >> 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 else
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
273 {
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
274 // encoded as 8 nibbles (4 bytes) per channel; switch channel every
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
275 // 4th byte
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
276 channel_counter = 0;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
277 channel_index_l = 0;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
278 channel_index_r = 1;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
279 channel_index = channel_index_l;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
280 for (i = 0;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
281 i < (block_size - MS_IMA_ADPCM_PREAMBLE_SIZE * channels); i++)
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
282 {
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
283 output[channel_index + 0] =
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
284 input[MS_IMA_ADPCM_PREAMBLE_SIZE * 2 + i] & 0x0F;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
285 output[channel_index + 2] =
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
286 input[MS_IMA_ADPCM_PREAMBLE_SIZE * 2 + i] >> 4;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
287 channel_index += 4;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
288 channel_counter++;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
289 if (channel_counter == 4)
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
290 {
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
291 channel_index_l = channel_index;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
292 channel_index = channel_index_r;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
293 }
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
294 else if (channel_counter == 8)
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
295 {
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
296 channel_index_r = channel_index;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
297 channel_index = channel_index_l;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
298 channel_counter = 0;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
299 }
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
300 }
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
301 }
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
302
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
303 decode_nibbles(output,
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
304 (block_size - MS_IMA_ADPCM_PREAMBLE_SIZE * channels) * 2,
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
305 channels,
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
306 predictor_l, index_l,
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
307 predictor_r, index_r);
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
308
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
309 return (block_size - MS_IMA_ADPCM_PREAMBLE_SIZE * channels) * 2;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
310 }
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
311
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
312 static int dk4_ima_adpcm_decode_block(unsigned short *output,
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
313 unsigned char *input, int channels, int block_size)
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
314 {
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
315 int i;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
316 int output_ptr;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
317 int predictor_l = 0;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
318 int predictor_r = 0;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
319 int index_l = 0;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
320 int index_r = 0;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
321
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
322 // the first predictor value goes straight to the output
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
323 predictor_l = output[0] = LE_16(&input[0]);
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
324 SE_16BIT(predictor_l);
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
325 index_l = input[2];
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
326 if (channels == 2)
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
327 {
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
328 predictor_r = output[1] = LE_16(&input[4]);
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
329 SE_16BIT(predictor_r);
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
330 index_r = input[6];
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
331 }
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
332
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
333 output_ptr = channels;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
334 for (i = MS_IMA_ADPCM_PREAMBLE_SIZE * channels; i < block_size; i++)
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
335 {
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
336 output[output_ptr++] = input[i] >> 4;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
337 output[output_ptr++] = input[i] & 0x0F;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
338 }
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
339
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
340 decode_nibbles(&output[channels],
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
341 (block_size - MS_IMA_ADPCM_PREAMBLE_SIZE * channels) * 2 - channels,
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
342 channels,
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
343 predictor_l, index_l,
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
344 predictor_r, index_r);
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
345
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
346 return (block_size - MS_IMA_ADPCM_PREAMBLE_SIZE * channels) * 2 - channels;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
347 }
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
348
5340
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
349 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
350 {
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
351 if (demux_read_data(sh_audio->ds, sh_audio->a_in_buffer,
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
352 sh_audio->ds->ss_mul) !=
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
353 sh_audio->ds->ss_mul)
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
354 return -1;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
355
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
356 if (sh_audio->format == 0x11)
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
357 {
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
358 return 2 * ms_ima_adpcm_decode_block(
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
359 (unsigned short*)buf, sh_audio->a_in_buffer, sh_audio->wf->nChannels,
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
360 sh_audio->ds->ss_mul);
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
361 }
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
362 else if (sh_audio->format == 0x61)
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
363 {
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
364 return 2 * dk4_ima_adpcm_decode_block(
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
365 (unsigned short*)buf, sh_audio->a_in_buffer, sh_audio->wf->nChannels,
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
366 sh_audio->ds->ss_mul);
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
367 }
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
368 else
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
369 {
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
370 return 2 * qt_ima_adpcm_decode_block(
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
371 (unsigned short*)buf, sh_audio->a_in_buffer, sh_audio->wf->nChannels);
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5340
diff changeset
372 }
5340
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
373 }