[jsyn] [jmsl] timing issue with SynthNote sample playback instrument and JMSL
jsyn at music.columbia.edu
jsyn at music.columbia.edu
Mon Jun 28 09:27:28 EDT 2010
Well I must say it provided a good code review for me!
Glad it's fixed,
Nick
jsyn at music.columbia.edu wrote:
> thank you thank you thank you! I of course feel like a complete idiot. Sorry to have wasted everyone's time with this ;)
>
> --Jason
>
> On Jun 28, 2010, at 7:52 AM, jsyn at music.columbia.edu wrote:
>
>
>> What a head-scratcher! But solved...
>>
>> I noticed the hold time was causing the predelay (ie if I changed hold time to 0 and it worked ok!). That made me suspicious and so after way too much time staring at your code I finally realized you reversed the interpretation of SynthNote.setStage()
>>
>> Proper interpretation:
>> setStage 0 = ON
>> setStage 1 = OFF
>>
>> You were turning it on in stage 1 instead, so JMSL was scheduling noteoff properly (after the hold time), and calling setStage(1), which turned your note ON when it should have been turned OFF. The 1 second hold time in your musicshape accounted for the 1 second delay.
>>
>> Just exchange the bodies of your case statements
>>
>> Thanks
>> Nick D
>>
>> Java Music Specification Language wrote:
>>
>>> My student and I have spent the afternoon debugging a weird timing issue with JMSL and JSyn (latest beta version). It could very well be something stupid we are doing, as I have not touched these parts of the JSyn/JMSL API in a very long time. Or it could be a bug with JMSL or JSyn. But I'm out of ideas, so I'm hoping someone can give me some advice!
>>>
>>> In short, we are creating a JMSL MusicShape that is assigned to a JSyn SynthNote. When the SynthNote is a standard Synthnote (like FilteredSawtoothBL), it works fine. When it is our custom SynthNote (which at this point simply plays back a mono audio file), there is about a 1-second delay in the sound.
>>>
>>> Below is a test class along with our SynthNote.
>>>
>>> Any help most appreciated!
>>>
>>> Jason Freeman
>>> Assistant Professor
>>> Center for Music Technology
>>> Georgia Tech
>>>
>>> ----
>>>
>>> package com.akito.lolc.sound.jsyn;
>>>
>>> import com.softsynth.jmsl.InstrumentAdapter;
>>> import com.softsynth.jmsl.JMSL;
>>> import com.softsynth.jmsl.JMSLMixerContainer;
>>> import com.softsynth.jmsl.MusicShape;
>>> import com.softsynth.jmsl.jsyn.JSynInsFromClassName;
>>> import com.softsynth.jmsl.jsyn.JSynMusicDevice;
>>> import com.softsynth.jmsl.jsyn.SynthClock;
>>>
>>> public class JSynTimingTester {
>>>
>>> private JMSLMixerContainer mixer;
>>>
>>> public JSynTimingTester() {
>>> JSynMusicDevice.instance().open();
>>> JMSL.clock = new SynthClock();
>>> JMSL.clock.setAdvance(0.25);
>>> mixer = new JMSLMixerContainer();
>>> mixer.start();
>>>
>>> //InstrumentAdapter ins = new JSynInsFromClassName(8, "com.akito.lolc.sound.jsyn.BufferedPlayerJS"); // 1 second delay!!!
>>> InstrumentAdapter ins = new JSynInsFromClassName(8, "com.softsynth.jsyn.circuits.FilteredSawtoothBL"); // no delay!!!
>>> mixer.addInstrument(ins);
>>>
>>> MusicShape shape = new MusicShape(4);
>>> shape.setInstrument(ins);
>>> shape.add(1.0, 64, 1.0, 1.0);
>>> shape.launch(JMSL.now());
>>> System.out.println("launching player");
>>>
>>> while (true) {
>>> try { Thread.sleep(10000); } catch (InterruptedException e) { }
>>> }
>>> }
>>>
>>> public static void main(String[] args) {
>>> new JSynTimingTester();
>>> }
>>>
>>> }
>>>
>>> ------
>>>
>>> package com.akito.lolc.sound.jsyn;
>>>
>>> import java.io.FileInputStream;
>>> import java.io.IOException;
>>> import java.io.InputStream;
>>> import java.util.LinkedList;
>>>
>>> import com.softsynth.jsyn.EnvelopePlayer;
>>> import com.softsynth.jsyn.Filter_StateVariable;
>>> import com.softsynth.jsyn.LineOut;
>>> import com.softsynth.jsyn.MultiplyUnit;
>>> import com.softsynth.jsyn.SampleReader_16F1;
>>> import com.softsynth.jsyn.SampleReader_16V1;
>>> import com.softsynth.jsyn.SawtoothOscillatorBL;
>>> import com.softsynth.jsyn.Synth;
>>> import com.softsynth.jsyn.SynthAlert;
>>> import com.softsynth.jsyn.SynthContext;
>>> import com.softsynth.jsyn.SynthEnvelope;
>>> import com.softsynth.jsyn.SynthException;
>>> import com.softsynth.jsyn.SynthInput;
>>> import com.softsynth.jsyn.SynthNote;
>>> import com.softsynth.jsyn.SynthSample;
>>> import com.softsynth.jsyn.SynthSampleAIFF;
>>> import com.softsynth.jsyn.SynthSampleWAV;
>>>
>>> public class BufferedPlayerJS extends SynthNote {
>>>
>>> SynthSample mySamp = null;
>>> public SampleReader_16F1 sampPlayer;
>>> InputStream stream;
>>>
>>> public BufferedPlayerJS() throws SynthException {
>>> this(Synth.getSharedContext());
>>> }
>>>
>>> public BufferedPlayerJS(SynthContext synthContext) throws SynthException {
>>> super(synthContext);
>>> sampPlayer = new SampleReader_16F1(synthContext);
>>>
>>> add(sampPlayer);
>>> addPort(amplitude = sampPlayer.amplitude);
>>> addPort(output = sampPlayer.output);
>>>
>>> amplitude.setup(0.0, 0.3, 1.0);
>>>
>>> try {
>>> String fileName = "lib/sound/BELL2.aif";
>>> stream = (InputStream) (new FileInputStream(fileName));
>>> switch (SynthSample.getFileType(fileName)) {
>>> case SynthSample.AIFF:
>>> mySamp = new SynthSampleAIFF();
>>> break;
>>> case SynthSample.WAV:
>>> mySamp = new SynthSampleWAV();
>>> break;
>>> default:
>>> System.out.println("Unrecognized sample file suffix.");
>>> break;
>>> }
>>>
>>> if (mySamp != null)
>>> mySamp.load(stream);
>>> else
>>> System.out.println("mySamp was null!");
>>> } catch (IOException e) {
>>> e.printStackTrace();
>>> } catch (SecurityException e) {
>>> e.printStackTrace();
>>> }
>>> sampPlayer.start();
>>> }
>>>
>>> public void setStage(int time, int stage) throws SynthException {
>>> switch (stage) {
>>> case 0:
>>> // we never stop!
>>> break;
>>> case 1:
>>> System.out.println("Sample: queuing for " + time + " curTime is " + Synth.getTickCount());
>>> sampPlayer.samplePort.queueOn(time, mySamp);
>>> break;
>>> }
>>> }
>>> }
>>> _______________________________________________
>>> jmsl mailing list
>>> jmsl at music.columbia.edu
>>> http://music.columbia.edu/mailman/listinfo/jmsl
>>>
>>>
>> _______________________________________________
>> JSyn mailing list
>> JSyn at music.columbia.edu
>> To change digest mode or to make other administrative changes visit:
>> http://music.columbia.edu/mailman/listinfo/jsyn
>>
>
> _______________________________________________
> JSyn mailing list
> JSyn at music.columbia.edu
> To change digest mode or to make other administrative changes visit:
> http://music.columbia.edu/mailman/listinfo/jsyn
>
More information about the JSyn
mailing list