Changeset 203 for libmpc/branches/r2d/libmpcenc
- Timestamp:
- 02/08/07 14:29:39 (18 years ago)
- Location:
- libmpc/branches/r2d/libmpcenc
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
libmpc/branches/r2d/libmpcenc/encode_sv7.c
r201 r203 58 58 */ 59 59 60 unsigned char MS_Flag [32]; // Flag to save if Subband was MS- or LR-coded61 int SCF_Last_L [32];62 int SCF_Last_R [32]; // Last coded SCF value63 static unsigned char DSCF_RLL_L [32];64 static unsigned char DSCF_RLL_R [32]; // Duration of the differential SCF-coding for RLL (run length limitation)65 int Res_L [32];66 int Res_R [32]; // Quantization precision of the subbands67 int SCF_Index_L [32] [3];68 int SCF_Index_R [32] [3]; // Scalefactor index for quantized subband values69 70 60 // initialize SV8 71 61 void … … 146 136 // formatting and writing SV8-bitstream for one frame 147 137 void 148 writeBitstream_SV8 ( mpc_encoder_t* e, int MaxBand , const SubbandQuantTyp* Q)138 writeBitstream_SV8 ( mpc_encoder_t* e, int MaxBand) 149 139 { 150 140 int n; … … 152 142 153 143 for( n = MaxBand; n >= 0; n--) 154 if ( Res_L[n] != 0 ||Res_R[n] != 0) break;144 if (e->Res_L[n] != 0 || e->Res_R[n] != 0) break; 155 145 156 146 n++; … … 168 158 169 159 if (MaxBand) { 170 writeBits(e, HuffRes[0][ Res_L[MaxBand - 1]].Code, HuffRes[0][Res_L[MaxBand - 1]].Length);171 writeBits(e, HuffRes[0][ Res_R[MaxBand - 1]].Code, HuffRes[0][Res_R[MaxBand - 1]].Length);160 writeBits(e, HuffRes[0][e->Res_L[MaxBand - 1]].Code, HuffRes[0][e->Res_L[MaxBand - 1]].Length); 161 writeBits(e, HuffRes[0][e->Res_R[MaxBand - 1]].Code, HuffRes[0][e->Res_R[MaxBand - 1]].Length); 172 162 for ( n = MaxBand - 2; n >= 0; n--) { 173 int tmp = Res_L[n] -Res_L[n + 1];163 int tmp = e->Res_L[n] - e->Res_L[n + 1]; 174 164 if (tmp < 0) tmp += 17; 175 writeBits(e, HuffRes[ Res_L[n + 1] > 2][tmp].Code, HuffRes[Res_L[n + 1] > 2][tmp].Length);176 177 tmp = Res_R[n] -Res_R[n + 1];165 writeBits(e, HuffRes[e->Res_L[n + 1] > 2][tmp].Code, HuffRes[e->Res_L[n + 1] > 2][tmp].Length); 166 167 tmp = e->Res_R[n] - e->Res_R[n + 1]; 178 168 if (tmp < 0) tmp += 17; 179 writeBits(e, HuffRes[ Res_R[n + 1] > 2][tmp].Code, HuffRes[Res_R[n + 1] > 2][tmp].Length);169 writeBits(e, HuffRes[e->Res_R[n + 1] > 2][tmp].Code, HuffRes[e->Res_R[n + 1] > 2][tmp].Length); 180 170 } 181 171 … … 184 174 int cnt = 0, tot = 0; 185 175 for( n = 0; n < MaxBand; n++) { 186 if ( Res_L[n] != 0 ||Res_R[n] != 0 ) {187 tmp = (tmp << 1) | MS_Flag[n];188 cnt += MS_Flag[n];176 if ( e->Res_L[n] != 0 || e->Res_R[n] != 0 ) { 177 tmp = (tmp << 1) | e->MS_Flag[n]; 178 cnt += e->MS_Flag[n]; 189 179 tot++; 190 180 } … … 200 190 if (e->framesInBlock == 0){ 201 191 for( n = 0; n < 32; n++) 202 DSCF_RLL_L[n] = DSCF_RLL_R[n] = 1; // new block -> force key frame192 e->DSCF_Flag_L[n] = e->DSCF_Flag_R[n] = 1; // new block -> force key frame 203 193 } 204 194 … … 207 197 for ( n = 0; n < MaxBand; n++ ) { 208 198 int tmp = 0, cnt = -1; 209 if ( Res_L[n]) {210 tmp = ( SCF_Index_L[n][1] == SCF_Index_L[n][0]) * 2 + (SCF_Index_L[n][2] ==SCF_Index_L[n][1]);199 if (e->Res_L[n]) { 200 tmp = (e->SCF_Index_L[n][1] == e->SCF_Index_L[n][0]) * 2 + (e->SCF_Index_L[n][2] == e->SCF_Index_L[n][1]); 211 201 cnt++; 212 202 } 213 if ( Res_R[n]) {214 tmp = (tmp << 2) | (( SCF_Index_R[n][1] == SCF_Index_R[n][0]) * 2 + (SCF_Index_R[n][2] ==SCF_Index_R[n][1]));203 if (e->Res_R[n]) { 204 tmp = (tmp << 2) | ((e->SCF_Index_R[n][1] == e->SCF_Index_R[n][0]) * 2 + (e->SCF_Index_R[n][2] == e->SCF_Index_R[n][1])); 215 205 cnt++; 216 206 } … … 222 212 223 213 for ( n = 0; n < MaxBand; n++ ) { 224 if ( Res_L[n] ) {214 if ( e->Res_L[n] ) { 225 215 int m; 226 if ( DSCF_RLL_L[n] == 1) {227 writeBits(e, SCF_Index_L[n][0] + 6, 7);228 DSCF_RLL_L[n] = 0;216 if (e->DSCF_Flag_L[n] == 1) { 217 writeBits(e, e->SCF_Index_L[n][0] + 6, 7); 218 e->DSCF_Flag_L[n] = 0; 229 219 } else { 230 unsigned int tmp = ( SCF_Index_L[n][0] -SCF_Last_L[n] + 31) & 127;220 unsigned int tmp = (e->SCF_Index_L[n][0] - e->SCF_Last_L[n] + 31) & 127; 231 221 if (tmp < 64) 232 222 writeBits(e, HuffDSCF_2[tmp].Code, HuffDSCF_2[tmp].Length); … … 237 227 } 238 228 for( m = 0; m < 2; m++){ 239 if ( SCF_Index_L[n][m+1] !=SCF_Index_L[n][m]) {240 unsigned int tmp = ( SCF_Index_L[n][m+1] -SCF_Index_L[n][m] + 31) & 127;229 if (e->SCF_Index_L[n][m+1] != e->SCF_Index_L[n][m]) { 230 unsigned int tmp = (e->SCF_Index_L[n][m+1] - e->SCF_Index_L[n][m] + 31) & 127; 241 231 if (tmp < 64) 242 232 writeBits(e, HuffDSCF_1[tmp].Code, HuffDSCF_1[tmp].Length); … … 247 237 } 248 238 } 249 SCF_Last_L[n] =SCF_Index_L[n][2];250 } 251 if ( Res_R[n] ) {239 e->SCF_Last_L[n] = e->SCF_Index_L[n][2]; 240 } 241 if ( e->Res_R[n] ) { 252 242 int m; 253 if ( DSCF_RLL_R[n] == 1) {254 writeBits(e, SCF_Index_R[n][0] + 6, 7);255 DSCF_RLL_R[n] = 0;243 if (e->DSCF_Flag_R[n] == 1) { 244 writeBits(e, e->SCF_Index_R[n][0] + 6, 7); 245 e->DSCF_Flag_R[n] = 0; 256 246 } else { 257 unsigned int tmp = ( SCF_Index_R[n][0] -SCF_Last_R[n] + 31) & 127;247 unsigned int tmp = (e->SCF_Index_R[n][0] - e->SCF_Last_R[n] + 31) & 127; 258 248 if (tmp < 64) 259 249 writeBits(e, HuffDSCF_2[tmp].Code, HuffDSCF_2[tmp].Length); … … 264 254 } 265 255 for( m = 0; m < 2; m++){ 266 if ( SCF_Index_R[n][m+1] !=SCF_Index_R[n][m]) {267 unsigned int tmp = ( SCF_Index_R[n][m+1] -SCF_Index_R[n][m] + 31) & 127;256 if (e->SCF_Index_R[n][m+1] != e->SCF_Index_R[n][m]) { 257 unsigned int tmp = (e->SCF_Index_R[n][m+1] - e->SCF_Index_R[n][m] + 31) & 127; 268 258 if (tmp < 64) 269 259 writeBits(e, HuffDSCF_1[tmp].Code, HuffDSCF_1[tmp].Length); … … 274 264 } 275 265 } 276 SCF_Last_R[n] =SCF_Index_R[n][2];266 e->SCF_Last_R[n] = e->SCF_Index_R[n][2]; 277 267 } 278 268 } … … 280 270 /*********************************** Samples *********************************/ 281 271 for ( n = 0; n < MaxBand; n++ ) { 282 int Res = Res_L[n];283 const unsigned int * q = Q[n].L;272 int Res = e->Res_L[n]; 273 const unsigned int * q = e->Q[n].L; 284 274 static const unsigned int thres[] = {0, 0, 3, 7, 9, 1, 3, 4, 8}; 285 275 static const int HuffQ2_var[5*5*5] = … … 357 347 } 358 348 359 Res = Res_R[n];360 } while (q == Q[n].L && (q =Q[n].R));349 Res = e->Res_R[n]; 350 } while (q == e->Q[n].L && (q = e->Q[n].R)); 361 351 } 362 352 -
libmpc/branches/r2d/libmpcenc/libmpcenc.h
r161 r203 36 36 37 37 typedef struct { 38 unsigned int L [36];39 unsigned int R [36];40 } SubbandQuantTyp;41 42 typedef struct {43 38 mpc_uint16_t Code; // >= 14 bit 44 39 mpc_uint16_t Length; // >= 4 bit … … 63 58 FILE * outputFile; // ouput file 64 59 65 unsigned int MS_Channelmode; 66 unsigned int Overflows; // = 0; // number of internal (filterbank) clippings 67 unsigned int MaxBand; /// number of non zero bands in last frame 60 mpc_uint32_t MS_Channelmode; 61 mpc_uint32_t Overflows; // = 0; // number of internal (filterbank) clippings 62 mpc_uint32_t MaxBand; /// number of non zero bands in last frame 63 64 mpc_int32_t SCF_Index_L [32] [3]; 65 mpc_int32_t SCF_Index_R [32] [3]; // holds scalefactor-indices 66 mpc_int32_t SCF_Last_L [32]; 67 mpc_int32_t SCF_Last_R [32]; // Last coded SCF value 68 mpc_quantizer Q [32]; // holds quantized samples 69 mpc_int32_t Res_L [32]; 70 mpc_int32_t Res_R [32]; // holds the chosen quantizer for each subband 71 mpc_bool_t DSCF_Flag_L [32]; 72 mpc_bool_t DSCF_Flag_R [32]; // differential SCF used? 73 mpc_bool_t MS_Flag[32]; // MS used? 68 74 } mpc_encoder_t; 69 75 76 void Init_SV8 ( mpc_encoder_t* ); 77 void writeStreamInfo ( mpc_encoder_t*e, 78 const unsigned int MaxBand, 79 const unsigned int MS_on, 80 const unsigned int SamplesCount, 81 const unsigned int SampleFreq, 82 const unsigned int ChannelCount); 83 void writeEncoderInfo ( mpc_encoder_t * e, 84 const float profile, 85 const int PNS_on, 86 const int version_major, 87 const int version_minor, 88 const int version_implement, 89 const int version_build ); 90 void writeBlock ( mpc_encoder_t * e, const char * key, const mpc_bool_t addCRC); 91 void writeMagic (mpc_encoder_t * e); 92 void writeBits (mpc_encoder_t * e, mpc_uint32_t input, unsigned int bits ); 93 void writeSeekTable (mpc_encoder_t * e); 94 void writeBitstream_SV8 ( mpc_encoder_t*, int); 95
Note: See TracChangeset
for help on using the changeset viewer.