00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
#ifndef _VrDECODER
00039
#define _VrDECODER
00040
#include <VrDecimatingSigProc.h>
00041
#include <string.h>
00042
#include <../G711_G721_G723/g72x.h>
00043
#if defined (ENABLE_MMX)
00044
#include <VrMMX.h>
00045
#endif
00046
00047
00048
00049
00050
00051
00052
00053
template<
class iType>
00054 class VrAudioDecoder :
public VrDecimatingSigProc<iType,iType> {
00055
protected:
00056
00057
#if defined (ENABLE_MMX)
00058
mmxTaps** processedTaps;
00059
#endif
00060
00061 const int outputBytes=120;
00062 const int headerSize=3;
00063 const int outputBlockSize=
outputBytes+
headerSize;
00064
00065
public:
00066 int outputsize,
inputsize;
00067 int num;
00068 short blockNum;
00069 int position;
00070 int enc_bits;
00071 int in_coding;
00072 int difference;
00073 struct g72x_state state;
00074 int (*dec_routine)(
int,
int, g72x_state *);
00075
00076 void choose_decoder(
int bits){
00077
enc_bits=bits;
00078
switch (bits){
00079
case 3:
00080
dec_routine = g723_24_decoder;
00081
break;
00082
case 4:
00083
dec_routine = g721_decoder;
00084
break;
00085
case 5:
00086
dec_routine = g723_40_decoder;
00087
break;
00088 }
00089 }
00090
00091 VrAudioDecoder(){
00092
num=0;
00093
difference=0;
00094 g72x_init_state(&state);
00095 }
00096
00097 virtual const char *
name() {
return "VrAudioDecoder"; }
00098
00099
virtual int work(
VrSampleRange output,
iType *o[],
00100
VrSampleRange inputs[],
iType *i[]);
00101
00102
virtual int forecast(
VrSampleRange output,
00103
VrSampleRange inputs[]);
00104
00105
virtual void initialize();
00106
00107
00108 };
00109
00110
template<
class iType>
int
00111 VrAudioDecoder<iType>::forecast(
VrSampleRange output,
00112
VrSampleRange inputs[]) {
00113
00114 cout <<
"forecast called. module "<<
name()<<endl;
00115
double maxratio=double(5.0)/(
double)8.0;
00116
00117 inputs[0].
index=(
long unsigned)((
int)output.
index-
difference);
00118
00119
int numblocks=output.
size/
outputBlockSize;
00120
00121 inputs[0].
size=double(output.
size)*maxratio*
outputBlockSize/
outputBytes;
00122
00123 cout <<
"ratio= "<<maxratio<<
" to get outputsize of "<<output.
size<<
" starting at " <<output.
index<<
" you need "<<inputs[0].
size<<
" starting at "<<inputs[0].
index<<endl;
00124
00125 cout <<
"forecast FINISHED. module "<<
name()<<endl;
00126
00127
return 0;
00128
00129 }
00130
00131
00132
template<
class iType>
int
00133 VrAudioDecoder<iType>::work(
VrSampleRange output,
iType *o[],
VrSampleRange inputs[],
iType *i[]) {
00134
00135
unsigned int in_buffer = 0;
00136
int in_bits = 0;
00137
unsigned char in_byte;
00138
int code;
00139 cout <<
"work called. module "<<
name()<<endl;;
00140 cout <<__FUNCTION__<<
" starting output.size ="<<output.
size<<
"starting output.index "<<output.
index<<endl;
00141
00142
iType *curInPos=i[0],*curOutPos=o[0];
00143
double ratio;
00144
short blocknum=0;
00145
unsigned char outputChar;
00146
00147
int bytes_read;
00148
unsigned total_bytes_written=0,total_bytes_read=0;
00149
00150
while (total_bytes_written<output.
size){
00151
choose_decoder((
int)*curInPos);
00152 ratio=double(*curInPos)/double(8);
00153 cout <<
"using " << ratio<<
" ratio "<<total_bytes_written<<
" out of "<<output.
size<<endl;
00154
00155 curInPos++;
00156 blocknum=((
unsigned char)*curInPos)<<8;
00157 curInPos++;
00158 blocknum|=(
unsigned char) *curInPos;
00159 curInPos++;
00160 bytes_read=
headerSize;
00161
int written =0;
00162 cout <<
"Decoding block "<<blocknum<<endl;
00163
00164
00165
while(bytes_read<outputBlockSize|| (in_bits>0)){
00166
if (in_bits <
enc_bits) {
00167 in_byte = *(curInPos++);
00168 bytes_read++;
00169 in_buffer |= (in_byte << in_bits);
00170 in_bits += 8;
00171 }
00172 code = in_buffer & ((1 <<
enc_bits) - 1);
00173 in_buffer >>=
enc_bits;
00174 in_bits -= enc_bits;
00175 outputChar = (*dec_routine)(code, AUDIO_ENCODING_ULAW, &
state);
00176 written++;
00177 *(curOutPos++)=outputChar;
00178 }
00179
00180
00181
00182 total_bytes_written+=written;
00183 total_bytes_read+=bytes_read;
00184
00185 cout <<bytes_read<<
" bytes read. "<< written <<
" bytes written"<<endl;
00186 }
00187
if (in_bits!=0)
00188 cout <<__FUNCTION__<<
" extra bits left over..."<<endl;
00189
00190 cout <<total_bytes_read<<
" total bytes read. "<< total_bytes_written <<
" total bytes written"<<endl;
00191
00192
int diff=total_bytes_written-total_bytes_read;
00193
difference+=diff;
00194 cout <<
"difference for this cycle "<<diff<<endl;
00195
00196 cout <<
"work FINISHED. module "<<
name()<<endl;
00197
return output.
size;
00198 }
00199
00200
00201
template<
class iType>
00202 void VrAudioDecoder<iType>::initialize()
00203 {
00204
setOutputSize(4800);
00205 }
00206
00207
#endif