📄 ms.c
字号:
/************************* MPEG-2 NBC Audio Decoder **************************
* *
"This software module was originally developed in the course of
development of the MPEG-2 NBC/MPEG-4 Audio standard ISO/IEC 13818-7,
14496-1,2 and 3. This software module is an implementation of a part of one or more
MPEG-2 NBC/MPEG-4 Audio tools as specified by the MPEG-2 NBC/MPEG-4
Audio standard. ISO/IEC gives users of the MPEG-2 NBC/MPEG-4 Audio
standards free license to this software module or modifications thereof for use in
hardware or software products claiming conformance to the MPEG-2 NBC/MPEG-4
Audio standards. Those intending to use this software module in hardware or
software products are advised that this use may infringe existing patents.
The original developer of this software module and his/her company, the subsequent
editors and their companies, and ISO/IEC have no liability for use of this software
module or modifications thereof in an implementation. Copyright is not released for
non MPEG-2 NBC/MPEG-4 Audio conforming products.The original developer
retains full right to use the code for his/her own purpose, assign or donate the
code to a third party and to inhibit third party from using the code for non
MPEG-2 NBC/MPEG-4 Audio conforming products. This copyright notice must
be included in all copies or derivative works."
Copyright(c)1996.
* *
****************************************************************************/
/*******************************************************************************************
*
* MS stereo coding module
*
* Authors:
* CL Chuck Lueck, TI <lueck@ti.com>
*
* Changes:
* 22-jan-98 CL Initial revision. Lacks psychoacoustics for MS stereo.
***************************************************************************************/
#include "psych.h"
#include "ms.h"
void MSPreprocess(double p_ratio_long[][MAX_SCFAC_BANDS],
double p_ratio_short[][MAX_SCFAC_BANDS],
CH_PSYCH_OUTPUT_LONG p_chpo_long[],
CH_PSYCH_OUTPUT_SHORT p_chpo_short[][MAX_SHORT_WINDOWS],
Ch_Info *channelInfo, /* Pointer to Ch_Info */
enum WINDOW_TYPE block_type[MAX_TIME_CHANNELS], /* Block type */
AACQuantInfo* quantInfo, /* Quant info */
int use_ms,
int numberOfChannels
)
{
int chanNum;
int sfbNum;
static int block = 0;
int used = 0, notused = 0;
int realyused = 0;
/* Look for channel_pair_elements */
for (chanNum=0;chanNum<numberOfChannels;chanNum++) {
if (channelInfo[chanNum].present) {
if ((channelInfo[chanNum].cpe)&&(channelInfo[chanNum].ch_is_left)) {
int leftChan=chanNum;
int rightChan=channelInfo[chanNum].paired_ch;
channelInfo[leftChan].ms_info.is_present=0;
channelInfo[leftChan].common_window = 0;
/* Perform MS if block_types are the same */
if ((block_type[leftChan]==block_type[rightChan])&&(use_ms==0)) {
int numGroups;
int groupIndex = 0;
int maxSfb;
int g,b,j;
int use_ms_short;
MS_Info *msInfo;
numGroups = quantInfo[leftChan].num_window_groups;
maxSfb = quantInfo[leftChan].max_sfb;
/* Determine which bands should be enabled */
msInfo = &(channelInfo[leftChan].ms_info);
for (g=0;g<numGroups;g++) {
for (sfbNum=0;sfbNum<maxSfb;sfbNum++) { //sfbNum表示一个窗的第几个sfb
use_ms_short = 1;
b = g*maxSfb+sfbNum; //在一个window_sequence中的第b个sbf,b是从group0的sfb0算起的。
if (block_type[leftChan] == ONLY_SHORT_WINDOW) {
for (j = groupIndex; j < quantInfo[leftChan].window_group_length[g]+groupIndex; j++) {
//j表示某一个窗对在window sequence中的位置
use_ms_short = min(use_ms_short, p_chpo_short[1][j].use_ms[sfbNum]);
//在一个group中,对于某个sfb,只要有一个窗不用ms_short,那这个group所有的窗的这个sfb都不用
}
msInfo->ms_used[b] = use_ms_short;
if (msInfo->ms_used[b]) {
realyused = 1;
used++; //统计使用ms的sfb的数目
for (j = groupIndex; j < quantInfo[leftChan].window_group_length[g]+groupIndex; j++) {
p_ratio_short[0][(g*maxSfb)+sfbNum] = p_chpo_short[2][j].p_ratio[sfbNum];
p_ratio_short[1][(g*maxSfb)+sfbNum] = p_chpo_short[3][j].p_ratio[sfbNum];
p_chpo_short[1][j].use_ms[sfbNum] = use_ms_short; //似乎多余
}
} else {
notused++; //统计不使用ms的sfb的数目
for (j = groupIndex; j < quantInfo[leftChan].window_group_length[g]+groupIndex; j++) {
p_ratio_short[0][(g*maxSfb)+sfbNum] = p_chpo_short[0][j].p_ratio[sfbNum];
p_ratio_short[1][(g*maxSfb)+sfbNum] = p_chpo_short[1][j].p_ratio[sfbNum];
p_chpo_short[1][j].use_ms[sfbNum] = use_ms_short;
}
} //这段代码可以简化
} else { //如果不是EIGHT_SHORT_WINDOW,则一切照常。
msInfo->ms_used[b] = p_chpo_long[1].use_ms[sfbNum];
if (msInfo->ms_used[b]) {
realyused = 1;
used++;
p_ratio_long[0][sfbNum] = p_chpo_long[2].p_ratio[sfbNum];
p_ratio_long[1][sfbNum] = p_chpo_long[3].p_ratio[sfbNum];
} else {
notused++;
p_ratio_long[0][sfbNum] = p_chpo_long[0].p_ratio[sfbNum];
p_ratio_long[1][sfbNum] = p_chpo_long[1].p_ratio[sfbNum];
}
}
}
groupIndex+=quantInfo[leftChan].window_group_length[g]; //移动groupIndex到下一个window_group的开头
}
if (realyused) //这一个window_sequence用到了ms
{
channelInfo[leftChan].common_window = 1; //因为用了ms,所以commom_window为1
channelInfo[leftChan].ms_info.is_present=1;
}
} else if ((block_type[leftChan]==block_type[rightChan])&&(use_ms == 1)) {
int chan;
int numGroups;
int groupIndex = 0;
int maxSfb;
int g,b,j;
MS_Info *msInfo;
channelInfo[0].ms_info.is_present = 1; //因为确定了用ms,所以可以确定common_window和is_present
channelInfo[0].common_window = 1;
for (chan = 0; chan < 2; chan++) {
maxSfb = quantInfo[chan].max_sfb;
/* Determine which bands should be enabled */
msInfo = &(channelInfo[leftChan].ms_info);
numGroups = quantInfo[chan].num_window_groups;
groupIndex = 0; //添加此句
for (g=0;g<numGroups;g++) {
for (sfbNum=0;sfbNum<maxSfb;sfbNum++) {
b = g*maxSfb+sfbNum;
// groupIndex = 0; //这句好像有错,应该不要
if (block_type[chan] == ONLY_SHORT_WINDOW) {
msInfo->ms_used[b] = 1;
for (j = groupIndex; j < quantInfo[chan].window_group_length[g]+groupIndex; j++) {
p_ratio_short[chan][(g*maxSfb)+sfbNum] = p_chpo_short[chan+2][j].p_ratio[sfbNum];
p_chpo_short[1][j].use_ms[sfbNum] = 1;
}
} else {
msInfo->ms_used[b] = 1;
p_ratio_long[chan][sfbNum] = p_chpo_long[chan+2].p_ratio[sfbNum];
p_chpo_long[1].use_ms[sfbNum] = 1;
}
}
groupIndex+=quantInfo[chan].window_group_length[g];
}
} //此段代码也可改进
} else { //左右通道块类型不一致
int chan;
int numGroups;
int groupIndex = 0;
int maxSfb;
int g,b,j;
MS_Info *msInfo;
for (chan = 0; chan < 2; chan++) {
maxSfb = quantInfo[chan].max_sfb;
/* Determine which bands should be enabled */
msInfo = &(channelInfo[leftChan].ms_info);
numGroups = quantInfo[chan].num_window_groups;
groupIndex = 0; //添加此句
for (g=0;g<numGroups;g++) {
for (sfbNum=0;sfbNum<maxSfb;sfbNum++) {
b = g*maxSfb+sfbNum;
// groupIndex = 0; //这句好像有错,应该不要
if (block_type[chan] == ONLY_SHORT_WINDOW) {
msInfo->ms_used[b] = 0; //左右声道窗类型不一致,,不能用ms
for (j = groupIndex; j < quantInfo[chan].window_group_length[g]+groupIndex; j++) {
p_ratio_short[chan][(g*maxSfb)+sfbNum] = p_chpo_short[chan][j].p_ratio[sfbNum];
p_chpo_short[1][j].use_ms[sfbNum] = 0;
}
} else {
msInfo->ms_used[b] = 0; //左右声道窗类型不一致,,不能用ms
p_ratio_long[chan][sfbNum] = p_chpo_long[chan].p_ratio[sfbNum];
p_chpo_long[1].use_ms[sfbNum] = 0;
}
}
groupIndex+=quantInfo[chan].window_group_length[g];
}
}
}
}
}
}
// printf("%d used: %d, notused: %d\n", block++, used, notused);
}
void MSEnergy(double *spectral_line_vector[MAX_TIME_CHANNELS],
double energy[MAX_TIME_CHANNELS][MAX_SCFAC_BANDS],
CH_PSYCH_OUTPUT_LONG p_chpo_long[],
CH_PSYCH_OUTPUT_SHORT p_chpo_short[][MAX_SHORT_WINDOWS],
int sfb_width_table[MAX_TIME_CHANNELS][MAX_SCFAC_BANDS],
Ch_Info *channelInfo, /* Pointer to Ch_Info */
enum WINDOW_TYPE block_type[MAX_TIME_CHANNELS], /* Block type */
AACQuantInfo* quantInfo, /* Quant info */
int use_ms,
int numberOfChannels
)
{
int chanNum, numWindows, bandNumber;
int windowLength, w, j;
int *p_use_ms;
for (chanNum=0;chanNum<numberOfChannels;chanNum++) {
double dtmp;
/* Compute energy in each scalefactor band of each window */
numWindows = (block_type[chanNum]==ONLY_SHORT_WINDOW) ? 8 : 1;
windowLength = 1024/8;
bandNumber=0;
for (w=0;w<numWindows;w++) {
int offset=0;
int sfb;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -