改变android中声音文件的频率

发布于 2024-09-24 01:58:22 字数 323 浏览 6 评论 0原文

我尝试更改单个声音文件的频率。我设法在 Android 中使用 SoundPool 来做到这一点。但结果听起来确实很糟糕。 所以我开始进行傅里叶变换 - 但我不确定这是否是我正在寻找的。

我想加载一个文件并在每次播放该文件时更改该文件的频率。所以我可以用一种音调创作旋律。 android/java 可以吗?


这就是我设法做到的方式。我所说的“坏”是指听起来不合时宜。

如果我想播放文件中音符的下一个频率,我必须将其乘以 2^(1/12)。但由于它只是一个浮点数,我想它不够精确,无法获得下一个音符的“真实”频率。

有没有一种“简单”的方法来实现这个目标?

I try to change the frequency of a single soundfile. I managed to do that in android with the SoundPool thing. But the result sounds really bad.
So I stepped about the Fourier Transformation - but I am not sure if this is what I am looking for.

I want to load a single file and change the frequency of that file every time that file is played. So I can create melodies out of one tone. Is that possible with android/java?


This is the way I managed to do it. With "bad" I mean it sounds out of tune.

If I want to play the next frequency of the note in the file I must multiply it by 2^(1/12). But since it's just a float, I guess it's not precise enough to get the "real" frequency of the next note.

Is there a "simple" way to achieve that goal?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

早乙女 2024-10-01 01:58:22

使用 SoundPool 最简单的方法是调整调用 play() 时的速率:

play(aSoundId, leftVolume, rightVolume, 1, 0, rate);

速率可以从 0.5f 到 2.0f 变化,尽管极端情况通常听起来不太好,所以您可能需要设置一个可接受的范围 (例如,0.4f)和最小速率(例如,0.85f)。然后您可以使用一个变量来控制您在该范围内的位置(例如,范围在 .0f 和 1.0f 之间的浮点数):

float rate = RATE_RANGE * pitch + MINIMUM_RATE;

The simplest way with the SoundPool is to adjust the rate on your call to play():

play(aSoundId, leftVolume, rightVolume, 1, 0, rate);

The rate can vary from .5f to 2.0f, though the extremes typically don't sound great, so you may want to set an acceptable range (e.g., .4f) and a minimum rate (e.g., .85f). Then you can have a variable to control where you are within that range (e.g., a float that ranges between .0f and 1.0f):

float rate = RATE_RANGE * pitch + MINIMUM_RATE;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文