Loading files
/*****************************************************************************
fnc.hpp
Copyright (c) 2020 Raphael DINGE
*Tab=3***********************************************************************/
#pragma once
/*\\\ INCLUDE FILES \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
#include "erb/config.h"
#include "erb/detail/Sram.h"
#if (erb_SDRAM_USE_FLAG)
#include "erb/detail/Sdram.h"
#endif
#include <algorithm>
namespace erb
{
/*
==============================================================================
Name : allocate_bytes_auto
==============================================================================
*/
void * allocate_bytes_auto (std::size_t size)
{
void * ptr = Sram::allocate_bytes_nullptr_on_error (size);
#if (erb_SDRAM_USE_FLAG)
if (ptr == nullptr)
{
ptr = Sdram::allocate_bytes_nullptr_on_error (size);
}
#endif
if (ptr == nullptr)
{
#if defined (erb_TARGET_DAISY)
asm ("bkpt 255");
#elif defined (erb_TARGET_VCV_RACK) || defined (erb_TARGET_UNIT_TEST)
// The module is consuming more memory than it can on the target platform
throw std::bad_alloc ();
#endif
}
return ptr;
}
/*
==============================================================================
Name : scale
==============================================================================
*/
template <std::size_t NbrChannels>
void scale (std::array <Buffer, NbrChannels> & buffers, float * const * in, float gain)
{
for (std::size_t i = 0 ; i < buffers.size () ; ++i)
{
auto & buffer = buffers [i];
const auto & in_arr = in [i];
for (std::size_t j = 0 ; j < erb_BUFFER_SIZE ; ++j)
{
buffer [j] = gain * in_arr [j];
}
}
}
/*
==============================================================================
Name : scale
==============================================================================
*/
template <std::size_t NbrChannels>
void scale (float ** out, const std::array <Buffer, NbrChannels> & buffers, float gain)
{
for (std::size_t i = 0 ; i < buffers.size () ; ++i)
{
auto & out_arr = out [i];
const auto & buffer = buffers [i];
for (std::size_t j = 0 ; j < erb_BUFFER_SIZE ; ++j)
{
out_arr [j] = gain * buffer [j];
}
}
}
/*
==============================================================================
Name : scale
==============================================================================
*/
void scale (Buffer & out, const float * in, float gain)
{
for (std::size_t i = 0 ; i < out.size () ; ++i)
{
out [i] = gain * in [i];
}
}
/*
==============================================================================
Name : scale
==============================================================================
*/
void scale (float * out, const Buffer & in, float gain)
{
for (std::size_t i = 0 ; i < in.size () ; ++i)
{
out [i] = gain * in [i];
}
}
/*
==============================================================================
Name : norm_to_u12
==============================================================================
*/
uint16_t norm_to_u12 (float norm_val)
{
return uint16_t (std::clamp (norm_val, 0.f, 1.f) * 4095.f);
}
/*
==============================================================================
Name : norm_to_u16
==============================================================================
*/
uint16_t norm_to_u16 (float norm_val)
{
return uint16_t (std::clamp (norm_val, 0.f, 1.f) * 65535.f);
}
/*
==============================================================================
Name : to_float_norm
==============================================================================
*/
float to_float_norm (uint16_t val)
{
constexpr float scale = 1.f / 65535.f;
return float (val) * scale;
}
} // namespace erb
/*\\\ EOF \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
1c962d8cfThis file is pinned to the selected release. Download the original to open it in your design tool.