如何使用c++找到WAV文件的最高音量级别
How to find highest volume level of a WAV file using C++
我想通过使用c++(库libsndfile)获得wav文件的最高音量级别的值?有什么建议吗?
您可以简单地在样本缓冲区(s)中样本的绝对值中找到最高的单个样本值(Peak)。它采用一般的形式:
t_sample PeakAmplitude(const t_sample* const buffer, const size_t& count) {
t_sample highest(0);
for (size_t idx(0); idx < count; ++idx) {
// or fabs if fp
highest = std::max(highest, abs(buffer[idx]));
}
return highest;
}
要获得平均值,可以使用RMS函数。说明:
t_sample RMSAmplitude(const t_sample* const buffer, const size_t& count) {
t_sample s2(0);
for (size_t idx(0); idx < count; ++idx) {
// mind your sample types and ranges
s2 += buffer[idx] * buffer[idx];
}
return sqrt(s2 / static_cast<double>(count));
}
RMS计算比Peak更接近人类感知。
要更深入地了解人类的感知,您可以使用称重过滤器。
相关文章:
- .cpp和.h文件中的模板专用化声明
- 为什么两个不同的未命名名称空间可以共存于一个cpp文件中
- 文本文件中的单词链表
- CMake-按正确顺序将项目与C运行时对象文件链接
- 使用新行和不使用新行读取文件
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- Qnetworkreply,QnetworkAccessManager- https下载文件 - 高CPU使用情况
- 如何在Windows和更高版本上保留内存,并将文件映射到内存中
- OpenGL/ES 2.0及更高版本:如何将多个着色器文件编译在一起
- 如何获取 wav 文件音量级别
- 对于二进制数据,哪个性能更高:将整个对象写入文件或分隔变量(无对象)
- 从 txt 文件中读取矩阵以执行高斯消除 (C++)
- 播放音频文件并调整系统音量
- 使用高斯消去法从文本文件中求逆矩阵.C++
- Boost错误:Boost.文件系统V3及更高版本需要std::wstring支持
- 如何在读取文件时获得更高的性能
- 如何使用c++找到WAV文件的最高音量级别
- 标准化一个波文件的音量级别
- Sublime不会高亮显示c++文件
- C++:如何将%USERPROFILE%路径转换为文件路径(应该适用于Windows XP及更高版本)