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