/*- * Copyright (c) 2008 Ariff Abdullah * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ #ifndef __SND_INTPCM_H__ #define __SND_INTPCM_H__ #include "pcm.h" #include "g711.h" typedef intpcm_t (*intpcm_read_t)(uint8_t *); typedef void (*intpcm_write_t)(uint8_t *, intpcm_t); #define INTPCM_DECLARE_OP(SIGN, BIT, ENDIAN, SHIFT) \ static __inline intpcm_t \ intpcm_read_##SIGN##BIT##ENDIAN(uint8_t *src) \ { \ \ return (_PCM_READ_##SIGN##BIT##_##ENDIAN(src) << SHIFT); \ } \ \ static __inline void \ intpcm_write_##SIGN##BIT##ENDIAN(uint8_t *dst, intpcm_t v) \ { \ \ _PCM_WRITE_##SIGN##BIT##_##ENDIAN(dst, v >> SHIFT); \ } #define INTPCM_DECLARE(t) \ \ G711_DECLARE_TABLE(t); \ \ static __inline intpcm_t \ intpcm_read_ulaw(uint8_t *src) \ { \ \ return (_G711_TO_INTPCM((t).ulaw_to_u8, *src) << 24); \ } \ \ static __inline intpcm_t \ intpcm_read_alaw(uint8_t *src) \ { \ \ return (_G711_TO_INTPCM((t).alaw_to_u8, *src) << 24); \ } \ \ static __inline void \ intpcm_write_ulaw(uint8_t *dst, intpcm_t v) \ { \ \ *dst = _INTPCM_TO_G711((t).u8_to_ulaw, v >> 24); \ } \ \ static __inline void \ intpcm_write_alaw(uint8_t *dst, intpcm_t v) \ { \ \ *dst = _INTPCM_TO_G711((t).u8_to_alaw, v >> 24); \ } \ \ INTPCM_DECLARE_OP(S, 8, NE, 24) \ INTPCM_DECLARE_OP(S, 16, LE, 16) \ INTPCM_DECLARE_OP(S, 16, BE, 16) \ INTPCM_DECLARE_OP(S, 24, LE, 8) \ INTPCM_DECLARE_OP(S, 24, BE, 8) \ INTPCM_DECLARE_OP(S, 32, LE, 0) \ INTPCM_DECLARE_OP(S, 32, BE, 0) \ INTPCM_DECLARE_OP(U, 8, NE, 24) \ INTPCM_DECLARE_OP(U, 16, LE, 16) \ INTPCM_DECLARE_OP(U, 16, BE, 16) \ INTPCM_DECLARE_OP(U, 24, LE, 8) \ INTPCM_DECLARE_OP(U, 24, BE, 8) \ INTPCM_DECLARE_OP(U, 32, LE, 0) \ INTPCM_DECLARE_OP(U, 32, BE, 0) #endif /* !__SND_INTPCM_H__ */