如果需要把8K, 16K, 32K, 48K采样率的音频数据降为4K的音频数据, 最简单的方法根据降频倍数来取点, 但是线性度不好.
另一种线性度好一点的方法是: 取适当个数的点数, 各点乘以各自点的系数, 然后相加取平均值.
降频倍数与系数的关系如下:
2倍: {0.3, 0.4, 0.3}
4倍: {0.15, 0.2, 0.3, 0.2, 0.15}
8倍: {0.1425, 0.1251, 0.1525, 0.1628, 0.1525, 0.1251, 0.1425}
12倍: {0.2487, 0.0952, 0.1042, 0.1074, 0.1042, 0.0952, 0.2487}
以下内容是webrtc中的注释:
/* Filter coefficients used when downsampling from the indicated
sample rates (8, 16, 32, 48 kHz) to 4 kHz.
Coefficients are in Q12. */
/* {0.3, 0.4, 0.3} */
const int16_t WebRtcNetEQ_kDownsample8kHzTbl[] = { 1229, 1638, 1229 };
#ifdef NETEQ_WIDEBAND
/* {0.15, 0.2, 0.3, 0.2, 0.15} */
const int16_t WebRtcNetEQ_kDownsample16kHzTbl[] =
{ 614, 819, 1229, 819, 614};
#endif
#ifdef NETEQ_32KHZ_WIDEBAND
/* {0.1425, 0.1251, 0.1525, 0.1628, 0.1525, 0.1251, 0.1425} */
const int16_t WebRtcNetEQ_kDownsample32kHzTbl[] =
{ 584, 512, 625, 667, 625, 512, 584};
#endif
#ifdef NETEQ_48KHZ_WIDEBAND
/* {0.2487, 0.0952, 0.1042, 0.1074, 0.1042, 0.0952, 0.2487} */
const int16_t WebRtcNetEQ_kDownsample48kHzTbl[] =
{ 1019, 390, 427, 440, 427, 390, 1019};
#endif