/*
 *  Copyright (c) 2024 - 2025 by Paul Hertz <ignotus@gmail.com>
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Library General Public License as published
 *   by the Free Software Foundation; either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU Library General Public License for more details.
 *
 *   You should have received a copy of the GNU Library General Public
 *   License along with this program; if not, write to the Free Software
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

package net.paulhertz.pixelaudio.sampler;

/**
 * Backend engine contract for sampler implementations.
 * Allows swapping implementations without changing higher layers.
 */
public interface PASampler {
	
    /**
     * Play command with all the useful arguments in standard order.
     * 
     * @param samplePos    index into the buffer to start sampling 
     * @param sampleLen    expected duration of the audio event, which is expected to return its actual duration
     * @param amplitude    maximum amplitude of signal generated by the sampler, linear value
     * @param env          ADSR style envelope for the entire event
     * @param pitch        pitch multiplier, where 1.0f implies pitch is unchanged and all samples are read
     * @param pan          location of audio event in stereo field, -1.0f = left, 0.0f = center, 1.0f = right
     * @return             actual duration of event in samples, typically sampleLen + envelope release time
     */
    int play(int samplePos, int sampleLen, float amplitude, ADSRParams env, float pitch, float pan);

    /** Returns true if any currently active voice is looping. */
    boolean isLooping();

    /** Stops all voices immediately. */
    void stopAll();

	void setSampleRate(float newRate);
	
	public void setBuffer(float[] buffer);
	
	public void setBuffer(float[] buffer, float playbackSampleRate);
	
}
