在 Java 上播放单个 MIDI 木版音符?

发布于 2024-08-08 19:26:23 字数 742 浏览 3 评论 0原文

我计划使用 Java 创建自己的节拍器(木版乐器),可以设置其 bpm、音量等。我已经尝试了从 getChannels() 获得的超过 16 个通道(MIDI 1.0 规范),但是根本听不到木刻的声音。

取自 http://www.jsresources.org 的代码

  /*
   * Turn the note on on MIDI channel 1.
   * (Index zero means MIDI channel 1)
   */
  MidiChannel[] channels = synth.getChannels();
  channels[0].noteOn(nNoteNumber, nVelocity);

  /*
   * Wait for the specified amount of time
   * (the duration of the note).
   */
  try
  {
   Thread.sleep(nDuration);
  }
  catch (InterruptedException e)
  {
  }

  /*
   * Turn the note off.
   */
  channels[0].noteOff(nNoteNumber);

这是 有什么关于这个的吗?谢谢。

I'm planning to create my own metronome (woodblock instrument) using Java that could set its bpm, volume, etc. And I have tried over 16 channels (MIDI 1.0 specification) obtained from getChannels() but there is no woodblock heard at all.

Here's the code taken from http://www.jsresources.org

  /*
   * Turn the note on on MIDI channel 1.
   * (Index zero means MIDI channel 1)
   */
  MidiChannel[] channels = synth.getChannels();
  channels[0].noteOn(nNoteNumber, nVelocity);

  /*
   * Wait for the specified amount of time
   * (the duration of the note).
   */
  try
  {
   Thread.sleep(nDuration);
  }
  catch (InterruptedException e)
  {
  }

  /*
   * Turn the note off.
   */
  channels[0].noteOff(nNoteNumber);

Anyone got anything about this? thanks.

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

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

发布评论

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

评论(3

↙厌世 2024-08-15 19:26:23

根据您的合成器,打击乐声音将位于通道 10 或通道 16(阵列中的索引 9 或 15)。木板声音将是音符编号 76 和 77,您可能希望使用音符力度值 128(以获得最大音量)。

我没有查看您正在使用的代码,但您可能还需要调用一个方法来打开合成器,然后才能播放任何内容。另外,由于您正在演奏打击乐音符,您也许能够在音符开启消息之后立即发送相应的音符关闭消息(因此您不必计算固定的音符持续时间)打击乐音符)。我使用过的大多数 MIDI 合成器即使在收到音符关闭消息后也会播放整个打击乐声音。

Depending on your synthesizer, the percussion sounds will be on channel 10 or channel 16 (indexes 9 or 15 in your array). The woodblock sounds would be note numbers 76 and 77, and you would probably want to use a note velocity value of 128 (for maximum volume).

I haven't looked at the code you're using, but you may also need to call a method to turn on the synthesizer before you can play anything. Also, since you're playing a percussion note, you may be able to send the corresponding note off message immediately after the note on message (so you don't have to figure out the duration of the fixed percussion note). Most MIDI synths that I've used play the entire percussion sound even after receiving the note off message.

树深时见影 2024-08-15 19:26:23

木版是一种打击乐器。当您在已分配鼓或打击乐音色的通道上演奏正确的音符时,您应该会听到它。 (在打击乐或鼓音色中,每个音符演奏不同的乐器:木块、军鼓、hi-tom、clave等)

a woodblock is a percussion instrument. you should hear it when you play the right note on a channel which has been assigned a drums or percussions patch. (in a percussions or drums patch, each note plays a different instrument: wood block, snare drum, hi-tom, clave, etc.)

橘香 2024-08-15 19:26:23

使用(例如)此通用 MIDI (GM) 参考来查找补丁。您需要通道 10 用于 GM 打击乐,音符编号 76 用于高木块,音符编号 77 用于低木块。

而且,乐器116是全键盘(从1到128的任何音高)木板。我相信这应该适用于任何非打击乐(即不是 10 或可能 16)通道。

注意:GM 似乎是从 1 开始的,而您的 API 似乎是从 0 开始的,因此您可能需要从其中一些值中减去 1。

Use (eg) this General MIDI (GM) reference to look up patches. You need channel 10 for GM percussion, and note number 76 for Hi Wood Block or 77 for Low Wood Block.

Also, instrument 116 is a full keyboard (any pitch from 1 to 128) woodblock. I believe that should work on any non-percussion (ie not 10, or possibly 16) channel.

Note: GM appears to be 1-based, whereas your API seems to be 0-based, so you may have to subtract one from some of these values.

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