- added Delay
- added MultiDelay - added Diffusor
This commit is contained in:
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* jayDSP, A cross-platform Digital Signal Processing library written in modern C++.
|
||||
* Copyright (C) 2025 Jens Ahrensfeld, All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
* File: diffusor.hpp
|
||||
* Author Jens Ahrensfeld on 26.10.2025.
|
||||
*/
|
||||
|
||||
#ifndef DSP_DIFFUSOR_H
|
||||
#define DSP_DIFFUSOR_H
|
||||
|
||||
#include "delay/multiDelay.hpp"
|
||||
#include <common/mix.hpp>
|
||||
|
||||
template<typename T, size_t numCh>
|
||||
class Diffusor
|
||||
{
|
||||
MultiDelay<T, numCh> m_dly;
|
||||
int m_shuffle_spec[numCh];
|
||||
|
||||
void print_shuffle()
|
||||
{
|
||||
std::cout << "shuffle" << std::endl;
|
||||
for (int i=0; i < numCh; i++)
|
||||
{
|
||||
std::cout << m_shuffle_spec[i] << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
void shuffle_init(double pn)
|
||||
{
|
||||
// Shuffle spec
|
||||
for (int i=0; i < numCh; i++)
|
||||
{
|
||||
m_shuffle_spec[i] = i;
|
||||
}
|
||||
|
||||
// Shuffle values
|
||||
for (int i=0; i < 2*numCh; i++)
|
||||
{
|
||||
int i1 = rand() & (numCh-1);
|
||||
int i2 = rand() & (numCh-1);
|
||||
int temp = m_shuffle_spec[i1];
|
||||
m_shuffle_spec[i1] = m_shuffle_spec[i2];
|
||||
m_shuffle_spec[i2] = temp;
|
||||
}
|
||||
|
||||
// Shuffle signs
|
||||
for (int i=0; i < numCh; i++)
|
||||
{
|
||||
double z = (double)rand()/(double)RAND_MAX;
|
||||
if (z < pn)
|
||||
{
|
||||
m_shuffle_spec[i] *= (T)-1;
|
||||
}
|
||||
}
|
||||
|
||||
print_shuffle();
|
||||
}
|
||||
public:
|
||||
Diffusor(uint maxDelaySize, double pn=0.5)
|
||||
: m_dly(maxDelaySize, 0)
|
||||
{
|
||||
shuffle_init(pn);
|
||||
}
|
||||
|
||||
void setDelay(uint delay)
|
||||
{
|
||||
m_dly.setDelay(delay, 0);
|
||||
}
|
||||
|
||||
uint getDelay()
|
||||
{
|
||||
return m_dly.getDelay();
|
||||
}
|
||||
|
||||
inline T process(T in)
|
||||
{
|
||||
T temp[numCh];
|
||||
m_dly.process(in, temp);
|
||||
|
||||
Shuffle<T, numCh>::inPlace(temp, m_shuffle_spec);
|
||||
Hadamard<T, numCh>::inPlace(temp);
|
||||
Householder<T, numCh>::inPlace(temp);
|
||||
|
||||
return temp[0];
|
||||
}
|
||||
|
||||
// In-place
|
||||
inline void process_multi(T in_out[numCh])
|
||||
{
|
||||
m_dly.process(in_out);
|
||||
|
||||
Shuffle<T, numCh>::inPlace(in_out, m_shuffle_spec);
|
||||
Hadamard<T, numCh>::inPlace(in_out);
|
||||
}
|
||||
|
||||
// Out-of-place
|
||||
inline void process_multi(T in[numCh], T out[numCh])
|
||||
{
|
||||
m_dly.process(in, out);
|
||||
|
||||
Shuffle<T, numCh>::outOfPlace(in, out, m_shuffle_spec);
|
||||
Hadamard<T, numCh>::inPlace(out);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // DSP_DIFFUSOR_H
|
||||
Reference in New Issue
Block a user