190da2b28SAriff Abdullah /*- 2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 3718cf2ccSPedro F. Giffuni * 490da2b28SAriff Abdullah * Copyright (c) 2008-2009 Ariff Abdullah <ariff@FreeBSD.org> 590da2b28SAriff Abdullah * All rights reserved. 690da2b28SAriff Abdullah * 790da2b28SAriff Abdullah * Redistribution and use in source and binary forms, with or without 890da2b28SAriff Abdullah * modification, are permitted provided that the following conditions 990da2b28SAriff Abdullah * are met: 1090da2b28SAriff Abdullah * 1. Redistributions of source code must retain the above copyright 1190da2b28SAriff Abdullah * notice, this list of conditions and the following disclaimer. 1290da2b28SAriff Abdullah * 2. Redistributions in binary form must reproduce the above copyright 1390da2b28SAriff Abdullah * notice, this list of conditions and the following disclaimer in the 1490da2b28SAriff Abdullah * documentation and/or other materials provided with the distribution. 1590da2b28SAriff Abdullah * 1690da2b28SAriff Abdullah * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1790da2b28SAriff Abdullah * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1890da2b28SAriff Abdullah * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1990da2b28SAriff Abdullah * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2090da2b28SAriff Abdullah * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2190da2b28SAriff Abdullah * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2290da2b28SAriff Abdullah * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2390da2b28SAriff Abdullah * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2490da2b28SAriff Abdullah * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2590da2b28SAriff Abdullah * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2690da2b28SAriff Abdullah * SUCH DAMAGE. 2790da2b28SAriff Abdullah * 2890da2b28SAriff Abdullah * $FreeBSD$ 2990da2b28SAriff Abdullah */ 3090da2b28SAriff Abdullah 3190da2b28SAriff Abdullah #ifndef _SND_INTPCM_H_ 3290da2b28SAriff Abdullah #define _SND_INTPCM_H_ 3390da2b28SAriff Abdullah 3490da2b28SAriff Abdullah typedef intpcm_t intpcm_read_t(uint8_t *); 3590da2b28SAriff Abdullah typedef void intpcm_write_t(uint8_t *, intpcm_t); 3690da2b28SAriff Abdullah 3790da2b28SAriff Abdullah extern intpcm_read_t *feeder_format_read_op(uint32_t); 3890da2b28SAriff Abdullah extern intpcm_write_t *feeder_format_write_op(uint32_t); 3990da2b28SAriff Abdullah 4090da2b28SAriff Abdullah #define INTPCM_DECLARE_OP_WRITE(SIGN, BIT, ENDIAN, SHIFT) \ 4190da2b28SAriff Abdullah static __inline void \ 4290da2b28SAriff Abdullah intpcm_write_##SIGN##BIT##ENDIAN(uint8_t *dst, intpcm_t v) \ 4390da2b28SAriff Abdullah { \ 4490da2b28SAriff Abdullah \ 4590da2b28SAriff Abdullah _PCM_WRITE_##SIGN##BIT##_##ENDIAN(dst, v >> SHIFT); \ 4690da2b28SAriff Abdullah } 4790da2b28SAriff Abdullah 4890da2b28SAriff Abdullah #define INTPCM_DECLARE_OP_8(SIGN, ENDIAN) \ 4990da2b28SAriff Abdullah static __inline intpcm_t \ 5090da2b28SAriff Abdullah intpcm_read_##SIGN##8##ENDIAN(uint8_t *src) \ 5190da2b28SAriff Abdullah { \ 5290da2b28SAriff Abdullah \ 5390da2b28SAriff Abdullah return (_PCM_READ_##SIGN##8##_##ENDIAN(src) << 24); \ 5490da2b28SAriff Abdullah } \ 5590da2b28SAriff Abdullah INTPCM_DECLARE_OP_WRITE(SIGN, 8, ENDIAN, 24) 5690da2b28SAriff Abdullah 5790da2b28SAriff Abdullah #define INTPCM_DECLARE_OP_16(SIGN, ENDIAN) \ 5890da2b28SAriff Abdullah static __inline intpcm_t \ 5990da2b28SAriff Abdullah intpcm_read_##SIGN##16##ENDIAN(uint8_t *src) \ 6090da2b28SAriff Abdullah { \ 6190da2b28SAriff Abdullah \ 6290da2b28SAriff Abdullah return (_PCM_READ_##SIGN##16##_##ENDIAN(src) << 16); \ 6390da2b28SAriff Abdullah } \ 6490da2b28SAriff Abdullah INTPCM_DECLARE_OP_WRITE(SIGN, 16, ENDIAN, 16) 6590da2b28SAriff Abdullah 6690da2b28SAriff Abdullah #define INTPCM_DECLARE_OP_24(SIGN, ENDIAN) \ 6790da2b28SAriff Abdullah static __inline intpcm_t \ 6890da2b28SAriff Abdullah intpcm_read_##SIGN##24##ENDIAN(uint8_t *src) \ 6990da2b28SAriff Abdullah { \ 7090da2b28SAriff Abdullah \ 7190da2b28SAriff Abdullah return (_PCM_READ_##SIGN##24##_##ENDIAN(src) << 8); \ 7290da2b28SAriff Abdullah } \ 7390da2b28SAriff Abdullah INTPCM_DECLARE_OP_WRITE(SIGN, 24, ENDIAN, 8) 7490da2b28SAriff Abdullah 7590da2b28SAriff Abdullah #define INTPCM_DECLARE_OP_32(SIGN, ENDIAN) \ 7690da2b28SAriff Abdullah static __inline intpcm_t \ 7790da2b28SAriff Abdullah intpcm_read_##SIGN##32##ENDIAN(uint8_t *src) \ 7890da2b28SAriff Abdullah { \ 7990da2b28SAriff Abdullah \ 8090da2b28SAriff Abdullah return (_PCM_READ_##SIGN##32##_##ENDIAN(src)); \ 8190da2b28SAriff Abdullah } \ 8290da2b28SAriff Abdullah \ 8390da2b28SAriff Abdullah static __inline void \ 8490da2b28SAriff Abdullah intpcm_write_##SIGN##32##ENDIAN(uint8_t *dst, intpcm_t v) \ 8590da2b28SAriff Abdullah { \ 8690da2b28SAriff Abdullah \ 8790da2b28SAriff Abdullah _PCM_WRITE_##SIGN##32##_##ENDIAN(dst, v); \ 8890da2b28SAriff Abdullah } 8990da2b28SAriff Abdullah 9090da2b28SAriff Abdullah #define INTPCM_DECLARE(t) \ 9190da2b28SAriff Abdullah \ 9290da2b28SAriff Abdullah G711_DECLARE_TABLE(t); \ 9390da2b28SAriff Abdullah \ 9490da2b28SAriff Abdullah static __inline intpcm_t \ 9590da2b28SAriff Abdullah intpcm_read_ulaw(uint8_t *src) \ 9690da2b28SAriff Abdullah { \ 9790da2b28SAriff Abdullah \ 9890da2b28SAriff Abdullah return (_G711_TO_INTPCM((t).ulaw_to_u8, *src) << 24); \ 9990da2b28SAriff Abdullah } \ 10090da2b28SAriff Abdullah \ 10190da2b28SAriff Abdullah static __inline intpcm_t \ 10290da2b28SAriff Abdullah intpcm_read_alaw(uint8_t *src) \ 10390da2b28SAriff Abdullah { \ 10490da2b28SAriff Abdullah \ 10590da2b28SAriff Abdullah return (_G711_TO_INTPCM((t).alaw_to_u8, *src) << 24); \ 10690da2b28SAriff Abdullah } \ 10790da2b28SAriff Abdullah \ 10890da2b28SAriff Abdullah static __inline void \ 10990da2b28SAriff Abdullah intpcm_write_ulaw(uint8_t *dst, intpcm_t v) \ 11090da2b28SAriff Abdullah { \ 11190da2b28SAriff Abdullah \ 11290da2b28SAriff Abdullah *dst = _INTPCM_TO_G711((t).u8_to_ulaw, v >> 24); \ 11390da2b28SAriff Abdullah } \ 11490da2b28SAriff Abdullah \ 11590da2b28SAriff Abdullah static __inline void \ 11690da2b28SAriff Abdullah intpcm_write_alaw(uint8_t *dst, intpcm_t v) \ 11790da2b28SAriff Abdullah { \ 11890da2b28SAriff Abdullah \ 11990da2b28SAriff Abdullah *dst = _INTPCM_TO_G711((t).u8_to_alaw, v >> 24); \ 12090da2b28SAriff Abdullah } \ 12190da2b28SAriff Abdullah \ 12290da2b28SAriff Abdullah INTPCM_DECLARE_OP_8(S, NE) \ 12390da2b28SAriff Abdullah INTPCM_DECLARE_OP_16(S, LE) \ 12490da2b28SAriff Abdullah INTPCM_DECLARE_OP_16(S, BE) \ 12590da2b28SAriff Abdullah INTPCM_DECLARE_OP_24(S, LE) \ 12690da2b28SAriff Abdullah INTPCM_DECLARE_OP_24(S, BE) \ 12790da2b28SAriff Abdullah INTPCM_DECLARE_OP_32(S, LE) \ 12890da2b28SAriff Abdullah INTPCM_DECLARE_OP_32(S, BE) \ 12990da2b28SAriff Abdullah INTPCM_DECLARE_OP_8(U, NE) \ 13090da2b28SAriff Abdullah INTPCM_DECLARE_OP_16(U, LE) \ 13190da2b28SAriff Abdullah INTPCM_DECLARE_OP_16(U, BE) \ 13290da2b28SAriff Abdullah INTPCM_DECLARE_OP_24(U, LE) \ 13390da2b28SAriff Abdullah INTPCM_DECLARE_OP_24(U, BE) \ 13490da2b28SAriff Abdullah INTPCM_DECLARE_OP_32(U, LE) \ 13590da2b28SAriff Abdullah INTPCM_DECLARE_OP_32(U, BE) 13690da2b28SAriff Abdullah 13790da2b28SAriff Abdullah #endif /* !_SND_INTPCM_H_ */ 138