MidiScope/Application/src/main/java/com/example/android/common/midi/synth/SynthVoice.java [22:82]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
public abstract class SynthVoice {
    private int mNoteIndex;
    private float mAmplitude;
    public static final int STATE_OFF = 0;
    public static final int STATE_ON = 1;
    private int mState = STATE_OFF;

    public SynthVoice() {
        mNoteIndex = -1;
    }

    public void noteOn(int noteIndex, int velocity) {
        mState = STATE_ON;
        this.mNoteIndex = noteIndex;
        setAmplitude(velocity / 128.0f);
    }

    public void noteOff() {
        mState = STATE_OFF;
    }

    /**
     * Add the output of this voice to an output buffer.
     *
     * @param outputBuffer
     * @param samplesPerFrame
     * @param level
     */
    public void mix(float[] outputBuffer, int samplesPerFrame, float level) {
        int numFrames = outputBuffer.length / samplesPerFrame;
        for (int i = 0; i < numFrames; i++) {
            float output = render();
            int offset = i * samplesPerFrame;
            for (int jf = 0; jf < samplesPerFrame; jf++) {
                outputBuffer[offset + jf] += output * level;
            }
        }
    }

    public abstract float render();

    public boolean isDone() {
        return mState == STATE_OFF;
    }

    public int getNoteIndex() {
        return mNoteIndex;
    }

    public float getAmplitude() {
        return mAmplitude;
    }

    public void setAmplitude(float amplitude) {
        this.mAmplitude = amplitude;
    }

    /**
     * @param scaler
     */
    public void setFrequencyScaler(float scaler) {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



MidiSynth/Application/src/main/java/com/example/android/common/midi/synth/SynthVoice.java [22:82]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
public abstract class SynthVoice {
    private int mNoteIndex;
    private float mAmplitude;
    public static final int STATE_OFF = 0;
    public static final int STATE_ON = 1;
    private int mState = STATE_OFF;

    public SynthVoice() {
        mNoteIndex = -1;
    }

    public void noteOn(int noteIndex, int velocity) {
        mState = STATE_ON;
        this.mNoteIndex = noteIndex;
        setAmplitude(velocity / 128.0f);
    }

    public void noteOff() {
        mState = STATE_OFF;
    }

    /**
     * Add the output of this voice to an output buffer.
     *
     * @param outputBuffer
     * @param samplesPerFrame
     * @param level
     */
    public void mix(float[] outputBuffer, int samplesPerFrame, float level) {
        int numFrames = outputBuffer.length / samplesPerFrame;
        for (int i = 0; i < numFrames; i++) {
            float output = render();
            int offset = i * samplesPerFrame;
            for (int jf = 0; jf < samplesPerFrame; jf++) {
                outputBuffer[offset + jf] += output * level;
            }
        }
    }

    public abstract float render();

    public boolean isDone() {
        return mState == STATE_OFF;
    }

    public int getNoteIndex() {
        return mNoteIndex;
    }

    public float getAmplitude() {
        return mAmplitude;
    }

    public void setAmplitude(float amplitude) {
        this.mAmplitude = amplitude;
    }

    /**
     * @param scaler
     */
    public void setFrequencyScaler(float scaler) {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



