Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate sounds by frequency in Java?

How do I generate my own sound by frequency in Java?

I can play WAV files or MIDI files, but now I don't need this. I want to create a simple guitar program, and I want to play chords with this program. But I don't know how to make the sounds to the chords. I can record them with my own guitar, but this is not what I want, I want to generate the sounds!

What would some example code look like?

like image 739
victorio Avatar asked Mar 04 '11 12:03

victorio


People also ask

How do you create a sine wave in Java?

Use the Java Sound API, and Math. sin to create the actual wave levels. http://www.developer.com/java/other/article.php/2226701 has an excellent tutorial around this that I had referenced some time ago. http://jsresources.org/examples/ was another useful reference.

Can you play sounds in Java?

Java API Support for MP3 Format. Currently, both Clip and SourceDataLine can play audio files in AIFC, AIFF, AU, SND, and WAV formats. We can check the supported audio format using AudioSystem: Type[] list = AudioSystem.

How do you record audio in Java?

Obtain a TargetDataLine object which represents an input data line from which audio data can be captured, using the method getLineInfo(DataLine.Info) of the AudioSystem class. Open and start the target data line to begin capturing audio data. Create an AudioInputStream object to read data from the target data line.


1 Answers

Guitar sounds are usually synthesized in software using some variant of the Karplus-Strong algorithm. There are numerous libraries for audio output depending on your requirements, but you could start with javax.sound.sampled.

like image 141
Matthew Gilliard Avatar answered Sep 23 '22 07:09

Matthew Gilliard