我使用了 JSyn 示例 PlayChords 和 PlaySegmentedEnvelope(这两个示例都很容易找到)来创建简单的复音。这段代码
synth = JSyn.createSynthesizer();
synth.add(osc1 = new SineOscillator());
synth.add(osc2 = new SineOscillator());
synth.add(envelopePlayer1 = new VariableRateMonoReader());
synth.add(envelopePlayer2 = new VariableRateMonoReader());
double[] pairs = {0.1, 1.0, 0.5, 1.0, 0.7, 0.3, 0.8, 0.0};
envelope = new SegmentedEnvelope(pairs);
synth.add(lineOut = new LineOut());
envelopePlayer1.output.connect(osc1.amplitude);
envelopePlayer2.output.connect(osc2.amplitude);
osc1.output.connect(0, lineOut.input, 0);
osc1.output.connect(0, lineOut.input, 1);
osc2.output.connect(0, lineOut.input, 0);
osc2.output.connect(0, lineOut.input, 1);
synth.start();
lineOut.start();
osc1.frequency.set(440.0);
envelopePlayer1.dataQueue.queue(envelope);
osc2.frequency.set(660.0);
envelopePlayer2.dataQueue.queue(envelope); // attack
synth.sleepFor(2.0);
synth.stop();
确实按预期播放了五分之一。但是,也播放了非常令人不安的噪音。怎么能改进到只玩第五个?