1193640Sariff/*- 2193640Sariff * Copyright (c) 2008-2009 Ariff Abdullah <ariff@FreeBSD.org> 3193640Sariff * All rights reserved. 4193640Sariff * 5193640Sariff * Redistribution and use in source and binary forms, with or without 6193640Sariff * modification, are permitted provided that the following conditions 7193640Sariff * are met: 8193640Sariff * 1. Redistributions of source code must retain the above copyright 9193640Sariff * notice, this list of conditions and the following disclaimer. 10193640Sariff * 2. Redistributions in binary form must reproduce the above copyright 11193640Sariff * notice, this list of conditions and the following disclaimer in the 12193640Sariff * documentation and/or other materials provided with the distribution. 13193640Sariff * 14193640Sariff * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15193640Sariff * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16193640Sariff * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17193640Sariff * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18193640Sariff * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19193640Sariff * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20193640Sariff * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21193640Sariff * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22193640Sariff * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23193640Sariff * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24193640Sariff * SUCH DAMAGE. 25193640Sariff * 26193640Sariff * $FreeBSD: releng/10.2/sys/dev/sound/pcm/intpcm.h 193640 2009-06-07 19:12:08Z ariff $ 27193640Sariff */ 28193640Sariff 29193640Sariff#ifndef _SND_INTPCM_H_ 30193640Sariff#define _SND_INTPCM_H_ 31193640Sariff 32193640Sarifftypedef intpcm_t intpcm_read_t(uint8_t *); 33193640Sarifftypedef void intpcm_write_t(uint8_t *, intpcm_t); 34193640Sariff 35193640Sariffextern intpcm_read_t *feeder_format_read_op(uint32_t); 36193640Sariffextern intpcm_write_t *feeder_format_write_op(uint32_t); 37193640Sariff 38193640Sariff#define INTPCM_DECLARE_OP_WRITE(SIGN, BIT, ENDIAN, SHIFT) \ 39193640Sariffstatic __inline void \ 40193640Sariffintpcm_write_##SIGN##BIT##ENDIAN(uint8_t *dst, intpcm_t v) \ 41193640Sariff{ \ 42193640Sariff \ 43193640Sariff _PCM_WRITE_##SIGN##BIT##_##ENDIAN(dst, v >> SHIFT); \ 44193640Sariff} 45193640Sariff 46193640Sariff#define INTPCM_DECLARE_OP_8(SIGN, ENDIAN) \ 47193640Sariffstatic __inline intpcm_t \ 48193640Sariffintpcm_read_##SIGN##8##ENDIAN(uint8_t *src) \ 49193640Sariff{ \ 50193640Sariff \ 51193640Sariff return (_PCM_READ_##SIGN##8##_##ENDIAN(src) << 24); \ 52193640Sariff} \ 53193640SariffINTPCM_DECLARE_OP_WRITE(SIGN, 8, ENDIAN, 24) 54193640Sariff 55193640Sariff#define INTPCM_DECLARE_OP_16(SIGN, ENDIAN) \ 56193640Sariffstatic __inline intpcm_t \ 57193640Sariffintpcm_read_##SIGN##16##ENDIAN(uint8_t *src) \ 58193640Sariff{ \ 59193640Sariff \ 60193640Sariff return (_PCM_READ_##SIGN##16##_##ENDIAN(src) << 16); \ 61193640Sariff} \ 62193640SariffINTPCM_DECLARE_OP_WRITE(SIGN, 16, ENDIAN, 16) 63193640Sariff 64193640Sariff#define INTPCM_DECLARE_OP_24(SIGN, ENDIAN) \ 65193640Sariffstatic __inline intpcm_t \ 66193640Sariffintpcm_read_##SIGN##24##ENDIAN(uint8_t *src) \ 67193640Sariff{ \ 68193640Sariff \ 69193640Sariff return (_PCM_READ_##SIGN##24##_##ENDIAN(src) << 8); \ 70193640Sariff} \ 71193640SariffINTPCM_DECLARE_OP_WRITE(SIGN, 24, ENDIAN, 8) 72193640Sariff 73193640Sariff#define INTPCM_DECLARE_OP_32(SIGN, ENDIAN) \ 74193640Sariffstatic __inline intpcm_t \ 75193640Sariffintpcm_read_##SIGN##32##ENDIAN(uint8_t *src) \ 76193640Sariff{ \ 77193640Sariff \ 78193640Sariff return (_PCM_READ_##SIGN##32##_##ENDIAN(src)); \ 79193640Sariff} \ 80193640Sariff \ 81193640Sariffstatic __inline void \ 82193640Sariffintpcm_write_##SIGN##32##ENDIAN(uint8_t *dst, intpcm_t v) \ 83193640Sariff{ \ 84193640Sariff \ 85193640Sariff _PCM_WRITE_##SIGN##32##_##ENDIAN(dst, v); \ 86193640Sariff} 87193640Sariff 88193640Sariff 89193640Sariff#define INTPCM_DECLARE(t) \ 90193640Sariff \ 91193640SariffG711_DECLARE_TABLE(t); \ 92193640Sariff \ 93193640Sariffstatic __inline intpcm_t \ 94193640Sariffintpcm_read_ulaw(uint8_t *src) \ 95193640Sariff{ \ 96193640Sariff \ 97193640Sariff return (_G711_TO_INTPCM((t).ulaw_to_u8, *src) << 24); \ 98193640Sariff} \ 99193640Sariff \ 100193640Sariffstatic __inline intpcm_t \ 101193640Sariffintpcm_read_alaw(uint8_t *src) \ 102193640Sariff{ \ 103193640Sariff \ 104193640Sariff return (_G711_TO_INTPCM((t).alaw_to_u8, *src) << 24); \ 105193640Sariff} \ 106193640Sariff \ 107193640Sariffstatic __inline void \ 108193640Sariffintpcm_write_ulaw(uint8_t *dst, intpcm_t v) \ 109193640Sariff{ \ 110193640Sariff \ 111193640Sariff *dst = _INTPCM_TO_G711((t).u8_to_ulaw, v >> 24); \ 112193640Sariff} \ 113193640Sariff \ 114193640Sariffstatic __inline void \ 115193640Sariffintpcm_write_alaw(uint8_t *dst, intpcm_t v) \ 116193640Sariff{ \ 117193640Sariff \ 118193640Sariff *dst = _INTPCM_TO_G711((t).u8_to_alaw, v >> 24); \ 119193640Sariff} \ 120193640Sariff \ 121193640SariffINTPCM_DECLARE_OP_8(S, NE) \ 122193640SariffINTPCM_DECLARE_OP_16(S, LE) \ 123193640SariffINTPCM_DECLARE_OP_16(S, BE) \ 124193640SariffINTPCM_DECLARE_OP_24(S, LE) \ 125193640SariffINTPCM_DECLARE_OP_24(S, BE) \ 126193640SariffINTPCM_DECLARE_OP_32(S, LE) \ 127193640SariffINTPCM_DECLARE_OP_32(S, BE) \ 128193640SariffINTPCM_DECLARE_OP_8(U, NE) \ 129193640SariffINTPCM_DECLARE_OP_16(U, LE) \ 130193640SariffINTPCM_DECLARE_OP_16(U, BE) \ 131193640SariffINTPCM_DECLARE_OP_24(U, LE) \ 132193640SariffINTPCM_DECLARE_OP_24(U, BE) \ 133193640SariffINTPCM_DECLARE_OP_32(U, LE) \ 134193640SariffINTPCM_DECLARE_OP_32(U, BE) 135193640Sariff 136193640Sariff#endif /* !_SND_INTPCM_H_ */ 137