Lace
Reaction score
0

Profile posts Postings Media Albums About

  • aaaaand... I just realized that, for some reason, I don't have those ptcops that I gave to Noxid for use in Hungry Mahins saved on my computer. It seems that they now only exist in pttune format.
    Tually, since it seems ur online again, I'll drop a hint now.

    Consider what you might do if you wanted a synthesizer that plays two different waveforms simultaneously, at the same frequency.
    For this particular synthesizer, this scheme works perfectly. However, there's a subtle flaw which makes it not work as expected for some synthesizers. I'm going to stop here for now and see if you can find said flaw on your own. A hint or two may be dropped along the way.
    To use the synthesizer would then be a matter of, at each sample frame, setting the inputs to their correct values, and then calling output.getValue() and doing something with the result (probably either playing it or writing it to a wav file).
    So, to set up the synthesizer, we'd do the following:

    Code:
    Input pitch=new Input();
    Input volume=new Input();
    Oscillator osc=new Oscillator(pitch);
    Multiplier output=new Multiplier(osc,volume);
    We'd also need some way of giving inputs to the synthesizer, for which we have the very simple Input device, which allows the programmer to freely modify the value it outputs:

    Code:
    class Input implements Device{
    	public double value;
    	public double getValue(){return value;}
    }
    The code for the Devices themselves (not specific to this particular synthesizer) would be the following:

    Code:
    interface Device{
    	public double getValue();
    }
    
    
    
    class Multiplier implements Device{
    	private Device[] inputs;
    	public Multiplier(Device... inputs){this.inputs=inputs;}
    	public double getValue(){
    		double ans=1;
    		for(Device inpute:inputs) ans*=input.getValue();
    		return ans;
    	}
    }
    
    
    
    class Oscillator implements Device{
    	private double state=0;
    	private Device input;
    	public Oscillator(Device input){this.input=input;}
    	public double getValue(){
    		state+=input.getValue();
    		while(state>=1) state--;
    		while(state<0) state++;
    		return state;
    	}
    }
    Basically, by thinking of a synthesizer in terms of a bunch of relatively simple "devices" strung together, you can create arbitrarily complex synthesizers without having to massively reprogram everything.
    Now, we're almost ready to start looking at some Java code for this. First, though, I want to attempt to illustrate the benefit of this block diagram approach.
    RSlOb.png
    Alright, so the waveforms we've made block diagrams for are square and sawtooth. We can easily make one for sine by introducing a device which outputs sin(2*pi*input).
  • Loading…
  • Loading…
  • Loading…
  • Loading…
Top