Home | History | Annotate | Line # | Download | only in common
      1  1.6  mlelstv /*	$NetBSD: auconv.h,v 1.6 2023/04/15 12:39:44 mlelstv 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  *
     19  1.1      mrg  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.1      mrg  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.1      mrg  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.1      mrg  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.1      mrg  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.1      mrg  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.1      mrg  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.1      mrg  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.1      mrg  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.1      mrg  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.1      mrg  * POSSIBILITY OF SUCH DAMAGE.
     30  1.1      mrg  */
     31  1.1      mrg 
     32  1.2      mrg #include <sys/types.h>
     33  1.2      mrg #include <sys/audioio.h>
     34  1.2      mrg 
     35  1.1      mrg /* Convert between signed and unsigned. */
     36  1.4    perry static inline void change_sign8(u_char *, int);
     37  1.4    perry static inline void change_sign16_le(u_char *, int);
     38  1.4    perry static inline void change_sign16_be(u_char *, int);
     39  1.4    perry static inline void change_sign32_le(u_char *, int);
     40  1.4    perry static inline void change_sign32_be(u_char *, int);
     41  1.1      mrg /* Convert between little and big endian. */
     42  1.4    perry static inline void swap_bytes(u_char *, int);
     43  1.4    perry static inline void swap_bytes32(u_char *, int);
     44  1.4    perry static inline void swap_bytes_change_sign16_le(u_char *, int);
     45  1.4    perry static inline void swap_bytes_change_sign16_be(u_char *, int);
     46  1.4    perry static inline void change_sign16_swap_bytes_le(u_char *, int);
     47  1.4    perry static inline void change_sign16_swap_bytes_be(u_char *, int);
     48  1.4    perry static inline void swap_bytes_change_sign32_le(u_char *, int);
     49  1.4    perry static inline void swap_bytes_change_sign32_be(u_char *, int);
     50  1.4    perry static inline void change_sign32_swap_bytes_le(u_char *, int);
     51  1.4    perry static inline void change_sign32_swap_bytes_be(u_char *, int);
     52  1.2      mrg 
     53  1.4    perry static inline void
     54  1.3  mycroft change_sign8(u_char *p, int cc)
     55  1.2      mrg {
     56  1.3  mycroft 	while (--cc >= 0) {
     57  1.2      mrg 		*p ^= 0x80;
     58  1.2      mrg 		++p;
     59  1.2      mrg 	}
     60  1.2      mrg }
     61  1.2      mrg 
     62  1.4    perry static inline void
     63  1.3  mycroft change_sign16_le(u_char *p, int cc)
     64  1.2      mrg {
     65  1.3  mycroft 	while ((cc -= 2) >= 0) {
     66  1.2      mrg 		p[1] ^= 0x80;
     67  1.2      mrg 		p += 2;
     68  1.2      mrg 	}
     69  1.2      mrg }
     70  1.2      mrg 
     71  1.4    perry static inline void
     72  1.3  mycroft change_sign16_be(u_char *p, int cc)
     73  1.2      mrg {
     74  1.3  mycroft 	while ((cc -= 2) >= 0) {
     75  1.2      mrg 		p[0] ^= 0x80;
     76  1.2      mrg 		p += 2;
     77  1.2      mrg 	}
     78  1.2      mrg }
     79  1.2      mrg 
     80  1.4    perry static inline void
     81  1.6  mlelstv change_sign24_le(u_char *p, int cc)
     82  1.6  mlelstv {
     83  1.6  mlelstv 	while ((cc -= 3) >= 0) {
     84  1.6  mlelstv 		p[2] ^= 0x80;
     85  1.6  mlelstv 		p += 3;
     86  1.6  mlelstv 	}
     87  1.6  mlelstv }
     88  1.6  mlelstv 
     89  1.6  mlelstv static inline void
     90  1.6  mlelstv change_sign24_be(u_char *p, int cc)
     91  1.6  mlelstv {
     92  1.6  mlelstv 	while ((cc -= 3) >= 0) {
     93  1.6  mlelstv 		p[0] ^= 0x80;
     94  1.6  mlelstv 		p += 3;
     95  1.6  mlelstv 	}
     96  1.6  mlelstv }
     97  1.6  mlelstv 
     98  1.6  mlelstv static inline void
     99  1.3  mycroft change_sign32_le(u_char *p, int cc)
    100  1.2      mrg {
    101  1.3  mycroft 	while ((cc -= 4) >= 0) {
    102  1.2      mrg 		p[3] ^= 0x80;
    103  1.2      mrg 		p += 4;
    104  1.2      mrg 	}
    105  1.2      mrg }
    106  1.2      mrg 
    107  1.4    perry static inline void
    108  1.3  mycroft change_sign32_be(u_char *p, int cc)
    109  1.2      mrg {
    110  1.3  mycroft 	while ((cc -= 4) >= 0) {
    111  1.2      mrg 		p[0] ^= 0x80;
    112  1.2      mrg 		p += 4;
    113  1.2      mrg 	}
    114  1.2      mrg }
    115  1.2      mrg 
    116  1.4    perry static inline void
    117  1.3  mycroft swap_bytes(u_char *p, int cc)
    118  1.2      mrg {
    119  1.2      mrg 	u_char t;
    120  1.2      mrg 
    121  1.3  mycroft 	while ((cc -= 2) >= 0) {
    122  1.2      mrg 		t = p[0];
    123  1.2      mrg 		p[0] = p[1];
    124  1.2      mrg 		p[1] = t;
    125  1.2      mrg 		p += 2;
    126  1.2      mrg 	}
    127  1.2      mrg }
    128  1.2      mrg 
    129  1.4    perry static inline void
    130  1.3  mycroft swap_bytes32(u_char *p, int cc)
    131  1.2      mrg {
    132  1.2      mrg 	u_char t;
    133  1.2      mrg 
    134  1.3  mycroft 	while ((cc -= 4) >= 0) {
    135  1.2      mrg 		t = p[0];
    136  1.2      mrg 		p[0] = p[3];
    137  1.2      mrg 		p[3] = t;
    138  1.2      mrg 		t = p[1];
    139  1.2      mrg 		p[1] = p[2];
    140  1.2      mrg 		p[2] = t;
    141  1.2      mrg 		p += 4;
    142  1.2      mrg 	}
    143  1.2      mrg }
    144  1.2      mrg 
    145  1.4    perry static inline void
    146  1.3  mycroft swap_bytes_change_sign16_le(u_char *p, int cc)
    147  1.2      mrg {
    148  1.2      mrg 	u_char t;
    149  1.2      mrg 
    150  1.3  mycroft 	while ((cc -= 2) >= 0) {
    151  1.2      mrg 		t = p[1];
    152  1.2      mrg 		p[1] = p[0] ^ 0x80;
    153  1.2      mrg 		p[0] = t;
    154  1.2      mrg 		p += 2;
    155  1.2      mrg 	}
    156  1.2      mrg }
    157  1.2      mrg 
    158  1.4    perry static inline void
    159  1.3  mycroft swap_bytes_change_sign16_be(u_char *p, int cc)
    160  1.2      mrg {
    161  1.2      mrg 	u_char t;
    162  1.2      mrg 
    163  1.3  mycroft 	while ((cc -= 2) >= 0) {
    164  1.2      mrg 		t = p[0];
    165  1.2      mrg 		p[0] = p[1] ^ 0x80;
    166  1.2      mrg 		p[1] = t;
    167  1.2      mrg 		p += 2;
    168  1.2      mrg 	}
    169  1.2      mrg }
    170  1.2      mrg 
    171  1.4    perry static inline void
    172  1.3  mycroft change_sign16_swap_bytes_le(u_char *p, int cc)
    173  1.2      mrg {
    174  1.2      mrg 	swap_bytes_change_sign16_be(p, cc);
    175  1.2      mrg }
    176  1.2      mrg 
    177  1.4    perry static inline void
    178  1.3  mycroft change_sign16_swap_bytes_be(u_char *p, int cc)
    179  1.2      mrg {
    180  1.2      mrg 	swap_bytes_change_sign16_le(p, cc);
    181  1.2      mrg }
    182  1.2      mrg 
    183  1.4    perry static inline void
    184  1.6  mlelstv swap_bytes_change_sign24_le(u_char *p, int cc)
    185  1.6  mlelstv {
    186  1.6  mlelstv 	u_char t;
    187  1.6  mlelstv 
    188  1.6  mlelstv 	while ((cc -= 3) >= 0) {
    189  1.6  mlelstv 		t = p[2];
    190  1.6  mlelstv 		p[2] = p[0] ^ 0x80;
    191  1.6  mlelstv 		p[0] = t;
    192  1.6  mlelstv 		p += 3;
    193  1.6  mlelstv 	}
    194  1.6  mlelstv }
    195  1.6  mlelstv 
    196  1.6  mlelstv static inline void
    197  1.6  mlelstv swap_bytes_change_sign24_be(u_char *p, int cc)
    198  1.6  mlelstv {
    199  1.6  mlelstv 	u_char t;
    200  1.6  mlelstv 
    201  1.6  mlelstv 	while ((cc -= 3) >= 0) {
    202  1.6  mlelstv 		t = p[0];
    203  1.6  mlelstv 		p[0] = p[2] ^ 0x80;
    204  1.6  mlelstv 		p[2] = t;
    205  1.6  mlelstv 		p += 3;
    206  1.6  mlelstv 	}
    207  1.6  mlelstv }
    208  1.6  mlelstv 
    209  1.6  mlelstv static inline void
    210  1.6  mlelstv change_sign24_swap_bytes_le(u_char *p, int cc)
    211  1.6  mlelstv {
    212  1.6  mlelstv 	swap_bytes_change_sign24_be(p, cc);
    213  1.6  mlelstv }
    214  1.6  mlelstv 
    215  1.6  mlelstv static inline void
    216  1.6  mlelstv change_sign24_swap_bytes_be(u_char *p, int cc)
    217  1.6  mlelstv {
    218  1.6  mlelstv 	swap_bytes_change_sign24_le(p, cc);
    219  1.6  mlelstv }
    220  1.6  mlelstv 
    221  1.6  mlelstv static inline void
    222  1.3  mycroft swap_bytes_change_sign32_le(u_char *p, int cc)
    223  1.2      mrg {
    224  1.2      mrg 	u_char t;
    225  1.2      mrg 
    226  1.3  mycroft 	while ((cc -= 4) >= 0) {
    227  1.2      mrg 		t = p[3];
    228  1.2      mrg 		p[3] = p[0] ^ 0x80;
    229  1.2      mrg 		p[0] = t;
    230  1.2      mrg 		t = p[1];
    231  1.2      mrg 		p[1] = p[2];
    232  1.2      mrg 		p[2] = t;
    233  1.2      mrg 		p += 4;
    234  1.2      mrg 	}
    235  1.2      mrg }
    236  1.2      mrg 
    237  1.4    perry static inline void
    238  1.3  mycroft swap_bytes_change_sign32_be(u_char *p, int cc)
    239  1.2      mrg {
    240  1.2      mrg 	u_char t;
    241  1.2      mrg 
    242  1.3  mycroft 	while ((cc -= 4) >= 0) {
    243  1.2      mrg 		t = p[0];
    244  1.2      mrg 		p[0] = p[3] ^ 0x80;
    245  1.2      mrg 		p[3] = t;
    246  1.2      mrg 		t = p[1];
    247  1.2      mrg 		p[1] = p[2];
    248  1.2      mrg 		p[2] = t;
    249  1.2      mrg 		p += 4;
    250  1.2      mrg 	}
    251  1.2      mrg }
    252  1.2      mrg 
    253  1.4    perry static inline void
    254  1.3  mycroft change_sign32_swap_bytes_le(u_char *p, int cc)
    255  1.2      mrg {
    256  1.2      mrg 	swap_bytes_change_sign32_be(p, cc);
    257  1.2      mrg }
    258  1.2      mrg 
    259  1.4    perry static inline void
    260  1.3  mycroft change_sign32_swap_bytes_be(u_char *p, int cc)
    261  1.2      mrg {
    262  1.2      mrg 	swap_bytes_change_sign32_le(p, cc);
    263  1.2      mrg }
    264