以 dB 表示音乐音频样本? [英] Representing music audio samples in terms of dB?

查看:37
本文介绍了以 dB 表示音乐音频样本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在启动一个项目,该项目将允许我使用 Java 读取声音样本,并取决于每个样本的属性(为了简化,我目前正在考虑关注分贝,或者找到某种方法来计算特定样本或样本集的总体音量"),返回 0-255 之间的值,其中 0 表示静音,255 表示最高声压(我想与参考点相比?我不知道怎么说呢).然后我想将这些值作为字节返回并发送到 Arduino,以便使用 PWM 控制 LED 的强度,并在视觉上看到"音乐.

I am starting a project which would allow me to use Java to read sound samples, and depending on the properties of each sample (I'm thinking focusing on decibels at the moment for the sake of simplification, or finding some way to compute the overall 'volume' of a specific sample or set of samples), return a value from 0-255 where 0 would be silence and 255 would be the highest sound pressure (Compared to a reference point, I suppose? I have no idea how to word this). I want to then have these values returned as bytes and sent to an Arduino in order to control the intensity of LED's using PWM, and visually 'see' the music.

我不是任何类型的音频文件格式专家,并且对数据如何存储在音乐文件中没有特别的了解.因此,我无法找到如何读取样本并找到一种将其整体音量级别表示为字节的方法.我查看了 javax.sound.sampled 包,这让我很困惑.任何有关我如何实现这一目标的见解将不胜感激.

I am not any sort of audio file format expert, and have no particular understanding of how the data is stored in a music file. As such, I am having trouble finding out how to read a sample and find a way to represent its overall volume level as a byte. I have looked through the javax.sound.sampled package and it is all very confusing to me. Any insight as to how I could accomplish this would be greatly appreciated.

推荐答案

正如 Bastyen(来自我的 +1)所指出的,计算分贝实际上并不简单,而是需要查看大量样本.但是,由于声音样本比动画中的视觉帧更频繁地运行,因此汇总测量的结果相当巧妙.

As Bastyen (+1 from me) indicates, calculating decibels is actually NOT simple, but requires looking at a large number of samples. However, since sound samples run MUCH more frequently than visual frames in an animation, making an aggregate measure works out rather neatly.

一个不错的视觉动画速率,例如每秒更新 60 次,最常见的声音采样率为每秒 44100 次.因此,735 个样本 (44100/60 = 735) 可能最终成为与可视化工具交互的不错选择.

A nice visual animation rate, for example, updates 60 times per second, and the most common sampling rate for sound is 44100 times per second. So, 735 samples (44100 / 60 = 735) might end up being a good choice for interfacing with a visualizer.

顺便说一下,在我读过的所有官方 Java 教程中(我是个大粉丝),我发现 javax.sound.sampled 附带的教程是最难的.http://docs.oracle.com/javase/tutorial/sound/TOC.html
但它们仍然值得一读.如果我负责重写,将会有更多的代码示例.一些最好的代码示例包含在多个部分中,例如使用文件和格式转换器"讨论.

By the way, of all the official Java tutorials I've read (I am a big fan), I have found the ones that accompany the javax.sound.sampled to be the most difficult. http://docs.oracle.com/javase/tutorial/sound/TOC.html
But they are still worth reading. If I were in charge of a rewrite, there would be many more code examples. Some of the best code examples are in several sections deep, e.g., the "Using Files and Format Converters" discussion.

如果您不希望计算 RMS,一个技巧是存储给定样本数量的局部高值和/或低值.将这些数字与分贝相关联是可疑的,但在将您选择的映射映射到可视化器之后,MAYBE 可能会很有用.部分问题在于给定波浪上单个点的值可能范围很广.局部高点可能更多是由于组成谐波的相位恰好对齐,而不是能量或音量.

If you don't wish to compute the RMS, a hack would be to store the local high and/or low value for the given number of samples. Relating these numbers to decibels would be dubious, but MAYBE could be useful after giving it a mapping of your choice to the visualizer. Part of the problem is that values for a single point on given wave can range wildly. The local high might be more due to the phase of the constituent harmonics happening to line up than about the energy or volume.

对于 8 位编码,您的 PCM 顶部和底部值可能不是 0 和 256,更可能是 -128 到 127.更常见的是 16 位编码(-32768 到 32767).但是,如果您遵循 Bastyen 的链接,您将掌握这一点.为了使您的代码独立于位编码,您可能会在进行任何其他计算之前对数据进行标准化(转换为 -1 和 1 之间的浮点数).

Your PCM top and bottom values would probably NOT be 0 and 256, more likely -128 to 127 for 8-bit encoding. More common still is 16-bit encoding (-32768 to 32767). But you will get the hang of this if you follow Bastyen's links. To make your code independent of the bit-encoding, you would likely normalize the data (convert to floats between -1 and 1) before doing any other calculations.

这篇关于以 dB 表示音乐音频样本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆