Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple way to play a single frequency in java?

Tags:

java

audio

I just want to play a very simple, straight forward note by giving my computer a certain frequency as an integer, and from there I can figure out how to make it play the note longer or shorter. It does not necessarily have to come out of the actual sound card - if it's generated and output by the internal speaker that's okay.

I looked at the midi libraries that java has included, and they are way more than what I want to do. This just needs to be very basic.

like image 608
nathas Avatar asked Jun 07 '10 18:06

nathas


People also ask

Can you play sounds in Java?

The Java Sound APIs are designed to play sounds smoothly and continuously, even very long sounds. As part of this tutorial, we'll play an audio file using Clip and SourceDataLine Sound APIs provided by Java. We'll also play different audio format files.


2 Answers

Look into JFugue -- it's really easy to do some basic stuff, and the capabilities are there if you want to expand later.

Player player = new Player();
player.play("A C# E");
like image 155
Alex Feinman Avatar answered Nov 03 '22 08:11

Alex Feinman


This example constructs and plays an equal tempered scale.

like image 3
trashgod Avatar answered Nov 03 '22 08:11

trashgod