Java music creation like in Keygen


Objective: you want to synthesize music in the style of chiptune / as in Keygen.

Ultimately, you should end up with a simple tracker. The task is complicated by the fact that you need to implement it in Java, i.e. the code should generate sounds in real time. I tried to work with javax.sound.midi using Sequencer , MidiEvent , etc. – everything is clear there, but this is an imitation of real instruments, i.e. not at all what you need.

Need to be able to generate sound from scratch using formulas to calculate. As I understand it, I need to use javax.sound.sampled , this package plays anything, including the sound generated by the code. But how exactly do you generate the sound? where to get the formulas? where to look for examples in Java? how to create a chiptune effect in a program?

There are thousands of keygens with music on the net, but I could not find the source for any of them. Basically, there is a lot of information on how to play v2m, mod, etc., but for some reason there is no information about the creation of these compositions. Has anyone come across this? At least show me where to dig, otherwise, frankly speaking, my hands are already giving up ..


Here is a small example of code generation taken from here . May help you.

byte[] buf = new byte[ 1 ];;
AudioFormat af = new AudioFormat( (float )44100, 8, 1, true, false );
SourceDataLine sdl = AudioSystem.getSourceDataLine( af );;
for( int i = 0; i < 1000 * (float )44100 / 1000; i++ ) {
    double angle = i / ( (float )44100 / 440 ) * 2.0 * Math.PI;
    buf[ 0 ] = (byte )( Math.sin( angle ) * 100 );
    sdl.write( buf, 0, 1 );
Scroll to Top