📄 ac3_parse.c
字号:
/***************************************************************************** * ac3_parse.c: ac3 parsing procedures ***************************************************************************** * Copyright (C) 1999, 2000 VideoLAN * * Authors: * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. *****************************************************************************/#include "defs.h"#include "int_types.h"#include "ac3_decoder.h"#include "ac3_internal.h"#include "ac3_bit_stream.h"/* Misc LUT */static u16 nfchans[] = { 2, 1, 2, 3, 3, 4, 4, 5 };struct frmsize_s { u16 bit_rate; u16 frm_size[3];};static struct frmsize_s frmsizecod_tbl[] = { { 32 ,{64 ,69 ,96 } }, { 32 ,{64 ,70 ,96 } }, { 40 ,{80 ,87 ,120 } }, { 40 ,{80 ,88 ,120 } }, { 48 ,{96 ,104 ,144 } }, { 48 ,{96 ,105 ,144 } }, { 56 ,{112 ,121 ,168 } }, { 56 ,{112 ,122 ,168 } }, { 64 ,{128 ,139 ,192 } }, { 64 ,{128 ,140 ,192 } }, { 80 ,{160 ,174 ,240 } }, { 80 ,{160 ,175 ,240 } }, { 96 ,{192 ,208 ,288 } }, { 96 ,{192 ,209 ,288 } }, { 112 ,{224 ,243 ,336 } }, { 112 ,{224 ,244 ,336 } }, { 128 ,{256 ,278 ,384 } }, { 128 ,{256 ,279 ,384 } }, { 160 ,{320 ,348 ,480 } }, { 160 ,{320 ,349 ,480 } }, { 192 ,{384 ,417 ,576 } }, { 192 ,{384 ,418 ,576 } }, { 224 ,{448 ,487 ,672 } }, { 224 ,{448 ,488 ,672 } }, { 256 ,{512 ,557 ,768 } }, { 256 ,{512 ,558 ,768 } }, { 320 ,{640 ,696 ,960 } }, { 320 ,{640 ,697 ,960 } }, { 384 ,{768 ,835 ,1152 } }, { 384 ,{768 ,836 ,1152 } }, { 448 ,{896 ,975 ,1344 } }, { 448 ,{896 ,976 ,1344 } }, { 512 ,{1024 ,1114 ,1536 } }, { 512 ,{1024 ,1115 ,1536 } }, { 576 ,{1152 ,1253 ,1728 } }, { 576 ,{1152 ,1254 ,1728 } }, { 640 ,{1280 ,1393 ,1920 } }, { 640 ,{1280 ,1394 ,1920 } }};static int fscod_tbl[] = {48000, 44100, 32000};/* Parse a syncinfo structure */int ac3_sync_frame (ac3dec_t * p_ac3dec, ac3_sync_info_t * p_sync_info) { int buf; p_ac3dec->bit_stream.total_bits_read = 0; p_ac3dec->bit_stream.i_available = 0; /* sync word - should be 0x0b77 */ NeedBits (&(p_ac3dec->bit_stream), 16); buf = p_ac3dec->bit_stream.buffer >> (32 - 16); DumpBits (&(p_ac3dec->bit_stream), 16); if (buf != 0x0b77) return 1; /* Get crc1 - we don't actually use this data though */ NeedBits (&(p_ac3dec->bit_stream), 16); DumpBits (&(p_ac3dec->bit_stream), 16); /* Get the sampling rate */ NeedBits (&(p_ac3dec->bit_stream), 2); p_ac3dec->syncinfo.fscod = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 2)); DumpBits (&(p_ac3dec->bit_stream), 2); if (p_ac3dec->syncinfo.fscod >= 3) return 1; /* Get the frame size code */ NeedBits (&(p_ac3dec->bit_stream), 6); p_ac3dec->syncinfo.frmsizecod = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 6)); DumpBits (&(p_ac3dec->bit_stream), 6); if (p_ac3dec->syncinfo.frmsizecod >= 38) return 1; p_sync_info->bit_rate = frmsizecod_tbl[p_ac3dec->syncinfo.frmsizecod].bit_rate; p_ac3dec->syncinfo.frame_size = frmsizecod_tbl[p_ac3dec->syncinfo.frmsizecod].frm_size[p_ac3dec->syncinfo.fscod]; p_sync_info->frame_size = 2 * p_ac3dec->syncinfo.frame_size; p_sync_info->sample_rate = fscod_tbl[p_ac3dec->syncinfo.fscod]; return 0;}/* * This routine fills a bsi struct from the AC3 stream */int parse_bsi (ac3dec_t * p_ac3dec){ u32 i; /* Check the AC-3 version number */ NeedBits (&(p_ac3dec->bit_stream), 5); p_ac3dec->bsi.bsid = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 5)); DumpBits (&(p_ac3dec->bit_stream), 5); if (p_ac3dec->bsi.bsid > 8) return 1; /* Get the audio service provided by the steram */ NeedBits (&(p_ac3dec->bit_stream), 3); p_ac3dec->bsi.bsmod = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 3)); DumpBits (&(p_ac3dec->bit_stream), 3); /* Get the audio coding mode (ie how many channels)*/ NeedBits (&(p_ac3dec->bit_stream), 3); p_ac3dec->bsi.acmod = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 3)); DumpBits (&(p_ac3dec->bit_stream), 3); /* Predecode the number of full bandwidth channels as we use this * number a lot */ p_ac3dec->bsi.nfchans = nfchans[p_ac3dec->bsi.acmod]; /* If it is in use, get the centre channel mix level */ if ((p_ac3dec->bsi.acmod & 0x1) && (p_ac3dec->bsi.acmod != 0x1)) { NeedBits (&(p_ac3dec->bit_stream), 2); p_ac3dec->bsi.cmixlev = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 2)); DumpBits (&(p_ac3dec->bit_stream), 2); } /* If it is in use, get the surround channel mix level */ if (p_ac3dec->bsi.acmod & 0x4) { NeedBits (&(p_ac3dec->bit_stream), 2); p_ac3dec->bsi.surmixlev = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 2)); DumpBits (&(p_ac3dec->bit_stream), 2); } /* Get the dolby surround mode if in 2/0 mode */ if (p_ac3dec->bsi.acmod == 0x2) { NeedBits (&(p_ac3dec->bit_stream), 2); p_ac3dec->bsi.dsurmod = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 2)); DumpBits (&(p_ac3dec->bit_stream), 2); } /* Is the low frequency effects channel on? */ NeedBits (&(p_ac3dec->bit_stream), 1); p_ac3dec->bsi.lfeon = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1)); DumpBits (&(p_ac3dec->bit_stream), 1); /* Get the dialogue normalization level */ NeedBits (&(p_ac3dec->bit_stream), 5); p_ac3dec->bsi.dialnorm = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 5)); DumpBits (&(p_ac3dec->bit_stream), 5); /* Does compression gain exist? */ NeedBits (&(p_ac3dec->bit_stream), 1); p_ac3dec->bsi.compre = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1)); DumpBits (&(p_ac3dec->bit_stream), 1); if (p_ac3dec->bsi.compre) { /* Get compression gain */ NeedBits (&(p_ac3dec->bit_stream), 8); p_ac3dec->bsi.compr = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 8)); DumpBits (&(p_ac3dec->bit_stream), 8); } /* Does language code exist? */ NeedBits (&(p_ac3dec->bit_stream), 1); p_ac3dec->bsi.langcode = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1)); DumpBits (&(p_ac3dec->bit_stream), 1); if (p_ac3dec->bsi.langcode) { /* Get langauge code */ NeedBits (&(p_ac3dec->bit_stream), 8); p_ac3dec->bsi.langcod = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 8)); DumpBits (&(p_ac3dec->bit_stream), 8); } /* Does audio production info exist? */ NeedBits (&(p_ac3dec->bit_stream), 1); p_ac3dec->bsi.audprodie = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1)); DumpBits (&(p_ac3dec->bit_stream), 1); if (p_ac3dec->bsi.audprodie) { /* Get mix level */ NeedBits (&(p_ac3dec->bit_stream), 5); p_ac3dec->bsi.mixlevel = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 5)); DumpBits (&(p_ac3dec->bit_stream), 5); /* Get room type */ NeedBits (&(p_ac3dec->bit_stream), 2); p_ac3dec->bsi.roomtyp = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 2)); DumpBits (&(p_ac3dec->bit_stream), 2); } /* If we're in dual mono mode then get some extra info */ if (p_ac3dec->bsi.acmod ==0) { /* Get the dialogue normalization level two */ NeedBits (&(p_ac3dec->bit_stream), 5); p_ac3dec->bsi.dialnorm2 = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 5)); DumpBits (&(p_ac3dec->bit_stream), 5); /* Does compression gain two exist? */ NeedBits (&(p_ac3dec->bit_stream), 1); p_ac3dec->bsi.compr2e = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1)); DumpBits (&(p_ac3dec->bit_stream), 1); if (p_ac3dec->bsi.compr2e) { /* Get compression gain two */ NeedBits (&(p_ac3dec->bit_stream), 8); p_ac3dec->bsi.compr2 = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 8)); DumpBits (&(p_ac3dec->bit_stream), 8); } /* Does language code two exist? */ NeedBits (&(p_ac3dec->bit_stream), 1); p_ac3dec->bsi.langcod2e = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1)); DumpBits (&(p_ac3dec->bit_stream), 1); if (p_ac3dec->bsi.langcod2e) { /* Get langauge code two */ NeedBits (&(p_ac3dec->bit_stream), 8); p_ac3dec->bsi.langcod2 = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 8)); DumpBits (&(p_ac3dec->bit_stream), 8); } /* Does audio production info two exist? */ NeedBits (&(p_ac3dec->bit_stream), 1); p_ac3dec->bsi.audprodi2e = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1)); DumpBits (&(p_ac3dec->bit_stream), 1); if (p_ac3dec->bsi.audprodi2e) { /* Get mix level two */ NeedBits (&(p_ac3dec->bit_stream), 5); p_ac3dec->bsi.mixlevel2 = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 5)); DumpBits (&(p_ac3dec->bit_stream), 5); /* Get room type two */ NeedBits (&(p_ac3dec->bit_stream), 2); p_ac3dec->bsi.roomtyp2 = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 2)); DumpBits (&(p_ac3dec->bit_stream), 2); } } /* Get the copyright bit */ NeedBits (&(p_ac3dec->bit_stream), 1); p_ac3dec->bsi.copyrightb = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -