1*2a1ad637SFrançois Tigeot /*- 2*2a1ad637SFrançois Tigeot * Copyright (c) 2008-2009 Ariff Abdullah <ariff@FreeBSD.org> 3*2a1ad637SFrançois Tigeot * All rights reserved. 4*2a1ad637SFrançois Tigeot * 5*2a1ad637SFrançois Tigeot * Redistribution and use in source and binary forms, with or without 6*2a1ad637SFrançois Tigeot * modification, are permitted provided that the following conditions 7*2a1ad637SFrançois Tigeot * are met: 8*2a1ad637SFrançois Tigeot * 1. Redistributions of source code must retain the above copyright 9*2a1ad637SFrançois Tigeot * notice, this list of conditions and the following disclaimer. 10*2a1ad637SFrançois Tigeot * 2. Redistributions in binary form must reproduce the above copyright 11*2a1ad637SFrançois Tigeot * notice, this list of conditions and the following disclaimer in the 12*2a1ad637SFrançois Tigeot * documentation and/or other materials provided with the distribution. 13*2a1ad637SFrançois Tigeot * 14*2a1ad637SFrançois Tigeot * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15*2a1ad637SFrançois Tigeot * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16*2a1ad637SFrançois Tigeot * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17*2a1ad637SFrançois Tigeot * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18*2a1ad637SFrançois Tigeot * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19*2a1ad637SFrançois Tigeot * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20*2a1ad637SFrançois Tigeot * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21*2a1ad637SFrançois Tigeot * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22*2a1ad637SFrançois Tigeot * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23*2a1ad637SFrançois Tigeot * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24*2a1ad637SFrançois Tigeot * SUCH DAMAGE. 25*2a1ad637SFrançois Tigeot * 26*2a1ad637SFrançois Tigeot * $FreeBSD: head/sys/dev/sound/pcm/intpcm.h 193640 2009-06-07 19:12:08Z ariff $ 27*2a1ad637SFrançois Tigeot */ 28*2a1ad637SFrançois Tigeot 29*2a1ad637SFrançois Tigeot #ifndef _SND_INTPCM_H_ 30*2a1ad637SFrançois Tigeot #define _SND_INTPCM_H_ 31*2a1ad637SFrançois Tigeot 32*2a1ad637SFrançois Tigeot typedef intpcm_t intpcm_read_t(uint8_t *); 33*2a1ad637SFrançois Tigeot typedef void intpcm_write_t(uint8_t *, intpcm_t); 34*2a1ad637SFrançois Tigeot 35*2a1ad637SFrançois Tigeot extern intpcm_read_t *feeder_format_read_op(uint32_t); 36*2a1ad637SFrançois Tigeot extern intpcm_write_t *feeder_format_write_op(uint32_t); 37*2a1ad637SFrançois Tigeot 38*2a1ad637SFrançois Tigeot #define INTPCM_DECLARE_OP_WRITE(SIGN, BIT, ENDIAN, SHIFT) \ 39*2a1ad637SFrançois Tigeot static __inline void \ 40*2a1ad637SFrançois Tigeot intpcm_write_##SIGN##BIT##ENDIAN(uint8_t *dst, intpcm_t v) \ 41*2a1ad637SFrançois Tigeot { \ 42*2a1ad637SFrançois Tigeot \ 43*2a1ad637SFrançois Tigeot _PCM_WRITE_##SIGN##BIT##_##ENDIAN(dst, v >> SHIFT); \ 44*2a1ad637SFrançois Tigeot } 45*2a1ad637SFrançois Tigeot 46*2a1ad637SFrançois Tigeot #define INTPCM_DECLARE_OP_8(SIGN, ENDIAN) \ 47*2a1ad637SFrançois Tigeot static __inline intpcm_t \ 48*2a1ad637SFrançois Tigeot intpcm_read_##SIGN##8##ENDIAN(uint8_t *src) \ 49*2a1ad637SFrançois Tigeot { \ 50*2a1ad637SFrançois Tigeot \ 51*2a1ad637SFrançois Tigeot return (_PCM_READ_##SIGN##8##_##ENDIAN(src) << 24); \ 52*2a1ad637SFrançois Tigeot } \ 53*2a1ad637SFrançois Tigeot INTPCM_DECLARE_OP_WRITE(SIGN, 8, ENDIAN, 24) 54*2a1ad637SFrançois Tigeot 55*2a1ad637SFrançois Tigeot #define INTPCM_DECLARE_OP_16(SIGN, ENDIAN) \ 56*2a1ad637SFrançois Tigeot static __inline intpcm_t \ 57*2a1ad637SFrançois Tigeot intpcm_read_##SIGN##16##ENDIAN(uint8_t *src) \ 58*2a1ad637SFrançois Tigeot { \ 59*2a1ad637SFrançois Tigeot \ 60*2a1ad637SFrançois Tigeot return (_PCM_READ_##SIGN##16##_##ENDIAN(src) << 16); \ 61*2a1ad637SFrançois Tigeot } \ 62*2a1ad637SFrançois Tigeot INTPCM_DECLARE_OP_WRITE(SIGN, 16, ENDIAN, 16) 63*2a1ad637SFrançois Tigeot 64*2a1ad637SFrançois Tigeot #define INTPCM_DECLARE_OP_24(SIGN, ENDIAN) \ 65*2a1ad637SFrançois Tigeot static __inline intpcm_t \ 66*2a1ad637SFrançois Tigeot intpcm_read_##SIGN##24##ENDIAN(uint8_t *src) \ 67*2a1ad637SFrançois Tigeot { \ 68*2a1ad637SFrançois Tigeot \ 69*2a1ad637SFrançois Tigeot return (_PCM_READ_##SIGN##24##_##ENDIAN(src) << 8); \ 70*2a1ad637SFrançois Tigeot } \ 71*2a1ad637SFrançois Tigeot INTPCM_DECLARE_OP_WRITE(SIGN, 24, ENDIAN, 8) 72*2a1ad637SFrançois Tigeot 73*2a1ad637SFrançois Tigeot #define INTPCM_DECLARE_OP_32(SIGN, ENDIAN) \ 74*2a1ad637SFrançois Tigeot static __inline intpcm_t \ 75*2a1ad637SFrançois Tigeot intpcm_read_##SIGN##32##ENDIAN(uint8_t *src) \ 76*2a1ad637SFrançois Tigeot { \ 77*2a1ad637SFrançois Tigeot \ 78*2a1ad637SFrançois Tigeot return (_PCM_READ_##SIGN##32##_##ENDIAN(src)); \ 79*2a1ad637SFrançois Tigeot } \ 80*2a1ad637SFrançois Tigeot \ 81*2a1ad637SFrançois Tigeot static __inline void \ 82*2a1ad637SFrançois Tigeot intpcm_write_##SIGN##32##ENDIAN(uint8_t *dst, intpcm_t v) \ 83*2a1ad637SFrançois Tigeot { \ 84*2a1ad637SFrançois Tigeot \ 85*2a1ad637SFrançois Tigeot _PCM_WRITE_##SIGN##32##_##ENDIAN(dst, v); \ 86*2a1ad637SFrançois Tigeot } 87*2a1ad637SFrançois Tigeot 88*2a1ad637SFrançois Tigeot 89*2a1ad637SFrançois Tigeot #define INTPCM_DECLARE(t) \ 90*2a1ad637SFrançois Tigeot \ 91*2a1ad637SFrançois Tigeot G711_DECLARE_TABLE(t); \ 92*2a1ad637SFrançois Tigeot \ 93*2a1ad637SFrançois Tigeot static __inline intpcm_t \ 94*2a1ad637SFrançois Tigeot intpcm_read_ulaw(uint8_t *src) \ 95*2a1ad637SFrançois Tigeot { \ 96*2a1ad637SFrançois Tigeot \ 97*2a1ad637SFrançois Tigeot return (_G711_TO_INTPCM((t).ulaw_to_u8, *src) << 24); \ 98*2a1ad637SFrançois Tigeot } \ 99*2a1ad637SFrançois Tigeot \ 100*2a1ad637SFrançois Tigeot static __inline intpcm_t \ 101*2a1ad637SFrançois Tigeot intpcm_read_alaw(uint8_t *src) \ 102*2a1ad637SFrançois Tigeot { \ 103*2a1ad637SFrançois Tigeot \ 104*2a1ad637SFrançois Tigeot return (_G711_TO_INTPCM((t).alaw_to_u8, *src) << 24); \ 105*2a1ad637SFrançois Tigeot } \ 106*2a1ad637SFrançois Tigeot \ 107*2a1ad637SFrançois Tigeot static __inline void \ 108*2a1ad637SFrançois Tigeot intpcm_write_ulaw(uint8_t *dst, intpcm_t v) \ 109*2a1ad637SFrançois Tigeot { \ 110*2a1ad637SFrançois Tigeot \ 111*2a1ad637SFrançois Tigeot *dst = _INTPCM_TO_G711((t).u8_to_ulaw, v >> 24); \ 112*2a1ad637SFrançois Tigeot } \ 113*2a1ad637SFrançois Tigeot \ 114*2a1ad637SFrançois Tigeot static __inline void \ 115*2a1ad637SFrançois Tigeot intpcm_write_alaw(uint8_t *dst, intpcm_t v) \ 116*2a1ad637SFrançois Tigeot { \ 117*2a1ad637SFrançois Tigeot \ 118*2a1ad637SFrançois Tigeot *dst = _INTPCM_TO_G711((t).u8_to_alaw, v >> 24); \ 119*2a1ad637SFrançois Tigeot } \ 120*2a1ad637SFrançois Tigeot \ 121*2a1ad637SFrançois Tigeot INTPCM_DECLARE_OP_8(S, NE) \ 122*2a1ad637SFrançois Tigeot INTPCM_DECLARE_OP_16(S, LE) \ 123*2a1ad637SFrançois Tigeot INTPCM_DECLARE_OP_16(S, BE) \ 124*2a1ad637SFrançois Tigeot INTPCM_DECLARE_OP_24(S, LE) \ 125*2a1ad637SFrançois Tigeot INTPCM_DECLARE_OP_24(S, BE) \ 126*2a1ad637SFrançois Tigeot INTPCM_DECLARE_OP_32(S, LE) \ 127*2a1ad637SFrançois Tigeot INTPCM_DECLARE_OP_32(S, BE) \ 128*2a1ad637SFrançois Tigeot INTPCM_DECLARE_OP_8(U, NE) \ 129*2a1ad637SFrançois Tigeot INTPCM_DECLARE_OP_16(U, LE) \ 130*2a1ad637SFrançois Tigeot INTPCM_DECLARE_OP_16(U, BE) \ 131*2a1ad637SFrançois Tigeot INTPCM_DECLARE_OP_24(U, LE) \ 132*2a1ad637SFrançois Tigeot INTPCM_DECLARE_OP_24(U, BE) \ 133*2a1ad637SFrançois Tigeot INTPCM_DECLARE_OP_32(U, LE) \ 134*2a1ad637SFrançois Tigeot INTPCM_DECLARE_OP_32(U, BE) 135*2a1ad637SFrançois Tigeot 136*2a1ad637SFrançois Tigeot #endif /* !_SND_INTPCM_H_ */ 137