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 * 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 General Public License version 2, or 00015 * the Lesser GNU General Public License version 2.1, as published by 00016 * the Free Software Foundation. 00017 * 00018 * This program is distributed in the hope that it will be useful, 00019 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00021 * GNU General Public License for more details. 00022 * 00023 * You should have received a copy of the GNU General Public License 00024 * along with this program; if not, write to the Free Software 00025 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00026 * 00027 * $Id: oki_adpcm.h,v 1.18 2008/02/09 15:33:40 steveu Exp $ 00028 */ 00029 00030 /*! \file */ 00031 00032 #if !defined(_SPANDSP_OKI_ADPCM_H_) 00033 #define _SPANDSP_OKI_ADPCM_H_ 00034 00035 /*! \page okiadpcm_page OKI (Dialogic) ADPCM encoding and decoding 00036 \section okiadpcm_page_sec_1 What does it do? 00037 OKI ADPCM is widely used in the CTI industry because it is the principal format 00038 supported by Dialogic. As the market leader, they tend to define "common 00039 practice". It offers a good balance of simplicity and quality at rates of 00040 24kbps or 32kbps. 32kbps is obtained by ADPCM compressing 8k samples/second linear 00041 PCM. 24kbps is obtained by resampling to 6k samples/second and using the same ADPCM 00042 compression algorithm on the slower samples. 00043 00044 The algorithms for this ADPCM codec can be found in "PC Telephony - The complete guide 00045 to designing, building and programming systems using Dialogic and Related Hardware" 00046 by Bob Edgar. pg 272-276. */ 00047 00048 /*! 00049 Oki (Dialogic) ADPCM conversion state descriptor. This defines the state of 00050 a single working instance of the Oki ADPCM converter. This is used for 00051 either linear to ADPCM or ADPCM to linear conversion. 00052 */ 00053 typedef struct 00054 { 00055 /*! \brief The bit rate - 24000 or 32000. */ 00056 int bit_rate; 00057 /*! \brief The last state of the ADPCM algorithm. */ 00058 int16_t last; 00059 /*! \brief Current index into the step size table. */ 00060 int16_t step_index; 00061 /*! \brief The compressed data byte in progress. */ 00062 uint8_t oki_byte; 00063 /*! \brief The signal history for the sample rate converter. */ 00064 int16_t history[32]; 00065 /*! \brief Pointer into the history buffer. */ 00066 int ptr; 00067 /*! \brief Odd/even sample counter. */ 00068 int mark; 00069 /*! \brief Phase accumulator for the sample rate converter. */ 00070 int phase; 00071 } oki_adpcm_state_t; 00072 00073 #if defined(__cplusplus) 00074 extern "C" 00075 { 00076 #endif 00077 00078 /*! Initialise an Oki ADPCM encode or decode context. 00079 \param s The Oki ADPCM context. 00080 \param bit_rate The required bit rate for the ADPCM data. 00081 The valid rates are 24000 and 32000. 00082 \return A pointer to the Oki ADPCM context, or NULL for error. */ 00083 oki_adpcm_state_t *oki_adpcm_init(oki_adpcm_state_t *s, int bit_rate); 00084 00085 /*! Free an Oki ADPCM encode or decode context. 00086 \param s The Oki ADPCM context. 00087 \return 0 for OK. */ 00088 int oki_adpcm_release(oki_adpcm_state_t *s); 00089 00090 /*! Decode a buffer of Oki ADPCM data to linear PCM. 00091 \param s The Oki ADPCM context. 00092 \param amp The audio sample buffer. 00093 \param oki_data 00094 \param oki_bytes 00095 \return The number of samples returned. */ 00096 int oki_adpcm_decode(oki_adpcm_state_t *s, 00097 int16_t amp[], 00098 const uint8_t oki_data[], 00099 int oki_bytes); 00100 00101 /*! Encode a buffer of linear PCM data to Oki ADPCM. 00102 \param s The Oki ADPCM context. 00103 \param oki_data The Oki ADPCM data produced 00104 \param amp The audio sample buffer. 00105 \param len The number of samples in the buffer. 00106 \return The number of bytes of Oki ADPCM data produced. */ 00107 int oki_adpcm_encode(oki_adpcm_state_t *s, 00108 uint8_t oki_data[], 00109 const int16_t amp[], 00110 int len); 00111 00112 #if defined(__cplusplus) 00113 } 00114 #endif 00115 00116 #endif 00117 /*- End of file ------------------------------------------------------------*/