2020-06-13 10:56:20 +02:00
|
|
|
//
|
|
|
|
// Created by versustune on 12.06.20.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
#include "VenoBuffer.h"
|
|
|
|
|
2020-06-13 16:52:16 +02:00
|
|
|
VenoBuffer::VenoBuffer ()
|
|
|
|
{
|
2020-06-13 10:56:20 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-06-13 16:52:16 +02:00
|
|
|
VenoBuffer::~VenoBuffer ()
|
|
|
|
{
|
|
|
|
buffer.clear ();
|
|
|
|
right.clear ();
|
|
|
|
left.clear ();
|
2020-06-13 10:56:20 +02:00
|
|
|
}
|
|
|
|
|
2020-06-13 16:52:16 +02:00
|
|
|
void VenoBuffer::reset (int size)
|
|
|
|
{
|
|
|
|
if (size != buffer.size ())
|
|
|
|
{
|
|
|
|
buffer.resize (size);
|
|
|
|
right.resize (size);
|
|
|
|
left.resize (size);
|
2020-06-13 10:56:20 +02:00
|
|
|
}
|
|
|
|
// reset to 0 dc :D
|
2020-06-13 16:52:16 +02:00
|
|
|
for (int i = 0; i < size; ++i)
|
|
|
|
{
|
2020-06-13 10:56:20 +02:00
|
|
|
buffer[i] = 0;
|
|
|
|
left[i] = 0;
|
|
|
|
right[i] = 0;
|
|
|
|
}
|
|
|
|
leftPeak = 0;
|
|
|
|
rightPeak = 0;
|
|
|
|
monoPeak = 0;
|
|
|
|
}
|
|
|
|
|
2020-06-13 16:52:16 +02:00
|
|
|
void VenoBuffer::addMonoSample (float value, int index)
|
|
|
|
{
|
2020-06-13 10:56:20 +02:00
|
|
|
buffer[index] = value;
|
|
|
|
}
|
|
|
|
|
2020-06-13 16:52:16 +02:00
|
|
|
void VenoBuffer::addLeftSample (float value, int index)
|
|
|
|
{
|
2020-06-13 10:56:20 +02:00
|
|
|
left[index] = value;
|
|
|
|
}
|
|
|
|
|
2020-06-13 16:52:16 +02:00
|
|
|
void VenoBuffer::addRightSample (float value, int index)
|
|
|
|
{
|
2020-06-13 10:56:20 +02:00
|
|
|
right[index] = value;
|
|
|
|
}
|
|
|
|
|
2020-06-13 16:52:16 +02:00
|
|
|
void VenoBuffer::calcPeak ()
|
|
|
|
{
|
|
|
|
for (int i = 0; i < buffer.size (); ++i)
|
|
|
|
{
|
|
|
|
auto l = std::abs (left[i]);
|
|
|
|
auto r = std::abs (right[i]);
|
|
|
|
auto m = std::abs (buffer[i]);
|
|
|
|
if (m > monoPeak)
|
|
|
|
{
|
2020-06-13 10:56:20 +02:00
|
|
|
monoPeak = m;
|
|
|
|
}
|
2020-06-13 16:52:16 +02:00
|
|
|
if (l > leftPeak)
|
|
|
|
{
|
2020-06-13 10:56:20 +02:00
|
|
|
leftPeak = l;
|
|
|
|
}
|
2020-06-13 16:52:16 +02:00
|
|
|
if (r > rightPeak)
|
|
|
|
{
|
2020-06-13 10:56:20 +02:00
|
|
|
rightPeak = r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-13 16:52:16 +02:00
|
|
|
const std::vector<float>& VenoBuffer::getBuffer () const
|
|
|
|
{
|
2020-06-13 10:56:20 +02:00
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
2020-06-13 16:52:16 +02:00
|
|
|
const std::vector<float>& VenoBuffer::getRight () const
|
|
|
|
{
|
2020-06-13 10:56:20 +02:00
|
|
|
return right;
|
|
|
|
}
|
|
|
|
|
2020-06-13 16:52:16 +02:00
|
|
|
const std::vector<float>& VenoBuffer::getLeft () const
|
|
|
|
{
|
2020-06-13 10:56:20 +02:00
|
|
|
return left;
|
|
|
|
}
|