Tones with midi Synth
You can generate tones with a synthesizer:
import javax.sound.midi.*; public class MidiSynthesizerSample { public static void main(String[] args) { int[] notes = new int[]{60, 62, 64, 65, 67, 69, 71, 72, 72, 71, 69, 67, 65, 64, 62, 60}; try { Synthesizer synthesizer = MidiSystem.getSynthesizer(); synthesizer.open(); MidiChannel channel = synthesizer.getChannels()[0]; for (int note : notes) { channel.noteOn(note, 50); try { Thread.sleep(200); } catch (InterruptedException e) { break; } finally { channel.noteOff(note); } } } catch (MidiUnavailableException e) { e.printStackTrace(); } } }
If you can adjust the volume of the channels,
getSetChannelVolumeMessage(int, int)
http://www.springworldgames.com/rmleditor/javadoc/com/springworldgames/music/MidiUtils.html#getSetChannelVolumeMessage (int, int)
I donβt know how to convert it to decibels, maybe it depends on the volume level of the sound card.
kisp
source share