Note that there are some explanatory texts on larger screens.

plurals
  1. POJSyn: Sine Wave on two channels
    primarykey
    data
    text
    <p><strong>I have figured the problem out before posting this question. Nevertheless I think this might help someone else, so I am posting it anyway. If anyone knows a better or more elegant way to do this, please post an answer. If I agree, I will of course accept your answer. Here is my original problem:</strong></p> <p>I am trying to get the following to work with <a href="http://www.softsynth.com/jsyn/" rel="nofollow">JSyn</a>:</p> <p>I want to play an 800Hz sine wave on two channels and switch on or off the individual channels whenever I want. So, for instance, I want the following sequence:</p> <pre><code> time 0s 0.3s 0.8s 1s 1s 1.1s 1.5s left |--------------------| |-----------| right |----| |------------------------| </code></pre> <p>I can generate the sine wave on either one, or both channels, but I have not figured out how to turn them on/off. Here is some code:</p> <pre><code>import com.jsyn.JSyn; import com.jsyn.Synthesizer; import com.jsyn.unitgen.LineOut; import com.jsyn.unitgen.SineOscillator; public class MusicTest { public static void main(String[] args) { playSound(); } public static void playSound() { Synthesizer synth = JSyn.createSynthesizer(); try { synth.start(); SineOscillator sineOsc1 = new SineOscillator(500, 0.2); SineOscillator sineOsc2 = new SineOscillator(500, 0.2); LineOut lineOut= new LineOut(); synth.add(lineOut); synth.add(sineOsc1); synth.add(sineOsc2); sineOsc1.output.connect(0, lineOut.input, 0); // left channel sineOsc2.output.connect(0, lineOut.input, 1); // right channel lineOut.start(); sineOsc1.start(); // start left sleep(1000); sineOsc2.start(); // after 1s, start right sleep(1000); sineOsc1.stop(); // after 1s, stop left sleep(1000); sineOsc2.stop(); // after 1s, stop lineOut.stop(); } finally { synth.stop(); } } private static void sleep(int ms) { try { Thread.sleep(ms); } catch (InterruptedException e) {} } } </code></pre> <p>Unfortunately, this does not work...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload