4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright (C) 4Front Technologies 1996-2008.
24 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
28 * Purpose: Test sounds for osstest
38 le_int(const unsigned char *p
, int l
)
44 for (i
= l
- 1; i
>= 0; i
--) {
45 val
= (val
<< 8) | p
[i
];
52 uncompress_wave(short *outbuf
)
54 #define WAVE_FORMAT_ADPCM 0x0002
56 int i
, n
, dataleft
, x
, l
= sizeof (inbuf
);
57 const unsigned char *hdr
= inbuf
;
63 adpcm_coeff coeff
[32];
64 static int AdaptionTable
[] = { 230, 230, 230, 230, 307, 409, 512, 614,
65 768, 614, 512, 409, 307, 230, 230, 230
68 unsigned char buf
[4096];
72 int nBlockAlign
= 2048;
73 int wSamplesPerBlock
= 2036, wNumCoeff
= 7;
77 /* filelen = le_int(&hdr[4], 4); */
79 while (p
< l
- 16 && memcmp(&hdr
[p
], "data", 4) != 0) {
80 n
= le_int(&hdr
[p
+ 4], 4);
82 if (memcmp(&hdr
[p
], "fmt ", 4) == 0) {
84 /* fmt = le_int(&hdr[p + 8], 2); */
85 channels
= le_int(&hdr
[p
+ 10], 2);
86 /* speed = le_int(&hdr[p + 12], 4); */
87 nBlockAlign
= le_int(&hdr
[p
+ 20], 2);
88 /* bytes_per_sample = le_int(&hdr[p + 20], 2); */
90 wSamplesPerBlock
= le_int(&hdr
[p
+ 26], 2);
91 wNumCoeff
= le_int(&hdr
[p
+ 28], 2);
95 for (i
= 0; i
< wNumCoeff
; i
++) {
96 coeff
[i
].coeff1
= (short)le_int(&hdr
[x
], 2);
98 coeff
[i
].coeff2
= (short)le_int(&hdr
[x
], 2);
106 if (p
< l
- 16 && memcmp(&hdr
[p
], "data", 4) == 0) {
108 dataleft
= n
= le_int(&hdr
[p
+ 4], 4);
114 #define OUT_SAMPLE(s) { \
117 else if (s < -32768) \
119 outbuf[outp++] = s; \
125 (buf[x + nib++] >> 4) & 0x0f : buf[x++ + --nib] & 0x0f)
130 while (dataleft
> nBlockAlign
) {
131 int predictor
[2], delta
[2], samp1
[2], samp2
[2];
135 (void) memcpy(buf
, &inbuf
[ppp
], nBlockAlign
);
137 dataleft
-= nBlockAlign
;
142 for (i
= 0; i
< channels
; i
++) {
143 predictor
[i
] = buf
[x
];
147 for (i
= 0; i
< channels
; i
++) {
148 delta
[i
] = (short)le_int(&buf
[x
], 2);
152 for (i
= 0; i
< channels
; i
++) {
153 samp1
[i
] = (short)le_int(&buf
[x
], 2);
155 OUT_SAMPLE(samp1
[i
]);
158 for (i
= 0; i
< channels
; i
++) {
159 samp2
[i
] = (short)le_int(&buf
[x
], 2);
161 OUT_SAMPLE(samp2
[i
]);
164 while (n
< (wSamplesPerBlock
* 2 * channels
))
165 for (i
= 0; i
< channels
; i
++) {
166 int pred
, new, error_delta
, i_delta
;
169 coeff
[predictor
[i
]].coeff1
)
171 coeff
[predictor
[i
]].coeff2
)) / 256;
172 i_delta
= error_delta
= GETNIBBLE
;
174 /* Convert to signed */
178 new = pred
+ (delta
[i
] * i_delta
);
181 delta
[i
] = delta
[i
] *
182 AdaptionTable
[error_delta
] / 256;