uint_32 ac3_decode_data(uint_8 *data_start, uint_32 length, uint_32 *start, short *audio_buf_ptr) { uint_8 *data_initial = data_start; uint_8 *data_end = data_start + length; uint_32 i, j = *start*2; int ret; // error_flag = buffer_size = 0; // syncinfo.syncword = 0xffff; // printf("In ac3_decode_data\n"); while ((ret = decode_buffer_syncframe(&syncinfo, &data_start, data_end)) > 0) { if (error_flag) { #ifdef _WIN32 SetDlgItemText(hDlg, IDC_INFO, "A.E.!"); #else printf("A.E.!\n"); #endif ZeroMemory(s16_samples, sizeof(sint_16) * 256 * 2 * 6); error_flag = 0; continue; } parse_bsi(&bsi); for (i=0; i<6; i++) { ZeroMemory(samples, sizeof(double) * 256 * (bsi.nfchans + bsi.lfeon)); parse_audblk(&bsi, &audblk); exponent_unpack(&bsi, &audblk); if (error_flag) goto error; bit_allocate(syncinfo.fscod, &bsi, &audblk); coeff_unpack(&bsi, &audblk, samples); if (error_flag) goto error; if (bsi.acmod == 0x2) rematrix(&audblk, samples); imdct(&bsi, &audblk, samples); downmix(&audblk, &bsi, samples, &s16_samples[i * 512]); sanity_check(&bsi, &audblk); if (error_flag) goto error; } memcpy(&audio_buf_ptr[(*start)/2], s16_samples, 6144); *start += 6144; error: ; } // if (ret == -1) // return(-1); sampling_rate=syncinfo.sampling_rate; AC3_byterate = syncinfo.bit_rate/8*1000; /* if (Decision_Flag || (!SRC_Flag && Normalization_Flag)) for (i=(j>>1); i<(start>>1); i++) if (Sound_Max < abs(ptrAC3Dec_Buffer[i])) { Sound_Max = abs(ptrAC3Dec_Buffer[i]); if (Decision_Flag && Sound_Max > Norm_Ratio) { sprintf(szBuffer, "%.2f", 327.68 * Norm_Ratio / Sound_Max); SetDlgItemText(hDlg, IDC_INFO, szBuffer); } } */ // return (data_end - data_initial); return (data_start - data_initial); }
int __stdcall ac3_decode_frame(ac3_state *state) { uint_32 i; int j; int error_flag=0; // debug(DAC3,"(decode_frame) begin frame %d\n",state->frame_count); //find a syncframe and parse parse_syncinfo(&state->syncinfo,&error_flag,state); if(error_flag) { // debug(DAC3," -- fail after parse_syncinfo\n"); goto error; } state->frame_count++; state->sampling_rate = state->syncinfo.sampling_rate; parse_bsi(&state->bsi,state); stats_print_banner(&state->syncinfo,&state->bsi,state); for(i=0; i < 6; i++) { //Initialize freq/time sample storage memset(state->samples,0,sizeof(float) * 256 * (state->bsi.nfchans + state->bsi.lfeon)); // Extract most of the audblk info from the bitstream // (minus the mantissas parse_audblk(&state->bsi,&state->audblk,state); // Take the differential exponent data and turn it into // absolute exponents exponent_unpack(&state->bsi,&state->audblk,&error_flag,state); if(error_flag) { // debug(DAC3," -- fail after exponent_unpack\n"); goto error; } // Figure out how many bits per mantissa bit_allocate(state->syncinfo.fscod,&state->bsi,&state->audblk,state); // Extract the mantissas from the stream and // generate floating point frequency coefficients coeff_unpack(&state->bsi,&state->audblk,state->samples,&error_flag,state); if(error_flag) { // debug(DAC3," -- fail after coeff_unpack\n"); goto error; } if(state->bsi.acmod == 0x2) { rematrix(&state->audblk,state->samples); } // Convert the frequency samples into time samples imdct(&state->bsi,&state->audblk,state->samples); // Downmix into the requested number of channels // and convert floating point to sint_16 for(j=0;j<256;j++) { state->left[i*256+j]=(sint_16)(state->samples[0][j]*32767.0f); state->center[i*256+j]=(sint_16)(state->samples[1][j]*32767.0f); state->right[i*256+j]=(sint_16)(state->samples[2][j]*32767.0f); state->sleft[i*256+j]=(sint_16)(state->samples[3][j]*32767.0f); state->sright[i*256+j]=(sint_16)(state->samples[4][j]*32767.0f); state->subwoofer[i*256+j]=(sint_16)(state->samples[5][j]*32767.0f); } sanity_check(&state->syncinfo,&state->bsi,&state->audblk,&error_flag,state); if(error_flag) { // debug(DAC3," -- sanity check fail\n"); goto error; } } parse_auxdata(&state->syncinfo,state); return 0; error: // debug(DAC3," -- FRAME ZEROED\n"); return -1; }