public static void Scan( TSAudioStream stream, TSStreamBuffer buffer, long bitrate, ref string tag) { if (stream.IsInitialized && (stream.StreamType == TSStreamType.DTS_HD_SECONDARY_AUDIO || (stream.CoreStream != null && stream.CoreStream.IsInitialized))) return; bool syncFound = false; uint sync = 0; for (int i = 0; i < buffer.Length; i++) { sync = (sync << 8) + buffer.ReadByte(); if (sync == 0x64582025) { syncFound = true; break; } } if (!syncFound) { tag = "CORE"; if (stream.CoreStream == null) { stream.CoreStream = new TSAudioStream(); stream.CoreStream.StreamType = TSStreamType.DTS_AUDIO; } if (!stream.CoreStream.IsInitialized) { buffer.BeginRead(); TSCodecDTS.Scan(stream.CoreStream, buffer, bitrate, ref tag); } return; } tag = "HD"; int temp1 = buffer.ReadBits(8); int nuSubStreamIndex = buffer.ReadBits(2); int nuExtSSHeaderSize = 0; int nuExtSSFSize = 0; int bBlownUpHeader = buffer.ReadBits(1); if (1 == bBlownUpHeader) { nuExtSSHeaderSize = buffer.ReadBits(12) + 1; nuExtSSFSize = buffer.ReadBits(20) + 1; } else { nuExtSSHeaderSize = buffer.ReadBits(8) + 1; nuExtSSFSize = buffer.ReadBits(16) + 1; } int nuNumAudioPresent = 1; int nuNumAssets = 1; int bStaticFieldsPresent = buffer.ReadBits(1); if (1 == bStaticFieldsPresent) { int nuRefClockCode = buffer.ReadBits(2); int nuExSSFrameDurationCode = buffer.ReadBits(3) + 1; long nuTimeStamp = 0; if (1 == buffer.ReadBits(1)) { nuTimeStamp = (buffer.ReadBits(18) << 18) + buffer.ReadBits(18); } nuNumAudioPresent = buffer.ReadBits(3) + 1; nuNumAssets = buffer.ReadBits(3) + 1; int[] nuActiveExSSMask = new int[nuNumAudioPresent]; for (int i = 0; i < nuNumAudioPresent; i++) { nuActiveExSSMask[i] = buffer.ReadBits(nuSubStreamIndex + 1); //? } for (int i = 0; i < nuNumAudioPresent; i++) { for (int j = 0; j < nuSubStreamIndex + 1; j++) { if (((j + 1) % 2) == 1) { int mask = buffer.ReadBits(8); } } } if (1 == buffer.ReadBits(1)) { int nuMixMetadataAdjLevel = buffer.ReadBits(2); int nuBits4MixOutMask = buffer.ReadBits(2) * 4 + 4; int nuNumMixOutConfigs = buffer.ReadBits(2) + 1; int[] nuMixOutChMask = new int[nuNumMixOutConfigs]; for (int i = 0; i < nuNumMixOutConfigs; i++) { nuMixOutChMask[i] = buffer.ReadBits(nuBits4MixOutMask); } } } int[] AssetSizes = new int[nuNumAssets]; for (int i = 0; i < nuNumAssets; i++) { if (1 == bBlownUpHeader) { AssetSizes[i] = buffer.ReadBits(20) + 1; } else { AssetSizes[i] = buffer.ReadBits(16) + 1; } } for (int i = 0; i < nuNumAssets; i++) { long bufferPosition = buffer.Position; int nuAssetDescriptorFSIZE = buffer.ReadBits(9) + 1; int DescriptorDataForAssetIndex = buffer.ReadBits(3); if (1 == bStaticFieldsPresent) { int AssetTypeDescrPresent = buffer.ReadBits(1); if (1 == AssetTypeDescrPresent) { int AssetTypeDescriptor = buffer.ReadBits(4); } int LanguageDescrPresent = buffer.ReadBits(1); if (1 == LanguageDescrPresent) { int LanguageDescriptor = buffer.ReadBits(24); } int bInfoTextPresent = buffer.ReadBits(1); if (1 == bInfoTextPresent) { int nuInfoTextByteSize = buffer.ReadBits(10) + 1; int[] InfoText = new int[nuInfoTextByteSize]; for (int j = 0; j < nuInfoTextByteSize; j++) { InfoText[j] = buffer.ReadBits(8); } } int nuBitResolution = buffer.ReadBits(5) + 1; int nuMaxSampleRate = buffer.ReadBits(4); int nuTotalNumChs = buffer.ReadBits(8) + 1; int bOne2OneMapChannels2Speakers = buffer.ReadBits(1); int nuSpkrActivityMask = 0; if (1 == bOne2OneMapChannels2Speakers) { int bEmbeddedStereoFlag = 0; if (nuTotalNumChs > 2) { bEmbeddedStereoFlag = buffer.ReadBits(1); } int bEmbeddedSixChFlag = 0; if (nuTotalNumChs > 6) { bEmbeddedSixChFlag = buffer.ReadBits(1); } int bSpkrMaskEnabled = buffer.ReadBits(1); int nuNumBits4SAMask = 0; if (1 == bSpkrMaskEnabled) { nuNumBits4SAMask = buffer.ReadBits(2); nuNumBits4SAMask = nuNumBits4SAMask * 4 + 4; nuSpkrActivityMask = buffer.ReadBits(nuNumBits4SAMask); } // TODO... } stream.SampleRate = SampleRates[nuMaxSampleRate]; stream.BitDepth = nuBitResolution; stream.LFE = 0; if ((nuSpkrActivityMask & 0x8) == 0x8) { ++stream.LFE; } if ((nuSpkrActivityMask & 0x1000) == 0x1000) { ++stream.LFE; } stream.ChannelCount = nuTotalNumChs - stream.LFE; } if (nuNumAssets > 1) { // TODO... break; } } // TODO if (stream.CoreStream != null) { TSAudioStream coreStream = (TSAudioStream)stream.CoreStream; if (coreStream.AudioMode == TSAudioMode.Extended && stream.ChannelCount == 5) { stream.AudioMode = TSAudioMode.Extended; } /* if (coreStream.DialNorm != 0) { stream.DialNorm = coreStream.DialNorm; } */ } if (stream.StreamType == TSStreamType.DTS_HD_MASTER_AUDIO) { stream.IsVBR = true; stream.IsInitialized = true; } else if (bitrate > 0) { stream.IsVBR = false; stream.BitRate = bitrate; if (stream.CoreStream != null) { stream.BitRate += stream.CoreStream.BitRate; stream.IsInitialized = true; } stream.IsInitialized = (stream.BitRate > 0 ? true : false); } }
public static void Scan( TSAudioStream stream, TSStreamBuffer buffer, long bitrate, ref string tag) { if (stream.IsInitialized) { return; } bool syncFound = false; uint sync = 0; for (int i = 0; i < buffer.Length; i++) { sync = (sync << 8) + buffer.ReadByte(); if (sync == 0x7FFE8001) { syncFound = true; break; } } if (!syncFound) { return; } int frame_type = buffer.ReadBits(1); int samples_deficit = buffer.ReadBits(5); int crc_present = buffer.ReadBits(1); int sample_blocks = buffer.ReadBits(7); int frame_size = buffer.ReadBits(14); if (frame_size < 95) { return; } int amode = buffer.ReadBits(6); int sample_rate = buffer.ReadBits(4); if (sample_rate < 0 || sample_rate >= dca_sample_rates.Length) { return; } int bit_rate = buffer.ReadBits(5); if (bit_rate < 0 || bit_rate >= dca_bit_rates.Length) { return; } int downmix = buffer.ReadBits(1); int dynrange = buffer.ReadBits(1); int timestamp = buffer.ReadBits(1); int aux_data = buffer.ReadBits(1); int hdcd = buffer.ReadBits(1); int ext_descr = buffer.ReadBits(3); int ext_coding = buffer.ReadBits(1); int aspf = buffer.ReadBits(1); int lfe = buffer.ReadBits(2); int predictor_history = buffer.ReadBits(1); if (crc_present == 1) { int crc = buffer.ReadBits(16); } int multirate_inter = buffer.ReadBits(1); int version = buffer.ReadBits(4); int copy_history = buffer.ReadBits(2); int source_pcm_res = buffer.ReadBits(3); int front_sum = buffer.ReadBits(1); int surround_sum = buffer.ReadBits(1); int dialog_norm = buffer.ReadBits(4); if (source_pcm_res < 0 || source_pcm_res >= dca_bits_per_sample.Length) { return; } int subframes = buffer.ReadBits(4); int total_channels = buffer.ReadBits(3) + 1 + ext_coding; stream.SampleRate = dca_sample_rates[sample_rate]; stream.ChannelCount = total_channels; stream.LFE = (lfe > 0 ? 1 : 0); stream.BitDepth = dca_bits_per_sample[source_pcm_res]; stream.DialNorm = -dialog_norm; if ((source_pcm_res & 0x1) == 0x1) { stream.AudioMode = TSAudioMode.Extended; } stream.BitRate = (uint)dca_bit_rates[bit_rate]; switch (stream.BitRate) { case 1: if (bitrate > 0) { stream.BitRate = bitrate; stream.IsVBR = false; stream.IsInitialized = true; } else { stream.BitRate = 0; } break; case 2: case 3: stream.IsVBR = true; stream.IsInitialized = true; break; default: stream.IsVBR = false; stream.IsInitialized = true; break; } }
public static void Scan( TSAudioStream stream, TSStreamBuffer buffer, long bitrate, ref string tag) { if (stream.IsInitialized && (stream.StreamType == TSStreamType.DTS_HD_SECONDARY_AUDIO || (stream.CoreStream != null && stream.CoreStream.IsInitialized))) { return; } bool syncFound = false; uint sync = 0; for (int i = 0; i < buffer.Length; i++) { sync = (sync << 8) + buffer.ReadByte(); if (sync == 0x64582025) { syncFound = true; break; } } if (!syncFound) { tag = "CORE"; if (stream.CoreStream == null) { stream.CoreStream = new TSAudioStream(); stream.CoreStream.StreamType = TSStreamType.DTS_AUDIO; } if (!stream.CoreStream.IsInitialized) { buffer.BeginRead(); TSCodecDTS.Scan(stream.CoreStream, buffer, bitrate, ref tag); } return; } tag = "HD"; int temp1 = buffer.ReadBits(8); int nuSubStreamIndex = buffer.ReadBits(2); int nuExtSSHeaderSize = 0; int nuExtSSFSize = 0; int bBlownUpHeader = buffer.ReadBits(1); if (1 == bBlownUpHeader) { nuExtSSHeaderSize = buffer.ReadBits(12) + 1; nuExtSSFSize = buffer.ReadBits(20) + 1; } else { nuExtSSHeaderSize = buffer.ReadBits(8) + 1; nuExtSSFSize = buffer.ReadBits(16) + 1; } int nuNumAudioPresent = 1; int nuNumAssets = 1; int bStaticFieldsPresent = buffer.ReadBits(1); if (1 == bStaticFieldsPresent) { int nuRefClockCode = buffer.ReadBits(2); int nuExSSFrameDurationCode = buffer.ReadBits(3) + 1; long nuTimeStamp = 0; if (1 == buffer.ReadBits(1)) { nuTimeStamp = (buffer.ReadBits(18) << 18) + buffer.ReadBits(18); } nuNumAudioPresent = buffer.ReadBits(3) + 1; nuNumAssets = buffer.ReadBits(3) + 1; int[] nuActiveExSSMask = new int[nuNumAudioPresent]; for (int i = 0; i < nuNumAudioPresent; i++) { nuActiveExSSMask[i] = buffer.ReadBits(nuSubStreamIndex + 1); //? } for (int i = 0; i < nuNumAudioPresent; i++) { for (int j = 0; j < nuSubStreamIndex + 1; j++) { if (((j + 1) % 2) == 1) { int mask = buffer.ReadBits(8); } } } if (1 == buffer.ReadBits(1)) { int nuMixMetadataAdjLevel = buffer.ReadBits(2); int nuBits4MixOutMask = buffer.ReadBits(2) * 4 + 4; int nuNumMixOutConfigs = buffer.ReadBits(2) + 1; int[] nuMixOutChMask = new int[nuNumMixOutConfigs]; for (int i = 0; i < nuNumMixOutConfigs; i++) { nuMixOutChMask[i] = buffer.ReadBits(nuBits4MixOutMask); } } } int[] AssetSizes = new int[nuNumAssets]; for (int i = 0; i < nuNumAssets; i++) { if (1 == bBlownUpHeader) { AssetSizes[i] = buffer.ReadBits(20) + 1; } else { AssetSizes[i] = buffer.ReadBits(16) + 1; } } for (int i = 0; i < nuNumAssets; i++) { long bufferPosition = buffer.Position; int nuAssetDescriptorFSIZE = buffer.ReadBits(9) + 1; int DescriptorDataForAssetIndex = buffer.ReadBits(3); if (1 == bStaticFieldsPresent) { int AssetTypeDescrPresent = buffer.ReadBits(1); if (1 == AssetTypeDescrPresent) { int AssetTypeDescriptor = buffer.ReadBits(4); } int LanguageDescrPresent = buffer.ReadBits(1); if (1 == LanguageDescrPresent) { int LanguageDescriptor = buffer.ReadBits(24); } int bInfoTextPresent = buffer.ReadBits(1); if (1 == bInfoTextPresent) { int nuInfoTextByteSize = buffer.ReadBits(10) + 1; int[] InfoText = new int[nuInfoTextByteSize]; for (int j = 0; j < nuInfoTextByteSize; j++) { InfoText[j] = buffer.ReadBits(8); } } int nuBitResolution = buffer.ReadBits(5) + 1; int nuMaxSampleRate = buffer.ReadBits(4); int nuTotalNumChs = buffer.ReadBits(8) + 1; int bOne2OneMapChannels2Speakers = buffer.ReadBits(1); int nuSpkrActivityMask = 0; if (1 == bOne2OneMapChannels2Speakers) { int bEmbeddedStereoFlag = 0; if (nuTotalNumChs > 2) { bEmbeddedStereoFlag = buffer.ReadBits(1); } int bEmbeddedSixChFlag = 0; if (nuTotalNumChs > 6) { bEmbeddedSixChFlag = buffer.ReadBits(1); } int bSpkrMaskEnabled = buffer.ReadBits(1); int nuNumBits4SAMask = 0; if (1 == bSpkrMaskEnabled) { nuNumBits4SAMask = buffer.ReadBits(2); nuNumBits4SAMask = nuNumBits4SAMask * 4 + 4; nuSpkrActivityMask = buffer.ReadBits(nuNumBits4SAMask); } // TODO... } stream.SampleRate = SampleRates[nuMaxSampleRate]; stream.BitDepth = nuBitResolution; stream.LFE = 0; if ((nuSpkrActivityMask & 0x8) == 0x8) { ++stream.LFE; } if ((nuSpkrActivityMask & 0x1000) == 0x1000) { ++stream.LFE; } stream.ChannelCount = nuTotalNumChs - stream.LFE; } if (nuNumAssets > 1) { // TODO... break; } } // TODO if (stream.CoreStream != null) { TSAudioStream coreStream = (TSAudioStream)stream.CoreStream; if (coreStream.AudioMode == TSAudioMode.Extended && stream.ChannelCount == 5) { stream.AudioMode = TSAudioMode.Extended; } /* * if (coreStream.DialNorm != 0) * { * stream.DialNorm = coreStream.DialNorm; * } */ } if (stream.StreamType == TSStreamType.DTS_HD_MASTER_AUDIO) { stream.IsVBR = true; stream.IsInitialized = true; } else if (bitrate > 0) { stream.IsVBR = false; stream.BitRate = bitrate; if (stream.CoreStream != null) { stream.BitRate += stream.CoreStream.BitRate; stream.IsInitialized = true; } stream.IsInitialized = (stream.BitRate > 0 ? true : false); } }
public static void Scan( TSAudioStream stream, TSStreamBuffer buffer, ref string tag) { if (stream.IsInitialized && stream.CoreStream != null && stream.CoreStream.IsInitialized) { return; } bool syncFound = false; uint sync = 0; for (int i = 0; i < buffer.Length; i++) { sync = (sync << 8) + buffer.ReadByte(); if (sync == 0xF8726FBA) { syncFound = true; break; } } if (!syncFound) { tag = "CORE"; if (stream.CoreStream == null) { stream.CoreStream = new TSAudioStream(); stream.CoreStream.StreamType = TSStreamType.AC3_AUDIO; } if (!stream.CoreStream.IsInitialized) { buffer.BeginRead(); TSCodecAC3.Scan(stream.CoreStream, buffer, ref tag); } return; } tag = "HD"; int ratebits = buffer.ReadBits(4); if (ratebits != 0xF) { stream.SampleRate = (((ratebits & 8) > 0 ? 44100 : 48000) << (ratebits & 7)); } int temp1 = buffer.ReadBits(8); int channels_thd_stream1 = buffer.ReadBits(5); int temp2 = buffer.ReadBits(2); stream.ChannelCount = 0; stream.LFE = 0; int c_LFE2 = buffer.ReadBits(1); if (c_LFE2 == 1) { stream.LFE += 1; } int c_Cvh = buffer.ReadBits(1); if (c_Cvh == 1) { stream.ChannelCount += 1; } int c_LRw = buffer.ReadBits(1); if (c_LRw == 1) { stream.ChannelCount += 2; } int c_LRsd = buffer.ReadBits(1); if (c_LRsd == 1) { stream.ChannelCount += 2; } int c_Ts = buffer.ReadBits(1); if (c_Ts == 1) { stream.ChannelCount += 1; } int c_Cs = buffer.ReadBits(1); if (c_Cs == 1) { stream.ChannelCount += 1; } int c_LRrs = buffer.ReadBits(1); if (c_LRrs == 1) { stream.ChannelCount += 2; } int c_LRc = buffer.ReadBits(1); if (c_LRc == 1) { stream.ChannelCount += 2; } int c_LRvh = buffer.ReadBits(1); if (c_LRvh == 1) { stream.ChannelCount += 2; } int c_LRs = buffer.ReadBits(1); if (c_LRs == 1) { stream.ChannelCount += 2; } int c_LFE = buffer.ReadBits(1); if (c_LFE == 1) { stream.LFE += 1; } int c_C = buffer.ReadBits(1); if (c_C == 1) { stream.ChannelCount += 1; } int c_LR = buffer.ReadBits(1); if (c_LR == 1) { stream.ChannelCount += 2; } int access_unit_size = 40 << (ratebits & 7); int access_unit_size_pow2 = 64 << (ratebits & 7); int a1 = buffer.ReadBits(16); int a2 = buffer.ReadBits(16); int a3 = buffer.ReadBits(16); int is_vbr = buffer.ReadBits(1); int peak_bitrate = buffer.ReadBits(15); peak_bitrate = (peak_bitrate * stream.SampleRate) >> 4; double peak_bitdepth = (double)peak_bitrate / (stream.ChannelCount + stream.LFE) / stream.SampleRate; if (peak_bitdepth > 14) { stream.BitDepth = 24; } else { stream.BitDepth = 16; } #if DEBUG System.Diagnostics.Debug.WriteLine(string.Format( "{0}\t{1}\t{2:F2}", stream.PID, peak_bitrate, peak_bitdepth)); #endif /* * // TODO: Get THD dialnorm from metadata * if (stream.CoreStream != null) * { * TSAudioStream coreStream = (TSAudioStream)stream.CoreStream; * if (coreStream.DialNorm != 0) * { * stream.DialNorm = coreStream.DialNorm; * } * } */ stream.IsVBR = true; stream.IsInitialized = true; }
public static void Scan( TSAudioStream stream, TSStreamBuffer buffer, ref string tag) { if (stream.IsInitialized && stream.CoreStream != null && stream.CoreStream.IsInitialized) return; bool syncFound = false; uint sync = 0; for (int i = 0; i < buffer.Length; i++) { sync = (sync << 8) + buffer.ReadByte(); if (sync == 0xF8726FBA) { syncFound = true; break; } } if (!syncFound) { tag = "CORE"; if (stream.CoreStream == null) { stream.CoreStream = new TSAudioStream(); stream.CoreStream.StreamType = TSStreamType.AC3_AUDIO; } if (!stream.CoreStream.IsInitialized) { buffer.BeginRead(); TSCodecAC3.Scan(stream.CoreStream, buffer, ref tag); } return; } tag = "HD"; int ratebits = buffer.ReadBits(4); if (ratebits != 0xF) { stream.SampleRate = (((ratebits & 8) > 0 ? 44100 : 48000) << (ratebits & 7)); } int temp1 = buffer.ReadBits(8); int channels_thd_stream1 = buffer.ReadBits(5); int temp2 = buffer.ReadBits(2); stream.ChannelCount = 0; stream.LFE = 0; int c_LFE2 = buffer.ReadBits(1); if (c_LFE2 == 1) { stream.LFE += 1; } int c_Cvh = buffer.ReadBits(1); if (c_Cvh == 1) { stream.ChannelCount += 1; } int c_LRw = buffer.ReadBits(1); if (c_LRw == 1) { stream.ChannelCount += 2; } int c_LRsd = buffer.ReadBits(1); if (c_LRsd == 1) { stream.ChannelCount += 2; } int c_Ts = buffer.ReadBits(1); if (c_Ts == 1) { stream.ChannelCount += 1; } int c_Cs = buffer.ReadBits(1); if (c_Cs == 1) { stream.ChannelCount += 1; } int c_LRrs = buffer.ReadBits(1); if (c_LRrs == 1) { stream.ChannelCount += 2; } int c_LRc = buffer.ReadBits(1); if (c_LRc == 1) { stream.ChannelCount += 2; } int c_LRvh = buffer.ReadBits(1); if (c_LRvh == 1) { stream.ChannelCount += 2; } int c_LRs = buffer.ReadBits(1); if (c_LRs == 1) { stream.ChannelCount += 2; } int c_LFE = buffer.ReadBits(1); if (c_LFE == 1) { stream.LFE += 1; } int c_C = buffer.ReadBits(1); if (c_C == 1) { stream.ChannelCount += 1; } int c_LR = buffer.ReadBits(1); if (c_LR == 1) { stream.ChannelCount += 2; } int access_unit_size = 40 << (ratebits & 7); int access_unit_size_pow2 = 64 << (ratebits & 7); int a1 = buffer.ReadBits(16); int a2 = buffer.ReadBits(16); int a3 = buffer.ReadBits(16); int is_vbr = buffer.ReadBits(1); int peak_bitrate = buffer.ReadBits(15); peak_bitrate = (peak_bitrate * stream.SampleRate) >> 4; double peak_bitdepth = (double)peak_bitrate / (stream.ChannelCount + stream.LFE) / stream.SampleRate; if (peak_bitdepth > 14) { stream.BitDepth = 24; } else { stream.BitDepth = 16; } #if DEBUG System.Diagnostics.Debug.WriteLine(string.Format( "{0}\t{1}\t{2:F2}", stream.PID, peak_bitrate, peak_bitdepth)); #endif /* // TODO: Get THD dialnorm from metadata if (stream.CoreStream != null) { TSAudioStream coreStream = (TSAudioStream)stream.CoreStream; if (coreStream.DialNorm != 0) { stream.DialNorm = coreStream.DialNorm; } } */ stream.IsVBR = true; stream.IsInitialized = true; }
public static void Scan( TSAudioStream stream, TSStreamBuffer buffer, long bitrate, ref string tag) { if (stream.IsInitialized) return; bool syncFound = false; uint sync = 0; for (int i = 0; i < buffer.Length; i++) { sync = (sync << 8) + buffer.ReadByte(); if (sync == 0x7FFE8001) { syncFound = true; break; } } if (!syncFound) return; int frame_type = buffer.ReadBits(1); int samples_deficit = buffer.ReadBits(5); int crc_present = buffer.ReadBits(1); int sample_blocks = buffer.ReadBits(7); int frame_size = buffer.ReadBits(14); if (frame_size < 95) { return; } int amode = buffer.ReadBits(6); int sample_rate = buffer.ReadBits(4); if (sample_rate < 0 || sample_rate >= dca_sample_rates.Length) { return; } int bit_rate = buffer.ReadBits(5); if (bit_rate < 0 || bit_rate >= dca_bit_rates.Length) { return; } int downmix = buffer.ReadBits(1); int dynrange = buffer.ReadBits(1); int timestamp = buffer.ReadBits(1); int aux_data = buffer.ReadBits(1); int hdcd = buffer.ReadBits(1); int ext_descr = buffer.ReadBits(3); int ext_coding = buffer.ReadBits(1); int aspf = buffer.ReadBits(1); int lfe = buffer.ReadBits(2); int predictor_history = buffer.ReadBits(1); if (crc_present == 1) { int crc = buffer.ReadBits(16); } int multirate_inter = buffer.ReadBits(1); int version = buffer.ReadBits(4); int copy_history = buffer.ReadBits(2); int source_pcm_res = buffer.ReadBits(3); int front_sum = buffer.ReadBits(1); int surround_sum = buffer.ReadBits(1); int dialog_norm = buffer.ReadBits(4); if (source_pcm_res < 0 || source_pcm_res >= dca_bits_per_sample.Length) { return; } int subframes = buffer.ReadBits(4); int total_channels = buffer.ReadBits(3) + 1 + ext_coding; stream.SampleRate = dca_sample_rates[sample_rate]; stream.ChannelCount = total_channels; stream.LFE = (lfe > 0 ? 1 : 0); stream.BitDepth = dca_bits_per_sample[source_pcm_res]; stream.DialNorm = -dialog_norm; if ((source_pcm_res & 0x1) == 0x1) { stream.AudioMode = TSAudioMode.Extended; } stream.BitRate = (uint)dca_bit_rates[bit_rate]; switch (stream.BitRate) { case 1: if (bitrate > 0) { stream.BitRate = bitrate; stream.IsVBR = false; stream.IsInitialized = true; } else { stream.BitRate = 0; } break; case 2: case 3: stream.IsVBR = true; stream.IsInitialized = true; break; default: stream.IsVBR = false; stream.IsInitialized = true; break; } }