spandsp 0.0.6
|
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 00030 /*! \file */ 00031 00032 #if !defined(_SPANDSP_IMA_ADPCM_H_) 00033 #define _SPANDSP_IMA_ADPCM_H_ 00034 00035 /*! \page ima_adpcm_page IMA/DVI/Intel ADPCM encoding and decoding 00036 \section ima_adpcm_page_sec_1 What does it do? 00037 IMA ADPCM offers a good balance of simplicity and quality at a rate of 00038 32kbps. 00039 00040 \section ima_adpcm_page_sec_2 How does it work? 00041 00042 \section ima_adpcm_page_sec_3 How do I use it? 00043 */ 00044 00045 enum 00046 { 00047 /*! IMA4 is the original IMA ADPCM variant */ 00048 IMA_ADPCM_IMA4 = 0, 00049 /*! DVI4 is the IMA ADPCM variant defined in RFC3551 */ 00050 IMA_ADPCM_DVI4 = 1, 00051 /*! VDVI is the variable bit rate IMA ADPCM variant defined in RFC3551 */ 00052 IMA_ADPCM_VDVI = 2 00053 }; 00054 00055 /*! 00056 IMA (DVI/Intel) ADPCM conversion state descriptor. This defines the state of 00057 a single working instance of the IMA ADPCM converter. This is used for 00058 either linear to ADPCM or ADPCM to linear conversion. 00059 */ 00060 typedef struct ima_adpcm_state_s ima_adpcm_state_t; 00061 00062 #if defined(__cplusplus) 00063 extern "C" 00064 { 00065 #endif 00066 00067 /*! Initialise an IMA ADPCM encode or decode context. 00068 \param s The IMA ADPCM context. 00069 \param variant IMA_ADPCM_IMA4, IMA_ADPCM_DVI4, or IMA_ADPCM_VDVI. 00070 \param chunk_size The size of a chunk, in samples. A chunk size of 00071 zero sample samples means treat each encode or decode operation 00072 as a chunk. 00073 \return A pointer to the IMA ADPCM context, or NULL for error. */ 00074 SPAN_DECLARE(ima_adpcm_state_t *) ima_adpcm_init(ima_adpcm_state_t *s, 00075 int variant, 00076 int chunk_size); 00077 00078 /*! Release an IMA ADPCM encode or decode context. 00079 \param s The IMA ADPCM context. 00080 \return 0 for OK. */ 00081 SPAN_DECLARE(int) ima_adpcm_release(ima_adpcm_state_t *s); 00082 00083 /*! Free an IMA ADPCM encode or decode context. 00084 \param s The IMA ADPCM context. 00085 \return 0 for OK. */ 00086 SPAN_DECLARE(int) ima_adpcm_free(ima_adpcm_state_t *s); 00087 00088 /*! Encode a buffer of linear PCM data to IMA ADPCM. 00089 \param s The IMA ADPCM context. 00090 \param ima_data The IMA ADPCM data produced. 00091 \param amp The audio sample buffer. 00092 \param len The number of samples in the buffer. 00093 \return The number of bytes of IMA ADPCM data produced. */ 00094 SPAN_DECLARE(int) ima_adpcm_encode(ima_adpcm_state_t *s, 00095 uint8_t ima_data[], 00096 const int16_t amp[], 00097 int len); 00098 00099 /*! Decode a buffer of IMA ADPCM data to linear PCM. 00100 \param s The IMA ADPCM context. 00101 \param amp The audio sample buffer. 00102 \param ima_data The IMA ADPCM data 00103 \param ima_bytes The number of bytes of IMA ADPCM data 00104 \return The number of samples returned. */ 00105 SPAN_DECLARE(int) ima_adpcm_decode(ima_adpcm_state_t *s, 00106 int16_t amp[], 00107 const uint8_t ima_data[], 00108 int ima_bytes); 00109 00110 #if defined(__cplusplus) 00111 } 00112 #endif 00113 00114 #endif 00115 /*- End of file ------------------------------------------------------------*/