1 Star 0 Fork 0

Ahwinds/shairport-sync

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
loudness.c 1.23 KB
一键复制 编辑 原始数据 按行查看 历史
Mike Brady 提交于 2019-11-13 21:58 . Update sample D-Bus commands
#include "loudness.h"
#include "common.h"
#include <math.h>
loudness_processor loudness_r;
loudness_processor loudness_l;
void _loudness_set_volume(loudness_processor *p, float volume) {
float gain = -(volume - config.loudness_reference_volume_db) * 0.5;
if (gain < 0)
gain = 0;
float Fc = 10.0;
float Q = 0.5;
// Formula from http://www.earlevel.com/main/2011/01/02/biquad-formulas/
float Fs = 44100.0;
float K = tan(M_PI * Fc / Fs);
float V = pow(10.0, gain / 20.0);
float norm = 1 / (1 + 1 / Q * K + K * K);
p->a0 = (1 + V / Q * K + K * K) * norm;
p->a1 = 2 * (K * K - 1) * norm;
p->a2 = (1 - V / Q * K + K * K) * norm;
p->b1 = p->a1;
p->b2 = (1 - 1 / Q * K + K * K) * norm;
}
float loudness_process(loudness_processor *p, float i0) {
float o0 = p->a0 * i0 + p->a1 * p->i1 + p->a2 * p->i2 - p->b1 * p->o1 - p->b2 * p->o2;
p->o2 = p->o1;
p->o1 = o0;
p->i2 = p->i1;
p->i1 = i0;
return o0;
}
void loudness_set_volume(float volume) {
float gain = -(volume - config.loudness_reference_volume_db) * 0.5;
if (gain < 0)
gain = 0;
debug(2, "Volume: %.1f dB - Loudness gain @10Hz: %.1f dB", volume, gain);
_loudness_set_volume(&loudness_l, volume);
_loudness_set_volume(&loudness_r, volume);
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ahwinds/shairport-sync.git
git@gitee.com:ahwinds/shairport-sync.git
ahwinds
shairport-sync
shairport-sync
master

搜索帮助