如何在java中生成具有不同分贝的纯音?

我需要在java中生成具有不同分贝级别(dB)的纯音。 有什么例子可以做到这一点吗?

这个http://jsresources.org/examples/OscillatorPlayer.html展示了如何创建纯正弦波(或几乎任何其他波形)并播放它们。 至于分贝,它们与振幅的关系是db ~ 20 * log10 (amplitude) ,即amplitude ~ 10 ^ (dB/20) ,所以就这样计算。

midi Synth的音调

您可以使用合成器生成音调:

 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(); } } } 

您可以在哪里设置频道的音量

 getSetChannelVolumeMessage(int, int) 

http://www.springworldgames.com/rmleditor/javadoc/com/springworldgames/music/MidiUtils.html#getSetChannelVolumeMessage(int,int)

我不知道如何将其转换为分贝,也许这取决于你的声卡音量。