COCKOS
CONFEDERATED FORUMS
Cockos : REAPER : NINJAM : Forums
Forum Home : Register : FAQ : Members List : Search :

Go Back   Cockos Incorporated Forums > Other Software Discussion > WDL users forum

Reply
 
Thread Tools Display Modes
Old 12-04-2016, 03:50 PM   #1
Youlean
Human being with feelings
 
Youlean's Avatar
 
Join Date: May 2015
Location: Serbia
Posts: 654
Default How do you calculate true peak values?

I can not warp my head around this. I taught that I figured this out, but after some testing it seams that my code doesn't work properly...

So here is what I am doing:
These are standard ITU coeffs for 4x oversampling.
Code:
class CircularBuffer
{
public:
	CircularBuffer()
	{
	}

	void SetBufferSize(int _bufferSize)
	{
		bufferSize = _bufferSize;
		buffer.resize(_bufferSize, 0);
	}

	void AddValue(double value)
	{
		buffer.push_back(value);
		buffer.push_back(0);
		buffer.push_back(0);
		buffer.push_back(0);
		buffer.pop_front();
		buffer.pop_front();
		buffer.pop_front();
		buffer.pop_front();
	}

	double GetAtIndex(int index)
	{
		return buffer[index];
	}

	int GetSize()
	{
		return bufferSize;
	}

private:
	double inputValue = 0;
	std::deque<double> buffer;
	int bufferSize = 0;
};


class youlean_true_peak
{
public:
	youlean_true_peak()
	{
		// For now it should be dividable with 4
		coefficients =
		{
			0.0017089843750,
			-0.0291748046875,
			-0.0189208984375,
			-0.0083007812500,
			0.0109863281250,
			0.0292968750000,
			0.0330810546875,
			0.0148925781250,
			-0.0196533203125,
			-0.0517578125000,
			-0.0582275390625,
			-0.0266113281250,
			0.0332031250000,
			0.0891113281250,
			0.1015625000000,
			0.0476074218750,
			-0.0594482421875,
			-0.1665039062500,
			-0.2003173828125,
			-0.1022949218750,
			0.1373291015625,
			0.4650878906250,
			0.7797851562500,
			0.9721679687500,
			0.9721679687500,
			0.7797851562500,
			0.4650878906250,
			0.1373291015625,
			-0.1022949218750,
			-0.2003173828125,
			-0.1665039062500,
			-0.0594482421875,
			0.0476074218750,
			0.1015625000000,
			0.0891113281250,
			0.0332031250000,
			-0.0266113281250,
			-0.0582275390625,
			-0.0517578125000,
			-0.0196533203125,
			0.0148925781250,
			0.0330810546875,
			0.0292968750000,
			0.0109863281250,
			-0.0083007812500,
			-0.0189208984375,
			-0.0291748046875,
			0.0017089843750
		};

		coeff_size = coefficients.size();

		audioBuffer.SetBufferSize(coeff_size + 4);
	}


	double get_true_peak(double audio)
	{
		audioBuffer.AddValue(audio);

		max_true_peak = 0;

		output_x1 = 0;
		output_x2 = 0;
		output_x3 = 0;
		output_x4 = 0;


		for (int i = 0; i < coeff_size; i++)
		{
			output_x1 += coefficients[i] * audioBuffer.GetAtIndex(i);
			output_x2 += coefficients[i] * audioBuffer.GetAtIndex(i + 1);
			output_x3 += coefficients[i] * audioBuffer.GetAtIndex(i + 2);
			output_x4 += coefficients[i] * audioBuffer.GetAtIndex(i + 3);
		}

		return IPMAX(IPMAX(IPMAX(std::abs(output_x1), std::abs(output_x3)), std::abs(output_x3)), std::abs(output_x4));
	}





private:
	CircularBuffer audioBuffer;
	std::vector <double> coefficients;

	double output_x1 = 0.f, output_x2 = 0.f, output_x3 = 0.f, output_x4 = 0.f,
		max_true_peak = 0.f;

	int coeff_size = 0;
};
What is not clear to me is how should I use these coeffs? I tried also making audio buffer coeff_size / 4 lenght, than getting first value in audio buffer and multiplying that value to first coeff and then storing that in output_x1, then multiplying first value in audio buffer with second coeff than storing that in output_x2....
Any help would be much appreciated. Also I was resampler.h, so can I use that to calculate true peak value?

EDIT: Found what it is. It was a some bug with IPMAX outside this code.

Last edited by Youlean; 12-05-2016 at 03:49 PM.
Youlean is offline   Reply With Quote
Old 01-12-2017, 10:24 AM   #2
bozmillar
Human being with feelings
 
bozmillar's Avatar
 
Join Date: Sep 2009
Posts: 623
Default

Nice work winning the KVR developer contest btw.
__________________
http://www.bozdigitallabs.com
bozmillar is offline   Reply With Quote
Old 01-12-2017, 03:02 PM   #3
Youlean
Human being with feelings
 
Youlean's Avatar
 
Join Date: May 2015
Location: Serbia
Posts: 654
Default

Quote:
Originally Posted by bozmillar View Post
Nice work winning the KVR developer contest btw.
Thanks. Are you going to NAMM this year?
Youlean is offline   Reply With Quote
Old 01-12-2017, 03:09 PM   #4
bozmillar
Human being with feelings
 
bozmillar's Avatar
 
Join Date: Sep 2009
Posts: 623
Default

Yep. I'll be up in the software.NAMM section. I'm not sure what room it is. I'll have to look it up. It's a pretty nice room to be in because it's nice and quite. There's even a "headphones only" policy.
__________________
http://www.bozdigitallabs.com
bozmillar is offline   Reply With Quote
Old 01-12-2017, 03:52 PM   #5
Youlean
Human being with feelings
 
Youlean's Avatar
 
Join Date: May 2015
Location: Serbia
Posts: 654
Default

Quote:
Originally Posted by bozmillar View Post
Yep. I'll be up in the software.NAMM section. I'm not sure what room it is. I'll have to look it up. It's a pretty nice room to be in because it's nice and quite. There's even a "headphones only" policy.
Great, let me know where you will be and I will come by..
Youlean is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 09:42 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.