我一直在尝试按照此处的示例进行操作,但它不起作用,并且我无法找到任何其他来源:[ http://www.softsynth.com/jsyn/tutorial/osc_control.php ][1]
据我所知,我完全遵循了这个示例代码片段(除了我发现该网页更新AddUnit
后的Add
某个时间):
[...] 使频率在更有用范围内的中心频率附近略微波动。我们可以通过使用 AddUnit 将振荡器的输出添加到我们可以设置的常数值来做到这一点。我们还可以将第一个振荡器的幅度减小到较小的范围内。
AddUnit freqAdder = new AddUnit();
sineOsc1.output.connect( freqAdder.inputA ); // pass through adder
freqAdder.output.connect( sineOsc2.frequency ); // control second oscillator freq
freqAdder.inputB.set( 500.0 ); // add constant that will center us at 500 Hz
sineOsc1.amplitude.set( 100.0 ); // reduce offset to +/- 100 Hz
因此 sineOsc2 的频率将是 sineOsc1.output 加上 inputB。
任何人都可以看到我的代码有什么问题(如下)?我已经有一个简单的振荡器声音工作。我只是听不到第二个更复杂的声音,它应该像警笛一样。
这可能是我对警笛声音的编码有问题,或者可能只是我的生成两个声音的编码有问题。(Synthesizers
需要 2 吗?我已经用 1 和 2 试过了Synthesizers
。)(需要 2 lineOuts 吗?其他网络资源说“不”。)
这是我的带有 2synthesizers
和 1 输出的代码:
(引号中的注释来自其他示例代码。我只了解这些注释的含义。)
import com.jsyn.JSyn;
import com.jsyn.Synthesizer;
import com.jsyn.unitgen.Add;
import com.jsyn.unitgen.LineOut;
import com.jsyn.unitgen.SineOscillator;
[...]
com.jsyn.Synthesizer synthPCMSonification = JSyn.createSynthesizer();
com.jsyn.Synthesizer synthPCMAlarm = JSyn.createSynthesizer();
// "an instance of Synthesizer"
com.jsyn.unitgen.SineOscillator oscData = new SineOscillator();
SineOscillator oscAlarmWaverEnvelope = new SineOscillator();
SineOscillator oscAlarmComplete = new SineOscillator();
// "a unit"
com.jsyn.unitgen.LineOut oscsLineOut = new LineOut();
// "a unit"
[...]
// "start synthesis engine"
synthPCMSonification.start();
synthPCMAlarm.start();
// "build unit generators"
synthPCMSonification.add(oscData);
//synthPCM.add(oscAlarmWaverEnvelope); //TODO: Figure out if need line
synthPCMAlarm.add(oscAlarmComplete);
synthPCMSonification.add(oscsLineOut);
synthPCMAlarm.add(oscsLineOut);
oscData.frequency.set(LOWEST_FREQUENCY_C);
oscData.amplitude.set(volSonification);
//create a frequency adder for a siren-like alarm
com.jsyn.unitgen.Add oscAlarmFreqAdder = new Add(); //used to be AddUnit
//set the alarm centre frequency
alarmCentreFreq = (LOWEST_FREQUENCY_C
* Math.pow(2, OCTAVES_SPANNED_C + 1));
//This formula centres the alarm one octave
//above the threshold's sonification freqency
alarmWaverFreq = alarmCentreFreq / 10;
//This sets the waver at one tenth of the centre freq
//Unfortunately, the waver appears to need to be the
//same amount above and below the centre
//(linear, vice perceptually-linear (exponential))
System.out.println(alarmCentreFreq + "-Hz alarm centre frequency");
oscAlarmFreqAdder.inputB.set(alarmCentreFreq);
//set the alarm waver envelope
//(alarm will range between centre-waver and centre+waver)
oscAlarmWaverEnvelope.frequency.set(alarmCentreFreq / 10);
//"pass through adder" (??)
oscAlarmWaverEnvelope.output.connect(oscAlarmFreqAdder.inputA);
//(entered this with by starting to type, then hitting [Ctrl]+[Space]!)
//"control the 2nd oscillator frequency" (?)
oscAlarmFreqAdder.output.connect(oscAlarmComplete.frequency);
//set alarm volume
oscAlarmComplete.amplitude.set(volAlarm);
// "connect unit generators"
// connect oscillator to both channels of stereo player
oscAlarmComplete.output.connect(0, oscsLineOut.input, 0);
oscAlarmComplete.output.connect(0, oscsLineOut.input, 1);
// "startUnitGenerators"
// "start execution of units. JSyn 'pulls' data so the only unit
// you have to start() is the last one, in this case our LineOut"
oscsLineOut.start();
有多少人知道和使用JSyn
?怎么样meta-oscillators
?
如果您曾经将不同的JSyn
部分连接在一起,或者甚至只是让它一次输出多个声音,那么您比我知道的更多...