#ifndef TESTHOST_AUDIOINPUTSOURCE_H_INCLUDED
#define TESTHOST_AUDIOINPUTSOURCE_H_INCLUDED

#include <JuceHeader.h>

/** Fills a plugin's input channels before each processBlock() call.

	silence (the default) is the correct choice for MIDI-driven instruments
	like JaySynth, which never read their input at all. sine/whiteNoise/
	pinkNoise/impulse exist so the same host can also test audio-effect
	plugins (reverbs, EQs, compressors) that need a real input signal to do
	anything meaningful.
*/
class AudioInputSource
{
public:
	enum Type
	{
		silence = 0,
		sine,
		whiteNoise,
		pinkNoise,
		impulse
	};

	AudioInputSource();

	void setSilence();
	void setSine (double frequencyHz, float amplitude);
	void setWhiteNoise (float amplitude);
	void setPinkNoise (float amplitude);
	/** A single amplitude-1 sample at t=0 followed by silence - the standard
		stimulus for capturing an effect's impulse response. */
	void setImpulse (float amplitude);

	void prepare (double sampleRateToUse);

	/** Fills channels [0, numChannels) of buffer with the next numSamples of
		signal, advancing internal phase/position state across calls. Leaves
		buffer's content beyond numChannels untouched. */
	void fillNextBlock (AudioSampleBuffer &buffer, int numChannels, int numSamples);

private:
	Type type;
	double frequencyHz;
	float amplitude;
	double sampleRate;
	double phase;
	Random random;
	int64 samplePosition;
	float pinkState[7];

	float nextPinkSample (float whiteSample);

	JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioInputSource)
};

#endif // TESTHOST_AUDIOINPUTSOURCE_H_INCLUDED
