ima_adpcm.h

Go to the documentation of this file.
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 version 2, as
00018  * published by the Free Software Foundation.
00019  *
00020  * This program is distributed in the hope that it will be useful,
00021  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00022  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023  * GNU General Public License for more details.
00024  *
00025  * You should have received a copy of the GNU General Public License
00026  * along with this program; if not, write to the Free Software
00027  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00028  *
00029  * $Id: ima_adpcm.h,v 1.15 2007/04/08 08:16:18 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     IMA_ADPCM_DVI4 = 0,
00050     IMA_ADPCM_VDVI = 1
00051 };
00052 
00053 /*!
00054     IMA (DVI/Intel) ADPCM conversion state descriptor. This defines the state of
00055     a single working instance of the IMA ADPCM converter. This is used for
00056     either linear to ADPCM or ADPCM to linear conversion.
00057 */
00058 typedef struct
00059 {
00060     int variant;
00061     int last;
00062     int step_index;
00063     uint16_t ima_byte;
00064     int bits;
00065 } ima_adpcm_state_t;
00066 
00067 #if defined(__cplusplus)
00068 extern "C"
00069 {
00070 #endif
00071 
00072 /*! Initialise an IMA ADPCM encode or decode context.
00073     \param s The IMA ADPCM context
00074     \param variant ???
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);
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 ------------------------------------------------------------*/

Generated on Tue Jul 24 11:29:28 2007 for libspandsp by  doxygen 1.5.2