Annotation of sys/dev/mulaw.c, Revision 1.1
1.1 ! nbrk 1: /* $OpenBSD: mulaw.c,v 1.13 2007/07/17 08:35:33 jakemsr Exp $ */
! 2: /* $NetBSD: mulaw.c,v 1.15 2001/01/18 20:28:20 jdolecek Exp $ */
! 3:
! 4: /*
! 5: * Copyright (c) 1991-1993 Regents of the University of California.
! 6: * All rights reserved.
! 7: *
! 8: * Redistribution and use in source and binary forms, with or without
! 9: * modification, are permitted provided that the following conditions
! 10: * are met:
! 11: * 1. Redistributions of source code must retain the above copyright
! 12: * notice, this list of conditions and the following disclaimer.
! 13: * 2. Redistributions in binary form must reproduce the above copyright
! 14: * notice, this list of conditions and the following disclaimer in the
! 15: * documentation and/or other materials provided with the distribution.
! 16: * 3. All advertising materials mentioning features or use of this software
! 17: * must display the following acknowledgement:
! 18: * This product includes software developed by the Computer Systems
! 19: * Engineering Group at Lawrence Berkeley Laboratory.
! 20: * 4. Neither the name of the University nor of the Laboratory may be used
! 21: * to endorse or promote products derived from this software without
! 22: * specific prior written permission.
! 23: *
! 24: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
! 25: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
! 26: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
! 27: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
! 28: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
! 29: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
! 30: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
! 31: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
! 32: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
! 33: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
! 34: * SUCH DAMAGE.
! 35: *
! 36: */
! 37:
! 38: #include <sys/types.h>
! 39: #include <sys/audioio.h>
! 40: #include <dev/mulaw.h>
! 41:
! 42: /*
! 43: * This table converts a (8 bit) mu-law value two a 16 bit value.
! 44: * The 16 bits are represented as an array of two bytes for easier access
! 45: * to the individual bytes.
! 46: */
! 47: static const u_char mulawtolin16[256][2] = {
! 48: {0x02,0x84}, {0x06,0x84}, {0x0a,0x84}, {0x0e,0x84},
! 49: {0x12,0x84}, {0x16,0x84}, {0x1a,0x84}, {0x1e,0x84},
! 50: {0x22,0x84}, {0x26,0x84}, {0x2a,0x84}, {0x2e,0x84},
! 51: {0x32,0x84}, {0x36,0x84}, {0x3a,0x84}, {0x3e,0x84},
! 52: {0x41,0x84}, {0x43,0x84}, {0x45,0x84}, {0x47,0x84},
! 53: {0x49,0x84}, {0x4b,0x84}, {0x4d,0x84}, {0x4f,0x84},
! 54: {0x51,0x84}, {0x53,0x84}, {0x55,0x84}, {0x57,0x84},
! 55: {0x59,0x84}, {0x5b,0x84}, {0x5d,0x84}, {0x5f,0x84},
! 56: {0x61,0x04}, {0x62,0x04}, {0x63,0x04}, {0x64,0x04},
! 57: {0x65,0x04}, {0x66,0x04}, {0x67,0x04}, {0x68,0x04},
! 58: {0x69,0x04}, {0x6a,0x04}, {0x6b,0x04}, {0x6c,0x04},
! 59: {0x6d,0x04}, {0x6e,0x04}, {0x6f,0x04}, {0x70,0x04},
! 60: {0x70,0xc4}, {0x71,0x44}, {0x71,0xc4}, {0x72,0x44},
! 61: {0x72,0xc4}, {0x73,0x44}, {0x73,0xc4}, {0x74,0x44},
! 62: {0x74,0xc4}, {0x75,0x44}, {0x75,0xc4}, {0x76,0x44},
! 63: {0x76,0xc4}, {0x77,0x44}, {0x77,0xc4}, {0x78,0x44},
! 64: {0x78,0xa4}, {0x78,0xe4}, {0x79,0x24}, {0x79,0x64},
! 65: {0x79,0xa4}, {0x79,0xe4}, {0x7a,0x24}, {0x7a,0x64},
! 66: {0x7a,0xa4}, {0x7a,0xe4}, {0x7b,0x24}, {0x7b,0x64},
! 67: {0x7b,0xa4}, {0x7b,0xe4}, {0x7c,0x24}, {0x7c,0x64},
! 68: {0x7c,0x94}, {0x7c,0xb4}, {0x7c,0xd4}, {0x7c,0xf4},
! 69: {0x7d,0x14}, {0x7d,0x34}, {0x7d,0x54}, {0x7d,0x74},
! 70: {0x7d,0x94}, {0x7d,0xb4}, {0x7d,0xd4}, {0x7d,0xf4},
! 71: {0x7e,0x14}, {0x7e,0x34}, {0x7e,0x54}, {0x7e,0x74},
! 72: {0x7e,0x8c}, {0x7e,0x9c}, {0x7e,0xac}, {0x7e,0xbc},
! 73: {0x7e,0xcc}, {0x7e,0xdc}, {0x7e,0xec}, {0x7e,0xfc},
! 74: {0x7f,0x0c}, {0x7f,0x1c}, {0x7f,0x2c}, {0x7f,0x3c},
! 75: {0x7f,0x4c}, {0x7f,0x5c}, {0x7f,0x6c}, {0x7f,0x7c},
! 76: {0x7f,0x88}, {0x7f,0x90}, {0x7f,0x98}, {0x7f,0xa0},
! 77: {0x7f,0xa8}, {0x7f,0xb0}, {0x7f,0xb8}, {0x7f,0xc0},
! 78: {0x7f,0xc8}, {0x7f,0xd0}, {0x7f,0xd8}, {0x7f,0xe0},
! 79: {0x7f,0xe8}, {0x7f,0xf0}, {0x7f,0xf8}, {0x80,0x00},
! 80: {0xfd,0x7c}, {0xf9,0x7c}, {0xf5,0x7c}, {0xf1,0x7c},
! 81: {0xed,0x7c}, {0xe9,0x7c}, {0xe5,0x7c}, {0xe1,0x7c},
! 82: {0xdd,0x7c}, {0xd9,0x7c}, {0xd5,0x7c}, {0xd1,0x7c},
! 83: {0xcd,0x7c}, {0xc9,0x7c}, {0xc5,0x7c}, {0xc1,0x7c},
! 84: {0xbe,0x7c}, {0xbc,0x7c}, {0xba,0x7c}, {0xb8,0x7c},
! 85: {0xb6,0x7c}, {0xb4,0x7c}, {0xb2,0x7c}, {0xb0,0x7c},
! 86: {0xae,0x7c}, {0xac,0x7c}, {0xaa,0x7c}, {0xa8,0x7c},
! 87: {0xa6,0x7c}, {0xa4,0x7c}, {0xa2,0x7c}, {0xa0,0x7c},
! 88: {0x9e,0xfc}, {0x9d,0xfc}, {0x9c,0xfc}, {0x9b,0xfc},
! 89: {0x9a,0xfc}, {0x99,0xfc}, {0x98,0xfc}, {0x97,0xfc},
! 90: {0x96,0xfc}, {0x95,0xfc}, {0x94,0xfc}, {0x93,0xfc},
! 91: {0x92,0xfc}, {0x91,0xfc}, {0x90,0xfc}, {0x8f,0xfc},
! 92: {0x8f,0x3c}, {0x8e,0xbc}, {0x8e,0x3c}, {0x8d,0xbc},
! 93: {0x8d,0x3c}, {0x8c,0xbc}, {0x8c,0x3c}, {0x8b,0xbc},
! 94: {0x8b,0x3c}, {0x8a,0xbc}, {0x8a,0x3c}, {0x89,0xbc},
! 95: {0x89,0x3c}, {0x88,0xbc}, {0x88,0x3c}, {0x87,0xbc},
! 96: {0x87,0x5c}, {0x87,0x1c}, {0x86,0xdc}, {0x86,0x9c},
! 97: {0x86,0x5c}, {0x86,0x1c}, {0x85,0xdc}, {0x85,0x9c},
! 98: {0x85,0x5c}, {0x85,0x1c}, {0x84,0xdc}, {0x84,0x9c},
! 99: {0x84,0x5c}, {0x84,0x1c}, {0x83,0xdc}, {0x83,0x9c},
! 100: {0x83,0x6c}, {0x83,0x4c}, {0x83,0x2c}, {0x83,0x0c},
! 101: {0x82,0xec}, {0x82,0xcc}, {0x82,0xac}, {0x82,0x8c},
! 102: {0x82,0x6c}, {0x82,0x4c}, {0x82,0x2c}, {0x82,0x0c},
! 103: {0x81,0xec}, {0x81,0xcc}, {0x81,0xac}, {0x81,0x8c},
! 104: {0x81,0x74}, {0x81,0x64}, {0x81,0x54}, {0x81,0x44},
! 105: {0x81,0x34}, {0x81,0x24}, {0x81,0x14}, {0x81,0x04},
! 106: {0x80,0xf4}, {0x80,0xe4}, {0x80,0xd4}, {0x80,0xc4},
! 107: {0x80,0xb4}, {0x80,0xa4}, {0x80,0x94}, {0x80,0x84},
! 108: {0x80,0x78}, {0x80,0x70}, {0x80,0x68}, {0x80,0x60},
! 109: {0x80,0x58}, {0x80,0x50}, {0x80,0x48}, {0x80,0x40},
! 110: {0x80,0x38}, {0x80,0x30}, {0x80,0x28}, {0x80,0x20},
! 111: {0x80,0x18}, {0x80,0x10}, {0x80,0x08}, {0x80,0x00},
! 112: };
! 113:
! 114: static const u_char lintomulaw[256] = {
! 115: 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,
! 116: 0x01, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03,
! 117: 0x03, 0x04, 0x04, 0x04, 0x04, 0x05, 0x05, 0x05,
! 118: 0x05, 0x06, 0x06, 0x06, 0x06, 0x07, 0x07, 0x07,
! 119: 0x07, 0x08, 0x08, 0x08, 0x08, 0x09, 0x09, 0x09,
! 120: 0x09, 0x0a, 0x0a, 0x0a, 0x0a, 0x0b, 0x0b, 0x0b,
! 121: 0x0b, 0x0c, 0x0c, 0x0c, 0x0c, 0x0d, 0x0d, 0x0d,
! 122: 0x0d, 0x0e, 0x0e, 0x0e, 0x0e, 0x0f, 0x0f, 0x0f,
! 123: 0x0f, 0x10, 0x10, 0x11, 0x11, 0x12, 0x12, 0x13,
! 124: 0x13, 0x14, 0x14, 0x15, 0x15, 0x16, 0x16, 0x17,
! 125: 0x17, 0x18, 0x18, 0x19, 0x19, 0x1a, 0x1a, 0x1b,
! 126: 0x1b, 0x1c, 0x1c, 0x1d, 0x1d, 0x1e, 0x1e, 0x1f,
! 127: 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26,
! 128: 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e,
! 129: 0x2f, 0x30, 0x32, 0x34, 0x36, 0x38, 0x3a, 0x3c,
! 130: 0x3e, 0x41, 0x45, 0x49, 0x4d, 0x53, 0x5b, 0x67,
! 131: 0xff, 0xe7, 0xdb, 0xd3, 0xcd, 0xc9, 0xc5, 0xc1,
! 132: 0xbe, 0xbc, 0xba, 0xb8, 0xb6, 0xb4, 0xb2, 0xb0,
! 133: 0xaf, 0xae, 0xad, 0xac, 0xab, 0xaa, 0xa9, 0xa8,
! 134: 0xa7, 0xa6, 0xa5, 0xa4, 0xa3, 0xa2, 0xa1, 0xa0,
! 135: 0x9f, 0x9f, 0x9e, 0x9e, 0x9d, 0x9d, 0x9c, 0x9c,
! 136: 0x9b, 0x9b, 0x9a, 0x9a, 0x99, 0x99, 0x98, 0x98,
! 137: 0x97, 0x97, 0x96, 0x96, 0x95, 0x95, 0x94, 0x94,
! 138: 0x93, 0x93, 0x92, 0x92, 0x91, 0x91, 0x90, 0x90,
! 139: 0x8f, 0x8f, 0x8f, 0x8f, 0x8e, 0x8e, 0x8e, 0x8e,
! 140: 0x8d, 0x8d, 0x8d, 0x8d, 0x8c, 0x8c, 0x8c, 0x8c,
! 141: 0x8b, 0x8b, 0x8b, 0x8b, 0x8a, 0x8a, 0x8a, 0x8a,
! 142: 0x89, 0x89, 0x89, 0x89, 0x88, 0x88, 0x88, 0x88,
! 143: 0x87, 0x87, 0x87, 0x87, 0x86, 0x86, 0x86, 0x86,
! 144: 0x85, 0x85, 0x85, 0x85, 0x84, 0x84, 0x84, 0x84,
! 145: 0x83, 0x83, 0x83, 0x83, 0x82, 0x82, 0x82, 0x82,
! 146: 0x81, 0x81, 0x81, 0x81, 0x80, 0x80, 0x80, 0x80,
! 147: };
! 148:
! 149: static const u_char alawtolin16[256][2] = {
! 150: {0x6a,0x80}, {0x6b,0x80}, {0x68,0x80}, {0x69,0x80},
! 151: {0x6e,0x80}, {0x6f,0x80}, {0x6c,0x80}, {0x6d,0x80},
! 152: {0x62,0x80}, {0x63,0x80}, {0x60,0x80}, {0x61,0x80},
! 153: {0x66,0x80}, {0x67,0x80}, {0x64,0x80}, {0x65,0x80},
! 154: {0x75,0x40}, {0x75,0xc0}, {0x74,0x40}, {0x74,0xc0},
! 155: {0x77,0x40}, {0x77,0xc0}, {0x76,0x40}, {0x76,0xc0},
! 156: {0x71,0x40}, {0x71,0xc0}, {0x70,0x40}, {0x70,0xc0},
! 157: {0x73,0x40}, {0x73,0xc0}, {0x72,0x40}, {0x72,0xc0},
! 158: {0x2a,0x00}, {0x2e,0x00}, {0x22,0x00}, {0x26,0x00},
! 159: {0x3a,0x00}, {0x3e,0x00}, {0x32,0x00}, {0x36,0x00},
! 160: {0x0a,0x00}, {0x0e,0x00}, {0x02,0x00}, {0x06,0x00},
! 161: {0x1a,0x00}, {0x1e,0x00}, {0x12,0x00}, {0x16,0x00},
! 162: {0x55,0x00}, {0x57,0x00}, {0x51,0x00}, {0x53,0x00},
! 163: {0x5d,0x00}, {0x5f,0x00}, {0x59,0x00}, {0x5b,0x00},
! 164: {0x45,0x00}, {0x47,0x00}, {0x41,0x00}, {0x43,0x00},
! 165: {0x4d,0x00}, {0x4f,0x00}, {0x49,0x00}, {0x4b,0x00},
! 166: {0x7e,0xa8}, {0x7e,0xb8}, {0x7e,0x88}, {0x7e,0x98},
! 167: {0x7e,0xe8}, {0x7e,0xf8}, {0x7e,0xc8}, {0x7e,0xd8},
! 168: {0x7e,0x28}, {0x7e,0x38}, {0x7e,0x08}, {0x7e,0x18},
! 169: {0x7e,0x68}, {0x7e,0x78}, {0x7e,0x48}, {0x7e,0x58},
! 170: {0x7f,0xa8}, {0x7f,0xb8}, {0x7f,0x88}, {0x7f,0x98},
! 171: {0x7f,0xe8}, {0x7f,0xf8}, {0x7f,0xc8}, {0x7f,0xd8},
! 172: {0x7f,0x28}, {0x7f,0x38}, {0x7f,0x08}, {0x7f,0x18},
! 173: {0x7f,0x68}, {0x7f,0x78}, {0x7f,0x48}, {0x7f,0x58},
! 174: {0x7a,0xa0}, {0x7a,0xe0}, {0x7a,0x20}, {0x7a,0x60},
! 175: {0x7b,0xa0}, {0x7b,0xe0}, {0x7b,0x20}, {0x7b,0x60},
! 176: {0x78,0xa0}, {0x78,0xe0}, {0x78,0x20}, {0x78,0x60},
! 177: {0x79,0xa0}, {0x79,0xe0}, {0x79,0x20}, {0x79,0x60},
! 178: {0x7d,0x50}, {0x7d,0x70}, {0x7d,0x10}, {0x7d,0x30},
! 179: {0x7d,0xd0}, {0x7d,0xf0}, {0x7d,0x90}, {0x7d,0xb0},
! 180: {0x7c,0x50}, {0x7c,0x70}, {0x7c,0x10}, {0x7c,0x30},
! 181: {0x7c,0xd0}, {0x7c,0xf0}, {0x7c,0x90}, {0x7c,0xb0},
! 182: {0x95,0x80}, {0x94,0x80}, {0x97,0x80}, {0x96,0x80},
! 183: {0x91,0x80}, {0x90,0x80}, {0x93,0x80}, {0x92,0x80},
! 184: {0x9d,0x80}, {0x9c,0x80}, {0x9f,0x80}, {0x9e,0x80},
! 185: {0x99,0x80}, {0x98,0x80}, {0x9b,0x80}, {0x9a,0x80},
! 186: {0x8a,0xc0}, {0x8a,0x40}, {0x8b,0xc0}, {0x8b,0x40},
! 187: {0x88,0xc0}, {0x88,0x40}, {0x89,0xc0}, {0x89,0x40},
! 188: {0x8e,0xc0}, {0x8e,0x40}, {0x8f,0xc0}, {0x8f,0x40},
! 189: {0x8c,0xc0}, {0x8c,0x40}, {0x8d,0xc0}, {0x8d,0x40},
! 190: {0xd6,0x00}, {0xd2,0x00}, {0xde,0x00}, {0xda,0x00},
! 191: {0xc6,0x00}, {0xc2,0x00}, {0xce,0x00}, {0xca,0x00},
! 192: {0xf6,0x00}, {0xf2,0x00}, {0xfe,0x00}, {0xfa,0x00},
! 193: {0xe6,0x00}, {0xe2,0x00}, {0xee,0x00}, {0xea,0x00},
! 194: {0xab,0x00}, {0xa9,0x00}, {0xaf,0x00}, {0xad,0x00},
! 195: {0xa3,0x00}, {0xa1,0x00}, {0xa7,0x00}, {0xa5,0x00},
! 196: {0xbb,0x00}, {0xb9,0x00}, {0xbf,0x00}, {0xbd,0x00},
! 197: {0xb3,0x00}, {0xb1,0x00}, {0xb7,0x00}, {0xb5,0x00},
! 198: {0x81,0x58}, {0x81,0x48}, {0x81,0x78}, {0x81,0x68},
! 199: {0x81,0x18}, {0x81,0x08}, {0x81,0x38}, {0x81,0x28},
! 200: {0x81,0xd8}, {0x81,0xc8}, {0x81,0xf8}, {0x81,0xe8},
! 201: {0x81,0x98}, {0x81,0x88}, {0x81,0xb8}, {0x81,0xa8},
! 202: {0x80,0x58}, {0x80,0x48}, {0x80,0x78}, {0x80,0x68},
! 203: {0x80,0x18}, {0x80,0x08}, {0x80,0x38}, {0x80,0x28},
! 204: {0x80,0xd8}, {0x80,0xc8}, {0x80,0xf8}, {0x80,0xe8},
! 205: {0x80,0x98}, {0x80,0x88}, {0x80,0xb8}, {0x80,0xa8},
! 206: {0x85,0x60}, {0x85,0x20}, {0x85,0xe0}, {0x85,0xa0},
! 207: {0x84,0x60}, {0x84,0x20}, {0x84,0xe0}, {0x84,0xa0},
! 208: {0x87,0x60}, {0x87,0x20}, {0x87,0xe0}, {0x87,0xa0},
! 209: {0x86,0x60}, {0x86,0x20}, {0x86,0xe0}, {0x86,0xa0},
! 210: {0x82,0xb0}, {0x82,0x90}, {0x82,0xf0}, {0x82,0xd0},
! 211: {0x82,0x30}, {0x82,0x10}, {0x82,0x70}, {0x82,0x50},
! 212: {0x83,0xb0}, {0x83,0x90}, {0x83,0xf0}, {0x83,0xd0},
! 213: {0x83,0x30}, {0x83,0x10}, {0x83,0x70}, {0x83,0x50},
! 214: };
! 215:
! 216: static const u_char lintoalaw[256] = {
! 217: 0x2a, 0x2a, 0x2a, 0x2a, 0x2b, 0x2b, 0x2b, 0x2b,
! 218: 0x28, 0x28, 0x28, 0x28, 0x29, 0x29, 0x29, 0x29,
! 219: 0x2e, 0x2e, 0x2e, 0x2e, 0x2f, 0x2f, 0x2f, 0x2f,
! 220: 0x2c, 0x2c, 0x2c, 0x2c, 0x2d, 0x2d, 0x2d, 0x2d,
! 221: 0x22, 0x22, 0x22, 0x22, 0x23, 0x23, 0x23, 0x23,
! 222: 0x20, 0x20, 0x20, 0x20, 0x21, 0x21, 0x21, 0x21,
! 223: 0x26, 0x26, 0x26, 0x26, 0x27, 0x27, 0x27, 0x27,
! 224: 0x24, 0x24, 0x24, 0x24, 0x25, 0x25, 0x25, 0x25,
! 225: 0x3a, 0x3a, 0x3b, 0x3b, 0x38, 0x38, 0x39, 0x39,
! 226: 0x3e, 0x3e, 0x3f, 0x3f, 0x3c, 0x3c, 0x3d, 0x3d,
! 227: 0x32, 0x32, 0x33, 0x33, 0x30, 0x30, 0x31, 0x31,
! 228: 0x36, 0x36, 0x37, 0x37, 0x34, 0x34, 0x35, 0x35,
! 229: 0x0a, 0x0b, 0x08, 0x09, 0x0e, 0x0f, 0x0c, 0x0d,
! 230: 0x02, 0x03, 0x00, 0x01, 0x06, 0x07, 0x04, 0x05,
! 231: 0x1a, 0x18, 0x1e, 0x1c, 0x12, 0x10, 0x16, 0x14,
! 232: 0x6a, 0x6e, 0x62, 0x66, 0x7a, 0x72, 0x4a, 0x5a,
! 233: 0xd5, 0xc5, 0xf5, 0xfd, 0xe5, 0xe1, 0xed, 0xe9,
! 234: 0x95, 0x97, 0x91, 0x93, 0x9d, 0x9f, 0x99, 0x9b,
! 235: 0x85, 0x84, 0x87, 0x86, 0x81, 0x80, 0x83, 0x82,
! 236: 0x8d, 0x8c, 0x8f, 0x8e, 0x89, 0x88, 0x8b, 0x8a,
! 237: 0xb5, 0xb5, 0xb4, 0xb4, 0xb7, 0xb7, 0xb6, 0xb6,
! 238: 0xb1, 0xb1, 0xb0, 0xb0, 0xb3, 0xb3, 0xb2, 0xb2,
! 239: 0xbd, 0xbd, 0xbc, 0xbc, 0xbf, 0xbf, 0xbe, 0xbe,
! 240: 0xb9, 0xb9, 0xb8, 0xb8, 0xbb, 0xbb, 0xba, 0xba,
! 241: 0xa5, 0xa5, 0xa5, 0xa5, 0xa4, 0xa4, 0xa4, 0xa4,
! 242: 0xa7, 0xa7, 0xa7, 0xa7, 0xa6, 0xa6, 0xa6, 0xa6,
! 243: 0xa1, 0xa1, 0xa1, 0xa1, 0xa0, 0xa0, 0xa0, 0xa0,
! 244: 0xa3, 0xa3, 0xa3, 0xa3, 0xa2, 0xa2, 0xa2, 0xa2,
! 245: 0xad, 0xad, 0xad, 0xad, 0xac, 0xac, 0xac, 0xac,
! 246: 0xaf, 0xaf, 0xaf, 0xaf, 0xae, 0xae, 0xae, 0xae,
! 247: 0xa9, 0xa9, 0xa9, 0xa9, 0xa8, 0xa8, 0xa8, 0xa8,
! 248: 0xab, 0xab, 0xab, 0xab, 0xaa, 0xaa, 0xaa, 0xaa,
! 249: };
! 250:
! 251: void
! 252: mulaw_to_ulinear8(void *v, u_char *p, int cc)
! 253: {
! 254: /* Use the 16 bit table for 8 bits too. */
! 255: while (--cc >= 0) {
! 256: *p = mulawtolin16[*p][0];
! 257: ++p;
! 258: }
! 259: }
! 260:
! 261: void
! 262: mulaw_to_slinear8(void *v, u_char *p, int cc)
! 263: {
! 264: /* Use the 16 bit table for 8 bits too. */
! 265: while (--cc >= 0) {
! 266: *p = mulawtolin16[*p][0] ^ 0x80;
! 267: ++p;
! 268: }
! 269: }
! 270:
! 271: void
! 272: mulaw_to_ulinear16_le(void *v, u_char *p, int cc)
! 273: {
! 274: u_char *q = p;
! 275:
! 276: p += cc;
! 277: q += cc << 1;
! 278: while (--cc >= 0) {
! 279: --p;
! 280: q -= 2;
! 281: q[1] = mulawtolin16[*p][0];
! 282: q[0] = mulawtolin16[*p][1];
! 283: }
! 284: }
! 285:
! 286: void
! 287: mulaw_to_ulinear16_be(void *v, u_char *p, int cc)
! 288: {
! 289: u_char *q = p;
! 290:
! 291: p += cc;
! 292: q += cc << 1;
! 293: while (--cc >= 0) {
! 294: --p;
! 295: q -= 2;
! 296: q[0] = mulawtolin16[*p][0];
! 297: q[1] = mulawtolin16[*p][1];
! 298: }
! 299: }
! 300:
! 301: void
! 302: mulaw_to_slinear16_le(void *v, u_char *p, int cc)
! 303: {
! 304: u_char *q = p;
! 305:
! 306: p += cc;
! 307: q += cc << 1;
! 308: while (--cc >= 0) {
! 309: --p;
! 310: q -= 2;
! 311: q[1] = mulawtolin16[*p][0] ^ 0x80;
! 312: q[0] = mulawtolin16[*p][1];
! 313: }
! 314: }
! 315:
! 316: void
! 317: mulaw_to_slinear16_le_mts(void *v, u_char *p, int cc)
! 318: {
! 319: u_char *q = p;
! 320:
! 321: p += cc;
! 322: q += cc * 4;
! 323: while (--cc >= 0) {
! 324: --p;
! 325: q -= 4;
! 326: q[1] = q[3] = mulawtolin16[*p][0] ^ 0x80;
! 327: q[0] = q[2] = mulawtolin16[*p][1];
! 328: }
! 329: }
! 330:
! 331: void
! 332: mulaw_to_slinear16_be(void *v, u_char *p, int cc)
! 333: {
! 334: u_char *q = p;
! 335:
! 336: p += cc;
! 337: q += cc << 1;
! 338: while (--cc >= 0) {
! 339: --p;
! 340: q -= 2;
! 341: q[0] = mulawtolin16[*p][0] ^ 0x80;
! 342: q[1] = mulawtolin16[*p][1];
! 343: }
! 344: }
! 345:
! 346: void
! 347: mulaw_to_slinear16_be_mts(void *v, u_char *p, int cc)
! 348: {
! 349: u_char *q = p;
! 350:
! 351: p += cc;
! 352: q += cc * 4;
! 353: while (--cc >= 0) {
! 354: --p;
! 355: q -= 4;
! 356: q[0] = q[2] = mulawtolin16[*p][0] ^ 0x80;
! 357: q[1] = q[3] = mulawtolin16[*p][1];
! 358: }
! 359: }
! 360:
! 361: void
! 362: slinear16_to_mulaw_le(void *v, u_char* p, int cc)
! 363: {
! 364: u_char *q = p + 1; /* q points higher byte. */
! 365:
! 366: while ((cc-= 2) >= 0) {
! 367: *p++ = lintomulaw[*q ^ 0x80];
! 368: q +=2 ;
! 369: }
! 370: }
! 371:
! 372: void
! 373: ulinear8_to_mulaw(void *v, u_char *p, int cc)
! 374: {
! 375: while (--cc >= 0) {
! 376: *p = lintomulaw[*p];
! 377: ++p;
! 378: }
! 379: }
! 380:
! 381: void
! 382: slinear8_to_mulaw(void *v, u_char *p, int cc)
! 383: {
! 384: while (--cc >= 0) {
! 385: *p = lintomulaw[*p ^ 0x80];
! 386: ++p;
! 387: }
! 388: }
! 389:
! 390: void
! 391: alaw_to_ulinear8(void *v, u_char *p, int cc)
! 392: {
! 393: /* Use the 16 bit table for 8 bits too. */
! 394: while (--cc >= 0) {
! 395: *p = alawtolin16[*p][0];
! 396: ++p;
! 397: }
! 398: }
! 399:
! 400: void
! 401: alaw_to_slinear8(void *v, u_char *p, int cc)
! 402: {
! 403: /* Use the 16 bit table for 8 bits too. */
! 404: while (--cc >= 0) {
! 405: *p = alawtolin16[*p][0] ^ 0x80;
! 406: ++p;
! 407: }
! 408: }
! 409:
! 410: void
! 411: alaw_to_ulinear16_le(void *v, u_char *p, int cc)
! 412: {
! 413: u_char *q = p;
! 414:
! 415: p += cc;
! 416: q += cc << 1;
! 417: while (--cc >= 0) {
! 418: --p;
! 419: q -= 2;
! 420: q[1] = alawtolin16[*p][0];
! 421: q[0] = alawtolin16[*p][1];
! 422: }
! 423: }
! 424:
! 425: void
! 426: alaw_to_ulinear16_be(void *v, u_char *p, int cc)
! 427: {
! 428: u_char *q = p;
! 429:
! 430: p += cc;
! 431: q += cc << 1;
! 432: while (--cc >= 0) {
! 433: --p;
! 434: q -= 2;
! 435: q[0] = alawtolin16[*p][0];
! 436: q[1] = alawtolin16[*p][1];
! 437: }
! 438: }
! 439:
! 440: void
! 441: alaw_to_slinear16_le(void *v, u_char *p, int cc)
! 442: {
! 443: u_char *q = p;
! 444:
! 445: p += cc;
! 446: q += cc << 1;
! 447: while (--cc >= 0) {
! 448: --p;
! 449: q -= 2;
! 450: q[1] = alawtolin16[*p][0] ^ 0x80;
! 451: q[0] = alawtolin16[*p][1];
! 452: }
! 453: }
! 454:
! 455: void
! 456: alaw_to_slinear16_be(void *v, u_char *p, int cc)
! 457: {
! 458: u_char *q = p;
! 459:
! 460: p += cc;
! 461: q += cc << 1;
! 462: while (--cc >= 0) {
! 463: --p;
! 464: q -= 2;
! 465: q[0] = alawtolin16[*p][0] ^ 0x80;
! 466: q[1] = alawtolin16[*p][1];
! 467: }
! 468: }
! 469:
! 470: void
! 471: ulinear8_to_alaw(void *v, u_char *p, int cc)
! 472: {
! 473: while (--cc >= 0) {
! 474: *p = lintoalaw[*p];
! 475: ++p;
! 476: }
! 477: }
! 478:
! 479: void
! 480: slinear8_to_alaw(void *v, u_char *p, int cc)
! 481: {
! 482: while (--cc >= 0) {
! 483: *p = lintoalaw[*p ^ 0x80];
! 484: ++p;
! 485: }
! 486: }
! 487:
! 488: void
! 489: slinear16_to_alaw_le(void *v, u_char *p, int cc)
! 490: {
! 491: u_char *q = p;
! 492:
! 493: while ((cc -= 2) >= 0) {
! 494: *p = lintoalaw[q[1] ^ 0x80];
! 495: ++p;
! 496: q += 2;
! 497: }
! 498: }
! 499:
! 500:
! 501: void
! 502: slinear16_to_alaw_be(void *v, u_char *p, int cc)
! 503: {
! 504: u_char *q = p;
! 505:
! 506: while ((cc -= 2) >= 0) {
! 507: *p = lintoalaw[q[0] ^ 0x80];
! 508: ++p;
! 509: q += 2;
! 510: }
! 511: }
! 512:
! 513: /*
! 514: * same as mulaw_to_ulinear16_le(), plus expand mono to stereo
! 515: */
! 516: void
! 517: mulaw_to_ulinear16_le_mts(void *v, u_char *p, int cc)
! 518: {
! 519: u_char *q = p;
! 520:
! 521: p += cc;
! 522: q += cc * 4;
! 523: while (--cc >= 0) {
! 524: --p;
! 525: q -= 4;
! 526: q[1] = q[3] = mulawtolin16[*p][0];
! 527: q[0] = q[2] = mulawtolin16[*p][1];
! 528: }
! 529: }
! 530:
! 531: /*
! 532: * same as mulaw_to_ulinear16_be(), plus expand mono to stereo
! 533: */
! 534: void
! 535: mulaw_to_ulinear16_be_mts(void *v, u_char *p, int cc)
! 536: {
! 537: u_char *q = p;
! 538:
! 539: p += cc;
! 540: q += cc * 4;
! 541: while (--cc >= 0) {
! 542: --p;
! 543: q -= 4;
! 544: q[0] = q[2] = mulawtolin16[*p][0];
! 545: q[1] = q[3] = mulawtolin16[*p][1];
! 546: }
! 547: }
! 548:
! 549: /*
! 550: * same as alaw_to_slinear16_le(), plus expand mono to stereo
! 551: */
! 552: void
! 553: alaw_to_slinear16_le_mts(void *v, u_char *p, int cc)
! 554: {
! 555: u_char *q = p;
! 556:
! 557: p += cc;
! 558: q += cc * 4;
! 559: while (--cc >= 0) {
! 560: --p;
! 561: q -= 4;
! 562: q[1] = q[3] = alawtolin16[*p][0] ^ 0x80;
! 563: q[0] = q[2] = alawtolin16[*p][1];
! 564: }
! 565: }
! 566:
! 567: /*
! 568: * same as alaw_to_slinear16_be(), plus expand mono to stereo
! 569: */
! 570: void
! 571: alaw_to_slinear16_be_mts(void *v, u_char *p, int cc)
! 572: {
! 573: u_char *q = p;
! 574:
! 575: p += cc;
! 576: q += cc * 4;
! 577: while (--cc >= 0) {
! 578: --p;
! 579: q -= 4;
! 580: q[0] = q[2] = alawtolin16[*p][0] ^ 0x80;
! 581: q[1] = q[3] = alawtolin16[*p][1];
! 582: }
! 583: }
! 584:
! 585: void
! 586: alaw_to_mulaw(void *v, u_char *p, int cc)
! 587: {
! 588: while (--cc >= 0) {
! 589: *p = lintomulaw[alawtolin16[*p][0]];
! 590: ++p;
! 591: }
! 592: }
! 593:
! 594: void
! 595: mulaw_to_alaw(void *v, u_char *p, int cc)
! 596: {
! 597: while (--cc >= 0) {
! 598: *p = lintoalaw[mulawtolin16[*p][0]];
! 599: ++p;
! 600: }
! 601: }
CVSweb