diff --git a/crap/mugi4.hpp b/crap/mugi4.hpp index 94a256d..30ea8bc 100644 --- a/crap/mugi4.hpp +++ b/crap/mugi4.hpp @@ -18,7 +18,7 @@ https://aaltodoc.aalto.fi/bitstream/handle/123456789/14420/article6.pdf #include "Param.hpp" #include "Crap.hpp" #include "os2piir.hpp" -#include "BufferOS2.hpp" +#include "Buffer2OS2.hpp" #define VT 0.026 #define N 4 @@ -123,7 +123,7 @@ struct mugi4 { }; struct Crap_mugi4 -:public AdjustAll> { +:public AdjustAll> { static constexpr ulong id = 0xD8D0D8D0; static constexpr char label[] = "crap_mugi4"; static constexpr char name[] = "crap mugi4 (moog-like)"; @@ -140,10 +140,11 @@ struct Crap_mugi4 memset(&filter, 0, sizeof(mugi4)); } - virtual inline v2df - process2(v2df in) + inline void + process2(v2df *buf, ulong rem) { - return filter.process(in); + for (ulong i = 0; i < rem; i++) + buf[i] = filter.process(buf[i]); } static inline void diff --git a/include/Buffer2OS2.hpp b/include/Buffer2OS2.hpp new file mode 100644 index 0000000..b81d299 --- /dev/null +++ b/include/Buffer2OS2.hpp @@ -0,0 +1,68 @@ +template +struct Buffer2OS2 : public virtual Mixin { + virtual inline void + process2(v2df *buf, ulong rem) = 0; + + halfband_t hb_up, hb_down; + + TEMPLATE void + _process(T *in_L, T *in_R, T *out_L, T *out_R, ulong count) + { + disable_denormals(); + v2df buf[BLOCK_SIZE]; + v2df over[FULL_SIZE]; + + for (ulong pos = 0; pos < count; pos += BLOCK_SIZE) { + ulong rem = BLOCK_SIZE; + if (pos + BLOCK_SIZE > count) + rem = count - pos; + + ulong rem2 = rem*OVERSAMPLING; + + for (ulong i = 0; i < rem; i++) { + buf[i][0] = in_L[i]; + buf[i][1] = in_R[i]; + } + + for (ulong i = 0; i < rem; i++) { + over[i*2+0] = interpolate_a(&hb_up, buf[i]); + over[i*2+1] = interpolate_b(&hb_up, buf[i]); + } + + process2(over, rem2); + + for (ulong i = 0; i < rem; i++) { + decimate_a(&hb_down, over[i*2+0]); + buf[i] = decimate_b(&hb_down, over[i*2+1]); + } + + for (ulong i = 0; i < rem; i++) { + out_L[i] = buf[i][0]; + out_R[i] = buf[i][1]; + } + + in_L += BLOCK_SIZE; + in_R += BLOCK_SIZE; + out_L += BLOCK_SIZE; + out_R += BLOCK_SIZE; + } + } + + void + process( + double *in_L, double *in_R, + double *out_L, double *out_R, + ulong count) + { + _process(in_L, in_R, out_L, out_R, count); + } + + void + process( + float *in_L, float *in_R, + float *out_L, float *out_R, + ulong count) + { + _process(in_L, in_R, out_L, out_R, count); + } +};