annotate libmpcodecs/ad_msadpcm.c @ 23946:9c431c0242f5

added missing ":"'s
author ptt
date Tue, 31 Jul 2007 14:19:33 +0000
parents fa99b3d31d13
children b21e1506e50b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
1 /*
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
2 MS ADPCM Decoder for MPlayer
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
3 by Mike Melanson
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
4
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
5 This file is responsible for decoding Microsoft ADPCM data.
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
6 Details about the data format can be found here:
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
7 http://www.pcisys.net/~melanson/codecs/
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
8 */
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
9
5340
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
10 #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
11 #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
12 #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
13
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
14 #include "config.h"
21372
1767c271d710 Remove bswap.h, use libavutil/bswap.h instead.
diego
parents: 13427
diff changeset
15 #include "libavutil/common.h"
21507
fa99b3d31d13 Hack around libavutil/bswap.h compilation problems due to always_inline undefined.
reimar
parents: 21372
diff changeset
16 #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
17 #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
18
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
19 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
20 {
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
21 "MS 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
22 "msadpcm",
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
23 "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
24 "Mike Melanson",
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
25 ""
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
26 };
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
27
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
28 LIBAD_EXTERN(msadpcm)
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
29
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
30 static int ms_adapt_table[] =
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
31 {
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
32 230, 230, 230, 230, 307, 409, 512, 614,
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
33 768, 614, 512, 409, 307, 230, 230, 230
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
34 };
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
35
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
36 static int ms_adapt_coeff1[] =
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
37 {
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
38 256, 512, 0, 192, 240, 460, 392
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
39 };
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
40
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
41 static int ms_adapt_coeff2[] =
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
42 {
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
43 0, -256, 0, 64, 0, -208, -232
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
44 };
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
45
6609
7745d73a5f20 bugfix by Keiki SATOH <kki@wakusei.ne.jp>
arpi
parents: 5481
diff changeset
46 #define MS_ADPCM_PREAMBLE_SIZE 6
5350
d59e27f2f5be fixed so the decoder cooperates better with the rest of the system
melanson
parents: 5340
diff changeset
47
7893
fa65f25f748a 100l - Michael is right, we don't need le2me here
arpi
parents: 7890
diff changeset
48 #define LE_16(x) ((x)[0]+(256*((x)[1])))
7890
arpi
parents: 7888
diff changeset
49 //#define LE_16(x) (le2me_16((x)[1]+(256*((x)[0]))))
7888
5abf74c67ace fixed unaligned access (bus error on sparc)
arpi
parents: 7180
diff changeset
50 //#define LE_16(x) (le2me_16(*(unsigned short *)(x)))
5abf74c67ace fixed unaligned access (bus error on sparc)
arpi
parents: 7180
diff changeset
51 //#define LE_32(x) (le2me_32(*(unsigned int *)(x)))
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
52
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
53 // useful macros
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
54 // clamp a number between 0 and 88
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
55 #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: 5350
diff changeset
56 // clamp a number within a signed 16-bit range
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
57 #define CLAMP_S16(x) if (x < -32768) x = -32768; \
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
58 else if (x > 32767) x = 32767;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
59 // clamp a number above 16
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
60 #define CLAMP_ABOVE_16(x) if (x < 16) x = 16;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
61 // sign extend a 16-bit value
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
62 #define SE_16BIT(x) if (x & 0x8000) x -= 0x10000;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
63 // sign extend a 4-bit value
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
64 #define SE_4BIT(x) if (x & 0x8) x -= 0x10;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
65
5350
d59e27f2f5be fixed so the decoder cooperates better with the rest of the system
melanson
parents: 5340
diff changeset
66 static int preinit(sh_audio_t *sh_audio)
d59e27f2f5be fixed so the decoder cooperates better with the rest of the system
melanson
parents: 5340
diff changeset
67 {
d59e27f2f5be fixed so the decoder cooperates better with the rest of the system
melanson
parents: 5340
diff changeset
68 sh_audio->audio_out_minsize = sh_audio->wf->nBlockAlign * 4;
d59e27f2f5be fixed so the decoder cooperates better with the rest of the system
melanson
parents: 5340
diff changeset
69 sh_audio->ds->ss_div =
d59e27f2f5be fixed so the decoder cooperates better with the rest of the system
melanson
parents: 5340
diff changeset
70 (sh_audio->wf->nBlockAlign - MS_ADPCM_PREAMBLE_SIZE) * 2;
5458
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5408
diff changeset
71 sh_audio->audio_in_minsize =
5350
d59e27f2f5be fixed so the decoder cooperates better with the rest of the system
melanson
parents: 5340
diff changeset
72 sh_audio->ds->ss_mul = sh_audio->wf->nBlockAlign;
d59e27f2f5be fixed so the decoder cooperates better with the rest of the system
melanson
parents: 5340
diff changeset
73 return 1;
d59e27f2f5be fixed so the decoder cooperates better with the rest of the system
melanson
parents: 5340
diff changeset
74 }
5340
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
75
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
76 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
77 {
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
78 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
79 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
80 sh_audio->i_bps = sh_audio->wf->nBlockAlign *
5350
d59e27f2f5be fixed so the decoder cooperates better with the rest of the system
melanson
parents: 5340
diff changeset
81 (sh_audio->channels*sh_audio->samplerate) / sh_audio->ds->ss_div;
13427
9d0b052c4f74 setting samplesize to 2 in decoders where neccessary.
reimar
parents: 7893
diff changeset
82 sh_audio->samplesize=2;
5350
d59e27f2f5be fixed so the decoder cooperates better with the rest of the system
melanson
parents: 5340
diff changeset
83
5340
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
84 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
85 }
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
86
5350
d59e27f2f5be fixed so the decoder cooperates better with the rest of the system
melanson
parents: 5340
diff changeset
87 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
88 {
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
5481
8ae2bf330ad5 control() done
arpi
parents: 5458
diff changeset
91 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
92 {
5481
8ae2bf330ad5 control() done
arpi
parents: 5458
diff changeset
93 if(cmd==ADCTRL_SKIP_FRAME){
8ae2bf330ad5 control() done
arpi
parents: 5458
diff changeset
94 demux_read_data(sh_audio->ds, sh_audio->a_in_buffer,sh_audio->ds->ss_mul);
8ae2bf330ad5 control() done
arpi
parents: 5458
diff changeset
95 return CONTROL_TRUE;
8ae2bf330ad5 control() done
arpi
parents: 5458
diff changeset
96 }
5340
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
97 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
98 }
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
99
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
100 static int ms_adpcm_decode_block(unsigned short *output, unsigned char *input,
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
101 int channels, int block_size)
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
102 {
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
103 int current_channel = 0;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
104 int idelta[2];
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
105 int sample1[2];
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
106 int sample2[2];
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
107 int coeff1[2];
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
108 int coeff2[2];
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
109 int stream_ptr = 0;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
110 int out_ptr = 0;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
111 int upper_nibble = 1;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
112 int nibble;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
113 int snibble; // signed nibble
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
114 int predictor;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
115
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
116 // fetch the header information, in stereo if both channels are present
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
117 if (input[stream_ptr] > 6)
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
118 mp_msg(MSGT_DECAUDIO, MSGL_WARN,
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
119 "MS ADPCM: coefficient (%d) out of range (should be [0..6])\n",
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
120 input[stream_ptr]);
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
121 coeff1[0] = ms_adapt_coeff1[input[stream_ptr]];
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
122 coeff2[0] = ms_adapt_coeff2[input[stream_ptr]];
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
123 stream_ptr++;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
124 if (channels == 2)
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
125 {
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
126 if (input[stream_ptr] > 6)
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
127 mp_msg(MSGT_DECAUDIO, MSGL_WARN,
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
128 "MS ADPCM: coefficient (%d) out of range (should be [0..6])\n",
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
129 input[stream_ptr]);
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
130 coeff1[1] = ms_adapt_coeff1[input[stream_ptr]];
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
131 coeff2[1] = ms_adapt_coeff2[input[stream_ptr]];
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
132 stream_ptr++;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
133 }
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
134
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
135 idelta[0] = LE_16(&input[stream_ptr]);
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
136 stream_ptr += 2;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
137 SE_16BIT(idelta[0]);
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
138 if (channels == 2)
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
139 {
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
140 idelta[1] = LE_16(&input[stream_ptr]);
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
141 stream_ptr += 2;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
142 SE_16BIT(idelta[1]);
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
143 }
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
144
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
145 sample1[0] = LE_16(&input[stream_ptr]);
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
146 stream_ptr += 2;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
147 SE_16BIT(sample1[0]);
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
148 if (channels == 2)
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
149 {
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
150 sample1[1] = LE_16(&input[stream_ptr]);
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
151 stream_ptr += 2;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
152 SE_16BIT(sample1[1]);
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
153 }
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
154
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
155 sample2[0] = LE_16(&input[stream_ptr]);
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
156 stream_ptr += 2;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
157 SE_16BIT(sample2[0]);
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
158 if (channels == 2)
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
159 {
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
160 sample2[1] = LE_16(&input[stream_ptr]);
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
161 stream_ptr += 2;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
162 SE_16BIT(sample2[1]);
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
163 }
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
164
6609
7745d73a5f20 bugfix by Keiki SATOH <kki@wakusei.ne.jp>
arpi
parents: 5481
diff changeset
165 if (channels == 1)
7745d73a5f20 bugfix by Keiki SATOH <kki@wakusei.ne.jp>
arpi
parents: 5481
diff changeset
166 {
7745d73a5f20 bugfix by Keiki SATOH <kki@wakusei.ne.jp>
arpi
parents: 5481
diff changeset
167 output[out_ptr++] = sample2[0];
7745d73a5f20 bugfix by Keiki SATOH <kki@wakusei.ne.jp>
arpi
parents: 5481
diff changeset
168 output[out_ptr++] = sample1[0];
7745d73a5f20 bugfix by Keiki SATOH <kki@wakusei.ne.jp>
arpi
parents: 5481
diff changeset
169 } else {
7745d73a5f20 bugfix by Keiki SATOH <kki@wakusei.ne.jp>
arpi
parents: 5481
diff changeset
170 output[out_ptr++] = sample2[0];
7745d73a5f20 bugfix by Keiki SATOH <kki@wakusei.ne.jp>
arpi
parents: 5481
diff changeset
171 output[out_ptr++] = sample2[1];
7745d73a5f20 bugfix by Keiki SATOH <kki@wakusei.ne.jp>
arpi
parents: 5481
diff changeset
172 output[out_ptr++] = sample1[0];
7745d73a5f20 bugfix by Keiki SATOH <kki@wakusei.ne.jp>
arpi
parents: 5481
diff changeset
173 output[out_ptr++] = sample1[1];
7745d73a5f20 bugfix by Keiki SATOH <kki@wakusei.ne.jp>
arpi
parents: 5481
diff changeset
174 }
7745d73a5f20 bugfix by Keiki SATOH <kki@wakusei.ne.jp>
arpi
parents: 5481
diff changeset
175
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
176 while (stream_ptr < block_size)
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
177 {
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
178 // get the next nibble
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
179 if (upper_nibble)
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
180 nibble = snibble = input[stream_ptr] >> 4;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
181 else
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
182 nibble = snibble = input[stream_ptr++] & 0x0F;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
183 upper_nibble ^= 1;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
184 SE_4BIT(snibble);
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
185
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
186 predictor = (
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
187 ((sample1[current_channel] * coeff1[current_channel]) +
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
188 (sample2[current_channel] * coeff2[current_channel])) / 256) +
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
189 (snibble * idelta[current_channel]);
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
190 CLAMP_S16(predictor);
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
191 sample2[current_channel] = sample1[current_channel];
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
192 sample1[current_channel] = predictor;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
193 output[out_ptr++] = predictor;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
194
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
195 // compute the next adaptive scale factor (a.k.a. the variable idelta)
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
196 idelta[current_channel] =
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
197 (ms_adapt_table[nibble] * idelta[current_channel]) / 256;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
198 CLAMP_ABOVE_16(idelta[current_channel]);
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
199
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
200 // toggle the channel
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
201 current_channel ^= channels - 1;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
202 }
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
203
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
204 return (block_size - (MS_ADPCM_PREAMBLE_SIZE * channels)) * 2;
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
205 }
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
206
5340
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
207 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
208 {
5350
d59e27f2f5be fixed so the decoder cooperates better with the rest of the system
melanson
parents: 5340
diff changeset
209 if (demux_read_data(sh_audio->ds, sh_audio->a_in_buffer,
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
210 sh_audio->ds->ss_mul) !=
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
211 sh_audio->ds->ss_mul)
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
212 return -1; /* EOF */
5350
d59e27f2f5be fixed so the decoder cooperates better with the rest of the system
melanson
parents: 5340
diff changeset
213
5340
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
214 return 2 * ms_adpcm_decode_block(
5408
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
215 (unsigned short*)buf, sh_audio->a_in_buffer,
f9cd6381e327 reworked ADPCM decoders; changes include:
melanson
parents: 5350
diff changeset
216 sh_audio->wf->nChannels, sh_audio->wf->nBlockAlign);
5340
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
217 }