In Java, is there a way to synthesize a tone of a specific frequency?

I am doing some work with binaural bits and trying to create a Java application that can play two sounds at slightly different frequencies .. the difference is 25-30 Hz.

In an ideal world, I would like to give Java two integer inputs, say 440 and 410, and Java plays 440 Hz sound and 410 Hz sound.

Given what I saw in the javax.sound.* Classes, it seems that Java only supports the equivalent of piano notes ... A4 @ 440Hz, then A-sharp-4 @ 466.164Hz, and in the other direction, G-sharp-4 @ 415.305 Hz. While “adjoining” ones are usually within the range for creating a binaural rhythm, I try to achieve more control in the frequency of my tones.

Since simple audio synthesis is nothing more than frequency, intensity and duration, it seems to me that somewhere in the bowels of the javax.sound.* classes javax.sound.* There is some kind of search that says when I say Java play "A4", it is 440 Hz. The question is whether there is a way to crack this table to say that “A4.1” is the equivalent of 449 Hz.

I was messing around with javax.sound.midi , not yet exploring javax.sound.sampled ; it seems that I will need to try my tones using the sampled classes; I prefer to synthesize. If I'm wrong, get me right.

Most of the third-party interfaces that I saw are focused specifically on the production of music and manipulation, and, as such, are limited in their ability to work with microtones. Does anyone have experience or recommendations for a solution?

+7
source share
2 answers

You can generate samples and send them to the sound card using the classes in javax.sound.sampled.* ; basically create a software generator.

It takes some knowledge, but can be very funny when you earn it;)

I played with these classes when I created this: http://bobusumisu.net/testing/bobusynth-alpha1/

Here is the tutorial that got me started: http://www.drdobbs.com/jvm/230500178

+5
source

This is only to complement the already provided and accepted answer (which I gave +1).

You can use wavetables as an alternative to triggering trigger functions on the fly - sorting half-sampled / half-synthesized. I also use a sine wave table with six independent cursors pointing to it for FM synthesis, and duplicated several Yamaha DX7 patches this way. But all this is done through javax.sound.sampled. Once a software synthesizer has been created, you can control it using the midi library classes.

Suppose you populate a 1K array with float for a single sine wave.

If you “play” the wave table, increasing and looping it and extracting each member of the array in turn (for recording on a sound card through SourceDataLine), you will get a height directly related to the sampling frequency. For 44100 samples per second, an array of 1024 elements will cycle 44100/1024 = 43.066 ... times to fill this “second” data (a very low step - about 43 Hz). If you skip every second element of the table, the step is twice as large, etc. To get a height of 440, you need to find the correct "increment" to use for the step along the array of wave tables, which can be found: incr = (wave size Table * desired step) / sample rate

For example (1024 * 440) / 44100 gives the increment: 10.21678 ... Thus, if the first value from waveTable is at location 0 of the array, the second value that will be used will be between locations 10 and 11. To get the value that is between two array locations, use linear interpolation.

I use this method with javax.sound.sampled libraries for "Terminal" at this link. A keyboard is displayed, but you can easily hear / see microtonal controls when moving the mouse around the keys.

http://www.hexara.com/VSL/JTheremin.htm

In the above position, the mouse (called via MouseMotionListener) is used to calculate the desired tone using this function:

 return Math.pow(2, ((mouseX + tuningLoc) / (octaveWidth))); 

where octaveWidth is the number of pixels that spans an octave.

+4
source

All Articles