Package

Source Code of SawHPFInst

import jm.audio.Instrument;
import jm.audio.io.SampleOut;
import jm.audio.synth.Envelope;
import jm.audio.synth.Filter;
import jm.audio.synth.Oscillator;
import jm.audio.synth.Volume;


/**
* A monophonic sawtooth waveform instrument implementation
* <p/>
* which includes a static high pass filter.
*
* @author Andrew Brown
*/


public final class SawHPFInst extends Instrument {

    //----------------------------------------------

    // Attributes

    //----------------------------------------------

    private int sampleRate;

    private int filterCutoff;

    private int channels;


    //----------------------------------------------

    // Constructor

    //----------------------------------------------

    /**
     * Basic default constructor to set an initial
     * <p/>
     * sampling rate and use a default cutoff.
     *
     * @param sampleRate
     */

    public SawHPFInst(int sampleRate) {

        this(sampleRate, 2000);

    }


    /**
     * Constructor that sets sample rate and the filter cutoff frequency.
     *
     * @param sampleRate   The number of samples per second (quality)
     * @param filterCutoff The frequency above which overtones are cut
     */

    public SawHPFInst(int sampleRate, int filterCutoff) {

        this.sampleRate = sampleRate;

        this.filterCutoff = filterCutoff;

        this.channels = 1;

    }


    //----------------------------------------------

    // Methods

    //----------------------------------------------

    /**
     * Initialisation method used to build the objects that
     * <p/>
     * this instrument will use and specify their interconnections.
     */

    public void createChain() {

        Oscillator wt = new Oscillator(this, Oscillator.SAWTOOTH_WAVE,
                this.sampleRate, this.channels);

        Filter filt = new Filter(wt, this.filterCutoff, Filter.HIGH_PASS);

        Envelope env = new Envelope(filt,
                new double[]{0.0, 0.0, 0.05, 1.0, 0.2,
                        0.4, 0.8, 0.3, 1.0, 0.0}
        );

        Volume vol = new Volume(env);

        SampleOut sout = new SampleOut(vol);

    }

}


TOP

Related Classes of SawHPFInst

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.