75template<
int SIZE_BITS>
78 enum {
SIZE = 1 << SIZE_BITS };
105 output[
i] =
data[
i].real();
120 std::vector<std::complex<float> > new_spec, iffted;
121 new_spec.resize(
SIZE);
125 for (
int i = 1;
i < cutoff;
i++)
138 for (
int i =
SIZE / 2;
i >= cutoff;
i--)
140 new_spec[
i / 2] += new_spec[
i] * fatt;
141 new_spec[
SIZE -
i / 2] += new_spec[
SIZE -
i] * fatt;
143 new_spec[
SIZE -
i] = 0.f;
150 for (
int i = cutoff;
i <
SIZE / 2;
i++)
152 new_spec[
SIZE -
i] = 0.f;
155 fft.
calculate(&new_spec.front(), &iffted.front(),
true);
157 output[
i] = iffted[
i].real();
162template<
int SIZE_BITS>
165 enum {
SIZE = 1 << SIZE_BITS };
166 using std::map<
uint32_t,
float *>::iterator;
167 using std::map<
uint32_t,
float *>::end;
168 using std::map<
uint32_t,
float *>::lower_bound;
176 bl.compute_spectrum(input);
186 uint32_t base = 1 << (32 - SIZE_BITS);
189 for (
unsigned int i = 0;
i < cutoff;
i++)
190 vmax = std::max(vmax,
abs(
bl.spectrum[
i]));
191 float vthres = vmax / 1024.0;
200 while(cutoff > 1 && cumul +
abs(
bl.spectrum[cutoff - 1]) < vthres)
202 cumul +=
abs(
bl.spectrum[cutoff - 1]);
206 float *wf =
new float[
SIZE+1];
207 bl.make_waveform(wf, cutoff, foldover);
209 float **storage = &(*this)[base * (top / cutoff)];
212 cutoff = (
int)(0.75 * cutoff);
219 iterator
i = upper_bound(phase_delta);
228 for (iterator
i = begin();
i != end();
i++)
236static inline float cerp(
float pm1,
float p0,
float p1,
float p2,
float t)
238 return (-
t*(
t-1)*(
t-2) * pm1 + 3*(
t+1)*(
t-1)*(
t-2) * p0 - 3*(
t+1)*
t*(
t-2) * p1 + (
t+1)*
t*(
t-1) * p2) * (1.0 / 6.0);
247template<
int SIZE_BITS>
268 wpos = (
phase + shift) >> (32 - SIZE_BITS);
270 return value1 + mix * value2;
277 wpos = (
phase + gshift + shift) >> (32 - SIZE_BITS);
279 return value1 + mix * value2;
288 wpos = (phase_mod + shift) >> (32 - SIZE_BITS);
290 return value1 + mix * value2;
322 phase2 ^= ((
int32_t)phase2)>>31;
324 float value = (phase2 >> 6) / 16777216.0 - 1.0;
334 for (
unsigned int i = 0;
i <
size;
i++)
337 for (
unsigned int i = 0;
i <
size;
i++)
340 for (
unsigned int i = 0;
i <
size;
i++)
341 thismax = std::max(thismax, fabsf(table[
i]));
342 if (thismax < 0.000001f)
344 double divv = 1.0 / thismax;
345 for (
unsigned int i = 0;
i <
size;
i++)
T limit(T val, T min, T max)
Definition Util.h:78
float abs(const fft_t *freqs, off_t x)
Definition OscilGen.cpp:52
void calculate(complex *input, complex *output, bool inverse) const
Definition fft.h:64
struct huft * t
Definition inflate.c:943
unsigned bl
Definition inflate.c:935
register unsigned i
Definition inflate.c:1575
static PuglViewHint int value
Definition pugl.h:1708
JHUFF_TBL long freq[]
Definition jchuff.h:50
int int32_t
Definition mid.cpp:97
unsigned int uint32_t
Definition mid.cpp:100
static void normalize_waveform(float *table, unsigned int size)
Simple stupid inline function to normalize a waveform (by removing DC offset and ensuring max absolut...
Definition osc.h:331
T lerp(T v1, T v2, U mix)
Definition primitives.h:267
T sine_table< T, N, Multiplier >::data[N+1]
Definition primitives.h:442
fixed_point< unsigned long long int, 24 > wpos
wave position (unsigned 64-bit int including 24-bit fractional part)
Definition fixed_point.h:264
void make_waveform(float output[SIZE], int cutoff, bool foldover=false)
Definition osc.h:117
void remove_dc()
remove DC offset of the spectrum (it usually does more harm than good!)
Definition osc.h:110
void compute_spectrum(float input[SIZE])
Import time domain waveform and calculate spectrum from it.
Definition osc.h:88
void compute_waveform(float output[SIZE])
Generate the waveform from the contained spectrum.
Definition osc.h:99
static dsp::fft< float, SIZE_BITS > & get_fft()
Definition osc.h:79
std::complex< float > spectrum[SIZE]
Definition osc.h:85
@ SIZE
Definition osc.h:78
void set_freq(float freq, float sr)
Set phase delta based on oscillator frequency and sample rate.
Definition osc.h:47
uint32_t phasedelta
Per-sample phase delta (phase increment), equal to 2^32*freq/sr.
Definition osc.h:40
void step()
Make one phase increment.
Definition osc.h:57
float get()
Make one phase increment and return a value from -0.5 to 0.5.
Definition osc.h:62
void reset()
Reset oscillator phase to zero.
Definition osc.h:42
uint32_t phase
Phase (from 0 to 0xFFFFFFFF).
Definition osc.h:38
void set_freq_odsr(float freq, double odsr)
Set phase delta based on oscillator frequency and inverse of sample rate.
Definition osc.h:52
float get()
Definition osc.h:316
float last
Previous value (not stored here, but may be used by calling code).
Definition osc.h:305
void reset()
Definition osc.h:311
triangle_lfo()
Definition osc.h:307
memcpy(hh, h, RAND_HEAD_LEN)
typedef int(UZ_EXP MsgFn)()