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.25 2009/04/11 18:11:19 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 IMA_ADPCM_IMA4, IMA_ADPCM_DVI4, or IMA_ADPCM_VDVI. 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 SPAN_DECLARE(ima_adpcm_state_t *) ima_adpcm_init(ima_adpcm_state_t *s, 00077 int variant, 00078 int chunk_size); 00079 00080 /*! Release an IMA ADPCM encode or decode context. 00081 \param s The IMA ADPCM context. 00082 \return 0 for OK. */ 00083 SPAN_DECLARE(int) ima_adpcm_release(ima_adpcm_state_t *s); 00084 00085 /*! Free an IMA ADPCM encode or decode context. 00086 \param s The IMA ADPCM context. 00087 \return 0 for OK. */ 00088 SPAN_DECLARE(int) ima_adpcm_free(ima_adpcm_state_t *s); 00089 00090 /*! Encode a buffer of linear PCM data to IMA ADPCM. 00091 \param s The IMA ADPCM context. 00092 \param ima_data The IMA ADPCM data produced. 00093 \param amp The audio sample buffer. 00094 \param len The number of samples in the buffer. 00095 \return The number of bytes of IMA ADPCM data produced. */ 00096 SPAN_DECLARE(int) ima_adpcm_encode(ima_adpcm_state_t *s, 00097 uint8_t ima_data[], 00098 const int16_t amp[], 00099 int len); 00100 00101 /*! Decode a buffer of IMA ADPCM data to linear PCM. 00102 \param s The IMA ADPCM context. 00103 \param amp The audio sample buffer. 00104 \param ima_data The IMA ADPCM data 00105 \param ima_bytes The number of bytes of IMA ADPCM data 00106 \return The number of samples returned. */ 00107 SPAN_DECLARE(int) ima_adpcm_decode(ima_adpcm_state_t *s, 00108 int16_t amp[], 00109 const uint8_t ima_data[], 00110 int ima_bytes); 00111 00112 #if defined(__cplusplus) 00113 } 00114 #endif 00115 00116 #endif 00117 /*- End of file ------------------------------------------------------------*/