diff options
author | Jacob Meuser <jakemsr@cvs.openbsd.org> | 2007-10-23 19:54:37 +0000 |
---|---|---|
committer | Jacob Meuser <jakemsr@cvs.openbsd.org> | 2007-10-23 19:54:37 +0000 |
commit | a3f84490b21b997c4a0b538d29c25f6e5cf95a59 (patch) | |
tree | 16f819913cc7aaf90bc04be82685f60e883f3c39 /sys/dev | |
parent | 62dc01380e92e90afcbb823f11321e091881b8bf (diff) |
- add a couple more mono-to-stereo conversions
- add stereo-to-mono conversions for mono recording
on stereo only devices
Diffstat (limited to 'sys/dev')
-rw-r--r-- | sys/dev/auconv.c | 149 | ||||
-rw-r--r-- | sys/dev/auconv.h | 16 | ||||
-rw-r--r-- | sys/dev/mulaw.c | 51 | ||||
-rw-r--r-- | sys/dev/mulaw.h | 8 |
4 files changed, 219 insertions, 5 deletions
diff --git a/sys/dev/auconv.c b/sys/dev/auconv.c index d3d409a2c57..1a1dba220b8 100644 --- a/sys/dev/auconv.c +++ b/sys/dev/auconv.c @@ -1,4 +1,4 @@ -/* $OpenBSD: auconv.c,v 1.7 2007/07/17 08:35:33 jakemsr Exp $ */ +/* $OpenBSD: auconv.c,v 1.8 2007/10/23 19:54:36 jakemsr Exp $ */ /* $NetBSD: auconv.c,v 1.3 1999/11/01 18:12:19 augustss Exp $ */ /* @@ -235,7 +235,7 @@ noswap_bytes_mts(void *v, u_char *p, int cc) } /* - * same as swap_bytes(), just expand mono to stereo + * same as swap_bytes(), plus expand mono to stereo */ void swap_bytes_mts(void *v, u_char *p, int cc) @@ -354,6 +354,40 @@ change_sign16_be_mts(void *v, u_char *p, int cc) } /* + * same as swap_bytes_change_sign16_le(), plus expand mono to stereo + */ +void +swap_bytes_change_sign16_le_mts(void *v, u_char *p, int cc) +{ + u_char *q = p; + + p += cc; + q += cc * 2; + while ((cc -= 2) >= 0) { + q -= 4; + q[0] = q[2] = *--p; + q[1] = q[3] = (*--p) ^ 0x80; + } +} + +/* + * same as swap_bytes_change_sign16_be(), plus expand mono to stereo + */ +void +swap_bytes_change_sign16_be_mts(void *v, u_char *p, int cc) +{ + u_char *q = p; + + p += cc; + q += cc * 2; + while ((cc -= 2) >= 0) { + q -= 4; + q[0] = q[2] = (*--p) ^ 0x80; + q[1] = q[3] = *--p; + } +} + +/* * same as change_sign16_swap_bytes_le(), plus expand mono to stereo */ void @@ -370,3 +404,114 @@ change_sign16_swap_bytes_be_mts(void *v, u_char *p, int cc) { change_sign16_le_mts(v, p, cc); } + + +void +linear16_decimator(void *v, u_char *p, int cc) +{ + u_char *q = p; + + while ((cc -= 4) >= 0) { + *q++ = p[0]; + *q++ = p[1]; + p += 4; + } +} + +void +linear16_to_linear8_le_stm(void *v, u_char *p, int cc) +{ + u_char *q = p; + + while ((cc -= 4) >= 0) { + *q++ = p[1]; + p += 4; + } +} + +void +linear16_to_linear8_be_stm(void *v, u_char *p, int cc) +{ + u_char *q = p; + + while ((cc -= 4) >= 0) { + *q++ = p[0]; + p += 4; + } +} + +void +linear16_to_ulinear8_le_stm(void *v, u_char *p, int cc) +{ + u_char *q = p; + + while ((cc -= 4) >= 0) { + *q++ = p[1] ^ 0x80; + p += 4; + } +} + +void +linear16_to_ulinear8_be_stm(void *v, u_char *p, int cc) +{ + u_char *q = p; + + while ((cc -= 4) >= 0) { + *q++ = p[0] ^ 0x80; + p += 4; + } +} + +void +change_sign16_le_stm(void *v, u_char *p, int cc) +{ + u_char *q = p; + + while ((cc -= 4) >= 0) { + *q++ = p[0]; + *q++ = p[1] ^ 0x80; + p += 4; + } +} + +void +change_sign16_be_stm(void *v, u_char *p, int cc) +{ + u_char *q = p; + + while ((cc -= 4) >= 0) { + *q++ = p[0] ^ 0x80; + *q++ = p[1]; + p += 4; + } +} + +void +swap_bytes_stm(void *v, u_char *p, int cc) +{ + u_char *q = p; + + while ((cc -= 4) >= 0) { + *q++ = p[1]; + *q++ = p[0]; + p += 4; + } +} + +void +swap_bytes_change_sign16_be_stm(void *v, u_char *p, int cc) +{ + u_char *q = p; + + while ((cc -= 4) >= 0) { + *q++ = p[1] ^ 0x80; + *q++ = p[0]; + p += 4; + } +} + +void +change_sign16_swap_bytes_le_stm(void *v, u_char *p, int cc) +{ + swap_bytes_change_sign16_be_stm(v, p, cc); +} diff --git a/sys/dev/auconv.h b/sys/dev/auconv.h index 3fc31073659..82c186a5d3e 100644 --- a/sys/dev/auconv.h +++ b/sys/dev/auconv.h @@ -1,4 +1,4 @@ -/* $OpenBSD: auconv.h,v 1.6 2002/05/06 02:34:57 nate Exp $ */ +/* $OpenBSD: auconv.h,v 1.7 2007/10/23 19:54:36 jakemsr Exp $ */ /* $NetBSD: auconv.h,v 1.5 1999/11/01 18:12:19 augustss Exp $ */ /*- @@ -69,6 +69,20 @@ extern void change_sign16_le_mts(void *, u_char *, int); extern void change_sign16_be_mts(void *, u_char *, int); extern void change_sign16_swap_bytes_le_mts(void *, u_char *, int); extern void change_sign16_swap_bytes_be_mts(void *, u_char *, int); +void swap_bytes_change_sign16_le_mts(void *, u_char *, int); +void swap_bytes_change_sign16_be_mts(void *, u_char *, int); + +/* 16-bit signed linear stereo to mono. drops every other sample */ +void linear16_decimator(void *, u_char *, int); +void linear16_to_linear8_le_stm(void *, u_char *, int); +void linear16_to_linear8_be_stm(void *, u_char *, int); +void linear16_to_ulinear8_le_stm(void *, u_char *, int); +void linear16_to_ulinear8_be_stm(void *, u_char *, int); +void change_sign16_le_stm(void *, u_char *, int); +void change_sign16_be_stm(void *, u_char *, int); +void swap_bytes_stm(void *, u_char *, int); +void swap_bytes_change_sign16_be_stm(void *, u_char *, int); +void change_sign16_swap_bytes_le_stm(void *, u_char *, int); /* backwards compat for now */ #if BYTE_ORDER == LITTLE_ENDIAN diff --git a/sys/dev/mulaw.c b/sys/dev/mulaw.c index 3b7d09b240b..7e97bc45f19 100644 --- a/sys/dev/mulaw.c +++ b/sys/dev/mulaw.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mulaw.c,v 1.13 2007/07/17 08:35:33 jakemsr Exp $ */ +/* $OpenBSD: mulaw.c,v 1.14 2007/10/23 19:54:36 jakemsr Exp $ */ /* $NetBSD: mulaw.c,v 1.15 2001/01/18 20:28:20 jdolecek Exp $ */ /* @@ -599,3 +599,52 @@ mulaw_to_alaw(void *v, u_char *p, int cc) ++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) +{ + u_char *q = p; + + while ((cc -= 4) >= 0) { + *p++ = lintomulaw[q[1] ^ 0x80]; + q += 4 ; + } +} + +void +slinear16_to_mulaw_be_stm(void *v, u_char* p, int cc) +{ + u_char *q = p; + + while ((cc -= 4) >= 0) { + *p++ = lintomulaw[q[0] ^ 0x80]; + q += 4 ; + } +} diff --git a/sys/dev/mulaw.h b/sys/dev/mulaw.h index 6d2c2d54828..1ec76461198 100644 --- a/sys/dev/mulaw.h +++ b/sys/dev/mulaw.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mulaw.h,v 1.12 2005/04/14 01:24:20 pascoe Exp $ */ +/* $OpenBSD: mulaw.h,v 1.13 2007/10/23 19:54:36 jakemsr Exp $ */ /* $NetBSD: mulaw.h,v 1.11 1999/11/01 18:12:19 augustss Exp $ */ /*- @@ -75,6 +75,12 @@ extern void slinear8_to_alaw(void *, u_char *, int); /* Convert 8-bit a-law to/from mulaw */ void alaw_to_mulaw(void *, u_char *, int); void mulaw_to_alaw(void *, u_char *, int); +/* Convert 16-bit signed linear stereo to 8-bit a-law mono */ +void slinear16_to_alaw_le_stm(void *, u_char *, int); +void slinear16_to_alaw_be_stm(void *, u_char *, int); +/* Convert 16-bit signed linear stereo to 8-bit mu-law mono */ +void slinear16_to_mulaw_le_stm(void *, u_char *, int); +void slinear16_to_mulaw_be_stm(void *, u_char *, int); /* backwards compat for now */ #if BYTE_ORDER == LITTLE_ENDIAN |