18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Audio support data for mISDN_dsp.
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Copyright 2002/2003 by Andreas Eversberg (jolly@eversberg.eu)
58c2ecf20Sopenharmony_ci * Rewritten by Peter
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * This software may be used and distributed according to the terms
88c2ecf20Sopenharmony_ci * of the GNU General Public License, incorporated herein by reference.
98c2ecf20Sopenharmony_ci *
108c2ecf20Sopenharmony_ci */
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#include <linux/delay.h>
138c2ecf20Sopenharmony_ci#include <linux/mISDNif.h>
148c2ecf20Sopenharmony_ci#include <linux/mISDNdsp.h>
158c2ecf20Sopenharmony_ci#include <linux/export.h>
168c2ecf20Sopenharmony_ci#include <linux/bitrev.h>
178c2ecf20Sopenharmony_ci#include "core.h"
188c2ecf20Sopenharmony_ci#include "dsp.h"
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci/* ulaw[unsigned char] -> signed 16-bit */
218c2ecf20Sopenharmony_cis32 dsp_audio_ulaw_to_s32[256];
228c2ecf20Sopenharmony_ci/* alaw[unsigned char] -> signed 16-bit */
238c2ecf20Sopenharmony_cis32 dsp_audio_alaw_to_s32[256];
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_cis32 *dsp_audio_law_to_s32;
268c2ecf20Sopenharmony_ciEXPORT_SYMBOL(dsp_audio_law_to_s32);
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci/* signed 16-bit -> law */
298c2ecf20Sopenharmony_ciu8 dsp_audio_s16_to_law[65536];
308c2ecf20Sopenharmony_ciEXPORT_SYMBOL(dsp_audio_s16_to_law);
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci/* alaw -> ulaw */
338c2ecf20Sopenharmony_ciu8 dsp_audio_alaw_to_ulaw[256];
348c2ecf20Sopenharmony_ci/* ulaw -> alaw */
358c2ecf20Sopenharmony_cistatic u8 dsp_audio_ulaw_to_alaw[256];
368c2ecf20Sopenharmony_ciu8 dsp_silence;
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci/*****************************************************
408c2ecf20Sopenharmony_ci * generate table for conversion of s16 to alaw/ulaw *
418c2ecf20Sopenharmony_ci *****************************************************/
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci#define AMI_MASK 0x55
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_cistatic inline unsigned char linear2alaw(short int linear)
468c2ecf20Sopenharmony_ci{
478c2ecf20Sopenharmony_ci	int mask;
488c2ecf20Sopenharmony_ci	int seg;
498c2ecf20Sopenharmony_ci	int pcm_val;
508c2ecf20Sopenharmony_ci	static int seg_end[8] = {
518c2ecf20Sopenharmony_ci		0xFF, 0x1FF, 0x3FF, 0x7FF, 0xFFF, 0x1FFF, 0x3FFF, 0x7FFF
528c2ecf20Sopenharmony_ci	};
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci	pcm_val = linear;
558c2ecf20Sopenharmony_ci	if (pcm_val >= 0) {
568c2ecf20Sopenharmony_ci		/* Sign (7th) bit = 1 */
578c2ecf20Sopenharmony_ci		mask = AMI_MASK | 0x80;
588c2ecf20Sopenharmony_ci	} else {
598c2ecf20Sopenharmony_ci		/* Sign bit = 0 */
608c2ecf20Sopenharmony_ci		mask = AMI_MASK;
618c2ecf20Sopenharmony_ci		pcm_val = -pcm_val;
628c2ecf20Sopenharmony_ci	}
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci	/* Convert the scaled magnitude to segment number. */
658c2ecf20Sopenharmony_ci	for (seg = 0; seg < 8; seg++) {
668c2ecf20Sopenharmony_ci		if (pcm_val <= seg_end[seg])
678c2ecf20Sopenharmony_ci			break;
688c2ecf20Sopenharmony_ci	}
698c2ecf20Sopenharmony_ci	/* Combine the sign, segment, and quantization bits. */
708c2ecf20Sopenharmony_ci	return  ((seg << 4) |
718c2ecf20Sopenharmony_ci		 ((pcm_val >> ((seg)  ?  (seg + 3)  :  4)) & 0x0F)) ^ mask;
728c2ecf20Sopenharmony_ci}
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_cistatic inline short int alaw2linear(unsigned char alaw)
768c2ecf20Sopenharmony_ci{
778c2ecf20Sopenharmony_ci	int i;
788c2ecf20Sopenharmony_ci	int seg;
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci	alaw ^= AMI_MASK;
818c2ecf20Sopenharmony_ci	i = ((alaw & 0x0F) << 4) + 8 /* rounding error */;
828c2ecf20Sopenharmony_ci	seg = (((int) alaw & 0x70) >> 4);
838c2ecf20Sopenharmony_ci	if (seg)
848c2ecf20Sopenharmony_ci		i = (i + 0x100) << (seg - 1);
858c2ecf20Sopenharmony_ci	return (short int) ((alaw & 0x80)  ?  i  :  -i);
868c2ecf20Sopenharmony_ci}
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_cistatic inline short int ulaw2linear(unsigned char ulaw)
898c2ecf20Sopenharmony_ci{
908c2ecf20Sopenharmony_ci	short mu, e, f, y;
918c2ecf20Sopenharmony_ci	static short etab[] = {0, 132, 396, 924, 1980, 4092, 8316, 16764};
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci	mu = 255 - ulaw;
948c2ecf20Sopenharmony_ci	e = (mu & 0x70) / 16;
958c2ecf20Sopenharmony_ci	f = mu & 0x0f;
968c2ecf20Sopenharmony_ci	y = f * (1 << (e + 3));
978c2ecf20Sopenharmony_ci	y += etab[e];
988c2ecf20Sopenharmony_ci	if (mu & 0x80)
998c2ecf20Sopenharmony_ci		y = -y;
1008c2ecf20Sopenharmony_ci	return y;
1018c2ecf20Sopenharmony_ci}
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci#define BIAS 0x84   /*!< define the add-in bias for 16 bit samples */
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_cistatic unsigned char linear2ulaw(short sample)
1068c2ecf20Sopenharmony_ci{
1078c2ecf20Sopenharmony_ci	static int exp_lut[256] = {
1088c2ecf20Sopenharmony_ci		0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
1098c2ecf20Sopenharmony_ci		4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
1108c2ecf20Sopenharmony_ci		5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
1118c2ecf20Sopenharmony_ci		5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
1128c2ecf20Sopenharmony_ci		6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
1138c2ecf20Sopenharmony_ci		6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
1148c2ecf20Sopenharmony_ci		6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
1158c2ecf20Sopenharmony_ci		6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
1168c2ecf20Sopenharmony_ci		7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
1178c2ecf20Sopenharmony_ci		7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
1188c2ecf20Sopenharmony_ci		7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
1198c2ecf20Sopenharmony_ci		7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
1208c2ecf20Sopenharmony_ci		7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
1218c2ecf20Sopenharmony_ci		7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
1228c2ecf20Sopenharmony_ci		7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
1238c2ecf20Sopenharmony_ci		7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7};
1248c2ecf20Sopenharmony_ci	int sign, exponent, mantissa;
1258c2ecf20Sopenharmony_ci	unsigned char ulawbyte;
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ci	/* Get the sample into sign-magnitude. */
1288c2ecf20Sopenharmony_ci	sign = (sample >> 8) & 0x80;	  /* set aside the sign */
1298c2ecf20Sopenharmony_ci	if (sign != 0)
1308c2ecf20Sopenharmony_ci		sample = -sample;	      /* get magnitude */
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_ci	/* Convert from 16 bit linear to ulaw. */
1338c2ecf20Sopenharmony_ci	sample = sample + BIAS;
1348c2ecf20Sopenharmony_ci	exponent = exp_lut[(sample >> 7) & 0xFF];
1358c2ecf20Sopenharmony_ci	mantissa = (sample >> (exponent + 3)) & 0x0F;
1368c2ecf20Sopenharmony_ci	ulawbyte = ~(sign | (exponent << 4) | mantissa);
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci	return ulawbyte;
1398c2ecf20Sopenharmony_ci}
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_civoid dsp_audio_generate_law_tables(void)
1428c2ecf20Sopenharmony_ci{
1438c2ecf20Sopenharmony_ci	int i;
1448c2ecf20Sopenharmony_ci	for (i = 0; i < 256; i++)
1458c2ecf20Sopenharmony_ci		dsp_audio_alaw_to_s32[i] = alaw2linear(bitrev8((u8)i));
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ci	for (i = 0; i < 256; i++)
1488c2ecf20Sopenharmony_ci		dsp_audio_ulaw_to_s32[i] = ulaw2linear(bitrev8((u8)i));
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ci	for (i = 0; i < 256; i++) {
1518c2ecf20Sopenharmony_ci		dsp_audio_alaw_to_ulaw[i] =
1528c2ecf20Sopenharmony_ci			linear2ulaw(dsp_audio_alaw_to_s32[i]);
1538c2ecf20Sopenharmony_ci		dsp_audio_ulaw_to_alaw[i] =
1548c2ecf20Sopenharmony_ci			linear2alaw(dsp_audio_ulaw_to_s32[i]);
1558c2ecf20Sopenharmony_ci	}
1568c2ecf20Sopenharmony_ci}
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_civoid
1598c2ecf20Sopenharmony_cidsp_audio_generate_s2law_table(void)
1608c2ecf20Sopenharmony_ci{
1618c2ecf20Sopenharmony_ci	int i;
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_ci	if (dsp_options & DSP_OPT_ULAW) {
1648c2ecf20Sopenharmony_ci		/* generating ulaw-table */
1658c2ecf20Sopenharmony_ci		for (i = -32768; i < 32768; i++) {
1668c2ecf20Sopenharmony_ci			dsp_audio_s16_to_law[i & 0xffff] =
1678c2ecf20Sopenharmony_ci				bitrev8(linear2ulaw(i));
1688c2ecf20Sopenharmony_ci		}
1698c2ecf20Sopenharmony_ci	} else {
1708c2ecf20Sopenharmony_ci		/* generating alaw-table */
1718c2ecf20Sopenharmony_ci		for (i = -32768; i < 32768; i++) {
1728c2ecf20Sopenharmony_ci			dsp_audio_s16_to_law[i & 0xffff] =
1738c2ecf20Sopenharmony_ci				bitrev8(linear2alaw(i));
1748c2ecf20Sopenharmony_ci		}
1758c2ecf20Sopenharmony_ci	}
1768c2ecf20Sopenharmony_ci}
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ci
1798c2ecf20Sopenharmony_ci/*
1808c2ecf20Sopenharmony_ci * the seven bit sample is the number of every second alaw-sample ordered by
1818c2ecf20Sopenharmony_ci * aplitude. 0x00 is negative, 0x7f is positive amplitude.
1828c2ecf20Sopenharmony_ci */
1838c2ecf20Sopenharmony_ciu8 dsp_audio_seven2law[128];
1848c2ecf20Sopenharmony_ciu8 dsp_audio_law2seven[256];
1858c2ecf20Sopenharmony_ci
1868c2ecf20Sopenharmony_ci/********************************************************************
1878c2ecf20Sopenharmony_ci * generate table for conversion law from/to 7-bit alaw-like sample *
1888c2ecf20Sopenharmony_ci ********************************************************************/
1898c2ecf20Sopenharmony_ci
1908c2ecf20Sopenharmony_civoid
1918c2ecf20Sopenharmony_cidsp_audio_generate_seven(void)
1928c2ecf20Sopenharmony_ci{
1938c2ecf20Sopenharmony_ci	int i, j, k;
1948c2ecf20Sopenharmony_ci	u8 spl;
1958c2ecf20Sopenharmony_ci	u8 sorted_alaw[256];
1968c2ecf20Sopenharmony_ci
1978c2ecf20Sopenharmony_ci	/* generate alaw table, sorted by the linear value */
1988c2ecf20Sopenharmony_ci	for (i = 0; i < 256; i++) {
1998c2ecf20Sopenharmony_ci		j = 0;
2008c2ecf20Sopenharmony_ci		for (k = 0; k < 256; k++) {
2018c2ecf20Sopenharmony_ci			if (dsp_audio_alaw_to_s32[k]
2028c2ecf20Sopenharmony_ci			    < dsp_audio_alaw_to_s32[i])
2038c2ecf20Sopenharmony_ci				j++;
2048c2ecf20Sopenharmony_ci		}
2058c2ecf20Sopenharmony_ci		sorted_alaw[j] = i;
2068c2ecf20Sopenharmony_ci	}
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_ci	/* generate tabels */
2098c2ecf20Sopenharmony_ci	for (i = 0; i < 256; i++) {
2108c2ecf20Sopenharmony_ci		/* spl is the source: the law-sample (converted to alaw) */
2118c2ecf20Sopenharmony_ci		spl = i;
2128c2ecf20Sopenharmony_ci		if (dsp_options & DSP_OPT_ULAW)
2138c2ecf20Sopenharmony_ci			spl = dsp_audio_ulaw_to_alaw[i];
2148c2ecf20Sopenharmony_ci		/* find the 7-bit-sample */
2158c2ecf20Sopenharmony_ci		for (j = 0; j < 256; j++) {
2168c2ecf20Sopenharmony_ci			if (sorted_alaw[j] == spl)
2178c2ecf20Sopenharmony_ci				break;
2188c2ecf20Sopenharmony_ci		}
2198c2ecf20Sopenharmony_ci		/* write 7-bit audio value */
2208c2ecf20Sopenharmony_ci		dsp_audio_law2seven[i] = j >> 1;
2218c2ecf20Sopenharmony_ci	}
2228c2ecf20Sopenharmony_ci	for (i = 0; i < 128; i++) {
2238c2ecf20Sopenharmony_ci		spl = sorted_alaw[i << 1];
2248c2ecf20Sopenharmony_ci		if (dsp_options & DSP_OPT_ULAW)
2258c2ecf20Sopenharmony_ci			spl = dsp_audio_alaw_to_ulaw[spl];
2268c2ecf20Sopenharmony_ci		dsp_audio_seven2law[i] = spl;
2278c2ecf20Sopenharmony_ci	}
2288c2ecf20Sopenharmony_ci}
2298c2ecf20Sopenharmony_ci
2308c2ecf20Sopenharmony_ci
2318c2ecf20Sopenharmony_ci/* mix 2*law -> law */
2328c2ecf20Sopenharmony_ciu8 dsp_audio_mix_law[65536];
2338c2ecf20Sopenharmony_ci
2348c2ecf20Sopenharmony_ci/******************************************************
2358c2ecf20Sopenharmony_ci * generate mix table to mix two law samples into one *
2368c2ecf20Sopenharmony_ci ******************************************************/
2378c2ecf20Sopenharmony_ci
2388c2ecf20Sopenharmony_civoid
2398c2ecf20Sopenharmony_cidsp_audio_generate_mix_table(void)
2408c2ecf20Sopenharmony_ci{
2418c2ecf20Sopenharmony_ci	int i, j;
2428c2ecf20Sopenharmony_ci	s32 sample;
2438c2ecf20Sopenharmony_ci
2448c2ecf20Sopenharmony_ci	i = 0;
2458c2ecf20Sopenharmony_ci	while (i < 256) {
2468c2ecf20Sopenharmony_ci		j = 0;
2478c2ecf20Sopenharmony_ci		while (j < 256) {
2488c2ecf20Sopenharmony_ci			sample = dsp_audio_law_to_s32[i];
2498c2ecf20Sopenharmony_ci			sample += dsp_audio_law_to_s32[j];
2508c2ecf20Sopenharmony_ci			if (sample > 32767)
2518c2ecf20Sopenharmony_ci				sample = 32767;
2528c2ecf20Sopenharmony_ci			if (sample < -32768)
2538c2ecf20Sopenharmony_ci				sample = -32768;
2548c2ecf20Sopenharmony_ci			dsp_audio_mix_law[(i << 8) | j] =
2558c2ecf20Sopenharmony_ci				dsp_audio_s16_to_law[sample & 0xffff];
2568c2ecf20Sopenharmony_ci			j++;
2578c2ecf20Sopenharmony_ci		}
2588c2ecf20Sopenharmony_ci		i++;
2598c2ecf20Sopenharmony_ci	}
2608c2ecf20Sopenharmony_ci}
2618c2ecf20Sopenharmony_ci
2628c2ecf20Sopenharmony_ci
2638c2ecf20Sopenharmony_ci/*************************************
2648c2ecf20Sopenharmony_ci * generate different volume changes *
2658c2ecf20Sopenharmony_ci *************************************/
2668c2ecf20Sopenharmony_ci
2678c2ecf20Sopenharmony_cistatic u8 dsp_audio_reduce8[256];
2688c2ecf20Sopenharmony_cistatic u8 dsp_audio_reduce7[256];
2698c2ecf20Sopenharmony_cistatic u8 dsp_audio_reduce6[256];
2708c2ecf20Sopenharmony_cistatic u8 dsp_audio_reduce5[256];
2718c2ecf20Sopenharmony_cistatic u8 dsp_audio_reduce4[256];
2728c2ecf20Sopenharmony_cistatic u8 dsp_audio_reduce3[256];
2738c2ecf20Sopenharmony_cistatic u8 dsp_audio_reduce2[256];
2748c2ecf20Sopenharmony_cistatic u8 dsp_audio_reduce1[256];
2758c2ecf20Sopenharmony_cistatic u8 dsp_audio_increase1[256];
2768c2ecf20Sopenharmony_cistatic u8 dsp_audio_increase2[256];
2778c2ecf20Sopenharmony_cistatic u8 dsp_audio_increase3[256];
2788c2ecf20Sopenharmony_cistatic u8 dsp_audio_increase4[256];
2798c2ecf20Sopenharmony_cistatic u8 dsp_audio_increase5[256];
2808c2ecf20Sopenharmony_cistatic u8 dsp_audio_increase6[256];
2818c2ecf20Sopenharmony_cistatic u8 dsp_audio_increase7[256];
2828c2ecf20Sopenharmony_cistatic u8 dsp_audio_increase8[256];
2838c2ecf20Sopenharmony_ci
2848c2ecf20Sopenharmony_cistatic u8 *dsp_audio_volume_change[16] = {
2858c2ecf20Sopenharmony_ci	dsp_audio_reduce8,
2868c2ecf20Sopenharmony_ci	dsp_audio_reduce7,
2878c2ecf20Sopenharmony_ci	dsp_audio_reduce6,
2888c2ecf20Sopenharmony_ci	dsp_audio_reduce5,
2898c2ecf20Sopenharmony_ci	dsp_audio_reduce4,
2908c2ecf20Sopenharmony_ci	dsp_audio_reduce3,
2918c2ecf20Sopenharmony_ci	dsp_audio_reduce2,
2928c2ecf20Sopenharmony_ci	dsp_audio_reduce1,
2938c2ecf20Sopenharmony_ci	dsp_audio_increase1,
2948c2ecf20Sopenharmony_ci	dsp_audio_increase2,
2958c2ecf20Sopenharmony_ci	dsp_audio_increase3,
2968c2ecf20Sopenharmony_ci	dsp_audio_increase4,
2978c2ecf20Sopenharmony_ci	dsp_audio_increase5,
2988c2ecf20Sopenharmony_ci	dsp_audio_increase6,
2998c2ecf20Sopenharmony_ci	dsp_audio_increase7,
3008c2ecf20Sopenharmony_ci	dsp_audio_increase8,
3018c2ecf20Sopenharmony_ci};
3028c2ecf20Sopenharmony_ci
3038c2ecf20Sopenharmony_civoid
3048c2ecf20Sopenharmony_cidsp_audio_generate_volume_changes(void)
3058c2ecf20Sopenharmony_ci{
3068c2ecf20Sopenharmony_ci	register s32 sample;
3078c2ecf20Sopenharmony_ci	int i;
3088c2ecf20Sopenharmony_ci	int num[]   = { 110, 125, 150, 175, 200, 300, 400, 500 };
3098c2ecf20Sopenharmony_ci	int denum[] = { 100, 100, 100, 100, 100, 100, 100, 100 };
3108c2ecf20Sopenharmony_ci
3118c2ecf20Sopenharmony_ci	i = 0;
3128c2ecf20Sopenharmony_ci	while (i < 256) {
3138c2ecf20Sopenharmony_ci		dsp_audio_reduce8[i] = dsp_audio_s16_to_law[
3148c2ecf20Sopenharmony_ci			(dsp_audio_law_to_s32[i] * denum[7] / num[7]) & 0xffff];
3158c2ecf20Sopenharmony_ci		dsp_audio_reduce7[i] = dsp_audio_s16_to_law[
3168c2ecf20Sopenharmony_ci			(dsp_audio_law_to_s32[i] * denum[6] / num[6]) & 0xffff];
3178c2ecf20Sopenharmony_ci		dsp_audio_reduce6[i] = dsp_audio_s16_to_law[
3188c2ecf20Sopenharmony_ci			(dsp_audio_law_to_s32[i] * denum[5] / num[5]) & 0xffff];
3198c2ecf20Sopenharmony_ci		dsp_audio_reduce5[i] = dsp_audio_s16_to_law[
3208c2ecf20Sopenharmony_ci			(dsp_audio_law_to_s32[i] * denum[4] / num[4]) & 0xffff];
3218c2ecf20Sopenharmony_ci		dsp_audio_reduce4[i] = dsp_audio_s16_to_law[
3228c2ecf20Sopenharmony_ci			(dsp_audio_law_to_s32[i] * denum[3] / num[3]) & 0xffff];
3238c2ecf20Sopenharmony_ci		dsp_audio_reduce3[i] = dsp_audio_s16_to_law[
3248c2ecf20Sopenharmony_ci			(dsp_audio_law_to_s32[i] * denum[2] / num[2]) & 0xffff];
3258c2ecf20Sopenharmony_ci		dsp_audio_reduce2[i] = dsp_audio_s16_to_law[
3268c2ecf20Sopenharmony_ci			(dsp_audio_law_to_s32[i] * denum[1] / num[1]) & 0xffff];
3278c2ecf20Sopenharmony_ci		dsp_audio_reduce1[i] = dsp_audio_s16_to_law[
3288c2ecf20Sopenharmony_ci			(dsp_audio_law_to_s32[i] * denum[0] / num[0]) & 0xffff];
3298c2ecf20Sopenharmony_ci		sample = dsp_audio_law_to_s32[i] * num[0] / denum[0];
3308c2ecf20Sopenharmony_ci		if (sample < -32768)
3318c2ecf20Sopenharmony_ci			sample = -32768;
3328c2ecf20Sopenharmony_ci		else if (sample > 32767)
3338c2ecf20Sopenharmony_ci			sample = 32767;
3348c2ecf20Sopenharmony_ci		dsp_audio_increase1[i] = dsp_audio_s16_to_law[sample & 0xffff];
3358c2ecf20Sopenharmony_ci		sample = dsp_audio_law_to_s32[i] * num[1] / denum[1];
3368c2ecf20Sopenharmony_ci		if (sample < -32768)
3378c2ecf20Sopenharmony_ci			sample = -32768;
3388c2ecf20Sopenharmony_ci		else if (sample > 32767)
3398c2ecf20Sopenharmony_ci			sample = 32767;
3408c2ecf20Sopenharmony_ci		dsp_audio_increase2[i] = dsp_audio_s16_to_law[sample & 0xffff];
3418c2ecf20Sopenharmony_ci		sample = dsp_audio_law_to_s32[i] * num[2] / denum[2];
3428c2ecf20Sopenharmony_ci		if (sample < -32768)
3438c2ecf20Sopenharmony_ci			sample = -32768;
3448c2ecf20Sopenharmony_ci		else if (sample > 32767)
3458c2ecf20Sopenharmony_ci			sample = 32767;
3468c2ecf20Sopenharmony_ci		dsp_audio_increase3[i] = dsp_audio_s16_to_law[sample & 0xffff];
3478c2ecf20Sopenharmony_ci		sample = dsp_audio_law_to_s32[i] * num[3] / denum[3];
3488c2ecf20Sopenharmony_ci		if (sample < -32768)
3498c2ecf20Sopenharmony_ci			sample = -32768;
3508c2ecf20Sopenharmony_ci		else if (sample > 32767)
3518c2ecf20Sopenharmony_ci			sample = 32767;
3528c2ecf20Sopenharmony_ci		dsp_audio_increase4[i] = dsp_audio_s16_to_law[sample & 0xffff];
3538c2ecf20Sopenharmony_ci		sample = dsp_audio_law_to_s32[i] * num[4] / denum[4];
3548c2ecf20Sopenharmony_ci		if (sample < -32768)
3558c2ecf20Sopenharmony_ci			sample = -32768;
3568c2ecf20Sopenharmony_ci		else if (sample > 32767)
3578c2ecf20Sopenharmony_ci			sample = 32767;
3588c2ecf20Sopenharmony_ci		dsp_audio_increase5[i] = dsp_audio_s16_to_law[sample & 0xffff];
3598c2ecf20Sopenharmony_ci		sample = dsp_audio_law_to_s32[i] * num[5] / denum[5];
3608c2ecf20Sopenharmony_ci		if (sample < -32768)
3618c2ecf20Sopenharmony_ci			sample = -32768;
3628c2ecf20Sopenharmony_ci		else if (sample > 32767)
3638c2ecf20Sopenharmony_ci			sample = 32767;
3648c2ecf20Sopenharmony_ci		dsp_audio_increase6[i] = dsp_audio_s16_to_law[sample & 0xffff];
3658c2ecf20Sopenharmony_ci		sample = dsp_audio_law_to_s32[i] * num[6] / denum[6];
3668c2ecf20Sopenharmony_ci		if (sample < -32768)
3678c2ecf20Sopenharmony_ci			sample = -32768;
3688c2ecf20Sopenharmony_ci		else if (sample > 32767)
3698c2ecf20Sopenharmony_ci			sample = 32767;
3708c2ecf20Sopenharmony_ci		dsp_audio_increase7[i] = dsp_audio_s16_to_law[sample & 0xffff];
3718c2ecf20Sopenharmony_ci		sample = dsp_audio_law_to_s32[i] * num[7] / denum[7];
3728c2ecf20Sopenharmony_ci		if (sample < -32768)
3738c2ecf20Sopenharmony_ci			sample = -32768;
3748c2ecf20Sopenharmony_ci		else if (sample > 32767)
3758c2ecf20Sopenharmony_ci			sample = 32767;
3768c2ecf20Sopenharmony_ci		dsp_audio_increase8[i] = dsp_audio_s16_to_law[sample & 0xffff];
3778c2ecf20Sopenharmony_ci
3788c2ecf20Sopenharmony_ci		i++;
3798c2ecf20Sopenharmony_ci	}
3808c2ecf20Sopenharmony_ci}
3818c2ecf20Sopenharmony_ci
3828c2ecf20Sopenharmony_ci
3838c2ecf20Sopenharmony_ci/**************************************
3848c2ecf20Sopenharmony_ci * change the volume of the given skb *
3858c2ecf20Sopenharmony_ci **************************************/
3868c2ecf20Sopenharmony_ci
3878c2ecf20Sopenharmony_ci/* this is a helper function for changing volume of skb. the range may be
3888c2ecf20Sopenharmony_ci * -8 to 8, which is a shift to the power of 2. 0 == no volume, 3 == volume*8
3898c2ecf20Sopenharmony_ci */
3908c2ecf20Sopenharmony_civoid
3918c2ecf20Sopenharmony_cidsp_change_volume(struct sk_buff *skb, int volume)
3928c2ecf20Sopenharmony_ci{
3938c2ecf20Sopenharmony_ci	u8 *volume_change;
3948c2ecf20Sopenharmony_ci	int i, ii;
3958c2ecf20Sopenharmony_ci	u8 *p;
3968c2ecf20Sopenharmony_ci	int shift;
3978c2ecf20Sopenharmony_ci
3988c2ecf20Sopenharmony_ci	if (volume == 0)
3998c2ecf20Sopenharmony_ci		return;
4008c2ecf20Sopenharmony_ci
4018c2ecf20Sopenharmony_ci	/* get correct conversion table */
4028c2ecf20Sopenharmony_ci	if (volume < 0) {
4038c2ecf20Sopenharmony_ci		shift = volume + 8;
4048c2ecf20Sopenharmony_ci		if (shift < 0)
4058c2ecf20Sopenharmony_ci			shift = 0;
4068c2ecf20Sopenharmony_ci	} else {
4078c2ecf20Sopenharmony_ci		shift = volume + 7;
4088c2ecf20Sopenharmony_ci		if (shift > 15)
4098c2ecf20Sopenharmony_ci			shift = 15;
4108c2ecf20Sopenharmony_ci	}
4118c2ecf20Sopenharmony_ci	volume_change = dsp_audio_volume_change[shift];
4128c2ecf20Sopenharmony_ci	i = 0;
4138c2ecf20Sopenharmony_ci	ii = skb->len;
4148c2ecf20Sopenharmony_ci	p = skb->data;
4158c2ecf20Sopenharmony_ci	/* change volume */
4168c2ecf20Sopenharmony_ci	while (i < ii) {
4178c2ecf20Sopenharmony_ci		*p = volume_change[*p];
4188c2ecf20Sopenharmony_ci		p++;
4198c2ecf20Sopenharmony_ci		i++;
4208c2ecf20Sopenharmony_ci	}
4218c2ecf20Sopenharmony_ci}
422