diff options
author | Alexandre Ratchov <ratchov@cvs.openbsd.org> | 2015-05-11 06:46:23 +0000 |
---|---|---|
committer | Alexandre Ratchov <ratchov@cvs.openbsd.org> | 2015-05-11 06:46:23 +0000 |
commit | cb499c42facd77434ebac9a75c6bd41df9f1ed9d (patch) | |
tree | cc19762f9b558b3e3639e919167faf31200d4068 /sys/dev/mulaw.c | |
parent | e7adfc42b4982d81907aac13902bddc965027d8d (diff) |
Remove all audio format conversion code from the kernel (btw holding
the kernel_lock), as we already do better conversions in
user-mode. Yet, no need for every single driver to fiddle with the
conversion code as they are done transparently by common MI code. With
help from armani and miod, support from mpi
ok armani@
Diffstat (limited to 'sys/dev/mulaw.c')
-rw-r--r-- | sys/dev/mulaw.c | 415 |
1 files changed, 11 insertions, 404 deletions
diff --git a/sys/dev/mulaw.c b/sys/dev/mulaw.c index c2a340c1f68..36477f319e0 100644 --- a/sys/dev/mulaw.c +++ b/sys/dev/mulaw.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mulaw.c,v 1.15 2015/03/14 03:38:46 jsg Exp $ */ +/* $OpenBSD: mulaw.c,v 1.16 2015/05/11 06:46:21 ratchov Exp $ */ /* $NetBSD: mulaw.c,v 1.15 2001/01/18 20:28:20 jdolecek Exp $ */ /* @@ -212,51 +212,6 @@ static const u_char alawtolin16[256][2] = { {0x83,0x30}, {0x83,0x10}, {0x83,0x70}, {0x83,0x50}, }; -static const u_char lintoalaw[256] = { - 0x2a, 0x2a, 0x2a, 0x2a, 0x2b, 0x2b, 0x2b, 0x2b, - 0x28, 0x28, 0x28, 0x28, 0x29, 0x29, 0x29, 0x29, - 0x2e, 0x2e, 0x2e, 0x2e, 0x2f, 0x2f, 0x2f, 0x2f, - 0x2c, 0x2c, 0x2c, 0x2c, 0x2d, 0x2d, 0x2d, 0x2d, - 0x22, 0x22, 0x22, 0x22, 0x23, 0x23, 0x23, 0x23, - 0x20, 0x20, 0x20, 0x20, 0x21, 0x21, 0x21, 0x21, - 0x26, 0x26, 0x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0xac, 0xac, - 0xaf, 0xaf, 0xaf, 0xaf, 0xae, 0xae, 0xae, 0xae, - 0xa9, 0xa9, 0xa9, 0xa9, 0xa8, 0xa8, 0xa8, 0xa8, - 0xab, 0xab, 0xab, 0xab, 0xaa, 0xaa, 0xaa, 0xaa, -}; - -void -mulaw_to_ulinear8(void *v, u_char *p, int cc) -{ - /* Use the 16 bit table for 8 bits too. */ - while (--cc >= 0) { - *p = mulawtolin16[*p][0]; - ++p; - } -} - void mulaw_to_slinear8(void *v, u_char *p, int cc) { @@ -268,116 +223,6 @@ mulaw_to_slinear8(void *v, u_char *p, int cc) } void -mulaw_to_ulinear16_le(void *v, u_char *p, int cc) -{ - u_char *q = p; - - p += cc; - q += cc << 1; - while (--cc >= 0) { - --p; - q -= 2; - q[1] = mulawtolin16[*p][0]; - q[0] = mulawtolin16[*p][1]; - } -} - -void -mulaw_to_ulinear16_be(void *v, u_char *p, int cc) -{ - u_char *q = p; - - p += cc; - q += cc << 1; - while (--cc >= 0) { - --p; - q -= 2; - q[0] = mulawtolin16[*p][0]; - q[1] = mulawtolin16[*p][1]; - } -} - -void -mulaw_to_slinear16_le(void *v, u_char *p, int cc) -{ - u_char *q = p; - - p += cc; - q += cc << 1; - while (--cc >= 0) { - --p; - q -= 2; - q[1] = mulawtolin16[*p][0] ^ 0x80; - q[0] = mulawtolin16[*p][1]; - } -} - -void -mulaw_to_slinear16_le_mts(void *v, u_char *p, int cc) -{ - u_char *q = p; - - p += cc; - q += cc * 4; - while (--cc >= 0) { - --p; - q -= 4; - q[1] = q[3] = mulawtolin16[*p][0] ^ 0x80; - q[0] = q[2] = mulawtolin16[*p][1]; - } -} - -void -mulaw_to_slinear16_be(void *v, u_char *p, int cc) -{ - u_char *q = p; - - p += cc; - q += cc << 1; - while (--cc >= 0) { - --p; - q -= 2; - q[0] = mulawtolin16[*p][0] ^ 0x80; - q[1] = mulawtolin16[*p][1]; - } -} - -void -mulaw_to_slinear16_be_mts(void *v, u_char *p, int cc) -{ - u_char *q = p; - - p += cc; - q += cc * 4; - while (--cc >= 0) { - --p; - q -= 4; - q[0] = q[2] = mulawtolin16[*p][0] ^ 0x80; - q[1] = q[3] = mulawtolin16[*p][1]; - } -} - -void -slinear16_to_mulaw_le(void *v, u_char* p, int cc) -{ - u_char *q = p + 1; /* q points higher byte. */ - - while ((cc-= 2) >= 0) { - *p++ = lintomulaw[*q ^ 0x80]; - q +=2 ; - } -} - -void -ulinear8_to_mulaw(void *v, u_char *p, int cc) -{ - while (--cc >= 0) { - *p = lintomulaw[*p]; - ++p; - } -} - -void slinear8_to_mulaw(void *v, u_char *p, int cc) { while (--cc >= 0) { @@ -387,263 +232,25 @@ slinear8_to_mulaw(void *v, u_char *p, int cc) } void -alaw_to_ulinear8(void *v, u_char *p, int cc) -{ - /* Use the 16 bit table for 8 bits too. */ - while (--cc >= 0) { - *p = alawtolin16[*p][0]; - ++p; - } -} - -void -alaw_to_slinear8(void *v, u_char *p, int cc) -{ - /* Use the 16 bit table for 8 bits too. */ - while (--cc >= 0) { - *p = alawtolin16[*p][0] ^ 0x80; - ++p; - } -} - -void -alaw_to_ulinear16_le(void *v, u_char *p, int cc) -{ - u_char *q = p; - - p += cc; - q += cc << 1; - while (--cc >= 0) { - --p; - q -= 2; - q[1] = alawtolin16[*p][0]; - q[0] = alawtolin16[*p][1]; - } -} - -void -alaw_to_ulinear16_be(void *v, u_char *p, int cc) -{ - u_char *q = p; - - p += cc; - q += cc << 1; - while (--cc >= 0) { - --p; - q -= 2; - q[0] = alawtolin16[*p][0]; - q[1] = alawtolin16[*p][1]; - } -} - -void -alaw_to_slinear16_le(void *v, u_char *p, int cc) -{ - u_char *q = p; - - p += cc; - q += cc << 1; - while (--cc >= 0) { - --p; - q -= 2; - q[1] = alawtolin16[*p][0] ^ 0x80; - q[0] = alawtolin16[*p][1]; - } -} - -void -alaw_to_slinear16_be(void *v, u_char *p, int cc) -{ - u_char *q = p; - - p += cc; - q += cc << 1; - while (--cc >= 0) { - --p; - q -= 2; - q[0] = alawtolin16[*p][0] ^ 0x80; - q[1] = alawtolin16[*p][1]; - } -} - -void -ulinear8_to_alaw(void *v, u_char *p, int cc) -{ - while (--cc >= 0) { - *p = lintoalaw[*p]; - ++p; - } -} - -void -slinear8_to_alaw(void *v, u_char *p, int cc) -{ - while (--cc >= 0) { - *p = lintoalaw[*p ^ 0x80]; - ++p; - } -} - -void -slinear16_to_alaw_le(void *v, u_char *p, int cc) -{ - u_char *q = p; - - while ((cc -= 2) >= 0) { - *p = lintoalaw[q[1] ^ 0x80]; - ++p; - q += 2; - } -} - - -void -slinear16_to_alaw_be(void *v, u_char *p, int cc) -{ - u_char *q = p; - - while ((cc -= 2) >= 0) { - *p = lintoalaw[q[0] ^ 0x80]; - ++p; - q += 2; - } -} - -/* - * same as mulaw_to_ulinear16_le(), plus expand mono to stereo - */ -void -mulaw_to_ulinear16_le_mts(void *v, u_char *p, int cc) -{ - u_char *q = p; - - p += cc; - q += cc * 4; - while (--cc >= 0) { - --p; - q -= 4; - q[1] = q[3] = mulawtolin16[*p][0]; - q[0] = q[2] = mulawtolin16[*p][1]; - } -} - -/* - * same as mulaw_to_ulinear16_be(), plus expand mono to stereo - */ -void -mulaw_to_ulinear16_be_mts(void *v, u_char *p, int cc) -{ - u_char *q = p; - - p += cc; - q += cc * 4; - while (--cc >= 0) { - --p; - q -= 4; - q[0] = q[2] = mulawtolin16[*p][0]; - q[1] = q[3] = mulawtolin16[*p][1]; - } -} - -/* - * same as alaw_to_slinear16_le(), plus expand mono to stereo - */ -void -alaw_to_slinear16_le_mts(void *v, u_char *p, int cc) -{ - u_char *q = p; - - p += cc; - q += cc * 4; - while (--cc >= 0) { - --p; - q -= 4; - q[1] = q[3] = alawtolin16[*p][0] ^ 0x80; - q[0] = q[2] = alawtolin16[*p][1]; - } -} - -/* - * same as alaw_to_slinear16_be(), plus expand mono to stereo - */ -void -alaw_to_slinear16_be_mts(void *v, u_char *p, int cc) -{ - u_char *q = p; - - p += cc; - q += cc * 4; - while (--cc >= 0) { - --p; - q -= 4; - q[0] = q[2] = alawtolin16[*p][0] ^ 0x80; - q[1] = q[3] = alawtolin16[*p][1]; - } -} - -void -alaw_to_mulaw(void *v, u_char *p, int cc) -{ - while (--cc >= 0) { - *p = lintomulaw[alawtolin16[*p][0]]; - ++p; - } -} - -void -mulaw_to_alaw(void *v, u_char *p, int cc) -{ - while (--cc >= 0) { - *p = lintoalaw[mulawtolin16[*p][0]]; - ++p; - } -} - - - -void -slinear16_to_alaw_le_stm(void *v, u_char *p, int cc) -{ - u_char *q = p; - - while ((cc -= 4) >= 0) { - *p = lintoalaw[q[1] ^ 0x80]; - ++p; - q += 4; - } -} - - -void -slinear16_to_alaw_be_stm(void *v, u_char *p, int cc) -{ - u_char *q = p; - - while ((cc -= 4) >= 0) { - *p = lintoalaw[q[0] ^ 0x80]; - ++p; - q += 4; - } -} - -void -slinear16_to_mulaw_le_stm(void *v, u_char* p, int cc) +mulaw24_to_slinear24(void *v, u_char *p, int cc) { - u_char *q = p; + int s, *q = (int *)p; while ((cc -= 4) >= 0) { - *p++ = lintomulaw[q[1] ^ 0x80]; - q += 4 ; + s = (*q >> 16) & 0xff; + *q = (int)((signed char)mulawtolin16[s][0] ^ 0x80) << 16 | + (u_int)mulawtolin16[s][1] << 8; + q++; } } void -slinear16_to_mulaw_be_stm(void *v, u_char* p, int cc) +slinear24_to_mulaw24(void *v, u_char *p, int cc) { - u_char *q = p; + u_int *q = (u_int *)p; while ((cc -= 4) >= 0) { - *p++ = lintomulaw[q[0] ^ 0x80]; - q += 4 ; + *q = lintomulaw[((*q >> 16) & 0xff) ^ 0x80] << 16; + q++; } } |