如何在android/java中合成钢琴声音

发布于 2024-10-05 21:19:26 字数 224 浏览 0 评论 0原文

我在 Android 上制作了一些简单的应用程序,并认为是时候制作一些更复杂的东西了。所以,我想我应该尝试一些已经存在的东西,但从头开始构建它。

我们的想法是创建一个应用程序,允许用户通过按显示屏上的虚拟键来弹钢琴。但我不确定如何合成每个音符的声音,最好将每个音符的副本存储在文件中,还是有一种更动态的方式动态合成音符和和弦。

我曾经使用过 C++,所以 NDK 的东西也可以。 感谢您的任何帮助。

I have made a few simple apps on android, and thought it was time for something a bit more complex. So, i thought I'd try something that's already out there, but build it from scratch.

The idea is to create an app that allows user to play piano by pressing virtual keys on the display. But I'm not sure how to go about synthesizing the sound of each note, is it best to have copies of of each note stored on file, or is there a more dynamic way of synthesising notes and chords on the fly.

I have worked with C++ so NDK stuff is also okay.
Thanks for any help.

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

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

发布评论

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

评论(2

極樂鬼 2024-10-12 21:19:26

声音播放(传递缓冲区)几乎必须通过 Android java api 完成

。综合可以在本机或 java 中完成,无论它喜欢哪一个。

短(未压缩)样本可以重复播放,但您可能还需要攻击瞬态。也许你可以有一个起音、一个延音和释放,只要按下琴键就重复延音。理想情况下,每个样本应该是其基本分量的整数个周期,这样当您在起音到维持或维持到衰减之间切换时,就不会出现瞬变。

我确信您可以在某个地方找到 FM 或其他合成器的代码...您可能很想在本机库中实现此代码,该库将缓冲区交给 java 代码以传递给音频 api。

不幸的是,android已经有一个内部midi合成器,但显然缺乏一个动态接口,所以它只能播放midi文件。

Sound playback (handing off buffers) pretty much has to be done from the Android java apis

Synthesis could be done in native or java, whichever it preferred.

Short (uncompressed) samples could be played back repeatedly, but you probably also want an attack transient. Perhaps you could have an attack, a sustain, and release, repeating the sustain as long as the key is down. Ideally each sample should be an integral number of periods of its fundamental component long so that you don't get a transient when you change between the attack to sustain or sustain to decay.

I'm sure you can find code somewhere for an FM or other synthesizer... this you might well want to implement in a native library that hands off buffers to java code to pass to the audio apis.

What is too bad is that android already has an internal midi synthesizer, but apparently lacks a dynamic interface to it, so it can only play midi files.

烟─花易冷 2024-10-12 21:19:26

到目前为止,最简单的解决方案是录制钢琴上每个音符的声音,并在按下琴键时播放。许多专业的虚拟钢琴乐器都是这样工作的,记录钢琴上以多种速度演奏的每个音符。显然,这可能会占用许多 GB 的磁盘空间,但对于手机应用程序来说,您可能只需将一个八度音阶中的每个音符录制成一个 MP3 就可以了。

实际上,通过算法合成钢琴的声音非常困难,直到最近,很少有人能够令人信服地做到这一点(pianoeq< /a> 是当前最好的实现之一)。

By far the easiest solution would be to record the sound of each note on the piano and play it back when the key is pressed. Many professional virtual piano instruments work this way, recording every note on the piano being played at multiple velocities. Obviously this can take many gigabytes of disk space, but for a mobile phone app, you might get away with a single MP3 recording of each note in an octave.

Actually algorithmically synthesizing the sound of a piano is very difficult to do, and until fairly recently, very few have done it convincingly (pianoteq is one of the best current implementations).

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