tags:

views:

133

answers:

3

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.

+1  A: 

This example constructs and plays an equal tempered scale.

trashgod
That is way more code than I was hoping for, but very solid, and the shortest out of anything else I searched for. Thanks!
alleywayjack
A: 

As far as i know there is no way to do this without some boilerplate code in Java. The most simple API is probably provided by the Applet class (can be used by non-Applets as well) in the form of the static newAudioClip(URL url)-method. However this gives you just the ability to play predefined audio clips and you have very little control over the audio. If you just need to play audio from a small, predefined set of clips it might suffice (you could have a set of wav-files containing your notes and play them this way, AudioClip's can be looped if desired).

Other than that, both midi and sampled audio API's are much more powerful, but the flexibility comes at a price: You need considerably more code to set them up.

Durandal
+1  A: 

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

Player = new Player();
player.play("A C# E");
Alex Feinman
Furthermore, you can use JFugue's MicrotoneHelper class to assign a specific frequency (in Hertz) to a letter, then use that letter as a note for playing the tone.
David
Ooh, is that new? I haven't played with it yet. (/me downloads the new version...)
Alex Feinman