How to generate pure tones with different decibels in java?

I need to generate pure tones with different decibel levels (dB) in java. is there any example of how to do this?

+8
java audio
source share
2 answers

This http://jsresources.org/examples/OscillatorPlayer.html shows how to create and reproduce pure sinusoidal (or almost any other) waveforms. As for decibels, their ratio to amplitude is db ~ 20 * log10 (amplitude) , i.e. amplitude ~ 10 ^ (dB/20) , so just calculate from that.

+3
source share

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.

+4
source share

All Articles