开发者

How to change pitch continuously in Java sound?

开发者 https://www.devze.com 2022-12-16 02:39 出处:网络
I\'m working with midi using the Java sound API. Basically I\'m trying to achieve a portamento effect where I can slide between different notes. The closest I\'ve gotten is using the setPitchBend() me

I'm working with midi using the Java sound API. Basically I'm trying to achieve a portamento effect where I can slide between different notes. The closest I've gotten is using the setPitchBend() method in MidiChannel. However, this only allows a range of 2 semitones from the note I started with. Is there another way to achieve this portamento effect, or maybe changing the pitch bend range?

If 开发者_运维知识库there's a way to accomplish this in JFugue, that would be acceptable as well.


JFugue supports microtones. (It does it through the JavaSound API, combined with a lot of math)

Whether it can do exactly what you're looking for is another question. I believe the problem you'll run into is that each new note you play will sounds like a new note, as opposed to a bunch of notes tied together. This would be particularly noticeable when a note has an attack and decay value other than 0, or if the instrument has inherently different sounds at the start and end of a note.

In JFugue, you can set the attack and decay of a note by adding 'a' and 'd', followed by values from 0-128, after the note: C5wa0d0 - C-note, 5th octave, whole duration, attack=0, decay=0.

The microtone helper, as currently written, allows you to define a single frequency to a string; for example, you can map 400 to "A400". Then to use this, you would say player.play("[A400]w") (note the brackets).

One way to get what you're looking for is to define frequencies and strings for however many microtones you want, then create a Pattern using a for loop... Pattern p = new Pattern("[A400]wa0d0 [A410]wa0d0 [A420]wa0d0"...); You can probably use a step greater than 1 Hertz for each note, because our ears can't distinguish such slight frequency differences.

If only there were a more elegant solution! But see if that helps.


MIDI has a portamento control for pitch slides. Try calling controlChange(65,127) to turn on the portametno control then playing the two notes. controlChange(5, xxx) should change the speed of the pitch slide. controlChange(65,0) will turn portamento off.


Just a guess - can you play out two notes of consecutive pitches, and fade one in as you fade the other one out?


This may be way out of date - it's nearly two decades since I gave up on MIDI and switched to fretless bass - but for longer slides you used to have to play one note, bend its pitch up to half-way to the next note, then play the next note note bent half way down, so they meet at the same pitch, then repeat the process.


The pitch bend control simply defines a range; it's up to the receiving end (e.g. the synthesizer) how to interpret it. If the receiving end supports two semitones, then two semitones is what you get - unless it can be reconfigured! On most synthesizers you can reconfigure the pitch bend range; what's your target device?

(I'm not familiar with JFugue.)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号