view AccessiblePeakMeter.h @ 2:33aaa48d4d16 tip

changed "meter type" to "sonification type"
author Fiore Martin <f.martin@qmul.ac.uk>
date Sat, 13 Jun 2015 15:14:20 +0100
parents c0ead20bda4d
children
line wrap: on
line source
// 
// AccessiblePeakMeter.h 
//
// Author: Fiore Martin 
// Started from IPlugMultiTargets example in WDL-OL, by Oli Larkin - https://github.com/olilarkin/wdl-ol
//
// Licensed under the Cockos WDL License, see README.txt
//


#ifndef __ACCESSIBLEPEAKMETER__
#define __ACCESSIBLEPEAKMETER__

#include "IPlug_include_in_plug_hdr.h"

#include "stk/include/SineWave.h"
#include "stk/include/Envelope.h"
#include "stk/include/ADSR.h"


class AccessiblePeakMeter : public IPlug
{
public:

	AccessiblePeakMeter(IPlugInstanceInfo instanceInfo);
	~AccessiblePeakMeter();

	void Reset();
	void OnParamChange(int paramIdx);
	void ProcessDoubleReplacing(double** inputs, double** outputs, int nFrames);
	bool HostRequestingAboutBox();

private:
	static const double DRYWET_DEFAULT;
	static const int SONIFICATION_TYPE_DEFAULT;
	static const double METERDECAY_DEFAULT;
	static const double THRESHOLD_DEFAULT;
	static const double BEEP_TIME;
	static const double DB_RANGE;
	static const double SONIFICATION_RANGE;
	static const int SONIFICATION_TYPE_CLIPPING;
	static const int SONIFICATION_TYPE_CONTINUOUS;
	static const int MAX_CHANNELS = 2;
	static const int NUM_PRESETS;
	static const double MIN_SONIFICATION_FREQ;
	static const int NUM_KNOB_FRAMES;
	static const double CLIPPING_CEILING_SNAP;

	/* parameters on GUI */
	double mDry;
	double mWet;
	double mMeterDecayRate;
	double mThreshold;

	double mSampleRate;
	
	/* paramters for peak level meter */
	double mPrevPeak[MAX_CHANNELS];
	int mMeterIdx[MAX_CHANNELS];
	
	/* 	struct Sonification is the sonification engine. It has two substructures containing
	    data specific to each type (clipping/continuous) 	
	 */
	struct Sonification {
		int type; // type of sonification : clipping - continous
		stk::SineWave ugen[MAX_CHANNELS]; // generator for both types of sonification

		struct Continous {
			/* this envelope is to turn off the countinuous sonification smoothly
			   without clicks. It's always 1, unless the sonification is being turned off. 
			 */
			stk::Envelope envelope[MAX_CHANNELS];
			bool isOn[MAX_CHANNELS];
		} continous;

		struct Clipping {
			/* max diff is used to keep the pitch more consistent over different blocks 
			   with maxDiff the beep sounds better cause is not constantly pitch modulated */
			double maxDiff[MAX_CHANNELS];
			stk::ADSR envelope[MAX_CHANNELS];
		} clipping;

		/* resets all the ugens. When srate is less than 0, type and ugen freq are 
		   not affected by resetas well as sample rate.   
		 */
		void reset(double srate = -1.0){

			for (int i = 0; i < MAX_CHANNELS; i++){

				ugen[i].reset();

				continous.isOn[i] = true;
				stk::Envelope & coe = continous.envelope[i];
				coe.setValue(1.0); // setValue also sets the target to the value 
				coe.setTime(0.2);
				
				clipping.maxDiff[i] = 0.0;
				stk::ADSR & cle = clipping.envelope[i];
				cle.setValue(0.0);
				cle.setReleaseTime(BEEP_TIME);
				cle.setAttackTime(0.01);
				cle.setSustainLevel(1);

				if (srate > 0.0){
					ugen[i].setSampleRate(srate);
					coe.setSampleRate(srate);
					cle.setSampleRate(srate);
				}
			}
		}

		Sonification() : type(SONIFICATION_TYPE_DEFAULT) {
			reset();
		}

	} mSonification;

	/* adds continous sonification on top of the original audio signal */
	void addContinuousSonification(double** inputs, double** outputs, int nFrames);
	/* adds clipping sonification on top of the original audio signal */
	void addClippingSonification(double** inputs, double** outputs, int nFrames);
	/* for dry/wet mix */
	inline double mix(double dry, double wet) const{
		return dry * mDry + wet * mWet;
	}
};


#endif //__ACCESSIBLEPEAKMETER__