00001 /* 00002 * SpanDSP - a series of DSP components for telephony 00003 * 00004 * ima_adpcm.c - Conversion routines between linear 16 bit PCM data and 00005 * IMA/DVI/Intel ADPCM format. 00006 * 00007 * Written by Steve Underwood <steveu@coppice.org> 00008 * 00009 * Copyright (C) 2004 Steve Underwood 00010 * 00011 * All rights reserved. 00012 * 00013 * This program is free software; you can redistribute it and/or modify 00014 * it under the terms of the GNU Lesser General Public License version 2.1, 00015 * as published by the Free Software Foundation. 00016 * 00017 * This program is distributed in the hope that it will be useful, 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 * GNU Lesser General Public License for more details. 00021 * 00022 * You should have received a copy of the GNU Lesser General Public 00023 * License along with this program; if not, write to the Free Software 00024 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00025 * 00026 * Based on a bit from here, a bit from there, eye of toad, 00027 * ear of bat, etc - plus, of course, my own 2 cents. 00028 * 00029 * $Id: ima_adpcm.h,v 1.21 2008/11/30 10:17:31 steveu Exp $ 00030 */ 00031 00032 /*! \file */ 00033 00034 #if !defined(_SPANDSP_IMA_ADPCM_H_) 00035 #define _SPANDSP_IMA_ADPCM_H_ 00036 00037 /*! \page ima_adpcm_page IMA/DVI/Intel ADPCM encoding and decoding 00038 \section ima_adpcm_page_sec_1 What does it do? 00039 IMA ADPCM offers a good balance of simplicity and quality at a rate of 00040 32kbps. 00041 00042 \section ima_adpcm_page_sec_2 How does it work? 00043 00044 \section ima_adpcm_page_sec_3 How do I use it? 00045 */ 00046 00047 enum 00048 { 00049 /*! IMA4 is the original IMA ADPCM variant */ 00050 IMA_ADPCM_IMA4 = 0, 00051 /*! DVI4 is the IMA ADPCM variant defined in RFC3551 */ 00052 IMA_ADPCM_DVI4 = 1, 00053 /*! VDVI is the variable bit rate IMA ADPCM variant defined in RFC3551 */ 00054 IMA_ADPCM_VDVI = 2 00055 }; 00056 00057 /*! 00058 IMA (DVI/Intel) ADPCM conversion state descriptor. This defines the state of 00059 a single working instance of the IMA ADPCM converter. This is used for 00060 either linear to ADPCM or ADPCM to linear conversion. 00061 */ 00062 typedef struct ima_adpcm_state_s ima_adpcm_state_t; 00063 00064 #if defined(__cplusplus) 00065 extern "C" 00066 { 00067 #endif 00068 00069 /*! Initialise an IMA ADPCM encode or decode context. 00070 \param s The IMA ADPCM context 00071 \param variant ??? 00072 \param chunk_size The size of a chunk, in samples. A chunk size of 00073 zero sample samples means treat each encode or decode operation 00074 as a chunk. 00075 \return A pointer to the IMA ADPCM context, or NULL for error. */ 00076 ima_adpcm_state_t *ima_adpcm_init(ima_adpcm_state_t *s, int variant, int chunk_size); 00077 00078 /*! Free an IMA ADPCM encode or decode context. 00079 \param s The IMA ADPCM context. 00080 \return 0 for OK. */ 00081 int ima_adpcm_release(ima_adpcm_state_t *s); 00082 00083 /*! Encode a buffer of linear PCM data to IMA ADPCM. 00084 \param s The IMA ADPCM context. 00085 \param ima_data The IMA ADPCM data produced. 00086 \param amp The audio sample buffer. 00087 \param len The number of samples in the buffer. 00088 \return The number of bytes of IMA ADPCM data produced. */ 00089 int ima_adpcm_encode(ima_adpcm_state_t *s, 00090 uint8_t ima_data[], 00091 const int16_t amp[], 00092 int len); 00093 00094 /*! Decode a buffer of IMA ADPCM data to linear PCM. 00095 \param s The IMA ADPCM context. 00096 \param amp The audio sample buffer. 00097 \param ima_data 00098 \param ima_bytes 00099 \return The number of samples returned. */ 00100 int ima_adpcm_decode(ima_adpcm_state_t *s, 00101 int16_t amp[], 00102 const uint8_t ima_data[], 00103 int ima_bytes); 00104 00105 #if defined(__cplusplus) 00106 } 00107 #endif 00108 00109 #endif 00110 /*- End of file ------------------------------------------------------------*/