gearmulator

Emulation of classic VA synths of the late 90s/2000s that are based on Motorola 56300 family DSPs
Log | Files | Refs | Submodules | README | LICENSE

bypassBuffer.h (1023B)


      1 #pragma once
      2 
      3 #include <vector>
      4 
      5 #include "dsp56kEmu/ringbuffer.h"
      6 
      7 namespace pluginLib
      8 {
      9 	class BypassBuffer
     10 	{
     11 	public:
     12 		using ChannelBuffer = dsp56k::RingBuffer<float, 32768, false, true>;
     13 
     14 		void write(const float* _data, uint32_t _channel, uint32_t _samples, uint32_t _latency)
     15 		{
     16 			if(_channel >= m_channels.size())
     17 			{
     18 				m_channels.resize(_channel + 1);
     19 				m_latency.resize(_channel + 1);
     20 			}
     21 
     22 			auto& ch = m_channels[_channel];
     23 			auto& latency = m_latency[_channel];
     24 
     25 			while(_latency > latency)
     26 			{
     27 				++latency;
     28 				ch.push_back(0.0f);
     29 			}
     30 
     31 			while(_latency < latency)
     32 			{
     33 				--latency;
     34 				ch.pop_front();
     35 			}
     36 
     37 			for(uint32_t i=0; i<_samples; ++i)
     38 				ch.push_back(_data[i]);
     39 		}
     40 
     41 		void read(float* _output, uint32_t _channel, const uint32_t _samples)
     42 		{
     43 			if(_channel >= m_channels.size())
     44 				return;
     45 
     46 			for(uint32_t i=0; i<_samples; ++i)
     47 				_output[i] = m_channels[_channel].pop_front();
     48 		}
     49 
     50 	private:
     51 		std::vector<ChannelBuffer> m_channels;
     52 		std::vector<uint32_t> m_latency;
     53 	};
     54 }