[jmsl] Patching a LineIn to a signal processing
SynthNoteAllPortsInstrumentSP
jmsl at music.columbia.edu
jmsl at music.columbia.edu
Sat Jan 5 11:38:24 EST 2008
Hello JMSL users
Here's a demo of how you can patch the output of a JSyn LineIn into a
JMSL signal processing instrument (SynthNoteAllPortsInstrumentSP).
The signal processing instrument is played by a MusicShape, so you will
hear the effect change as you sing or talk into this...
This also shows you how to enable input for the JSynMusicDevice
Two Java classes below, the main class and the signal processing SynthNote
Thanks to Joel Mellin for bring up the topic.
Nick D
/*
* Created on Jan 4, 2008 by Nick Didkovsky
*
*/
package didkovsky;
import java.awt.Component;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import com.softsynth.jmsl.*;
import com.softsynth.jmsl.jsyn.JSynMusicDevice;
import com.softsynth.jmsl.jsyn.SynthNoteAllPortsInstrumentSP;
import com.softsynth.jsyn.*;
public class LineInSignalProcessingDemo {
JMSLMixerContainer mixer;
SynthNoteAllPortsInstrumentSP signalProcessingInstrument;
LineIn lineIn;
MusicShape signalProcessingMusicShape;
void setupJSynMusicDevice() {
JSynMusicDevice dev = JSynMusicDevice.instance();
dev.setFlags(Synth.FLAG_ENABLE_INPUT);
dev.open();
}
void buildMixer() {
mixer = new JMSLMixerContainer();
mixer.start();
}
void buildInstrument() {
signalProcessingInstrument = new
SynthNoteAllPortsInstrumentSP(1, SignalProcessingSynthNote.class.getName());
mixer.addInstrument(signalProcessingInstrument);
lineIn = new LineIn();
lineIn.start();
signalProcessingInstrument.addSignalSource(lineIn.output);
}
void buildSignalProcessingMusicShape() {
signalProcessingMusicShape = new
MusicShape(signalProcessingInstrument.getDimensionNameSpace());
signalProcessingMusicShape.setInstrument(signalProcessingInstrument);
signalProcessingMusicShape.prefab();
signalProcessingMusicShape.print();
signalProcessingMusicShape.setRepeats(1000);
}
Component getMixerControlPanel() {
return mixer.getPanAmpControlPanel();
}
void launchPiece(double playtime) {
signalProcessingMusicShape.launch(playtime);
}
void finish() {
signalProcessingMusicShape.finish();
try {
signalProcessingMusicShape.waitForDone();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
JMSL.clock.setAdvance(0.1);
final LineInSignalProcessingDemo demo = new
LineInSignalProcessingDemo();
demo.setupJSynMusicDevice();
demo.buildMixer();
demo.buildInstrument();
demo.buildSignalProcessingMusicShape();
demo.launchPiece(JMSL.now() + 2);
Frame f = new Frame("LineInSignalProcessingDemo by Nick Didkovsky");
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
demo.finish();
JMSL.closeMusicDevices();
System.exit(0);
}
});
f.add(demo.getMixerControlPanel());
f.pack();
f.setVisible(true);
}
}
package didkovsky;
import com.softsynth.jsyn.*;
/**************
*
* Multiply input signal by a square wave
*
** WARNING - this code automatically generated by Wire.
** The real source is probably a Wire patch.
** Do NOT edit this file unless you copy it to another directory and
change the name.
** Otherwise it is likely to get clobbered the next time you
** export Java source code from Wire.
**
** Wire is available from: http://www.softsynth.com/wire/
*/
public class SignalProcessingSynthNote extends SynthNote
{
// Declare units and ports.
public SynthInput input;
MultiplyUnit mult;
SquareOscillatorBL sqrOscBl;
public SignalProcessingSynthNote()
{
this( Synth.getSharedContext() );
}
public SignalProcessingSynthNote( SynthContext synthContext )
{
super( synthContext );
// Create unit generators.
add( mult = new MultiplyUnit(synthContext) );
add( sqrOscBl = new SquareOscillatorBL(synthContext) );
// Connect units and ports.
addPort( frequency = sqrOscBl.frequency, "frequency" );
frequency.setup( 0.0, 261.6263168, 3000.0 );
addPort( amplitude = sqrOscBl.amplitude, "amplitude" );
amplitude.setup( 0.0, 0.5, 1.0 );
addPort( output = mult.output, "output" );
addPort( input = mult.inputA, "input" );
input.setup( 0.0, 0.21476459503173828, 1.0 );
sqrOscBl.phase.set( 0, -0.62646484375 );
sqrOscBl.output.connect( mult.inputB);
}
public void setStage( int time, int stage )
{
switch( stage )
{
case 0:
start( time );
break;
case 1:
break;
default:
break;
}
}
}
More information about the jmsl
mailing list