reVeno/Source/Veno/Audio/VenoBuffer.cpp

91 lines
1.5 KiB
C++
Raw Normal View History

2020-06-13 10:56:20 +02:00
//
// Created by versustune on 12.06.20.
//
#include <cmath>
#include "VenoBuffer.h"
VenoBuffer::VenoBuffer ()
{
2020-06-13 10:56:20 +02:00
}
VenoBuffer::~VenoBuffer ()
{
buffer.clear ();
right.clear ();
left.clear ();
2020-06-13 10:56:20 +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
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;
}
void VenoBuffer::addMonoSample (float value, int index)
{
2020-06-13 10:56:20 +02:00
buffer[index] = value;
}
void VenoBuffer::addLeftSample (float value, int index)
{
2020-06-13 10:56:20 +02:00
left[index] = value;
}
void VenoBuffer::addRightSample (float value, int index)
{
2020-06-13 10:56:20 +02:00
right[index] = value;
}
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;
}
if (l > leftPeak)
{
2020-06-13 10:56:20 +02:00
leftPeak = l;
}
if (r > rightPeak)
{
2020-06-13 10:56:20 +02:00
rightPeak = r;
}
}
}
const std::vector<float>& VenoBuffer::getBuffer () const
{
2020-06-13 10:56:20 +02:00
return buffer;
}
const std::vector<float>& VenoBuffer::getRight () const
{
2020-06-13 10:56:20 +02:00
return right;
}
const std::vector<float>& VenoBuffer::getLeft () const
{
2020-06-13 10:56:20 +02:00
return left;
}