00001 /* 00002 * SpanDSP - a series of DSP components for telephony 00003 * 00004 * imaadpcm.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 * Based on a bit from here, a bit from there, eye of toad, 00012 * ear of bat, etc - plus, of course, my own 2 cents. 00013 * 00014 * All rights reserved. 00015 * 00016 * This program is free software; you can redistribute it and/or modify 00017 * it under the terms of the GNU General Public License as published by 00018 * the Free Software Foundation; either version 2 of the License, or 00019 * (at your option) any later version. 00020 * 00021 * This program is distributed in the hope that it will be useful, 00022 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00023 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00024 * GNU General Public License for more details. 00025 * 00026 * You should have received a copy of the GNU General Public License 00027 * along with this program; if not, write to the Free Software 00028 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00029 * 00030 * $Id: ima_adpcm.h,v 1.5 2005/11/27 12:36:22 steveu Exp $ 00031 */ 00032 00033 /*! \file */ 00034 00035 #if !defined(_IMA_ADPCM_H_) 00036 #define _IMA_ADPCM_H_ 00037 00038 /*! \page ima_adpcm_page IMA/DVI/Intel ADPCM encoding and decoding 00039 \section ima_adpcm_page_sec_1 What does it do? 00040 IMA ADPCM offers a good balance of simplicity and quality at a rate of 00041 32kbps. 00042 00043 \section ima_adpcm_page_sec_2 How does it work? 00044 00045 \section ima_adpcm_page_sec_3 How do I use it? 00046 */ 00047 00048 /*! 00049 IMA (DVI/Intel) ADPCM conversion state descriptor. This defines the state of 00050 a single working instance of the IMA ADPCM converter. This is used for 00051 either linear to ADPCM or ADPCM to linear conversion. 00052 */ 00053 typedef struct 00054 { 00055 int16_t last; 00056 int16_t step_index; 00057 uint8_t ima_byte; 00058 int mark; 00059 } ima_adpcm_state_t; 00060 00061 #ifdef __cplusplus 00062 extern "C" { 00063 #endif 00064 00065 /*! Initialise an IMA ADPCM encode or decode context. 00066 \param s The IMA ADPCM context 00067 \return A pointer to the IMA ADPCM context, or NULL for error. */ 00068 ima_adpcm_state_t *ima_adpcm_init(ima_adpcm_state_t *s); 00069 00070 /*! Free an IMA ADPCM encode or decode context. 00071 \param s The IMA ADPCM context. 00072 \return 0 for OK. */ 00073 int ima_adpcm_release(ima_adpcm_state_t *s); 00074 00075 /*! Decode a buffer of IMA ADPCM data to linear PCM. 00076 \param s The IMA ADPCM context. 00077 \param amp 00078 \param ima_data 00079 \param ima_bytes 00080 \return The number of samples returned. */ 00081 int ima_adpcm_to_linear(ima_adpcm_state_t *s, 00082 int16_t *amp, 00083 const uint8_t *ima_data, 00084 int ima_bytes); 00085 00086 /*! Encode a buffer of linear PCM data to IMA ADPCM. 00087 \param s The IMA ADPCM context. 00088 \param ima_data 00089 \param amp 00090 \param samples 00091 \return The number of bytes of IMA ADPCM data produced. */ 00092 int ima_linear_to_adpcm(ima_adpcm_state_t *s, 00093 uint8_t *ima_data, 00094 const int16_t *amp, 00095 int samples); 00096 00097 #ifdef __cplusplus 00098 } 00099 #endif 00100 00101 #endif 00102 /*- End of file ------------------------------------------------------------*/