oki_adpcm.h

Go to the documentation of this file.
00001 /*
00002  * SpanDSP - a series of DSP components for telephony
00003  *
00004  * oki_adpcm.h - Conversion routines between linear 16 bit PCM data and
00005  *                       OKI (Dialogic) ADPCM format.
00006  *
00007  * Written by Steve Underwood <steveu@coppice.org>
00008  *
00009  * Copyright (C) 2001 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: oki_adpcm.h,v 1.9 2005/11/27 12:36:22 steveu Exp $
00031  */
00032 
00033 /*! \file */
00034 
00035 #if !defined(_OKI_ADPCM_H_)
00036 #define _OKI_ADPCM_H_
00037 
00038 /*! \page okiadpcm_page OKI (Dialogic) ADPCM encoding and decoding
00039 \section okiadpcm_page_sec_1 What does it do?
00040 OKI ADPCM is widely used in the CTI industry because it is the principal format
00041 supported by Dialogic. As the market leader, they tend to define "common
00042 practice". It offers a good balance of simplicity and quality at rates of
00043 24kbps or 32kbps. 32kbps is obtained by ADPCM compressing 8k samples/second linear
00044 PCM. 24kbps is obtained by resampling to 6k samples/second and using the same ADPCM
00045 compression algorithm on the slower samples.
00046 
00047 The algorithms for this ADPCM codec can be found in "PC Telephony - The complete guide
00048 to designing, building and programming systems using Dialogic and Related Hardware"
00049 by Bob Edgar. pg 272-276. */
00050 
00051 /*!
00052     Oki (Dialogic) ADPCM conversion state descriptor. This defines the state of
00053     a single working instance of the Oki ADPCM converter. This is used for
00054     either linear to ADPCM or ADPCM to linear conversion.
00055 */
00056 typedef struct
00057 {
00058     int bit_rate;
00059     int16_t last;
00060     int16_t step_index;
00061     uint8_t oki_byte;
00062     int16_t history[32];
00063     int ptr;
00064     int mark;
00065     int phase;
00066 } oki_adpcm_state_t;
00067 
00068 #ifdef __cplusplus
00069 extern "C" {
00070 #endif
00071 
00072 /*! Initialise an Oki ADPCM encode or decode context.
00073     \param s The Oki ADPCM context.
00074     \param bit_rate The required bit rate for the ADPCM data.
00075            The valid rates are 24000 and 32000.
00076     \return A pointer to the Oki ADPCM context, or NULL for error. */
00077 oki_adpcm_state_t *oki_adpcm_init(oki_adpcm_state_t *s, int bit_rate);
00078 
00079 /*! Free an Oki ADPCM encode or decode context.
00080     \param s The Oki ADPCM context.
00081     \return 0 for OK. */
00082 int oki_adpcm_release(oki_adpcm_state_t *s);
00083 
00084 /*! Decode a buffer of Oki ADPCM data to linear PCM.
00085     \param s The Oki ADPCM context.
00086     \param amp
00087     \param oki_data
00088     \param oki_bytes
00089     \return The number of samples returned. */
00090 int oki_adpcm_to_linear(oki_adpcm_state_t *s,
00091                         int16_t *amp,
00092                         const uint8_t *oki_data,
00093                         int oki_bytes);
00094 
00095 /*! Encode a buffer of linear PCM data to Oki ADPCM.
00096     \param s The Oki ADPCM context.
00097     \param oki_data
00098     \param amp
00099     \param samples
00100     \return The number of bytes of Oki ADPCM data produced. */
00101 int oki_linear_to_adpcm(oki_adpcm_state_t *s,
00102                         uint8_t *oki_data,
00103                         const int16_t *amp,
00104                         int samples);
00105 
00106 #ifdef __cplusplus
00107 }
00108 #endif
00109 
00110 #endif
00111 /*- End of file ------------------------------------------------------------*/

Generated on Fri Nov 10 09:40:24 2006 for libspandsp by  doxygen 1.5.1