static void writeSampleRate(HANDLE_FDK_BITSTREAM hBitstreamBuffer, int sampleRate) { int sampleRateIndex = getSamplingRateIndex(sampleRate); FDKwriteBits( hBitstreamBuffer, sampleRateIndex, 4 ); if( sampleRateIndex == 15 ) { FDKwriteBits( hBitstreamBuffer, sampleRate, 24 ); } }
INT adtsWrite_Init(HANDLE_ADTS hAdts, CODER_CONFIG *config) { /* Sanity checks */ if ( config->nSubFrames < 1 || config->nSubFrames > 4 || (int)config->aot > 4 || (int)config->aot < 1 ) { return -1; } /* fixed header */ if (config->flags & CC_MPEG_ID) { hAdts->mpeg_id = 0; /* MPEG 4 */ } else { hAdts->mpeg_id = 1; /* MPEG 2 */ } hAdts->layer=0; hAdts->protection_absent = ! (config->flags & CC_PROTECTION); hAdts->profile = ((int)config->aot) - 1; hAdts->sample_freq_index = getSamplingRateIndex(config->samplingRate); hAdts->sample_freq = config->samplingRate; hAdts->private_bit=0; hAdts->channel_mode = config->channelMode; hAdts->original=0; hAdts->home=0; /* variable header */ hAdts->copyright_id=0; hAdts->copyright_start=0; hAdts->num_raw_blocks=config->nSubFrames-1; /* 0 means 1 raw data block */ FDKcrcInit(&hAdts->crcInfo, 0x8005, 0xFFFF, 16); hAdts->currentBlock = 0; return 0; }
int transportEnc_writePCE(HANDLE_FDK_BITSTREAM hBs, CHANNEL_MODE channelMode, INT sampleRate, int instanceTagPCE, int profile, int matrixMixdownA, int pseudoSurroundEnable, UINT alignAnchor) { int sampleRateIndex, i; const PCE_CONFIGURATION* config = NULL; const MP4_ELEMENT_ID* pEl_list = NULL; UCHAR cpeCnt=0, sceCnt=0, lfeCnt=0; sampleRateIndex = getSamplingRateIndex(sampleRate); if (sampleRateIndex == 15) { return -1; } if ((config=getPceEntry(channelMode))==NULL) { return -1; } /* Pointer to first element in element list. */ pEl_list = &config->el_list[0]; FDKwriteBits(hBs, instanceTagPCE, 4); /* Element instance tag */ FDKwriteBits(hBs, profile, 2); /* Object type */ FDKwriteBits(hBs, sampleRateIndex, 4); /* Sample rate index*/ FDKwriteBits(hBs, config->num_front_channel_elements, 4); /* Front channel Elements */ FDKwriteBits(hBs, config->num_side_channel_elements , 4); /* No Side Channel Elements */ FDKwriteBits(hBs, config->num_back_channel_elements , 4); /* No Back channel Elements */ FDKwriteBits(hBs, config->num_lfe_channel_elements , 2); /* No Lfe channel elements */ FDKwriteBits(hBs, 0, 3); /* No assoc data elements */ FDKwriteBits(hBs, 0, 4); /* No valid cc elements */ FDKwriteBits(hBs, 0, 1); /* Mono mixdown present */ FDKwriteBits(hBs, 0, 1); /* Stereo mixdown present */ if ( matrixMixdownA!=0 && ((channelMode==MODE_1_2_2)||(channelMode==MODE_1_2_2_1)) ) { FDKwriteBits(hBs, 1, 1); /* Matrix mixdown present */ FDKwriteBits(hBs, (matrixMixdownA-1)&0x3, 2); /* matrix_mixdown_idx */ FDKwriteBits(hBs, pseudoSurroundEnable&0x1, 1); /* pseudo_surround_enable */ } else { FDKwriteBits(hBs, 0, 1); /* Matrix mixdown not present */ } for(i=0; i<config->num_front_channel_elements; i++) { UCHAR isCpe = (*pEl_list++==ID_CPE) ? 1 : 0; UCHAR tag = (isCpe) ? cpeCnt++ : sceCnt++; FDKwriteBits(hBs, isCpe, 1); /* Front channel Elements is CPE? */ FDKwriteBits(hBs, tag, 4); /* Front channel Instance Tag.*/ } for(i=0; i<config->num_side_channel_elements; i++) { UCHAR isCpe = (*pEl_list++==ID_CPE) ? 1 : 0; UCHAR tag = (isCpe) ? cpeCnt++ : sceCnt++; FDKwriteBits(hBs, isCpe, 1); /* Front channel Elements is CPE? */ FDKwriteBits(hBs, tag, 4); /* Front channel Instance Tag.*/ } for(i=0; i<config->num_back_channel_elements; i++) { UCHAR isCpe = (*pEl_list++==ID_CPE) ? 1 : 0; UCHAR tag = (isCpe) ? cpeCnt++ : sceCnt++; FDKwriteBits(hBs, isCpe, 1); /* Front channel Elements is CPE? */ FDKwriteBits(hBs, tag, 4); /* Front channel Instance Tag.*/ } for(i=0; i<config->num_lfe_channel_elements; i++) { FDKwriteBits(hBs, lfeCnt++, 4); /* LFE channel Instance Tag. */ } /* - num_valid_cc_elements always 0. - num_assoc_data_elements always 0. */ /* Byte alignment: relative to alignAnchor ADTS: align with respect to the first bit of the raw_data_block() ADIF: align with respect to the first bit of the header LATM: align with respect to the first bit of the ASC */ FDKbyteAlign(hBs, alignAnchor); /* Alignment */ FDKwriteBits(hBs, 0 ,8); /* Do no write any comment. */ /* - comment_field_bytes always 0. */ return 0; }