15 #include <linux/export.h>
34 static u8 dsp_audio_ulaw_to_alaw[256];
44 static inline unsigned char linear2alaw(
short int linear)
49 static int seg_end[8] = {
50 0xFF, 0x1FF, 0x3FF, 0x7FF, 0xFFF, 0x1FFF, 0x3FFF, 0x7FFF
64 for (seg = 0; seg < 8; seg++) {
65 if (pcm_val <= seg_end[seg])
70 ((pcm_val >> ((seg) ? (seg + 3) : 4)) & 0x0F)) ^
mask;
74 static inline short int alaw2linear(
unsigned char alaw)
80 i = ((alaw & 0x0F) << 4) + 8 ;
81 seg = (((
int) alaw & 0x70) >> 4);
83 i = (i + 0x100) << (seg - 1);
84 return (
short int) ((alaw & 0x80) ? i : -i);
87 static inline short int ulaw2linear(
unsigned char ulaw)
90 static short etab[] = {0, 132, 396, 924, 1980, 4092, 8316, 16764};
95 y = f * (1 << (e + 3));
104 static unsigned char linear2ulaw(short sample)
106 static int exp_lut[256] = {
107 0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
108 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
109 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
110 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
111 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
112 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
113 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
114 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
115 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
116 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
117 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
118 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
119 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
120 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
121 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
122 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7};
124 unsigned char ulawbyte;
127 sign = (
sample >> 8) & 0x80;
133 exponent = exp_lut[(
sample >> 7) & 0xFF];
134 mantissa = (
sample >> (exponent + 3)) & 0x0F;
135 ulawbyte = ~(sign | (exponent << 4) | mantissa);
140 static int reverse_bits(
int i)
145 for (j = 0; j < 8; j++) {
146 if ((i & (1 << j)) != 0)
156 for (i = 0; i < 256; i++)
159 for (i = 0; i < 256; i++)
162 for (i = 0; i < 256; i++) {
165 dsp_audio_ulaw_to_alaw[
i] =
177 for (i = -32768; i < 32768; i++) {
179 reverse_bits(linear2ulaw(i));
183 for (i = -32768; i < 32768; i++) {
185 reverse_bits(linear2alaw(i));
210 for (i = 0; i < 256; i++) {
212 for (k = 0; k < 256; k++) {
221 for (i = 0; i < 256; i++) {
225 spl = dsp_audio_ulaw_to_alaw[
i];
227 for (j = 0; j < 256; j++) {
228 if (sorted_alaw[j] == spl)
232 dsp_audio_law2seven[
i] = j >> 1;
234 for (i = 0; i < 128; i++) {
235 spl = sorted_alaw[i << 1];
238 dsp_audio_seven2law[
i] = spl;
266 dsp_audio_mix_law[(i << 8) | j] =
279 static u8 dsp_audio_reduce8[256];
280 static u8 dsp_audio_reduce7[256];
281 static u8 dsp_audio_reduce6[256];
282 static u8 dsp_audio_reduce5[256];
283 static u8 dsp_audio_reduce4[256];
284 static u8 dsp_audio_reduce3[256];
285 static u8 dsp_audio_reduce2[256];
286 static u8 dsp_audio_reduce1[256];
287 static u8 dsp_audio_increase1[256];
288 static u8 dsp_audio_increase2[256];
289 static u8 dsp_audio_increase3[256];
290 static u8 dsp_audio_increase4[256];
291 static u8 dsp_audio_increase5[256];
292 static u8 dsp_audio_increase6[256];
293 static u8 dsp_audio_increase7[256];
294 static u8 dsp_audio_increase8[256];
296 static u8 *dsp_audio_volume_change[16] = {
320 int num[] = { 110, 125, 150, 175, 200, 300, 400, 500 };
321 int denum[] = { 100, 100, 100, 100, 100, 100, 100, 100 };
344 else if (sample > 32767)
350 else if (sample > 32767)
356 else if (sample > 32767)
362 else if (sample > 32767)
368 else if (sample > 32767)
374 else if (sample > 32767)
380 else if (sample > 32767)
386 else if (sample > 32767)
423 volume_change = dsp_audio_volume_change[shift];
429 *p = volume_change[*
p];