⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 util.c

📁 《Visual C++小波变换技术与工程实践》作者:靳济芳。书上的代码。第3章:语音的去噪处理
💻 C
字号:
/*
 * FAAC - Freeware Advanced Audio Coder
 * Copyright (C) 2001 Menno Bakker
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.

 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * $Id: util.c,v 1.3 2001/06/04 23:02:24 wmay Exp $
 */

#include <math.h>

#include "util.h"

/* Returns the sample rate index */
int GetSRIndex(unsigned int sampleRate)
{
	if (92017 <= sampleRate) return 0;
	if (75132 <= sampleRate) return 1;
	if (55426 <= sampleRate) return 2;
	if (46009 <= sampleRate) return 3;
	if (37566 <= sampleRate) return 4;
	if (27713 <= sampleRate) return 5;
	if (23004 <= sampleRate) return 6;
	if (18783 <= sampleRate) return 7;
	if (13856 <= sampleRate) return 8;
	if (11502 <= sampleRate) return 9;
	if (9391 <= sampleRate) return 10;

	return 11;
}

/* Returns the maximum bitrate per channel for that sampling frequency */
unsigned int MaxBitrate(unsigned long sampleRate)
{
	/*
	 *  Maximum of 6144 bit for a channel
	 */
	return (unsigned int)(6144.0 * (double)sampleRate/1024.0 + .5);
}

/* Returns the minimum bitrate per channel for that sampling frequency */
unsigned int MinBitrate()
{
	return 8000;
}


/* Max prediction band for backward predictionas function of fs index */
const int MaxPredSfb[] = { 33, 33, 38, 40, 40, 40, 41, 41, 37, 37, 37, 34, 0 };

int GetMaxPredSfb(int samplingRateIdx)
{
	return MaxPredSfb[samplingRateIdx];
}



/* Calculate bit_allocation based on PE */
unsigned int BitAllocation(double pe, int short_block)
{
	double pew1;
	double pew2;
	double bit_allocation;

	if (short_block) {
		pew1 = 0.6;
		pew2 = 24.0;
	} else {
		pew1 = 0.3;
		pew2 = 6.0;
	}
	bit_allocation = pew1 * pe + pew2 * sqrt(pe);
	bit_allocation = min(max(0.0, bit_allocation), 6144.0);

	return (unsigned int)(bit_allocation+0.5);
}

/* Returns the maximum bit reservoir size */
unsigned int MaxBitresSize(unsigned long bitRate, unsigned long sampleRate)
{
	return 6144 - (unsigned int)((double)bitRate/(double)sampleRate*1024.0);
}

/* Returns whether or not we're on a big-endian machine */
int IsBigEndian(void)
{
    union {
        unsigned long longval;
        char charval[sizeof(unsigned long)];
    } u;

    u.longval = 0x41424344L;  /* ABCD in ASCII */
	return (u.charval[0] == 'A');
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -