G726.h

Go to the documentation of this file.
00001 /*
00002 This program is distributed under the terms of the 'MIT license'. The text
00003 of this licence follows...
00004 
00005 Copyright (c) 2004 J.D.Medhurst (a.k.a. Tixy)
00006 
00007 Permission is hereby granted, free of charge, to any person obtaining a copy
00008 of this software and associated documentation files (the "Software"), to deal
00009 in the Software without restriction, including without limitation the rights
00010 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00011 copies of the Software, and to permit persons to whom the Software is
00012 furnished to do so, subject to the following conditions:
00013 
00014 The above copyright notice and this permission notice shall be included in
00015 all copies or substantial portions of the Software.
00016 
00017 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00018 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00019 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
00020 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00021 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00022 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00023 THE SOFTWARE.
00024 */
00025 
00032 #ifndef G726_H
00033 #define G726_H
00034 
00062 class G726
00063     {
00064 public:
00068     enum Law{
00069         uLaw=0,     
00070         ALaw=1,     
00071         PCM16=2     
00073         };
00074 
00078     enum Rate{
00079         Rate16kBits=2,  
00080         Rate24kBits=3,  
00081         Rate32kBits=4,  
00082         Rate40kBits=5   
00083         };
00084 
00090     inline G726()
00091         {
00092         Reset();
00093         }
00094 
00099     void Reset();
00100 
00106     void SetLaw(Law law);
00107 
00113     void SetRate(Rate rate);
00114 
00127     unsigned Encode(unsigned pcm);
00128 
00142     unsigned Decode(unsigned adpcm);
00143 
00172     unsigned Encode(void* dst, int dstOffset, const void* src, size_t srcSize);
00173 
00203     unsigned Decode(void* dst, const void* src, int srcOffset, unsigned srcSize);
00204 private:
00205     void InputPCMFormatConversionAndDifferenceSignalComputation(unsigned S,int SE,int& D);
00206     void AdaptiveQuantizer(int D,unsigned Y,unsigned& I);
00207     void InverseAdaptiveQuantizer(unsigned I,unsigned Y,unsigned& DQ);
00208     void QuantizerScaleFactorAdaptation1(unsigned AL,unsigned& Y);
00209     void QuantizerScaleFactorAdaptation2(unsigned I,unsigned Y);
00210     void AdaptationSpeedControl1(unsigned& AL);
00211     void AdaptationSpeedControl2(unsigned I,unsigned y,unsigned TDP,unsigned TR);
00212     void AdaptativePredictorAndReconstructedSignalCalculator1(int& SE,int& SEZ);
00213     void AdaptativePredictorAndReconstructedSignalCalculator2(unsigned DQ,unsigned TR,int SE,int SEZ,int& SR,int& A2P);
00214     void ToneAndTransitionDetector1(unsigned DQ,unsigned& TR);
00215     void ToneAndTransitionDetector2(int A2P,unsigned TR,unsigned& TDP);
00216     void OutputPCMFormatConversionAndSynchronousCodingAdjustment(int SR,int SE,unsigned Y,unsigned I,unsigned& SD);
00217     void DifferenceSignalComputation(int SL,int SE,int& D);
00218     void OutputLimiting(int SR,int& S0);
00219     unsigned EncodeDecode(unsigned input,bool encode);
00220 private:
00221     Law LAW;
00222     Rate RATE;
00223     // Persistant state for DELAY elements...
00224     int A1;
00225     int A2;
00226     unsigned AP;
00227     int Bn[6];
00228     unsigned DML;
00229     unsigned DMS;
00230     unsigned DQn[6];
00231     int PK1;
00232     int PK2;
00233     unsigned SR1;
00234     unsigned SR2;
00235     unsigned TD;
00236     unsigned YL;
00237     unsigned YU;
00238 
00239     friend class G726Test;
00240     };
00241 
00251 #define IMPLEMENT_G191_BUGS
00252  // End of group
00254 
00255 #endif
00256 

Generated by  doxygen 1.6.1