1960366cfSKarsten Keil /*
2960366cfSKarsten Keil * Audio support data for mISDN_dsp.
3960366cfSKarsten Keil *
4960366cfSKarsten Keil * Copyright 2002/2003 by Andreas Eversberg (jolly@eversberg.eu)
5960366cfSKarsten Keil * Rewritten by Peter
6960366cfSKarsten Keil *
7960366cfSKarsten Keil * This software may be used and distributed according to the terms
8960366cfSKarsten Keil * of the GNU General Public License, incorporated herein by reference.
9960366cfSKarsten Keil *
10960366cfSKarsten Keil */
11960366cfSKarsten Keil
12960366cfSKarsten Keil #include <linux/delay.h>
13960366cfSKarsten Keil #include <linux/mISDNif.h>
14960366cfSKarsten Keil #include <linux/mISDNdsp.h>
155d76fc21SPaul Gortmaker #include <linux/export.h>
16*bec7a630Syalin wang #include <linux/bitrev.h>
17960366cfSKarsten Keil #include "core.h"
18960366cfSKarsten Keil #include "dsp.h"
19960366cfSKarsten Keil
20960366cfSKarsten Keil /* ulaw[unsigned char] -> signed 16-bit */
21960366cfSKarsten Keil s32 dsp_audio_ulaw_to_s32[256];
22960366cfSKarsten Keil /* alaw[unsigned char] -> signed 16-bit */
23960366cfSKarsten Keil s32 dsp_audio_alaw_to_s32[256];
24960366cfSKarsten Keil
25960366cfSKarsten Keil s32 *dsp_audio_law_to_s32;
26960366cfSKarsten Keil EXPORT_SYMBOL(dsp_audio_law_to_s32);
27960366cfSKarsten Keil
28960366cfSKarsten Keil /* signed 16-bit -> law */
29960366cfSKarsten Keil u8 dsp_audio_s16_to_law[65536];
30960366cfSKarsten Keil EXPORT_SYMBOL(dsp_audio_s16_to_law);
31960366cfSKarsten Keil
32960366cfSKarsten Keil /* alaw -> ulaw */
33960366cfSKarsten Keil u8 dsp_audio_alaw_to_ulaw[256];
34960366cfSKarsten Keil /* ulaw -> alaw */
355b834354SHannes Eder static u8 dsp_audio_ulaw_to_alaw[256];
36960366cfSKarsten Keil u8 dsp_silence;
37960366cfSKarsten Keil
38960366cfSKarsten Keil
39960366cfSKarsten Keil /*****************************************************
40960366cfSKarsten Keil * generate table for conversion of s16 to alaw/ulaw *
41960366cfSKarsten Keil *****************************************************/
42960366cfSKarsten Keil
43960366cfSKarsten Keil #define AMI_MASK 0x55
44960366cfSKarsten Keil
linear2alaw(short int linear)45960366cfSKarsten Keil static inline unsigned char linear2alaw(short int linear)
46960366cfSKarsten Keil {
47960366cfSKarsten Keil int mask;
48960366cfSKarsten Keil int seg;
49960366cfSKarsten Keil int pcm_val;
50960366cfSKarsten Keil static int seg_end[8] = {
51960366cfSKarsten Keil 0xFF, 0x1FF, 0x3FF, 0x7FF, 0xFFF, 0x1FFF, 0x3FFF, 0x7FFF
52960366cfSKarsten Keil };
53960366cfSKarsten Keil
54960366cfSKarsten Keil pcm_val = linear;
55960366cfSKarsten Keil if (pcm_val >= 0) {
56960366cfSKarsten Keil /* Sign (7th) bit = 1 */
57960366cfSKarsten Keil mask = AMI_MASK | 0x80;
58960366cfSKarsten Keil } else {
59960366cfSKarsten Keil /* Sign bit = 0 */
60960366cfSKarsten Keil mask = AMI_MASK;
61960366cfSKarsten Keil pcm_val = -pcm_val;
62960366cfSKarsten Keil }
63960366cfSKarsten Keil
64960366cfSKarsten Keil /* Convert the scaled magnitude to segment number. */
65960366cfSKarsten Keil for (seg = 0; seg < 8; seg++) {
66960366cfSKarsten Keil if (pcm_val <= seg_end[seg])
67960366cfSKarsten Keil break;
68960366cfSKarsten Keil }
69960366cfSKarsten Keil /* Combine the sign, segment, and quantization bits. */
70960366cfSKarsten Keil return ((seg << 4) |
71960366cfSKarsten Keil ((pcm_val >> ((seg) ? (seg + 3) : 4)) & 0x0F)) ^ mask;
72960366cfSKarsten Keil }
73960366cfSKarsten Keil
74960366cfSKarsten Keil
alaw2linear(unsigned char alaw)75960366cfSKarsten Keil static inline short int alaw2linear(unsigned char alaw)
76960366cfSKarsten Keil {
77960366cfSKarsten Keil int i;
78960366cfSKarsten Keil int seg;
79960366cfSKarsten Keil
80960366cfSKarsten Keil alaw ^= AMI_MASK;
81960366cfSKarsten Keil i = ((alaw & 0x0F) << 4) + 8 /* rounding error */;
82960366cfSKarsten Keil seg = (((int) alaw & 0x70) >> 4);
83960366cfSKarsten Keil if (seg)
84960366cfSKarsten Keil i = (i + 0x100) << (seg - 1);
85960366cfSKarsten Keil return (short int) ((alaw & 0x80) ? i : -i);
86960366cfSKarsten Keil }
87960366cfSKarsten Keil
ulaw2linear(unsigned char ulaw)88960366cfSKarsten Keil static inline short int ulaw2linear(unsigned char ulaw)
89960366cfSKarsten Keil {
90960366cfSKarsten Keil short mu, e, f, y;
91960366cfSKarsten Keil static short etab[] = {0, 132, 396, 924, 1980, 4092, 8316, 16764};
92960366cfSKarsten Keil
93960366cfSKarsten Keil mu = 255 - ulaw;
94960366cfSKarsten Keil e = (mu & 0x70) / 16;
95960366cfSKarsten Keil f = mu & 0x0f;
96960366cfSKarsten Keil y = f * (1 << (e + 3));
97960366cfSKarsten Keil y += etab[e];
98960366cfSKarsten Keil if (mu & 0x80)
99960366cfSKarsten Keil y = -y;
100960366cfSKarsten Keil return y;
101960366cfSKarsten Keil }
102960366cfSKarsten Keil
103960366cfSKarsten Keil #define BIAS 0x84 /*!< define the add-in bias for 16 bit samples */
104960366cfSKarsten Keil
linear2ulaw(short sample)105960366cfSKarsten Keil static unsigned char linear2ulaw(short sample)
106960366cfSKarsten Keil {
107960366cfSKarsten Keil static int exp_lut[256] = {
108960366cfSKarsten Keil 0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
109960366cfSKarsten Keil 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
110960366cfSKarsten Keil 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
111960366cfSKarsten Keil 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
112960366cfSKarsten Keil 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
113960366cfSKarsten Keil 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
114960366cfSKarsten Keil 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
115960366cfSKarsten Keil 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
116960366cfSKarsten Keil 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
117960366cfSKarsten Keil 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
118960366cfSKarsten Keil 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
119960366cfSKarsten Keil 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
120960366cfSKarsten Keil 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
121960366cfSKarsten Keil 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
122960366cfSKarsten Keil 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
123960366cfSKarsten Keil 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7};
124960366cfSKarsten Keil int sign, exponent, mantissa;
125960366cfSKarsten Keil unsigned char ulawbyte;
126960366cfSKarsten Keil
127960366cfSKarsten Keil /* Get the sample into sign-magnitude. */
128960366cfSKarsten Keil sign = (sample >> 8) & 0x80; /* set aside the sign */
129960366cfSKarsten Keil if (sign != 0)
130960366cfSKarsten Keil sample = -sample; /* get magnitude */
131960366cfSKarsten Keil
132960366cfSKarsten Keil /* Convert from 16 bit linear to ulaw. */
133960366cfSKarsten Keil sample = sample + BIAS;
134960366cfSKarsten Keil exponent = exp_lut[(sample >> 7) & 0xFF];
135960366cfSKarsten Keil mantissa = (sample >> (exponent + 3)) & 0x0F;
136960366cfSKarsten Keil ulawbyte = ~(sign | (exponent << 4) | mantissa);
137960366cfSKarsten Keil
138960366cfSKarsten Keil return ulawbyte;
139960366cfSKarsten Keil }
140960366cfSKarsten Keil
dsp_audio_generate_law_tables(void)141960366cfSKarsten Keil void dsp_audio_generate_law_tables(void)
142960366cfSKarsten Keil {
143960366cfSKarsten Keil int i;
144960366cfSKarsten Keil for (i = 0; i < 256; i++)
145*bec7a630Syalin wang dsp_audio_alaw_to_s32[i] = alaw2linear(bitrev8((u8)i));
146960366cfSKarsten Keil
147960366cfSKarsten Keil for (i = 0; i < 256; i++)
148*bec7a630Syalin wang dsp_audio_ulaw_to_s32[i] = ulaw2linear(bitrev8((u8)i));
149960366cfSKarsten Keil
150960366cfSKarsten Keil for (i = 0; i < 256; i++) {
151960366cfSKarsten Keil dsp_audio_alaw_to_ulaw[i] =
152960366cfSKarsten Keil linear2ulaw(dsp_audio_alaw_to_s32[i]);
153960366cfSKarsten Keil dsp_audio_ulaw_to_alaw[i] =
154960366cfSKarsten Keil linear2alaw(dsp_audio_ulaw_to_s32[i]);
155960366cfSKarsten Keil }
156960366cfSKarsten Keil }
157960366cfSKarsten Keil
158960366cfSKarsten Keil void
dsp_audio_generate_s2law_table(void)159960366cfSKarsten Keil dsp_audio_generate_s2law_table(void)
160960366cfSKarsten Keil {
161960366cfSKarsten Keil int i;
162960366cfSKarsten Keil
163960366cfSKarsten Keil if (dsp_options & DSP_OPT_ULAW) {
164960366cfSKarsten Keil /* generating ulaw-table */
165960366cfSKarsten Keil for (i = -32768; i < 32768; i++) {
166960366cfSKarsten Keil dsp_audio_s16_to_law[i & 0xffff] =
167*bec7a630Syalin wang bitrev8(linear2ulaw(i));
168960366cfSKarsten Keil }
169960366cfSKarsten Keil } else {
170960366cfSKarsten Keil /* generating alaw-table */
171960366cfSKarsten Keil for (i = -32768; i < 32768; i++) {
172960366cfSKarsten Keil dsp_audio_s16_to_law[i & 0xffff] =
173*bec7a630Syalin wang bitrev8(linear2alaw(i));
174960366cfSKarsten Keil }
175960366cfSKarsten Keil }
176960366cfSKarsten Keil }
177960366cfSKarsten Keil
178960366cfSKarsten Keil
179960366cfSKarsten Keil /*
180960366cfSKarsten Keil * the seven bit sample is the number of every second alaw-sample ordered by
181960366cfSKarsten Keil * aplitude. 0x00 is negative, 0x7f is positive amplitude.
182960366cfSKarsten Keil */
183960366cfSKarsten Keil u8 dsp_audio_seven2law[128];
184960366cfSKarsten Keil u8 dsp_audio_law2seven[256];
185960366cfSKarsten Keil
186960366cfSKarsten Keil /********************************************************************
187960366cfSKarsten Keil * generate table for conversion law from/to 7-bit alaw-like sample *
188960366cfSKarsten Keil ********************************************************************/
189960366cfSKarsten Keil
190960366cfSKarsten Keil void
dsp_audio_generate_seven(void)191960366cfSKarsten Keil dsp_audio_generate_seven(void)
192960366cfSKarsten Keil {
193960366cfSKarsten Keil int i, j, k;
194960366cfSKarsten Keil u8 spl;
195960366cfSKarsten Keil u8 sorted_alaw[256];
196960366cfSKarsten Keil
197960366cfSKarsten Keil /* generate alaw table, sorted by the linear value */
198960366cfSKarsten Keil for (i = 0; i < 256; i++) {
199960366cfSKarsten Keil j = 0;
200960366cfSKarsten Keil for (k = 0; k < 256; k++) {
201960366cfSKarsten Keil if (dsp_audio_alaw_to_s32[k]
202eac74af9SKarsten Keil < dsp_audio_alaw_to_s32[i])
203960366cfSKarsten Keil j++;
204960366cfSKarsten Keil }
205960366cfSKarsten Keil sorted_alaw[j] = i;
206960366cfSKarsten Keil }
207960366cfSKarsten Keil
208960366cfSKarsten Keil /* generate tabels */
209960366cfSKarsten Keil for (i = 0; i < 256; i++) {
210960366cfSKarsten Keil /* spl is the source: the law-sample (converted to alaw) */
211960366cfSKarsten Keil spl = i;
212960366cfSKarsten Keil if (dsp_options & DSP_OPT_ULAW)
213960366cfSKarsten Keil spl = dsp_audio_ulaw_to_alaw[i];
214960366cfSKarsten Keil /* find the 7-bit-sample */
215960366cfSKarsten Keil for (j = 0; j < 256; j++) {
216960366cfSKarsten Keil if (sorted_alaw[j] == spl)
217960366cfSKarsten Keil break;
218960366cfSKarsten Keil }
219960366cfSKarsten Keil /* write 7-bit audio value */
220960366cfSKarsten Keil dsp_audio_law2seven[i] = j >> 1;
221960366cfSKarsten Keil }
222960366cfSKarsten Keil for (i = 0; i < 128; i++) {
223960366cfSKarsten Keil spl = sorted_alaw[i << 1];
224960366cfSKarsten Keil if (dsp_options & DSP_OPT_ULAW)
225960366cfSKarsten Keil spl = dsp_audio_alaw_to_ulaw[spl];
226960366cfSKarsten Keil dsp_audio_seven2law[i] = spl;
227960366cfSKarsten Keil }
228960366cfSKarsten Keil }
229960366cfSKarsten Keil
230960366cfSKarsten Keil
231960366cfSKarsten Keil /* mix 2*law -> law */
232960366cfSKarsten Keil u8 dsp_audio_mix_law[65536];
233960366cfSKarsten Keil
234960366cfSKarsten Keil /******************************************************
235960366cfSKarsten Keil * generate mix table to mix two law samples into one *
236960366cfSKarsten Keil ******************************************************/
237960366cfSKarsten Keil
238960366cfSKarsten Keil void
dsp_audio_generate_mix_table(void)239960366cfSKarsten Keil dsp_audio_generate_mix_table(void)
240960366cfSKarsten Keil {
241960366cfSKarsten Keil int i, j;
242960366cfSKarsten Keil s32 sample;
243960366cfSKarsten Keil
244960366cfSKarsten Keil i = 0;
245960366cfSKarsten Keil while (i < 256) {
246960366cfSKarsten Keil j = 0;
247960366cfSKarsten Keil while (j < 256) {
248960366cfSKarsten Keil sample = dsp_audio_law_to_s32[i];
249960366cfSKarsten Keil sample += dsp_audio_law_to_s32[j];
250960366cfSKarsten Keil if (sample > 32767)
251960366cfSKarsten Keil sample = 32767;
252960366cfSKarsten Keil if (sample < -32768)
253960366cfSKarsten Keil sample = -32768;
254960366cfSKarsten Keil dsp_audio_mix_law[(i << 8) | j] =
255960366cfSKarsten Keil dsp_audio_s16_to_law[sample & 0xffff];
256960366cfSKarsten Keil j++;
257960366cfSKarsten Keil }
258960366cfSKarsten Keil i++;
259960366cfSKarsten Keil }
260960366cfSKarsten Keil }
261960366cfSKarsten Keil
262960366cfSKarsten Keil
263960366cfSKarsten Keil /*************************************
264960366cfSKarsten Keil * generate different volume changes *
265960366cfSKarsten Keil *************************************/
266960366cfSKarsten Keil
267960366cfSKarsten Keil static u8 dsp_audio_reduce8[256];
268960366cfSKarsten Keil static u8 dsp_audio_reduce7[256];
269960366cfSKarsten Keil static u8 dsp_audio_reduce6[256];
270960366cfSKarsten Keil static u8 dsp_audio_reduce5[256];
271960366cfSKarsten Keil static u8 dsp_audio_reduce4[256];
272960366cfSKarsten Keil static u8 dsp_audio_reduce3[256];
273960366cfSKarsten Keil static u8 dsp_audio_reduce2[256];
274960366cfSKarsten Keil static u8 dsp_audio_reduce1[256];
275960366cfSKarsten Keil static u8 dsp_audio_increase1[256];
276960366cfSKarsten Keil static u8 dsp_audio_increase2[256];
277960366cfSKarsten Keil static u8 dsp_audio_increase3[256];
278960366cfSKarsten Keil static u8 dsp_audio_increase4[256];
279960366cfSKarsten Keil static u8 dsp_audio_increase5[256];
280960366cfSKarsten Keil static u8 dsp_audio_increase6[256];
281960366cfSKarsten Keil static u8 dsp_audio_increase7[256];
282960366cfSKarsten Keil static u8 dsp_audio_increase8[256];
283960366cfSKarsten Keil
284960366cfSKarsten Keil static u8 *dsp_audio_volume_change[16] = {
285960366cfSKarsten Keil dsp_audio_reduce8,
286960366cfSKarsten Keil dsp_audio_reduce7,
287960366cfSKarsten Keil dsp_audio_reduce6,
288960366cfSKarsten Keil dsp_audio_reduce5,
289960366cfSKarsten Keil dsp_audio_reduce4,
290960366cfSKarsten Keil dsp_audio_reduce3,
291960366cfSKarsten Keil dsp_audio_reduce2,
292960366cfSKarsten Keil dsp_audio_reduce1,
293960366cfSKarsten Keil dsp_audio_increase1,
294960366cfSKarsten Keil dsp_audio_increase2,
295960366cfSKarsten Keil dsp_audio_increase3,
296960366cfSKarsten Keil dsp_audio_increase4,
297960366cfSKarsten Keil dsp_audio_increase5,
298960366cfSKarsten Keil dsp_audio_increase6,
299960366cfSKarsten Keil dsp_audio_increase7,
300960366cfSKarsten Keil dsp_audio_increase8,
301960366cfSKarsten Keil };
302960366cfSKarsten Keil
303960366cfSKarsten Keil void
dsp_audio_generate_volume_changes(void)304960366cfSKarsten Keil dsp_audio_generate_volume_changes(void)
305960366cfSKarsten Keil {
306960366cfSKarsten Keil register s32 sample;
307960366cfSKarsten Keil int i;
308960366cfSKarsten Keil int num[] = { 110, 125, 150, 175, 200, 300, 400, 500 };
309960366cfSKarsten Keil int denum[] = { 100, 100, 100, 100, 100, 100, 100, 100 };
310960366cfSKarsten Keil
311960366cfSKarsten Keil i = 0;
312960366cfSKarsten Keil while (i < 256) {
313960366cfSKarsten Keil dsp_audio_reduce8[i] = dsp_audio_s16_to_law[
314960366cfSKarsten Keil (dsp_audio_law_to_s32[i] * denum[7] / num[7]) & 0xffff];
315960366cfSKarsten Keil dsp_audio_reduce7[i] = dsp_audio_s16_to_law[
316960366cfSKarsten Keil (dsp_audio_law_to_s32[i] * denum[6] / num[6]) & 0xffff];
317960366cfSKarsten Keil dsp_audio_reduce6[i] = dsp_audio_s16_to_law[
318960366cfSKarsten Keil (dsp_audio_law_to_s32[i] * denum[5] / num[5]) & 0xffff];
319960366cfSKarsten Keil dsp_audio_reduce5[i] = dsp_audio_s16_to_law[
320960366cfSKarsten Keil (dsp_audio_law_to_s32[i] * denum[4] / num[4]) & 0xffff];
321960366cfSKarsten Keil dsp_audio_reduce4[i] = dsp_audio_s16_to_law[
322960366cfSKarsten Keil (dsp_audio_law_to_s32[i] * denum[3] / num[3]) & 0xffff];
323960366cfSKarsten Keil dsp_audio_reduce3[i] = dsp_audio_s16_to_law[
324960366cfSKarsten Keil (dsp_audio_law_to_s32[i] * denum[2] / num[2]) & 0xffff];
325960366cfSKarsten Keil dsp_audio_reduce2[i] = dsp_audio_s16_to_law[
326960366cfSKarsten Keil (dsp_audio_law_to_s32[i] * denum[1] / num[1]) & 0xffff];
327960366cfSKarsten Keil dsp_audio_reduce1[i] = dsp_audio_s16_to_law[
328960366cfSKarsten Keil (dsp_audio_law_to_s32[i] * denum[0] / num[0]) & 0xffff];
329960366cfSKarsten Keil sample = dsp_audio_law_to_s32[i] * num[0] / denum[0];
330960366cfSKarsten Keil if (sample < -32768)
331960366cfSKarsten Keil sample = -32768;
332960366cfSKarsten Keil else if (sample > 32767)
333960366cfSKarsten Keil sample = 32767;
334960366cfSKarsten Keil dsp_audio_increase1[i] = dsp_audio_s16_to_law[sample & 0xffff];
335960366cfSKarsten Keil sample = dsp_audio_law_to_s32[i] * num[1] / denum[1];
336960366cfSKarsten Keil if (sample < -32768)
337960366cfSKarsten Keil sample = -32768;
338960366cfSKarsten Keil else if (sample > 32767)
339960366cfSKarsten Keil sample = 32767;
340960366cfSKarsten Keil dsp_audio_increase2[i] = dsp_audio_s16_to_law[sample & 0xffff];
341960366cfSKarsten Keil sample = dsp_audio_law_to_s32[i] * num[2] / denum[2];
342960366cfSKarsten Keil if (sample < -32768)
343960366cfSKarsten Keil sample = -32768;
344960366cfSKarsten Keil else if (sample > 32767)
345960366cfSKarsten Keil sample = 32767;
346960366cfSKarsten Keil dsp_audio_increase3[i] = dsp_audio_s16_to_law[sample & 0xffff];
347960366cfSKarsten Keil sample = dsp_audio_law_to_s32[i] * num[3] / denum[3];
348960366cfSKarsten Keil if (sample < -32768)
349960366cfSKarsten Keil sample = -32768;
350960366cfSKarsten Keil else if (sample > 32767)
351960366cfSKarsten Keil sample = 32767;
352960366cfSKarsten Keil dsp_audio_increase4[i] = dsp_audio_s16_to_law[sample & 0xffff];
353960366cfSKarsten Keil sample = dsp_audio_law_to_s32[i] * num[4] / denum[4];
354960366cfSKarsten Keil if (sample < -32768)
355960366cfSKarsten Keil sample = -32768;
356960366cfSKarsten Keil else if (sample > 32767)
357960366cfSKarsten Keil sample = 32767;
358960366cfSKarsten Keil dsp_audio_increase5[i] = dsp_audio_s16_to_law[sample & 0xffff];
359960366cfSKarsten Keil sample = dsp_audio_law_to_s32[i] * num[5] / denum[5];
360960366cfSKarsten Keil if (sample < -32768)
361960366cfSKarsten Keil sample = -32768;
362960366cfSKarsten Keil else if (sample > 32767)
363960366cfSKarsten Keil sample = 32767;
364960366cfSKarsten Keil dsp_audio_increase6[i] = dsp_audio_s16_to_law[sample & 0xffff];
365960366cfSKarsten Keil sample = dsp_audio_law_to_s32[i] * num[6] / denum[6];
366960366cfSKarsten Keil if (sample < -32768)
367960366cfSKarsten Keil sample = -32768;
368960366cfSKarsten Keil else if (sample > 32767)
369960366cfSKarsten Keil sample = 32767;
370960366cfSKarsten Keil dsp_audio_increase7[i] = dsp_audio_s16_to_law[sample & 0xffff];
371960366cfSKarsten Keil sample = dsp_audio_law_to_s32[i] * num[7] / denum[7];
372960366cfSKarsten Keil if (sample < -32768)
373960366cfSKarsten Keil sample = -32768;
374960366cfSKarsten Keil else if (sample > 32767)
375960366cfSKarsten Keil sample = 32767;
376960366cfSKarsten Keil dsp_audio_increase8[i] = dsp_audio_s16_to_law[sample & 0xffff];
377960366cfSKarsten Keil
378960366cfSKarsten Keil i++;
379960366cfSKarsten Keil }
380960366cfSKarsten Keil }
381960366cfSKarsten Keil
382960366cfSKarsten Keil
383960366cfSKarsten Keil /**************************************
384960366cfSKarsten Keil * change the volume of the given skb *
385960366cfSKarsten Keil **************************************/
386960366cfSKarsten Keil
387960366cfSKarsten Keil /* this is a helper function for changing volume of skb. the range may be
388960366cfSKarsten Keil * -8 to 8, which is a shift to the power of 2. 0 == no volume, 3 == volume*8
389960366cfSKarsten Keil */
390960366cfSKarsten Keil void
dsp_change_volume(struct sk_buff * skb,int volume)391960366cfSKarsten Keil dsp_change_volume(struct sk_buff *skb, int volume)
392960366cfSKarsten Keil {
393960366cfSKarsten Keil u8 *volume_change;
394960366cfSKarsten Keil int i, ii;
395960366cfSKarsten Keil u8 *p;
396960366cfSKarsten Keil int shift;
397960366cfSKarsten Keil
398960366cfSKarsten Keil if (volume == 0)
399960366cfSKarsten Keil return;
400960366cfSKarsten Keil
401960366cfSKarsten Keil /* get correct conversion table */
402960366cfSKarsten Keil if (volume < 0) {
403960366cfSKarsten Keil shift = volume + 8;
404960366cfSKarsten Keil if (shift < 0)
405960366cfSKarsten Keil shift = 0;
406960366cfSKarsten Keil } else {
407960366cfSKarsten Keil shift = volume + 7;
408960366cfSKarsten Keil if (shift > 15)
409960366cfSKarsten Keil shift = 15;
410960366cfSKarsten Keil }
411960366cfSKarsten Keil volume_change = dsp_audio_volume_change[shift];
412960366cfSKarsten Keil i = 0;
413960366cfSKarsten Keil ii = skb->len;
414960366cfSKarsten Keil p = skb->data;
415960366cfSKarsten Keil /* change volume */
416960366cfSKarsten Keil while (i < ii) {
417960366cfSKarsten Keil *p = volume_change[*p];
418960366cfSKarsten Keil p++;
419960366cfSKarsten Keil i++;
420960366cfSKarsten Keil }
421960366cfSKarsten Keil }
422