Home | History | Annotate | Line # | Download | only in common
auconv.h revision 1.4
      1 /*	$NetBSD: auconv.h,v 1.4 2005/12/24 21:48:16 perry Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1997 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Lennart Augustsson.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *        This product includes software developed by the NetBSD
     21  *        Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 #include <sys/types.h>
     40 #include <sys/audioio.h>
     41 
     42 /* Convert between signed and unsigned. */
     43 static inline void change_sign8(u_char *, int);
     44 static inline void change_sign16_le(u_char *, int);
     45 static inline void change_sign16_be(u_char *, int);
     46 static inline void change_sign32_le(u_char *, int);
     47 static inline void change_sign32_be(u_char *, int);
     48 /* Convert between little and big endian. */
     49 static inline void swap_bytes(u_char *, int);
     50 static inline void swap_bytes32(u_char *, int);
     51 static inline void swap_bytes_change_sign16_le(u_char *, int);
     52 static inline void swap_bytes_change_sign16_be(u_char *, int);
     53 static inline void change_sign16_swap_bytes_le(u_char *, int);
     54 static inline void change_sign16_swap_bytes_be(u_char *, int);
     55 static inline void swap_bytes_change_sign32_le(u_char *, int);
     56 static inline void swap_bytes_change_sign32_be(u_char *, int);
     57 static inline void change_sign32_swap_bytes_le(u_char *, int);
     58 static inline void change_sign32_swap_bytes_be(u_char *, int);
     59 
     60 static inline void
     61 change_sign8(u_char *p, int cc)
     62 {
     63 	while (--cc >= 0) {
     64 		*p ^= 0x80;
     65 		++p;
     66 	}
     67 }
     68 
     69 static inline void
     70 change_sign16_le(u_char *p, int cc)
     71 {
     72 	while ((cc -= 2) >= 0) {
     73 		p[1] ^= 0x80;
     74 		p += 2;
     75 	}
     76 }
     77 
     78 static inline void
     79 change_sign16_be(u_char *p, int cc)
     80 {
     81 	while ((cc -= 2) >= 0) {
     82 		p[0] ^= 0x80;
     83 		p += 2;
     84 	}
     85 }
     86 
     87 static inline void
     88 change_sign32_le(u_char *p, int cc)
     89 {
     90 	while ((cc -= 4) >= 0) {
     91 		p[3] ^= 0x80;
     92 		p += 4;
     93 	}
     94 }
     95 
     96 static inline void
     97 change_sign32_be(u_char *p, int cc)
     98 {
     99 	while ((cc -= 4) >= 0) {
    100 		p[0] ^= 0x80;
    101 		p += 4;
    102 	}
    103 }
    104 
    105 static inline void
    106 swap_bytes(u_char *p, int cc)
    107 {
    108 	u_char t;
    109 
    110 	while ((cc -= 2) >= 0) {
    111 		t = p[0];
    112 		p[0] = p[1];
    113 		p[1] = t;
    114 		p += 2;
    115 	}
    116 }
    117 
    118 static inline void
    119 swap_bytes32(u_char *p, int cc)
    120 {
    121 	u_char t;
    122 
    123 	while ((cc -= 4) >= 0) {
    124 		t = p[0];
    125 		p[0] = p[3];
    126 		p[3] = t;
    127 		t = p[1];
    128 		p[1] = p[2];
    129 		p[2] = t;
    130 		p += 4;
    131 	}
    132 }
    133 
    134 static inline void
    135 swap_bytes_change_sign16_le(u_char *p, int cc)
    136 {
    137 	u_char t;
    138 
    139 	while ((cc -= 2) >= 0) {
    140 		t = p[1];
    141 		p[1] = p[0] ^ 0x80;
    142 		p[0] = t;
    143 		p += 2;
    144 	}
    145 }
    146 
    147 static inline void
    148 swap_bytes_change_sign16_be(u_char *p, int cc)
    149 {
    150 	u_char t;
    151 
    152 	while ((cc -= 2) >= 0) {
    153 		t = p[0];
    154 		p[0] = p[1] ^ 0x80;
    155 		p[1] = t;
    156 		p += 2;
    157 	}
    158 }
    159 
    160 static inline void
    161 change_sign16_swap_bytes_le(u_char *p, int cc)
    162 {
    163 	swap_bytes_change_sign16_be(p, cc);
    164 }
    165 
    166 static inline void
    167 change_sign16_swap_bytes_be(u_char *p, int cc)
    168 {
    169 	swap_bytes_change_sign16_le(p, cc);
    170 }
    171 
    172 static inline void
    173 swap_bytes_change_sign32_le(u_char *p, int cc)
    174 {
    175 	u_char t;
    176 
    177 	while ((cc -= 4) >= 0) {
    178 		t = p[3];
    179 		p[3] = p[0] ^ 0x80;
    180 		p[0] = t;
    181 		t = p[1];
    182 		p[1] = p[2];
    183 		p[2] = t;
    184 		p += 4;
    185 	}
    186 }
    187 
    188 static inline void
    189 swap_bytes_change_sign32_be(u_char *p, int cc)
    190 {
    191 	u_char t;
    192 
    193 	while ((cc -= 4) >= 0) {
    194 		t = p[0];
    195 		p[0] = p[3] ^ 0x80;
    196 		p[3] = t;
    197 		t = p[1];
    198 		p[1] = p[2];
    199 		p[2] = t;
    200 		p += 4;
    201 	}
    202 }
    203 
    204 static inline void
    205 change_sign32_swap_bytes_le(u_char *p, int cc)
    206 {
    207 	swap_bytes_change_sign32_be(p, cc);
    208 }
    209 
    210 static inline void
    211 change_sign32_swap_bytes_be(u_char *p, int cc)
    212 {
    213 	swap_bytes_change_sign32_le(p, cc);
    214 }
    215