1 /* 2 * SpanDSP - a series of DSP components for telephony 3 * 4 * g722.h - The ITU G.722 codec. 5 * 6 * Written by Steve Underwood <[email protected]> 7 * 8 * Copyright (C) 2005 Steve Underwood 9 * 10 * Despite my general liking of the GPL, I place my own contributions 11 * to this code in the public domain for the benefit of all mankind - 12 * even the slimy ones who might try to proprietize my work and use it 13 * to my detriment. 14 * 15 * Based on a single channel G.722 codec which is: 16 * 17 ***** Copyright (c) CMU 1993 ***** 18 * Computer Science, Speech Group 19 * Chengxiang Lu and Alex Hauptmann 20 * 21 * $Id: g722.h,v 1.10 2006/06/16 12:45:53 steveu Exp $ 22 * 23 * Modifications for WebRtc, 2011/04/28, by tlegrand: 24 * -Changed to use WebRtc types 25 * -Added new defines for minimum and maximum values of short int 26 */ 27 28 /*! \file */ 29 30 #ifndef MODULES_THIRD_PARTY_G722_G722_H_ 31 #define MODULES_THIRD_PARTY_G722_G722_H_ 32 33 #include <stddef.h> 34 #include <stdint.h> 35 36 /*! \page g722_page G.722 encoding and decoding 37 \section g722_page_sec_1 What does it do? 38 The G.722 module is a bit exact implementation of the ITU G.722 specification 39 for all three specified bit rates - 64000bps, 56000bps and 48000bps. It passes 40 the ITU tests. 41 42 To allow fast and flexible interworking with narrow band telephony, the encoder 43 and decoder support an option for the linear audio to be an 8k samples/second 44 stream. In this mode the codec is considerably faster, and still fully 45 compatible with wideband terminals using G.722. 46 47 \section g722_page_sec_2 How does it work? 48 ???. 49 */ 50 51 #define WEBRTC_INT16_MAX 32767 52 #define WEBRTC_INT16_MIN -32768 53 54 enum { G722_SAMPLE_RATE_8000 = 0x0001, G722_PACKED = 0x0002 }; 55 56 typedef struct { 57 /*! TRUE if the operating in the special ITU test mode, with the band split 58 filters disabled. */ 59 int itu_test_mode; 60 /*! TRUE if the G.722 data is packed */ 61 int packed; 62 /*! TRUE if encode from 8k samples/second */ 63 int eight_k; 64 /*! 6 for 48000kbps, 7 for 56000kbps, or 8 for 64000kbps. */ 65 int bits_per_sample; 66 67 /*! Signal history for the QMF */ 68 int x[24]; 69 70 struct { 71 int s; 72 int sp; 73 int sz; 74 int r[3]; 75 int a[3]; 76 int ap[3]; 77 int p[3]; 78 int d[7]; 79 int b[7]; 80 int bp[7]; 81 int sg[7]; 82 int nb; 83 int det; 84 } band[2]; 85 86 unsigned int in_buffer; 87 int in_bits; 88 unsigned int out_buffer; 89 int out_bits; 90 } G722EncoderState; 91 92 typedef struct { 93 /*! TRUE if the operating in the special ITU test mode, with the band split 94 filters disabled. */ 95 int itu_test_mode; 96 /*! TRUE if the G.722 data is packed */ 97 int packed; 98 /*! TRUE if decode to 8k samples/second */ 99 int eight_k; 100 /*! 6 for 48000kbps, 7 for 56000kbps, or 8 for 64000kbps. */ 101 int bits_per_sample; 102 103 /*! Signal history for the QMF */ 104 int x[24]; 105 106 struct { 107 int s; 108 int sp; 109 int sz; 110 int r[3]; 111 int a[3]; 112 int ap[3]; 113 int p[3]; 114 int d[7]; 115 int b[7]; 116 int bp[7]; 117 int sg[7]; 118 int nb; 119 int det; 120 } band[2]; 121 122 unsigned int in_buffer; 123 int in_bits; 124 unsigned int out_buffer; 125 int out_bits; 126 } G722DecoderState; 127 128 #ifdef __cplusplus 129 extern "C" { 130 #endif 131 132 G722EncoderState* WebRtc_g722_encode_init(G722EncoderState* s, 133 int rate, 134 int options); 135 int WebRtc_g722_encode_release(G722EncoderState* s); 136 size_t WebRtc_g722_encode(G722EncoderState* s, 137 uint8_t g722_data[], 138 const int16_t amp[], 139 size_t len); 140 141 G722DecoderState* WebRtc_g722_decode_init(G722DecoderState* s, 142 int rate, 143 int options); 144 int WebRtc_g722_decode_release(G722DecoderState* s); 145 size_t WebRtc_g722_decode(G722DecoderState* s, 146 int16_t amp[], 147 const uint8_t g722_data[], 148 size_t len); 149 150 #ifdef __cplusplus 151 } 152 #endif 153 154 #endif /* MODULES_THIRD_PARTY_G722_G722_H_ */ 155