public void init() { synth = JSyn.createSynthesizer(); // Add a tone generator. (band limited sawtooth) synth.add(osc = new SawtoothOscillatorBL()); // Add a lag to smooth out amplitude changes and avoid pops. synth.add(lag = new LinearRamp()); // Add an output mixer. synth.add(lineOut = new LineOut()); // Connect the oscillator to both left and right output. osc.output.connect(0, lineOut.input, 0); osc.output.connect(0, lineOut.input, 1); // Set the minimum, current and maximum values for the port. lag.output.connect(osc.amplitude); lag.input.setup(0.0, 0.5, 1.0); lag.time.set(0.2); // Arrange the faders in a stack. setLayout(new GridLayout(0, 1)); ExponentialRangeModel amplitudeModel = PortModelFactory.createExponentialModel(lag.input); RotaryTextController knob = new RotaryTextController(amplitudeModel, 5); JPanel knobPanel = new JPanel(); knobPanel.add(knob); add(knobPanel); osc.frequency.setup(50.0, 300.0, 10000.0); add(PortControllerFactory.createExponentialPortSlider(osc.frequency)); validate(); }
private void test() throws IOException { // Create a context for the synthesizer. synth = JSyn.createSynthesizer(); // Add a tone generator. synth.add(channelIn = new ChannelIn()); // Add an output mixer. synth.add(channelOut = new ChannelOut()); synth.add(minner = new Minimum()); synth.add(maxxer = new Maximum()); synth.add(reader = new FixedRateMonoReader()); synth.add(writer = new FixedRateMonoWriter()); sample = new FloatSample(44100 * DELAY_SECONDS, 1); maxxer.inputB.set(-0.98); // clip minner.inputB.set(0.98); // Connect the input to the output. channelIn.output.connect(minner.inputA); minner.output.connect(maxxer.inputA); maxxer.output.connect(writer.input); reader.output.connect(channelOut.input); // Both stereo. int numInputChannels = 2; int numOutputChannels = 2; synth.start( 44100, AudioDeviceManager.USE_DEFAULT_DEVICE, numInputChannels, AudioDeviceManager.USE_DEFAULT_DEVICE, numOutputChannels); writer.start(); channelOut.start(); // For a long echo, read cursor should be just in front of the write cursor. reader.dataQueue.queue(sample, 1000, sample.getNumFrames() - 1000); // Loop both forever. reader.dataQueue.queueLoop(sample, 0, sample.getNumFrames()); writer.dataQueue.queueLoop(sample, 0, sample.getNumFrames()); System.out.println( "Start talking. You should hear an echo after " + DELAY_SECONDS + " seconds."); // Sleep a while. try { double time = synth.getCurrentTime(); // Sleep for a while synth.sleepUntil(time + 30.0); } catch (InterruptedException e) { e.printStackTrace(); } saveEcho(new File("saved_echo.wav")); // Stop everything. synth.stop(); }
protected Speaker(String id) { super(TYPE, REVISION, MANUFACTURER); this.id = id; synth = JSyn.createSynthesizer(); synth.add(lineOut); synth.add(squareOscillator0); synth.add(squareOscillator1); synth.start(); lineOut.start(); squareOscillator0.start(); squareOscillator1.start(); squareOscillator0.output.connect(0, lineOut.input, 0); squareOscillator0.output.connect(0, lineOut.input, 1); squareOscillator1.output.connect(0, lineOut.input, 0); squareOscillator1.output.connect(0, lineOut.input, 1); }
@Override public void init() { synth = JSyn.createSynthesizer(); // Add a tone generator. synth.add(osc1 = new SineOscillator()); synth.add(osc2 = new SineOscillator()); // Add a lag to smooth out amplitude changes and avoid pops. synth.add(lag = new LinearRamp()); // Add an output mixer. synth.add(lineOut = new LineOut()); // Connect the oscillator to the output. osc1.output.connect(0, lineOut.input, 0); osc2.output.connect(0, lineOut.input, 1); // Arrange the faders in a stack. setLayout(new GridLayout(0, 1)); JPanel infoPanel = new JPanel(); infoPanel.setLayout(new GridLayout(0, 1)); infoPanel.add(new JLabel("About: " + synth, SwingConstants.CENTER)); infoPanel.add(new JLabel("From: http://www.softsynth.com/", SwingConstants.CENTER)); infoPanel.add(new JLabel("(C) 1997-2011 Mobileer Inc", SwingConstants.CENTER)); add(infoPanel); // Set the minimum, current and maximum values for the port. lag.output.connect(osc1.amplitude); lag.output.connect(osc2.amplitude); lag.input.setup(0.001, 0.5, 1.0); lag.time.set(0.1); lag.input.setName("Amplitude"); add(PortControllerFactory.createExponentialPortSlider(lag.input)); osc1.frequency.setup(50.0, 300.0, 3000.0); osc1.frequency.setName("Frequency (Left)"); add(PortControllerFactory.createExponentialPortSlider(osc1.frequency)); osc2.frequency.setup(50.0, 302.0, 3000.0); osc2.frequency.setName("Frequency (Right)"); add(PortControllerFactory.createExponentialPortSlider(osc2.frequency)); validate(); }