Note: I do NOT want to "read audio file foo.bar and play it."
I want to programmatically generate audio files on the fly and play them.
Does Java have built in libraries for this, or does this fall into the system-dependent libraries?
Thanks!
Note: I do NOT want to "read audio file foo.bar and play it."
I want to programmatically generate audio files on the fly and play them.
Does Java have built in libraries for this, or does this fall into the system-dependent libraries?
Thanks!
The easiest way to do this is with java's in built MIDI libraries:
Jcollider is a Java interface to the SuperCollider synthesis server. If you want to synthesize music, this will make things much easier (it abstracts away from the tone generator to a synthesizer, takes care of things like graph generation, deleting muted synths from the synthesis graph until they are needed again, patching signals between synths dynamically, etc.).
This Sun forum post has some interesting code for generating sin tones. Also, given that the WAV file format is not overly complicated, you could create a table representing the desired waveform and then write it to a file. There are a few examples around, e.g. a raw audio converter and how to write a wav file.
Have you looked at JSyn? I don't think the Java Core libraries can do what you want.
Java's Built-in Midi Capabilities
The off-the-shelf Java 8 JRE definitely has what you specifically requested: A built-in synth library. It is described in some detail in Synthesizing Sound.
A quite refined example provides a visual keyboard access to a sampled music synth.
The javax.sound.midi library contains instruments that and the ability to play notes on them, based on MIDI and sampled instrument technology. The sounds are not as authentic as those of the classic Kurzweil musical instrument line, but the framework supports that level of sophistication if you wish to do your own sampling in multiple pitch ranges for a single instrument and work out the details of a fairly seamless transition between ranges.
Trivial Example for Quick View of Usage
Here's a trivial example class.
Using multi-threading or an implementations of javax.sound.midi.Sequencer like those available on GitHub.com will provide the structure necessary to actually make music.
Waveform Generation
If you wish to generate your own waveforms rather than using samples, then the answer to your question is, "No," however you can play with this tone synthesizer I wrote for this question. It has several features.
This synth lacks many features of high end waveform-generating synths.
SimpleSynth is a good demonstration of
Standard digital audio terminology was used for both constant and variable naming. The math is explained in comments.
Topics of Study to Augment Music Synthesis Expertise
There are a few topics to read up on if you wish to become a digital synth expert.
See Java Sound API.
Looking a bit more, I also found Jass.