简体   繁体   English

如何使用C ++查找WAV文件的最高音量

[英]How to find highest volume level of a WAV file using C++

I want to get the value of the highest volume level of a WAV-file by using C++ (library libsndfile)? 我想通过使用C ++(库libsndfile)获得WAV文件的最高音量级别的值吗? Any suggestions on how to do it? 有什么建议吗?

You can simply find the highest single sample value (Peak) among the absolute values of the samples in the sample buffer(s). 您可以简单地在样本缓冲区中的样本绝对值中找到最高的单个样本值(Peak)。 This takes the general form: 它采用一般形式:

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;
}

To get averages, you can use RMS functions. 要获得平均值,可以使用RMS函数。 Illustration: 插图:

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 calculations are closer to human perception than Peak. RMS计算比Peak更接近于人类的感知。

To go even deeper into human perception, you can employ Weighing Filters . 要更深入地了解人类,您可以使用称重过滤器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM