//	InterestingNoise.h - Class used to generate interesting-sounding noise.
//  ----------------------------------------------------------------------------
//	This file is part of 'NiallsAVLib', base code for any kind of audiovisual
//	apps.
//	Copyright (C) 2012  Niall Moody
//	
//	This program is free software: you can redistribute it and/or modify
//	it under the terms of the GNU 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 General Public License for more details.
//
//	You should have received a copy of the GNU General Public License
//	along with this program.  If not, see <http://www.gnu.org/licenses/>.
//	----------------------------------------------------------------------------

#ifndef INTERESTINGNOISE_H_
#define INTERESTINGNOISE_H_

///	Class used to generate interesting-sounding noise.
class InterestingNoise
{
  public:
	///	Constructor.
	InterestingNoise();
	///	Destructor.
	~InterestingNoise();

	///	Writes the noise to the passed-in buffer.
	void getAudio(float *buffer, int numSamples);

	///	Tells the noise to attenuate its levels.
	void setAttenuate(bool val);
	///	Sets the noise's level.
	void setLevel(float val);
  private:
	///	Simple low-pass filter struct.
	struct LowPassFilter
	{
		///	Current cutoff frequency.
		float freq;

		///	Coefficient.
		float a0;
		///	Coefficient.
		float b1;

		///	Previous output.
		float lastOut;
	};
	///	Resonant filter struct
	struct ResonantFilter
	{
		///	Filter freq.
		float freq;

		///	Filter coefficient.
		float coeff;

		///	Previous val.
		float buf0;
		///	Previous val.
		float buf1;
	};

	///	Used to fade the noise in on creation.
	float fadeIn;
	///	Used to attenuate the noise's amplitude.
	bool attenuate;
	///	Used to attenuate the noise's amplitude.
	float attVal;

	///	The noise's level.
	float level;

	///	Used to filter the noise.
	LowPassFilter filter;
	///	Used to alter the filter's cutoff with time.
	float nextFreq;

	///	Used to produce an occasional whine.
	ResonantFilter whine;
	///	Used to fade the whine in and out.
	float whineFade;
	///	Used to fade the whine in and out.
	float whineDir;
};

#endif
