10 posts

Page

**1**of**1**- KVRAF
- 3414 posts since 14 Nov, 2006, from Pacific NW

joshb wrote:Can anyone give me any insight into a wavefolding algorithm? I believe it's also referred to as foldover?

Thx

Try this:

out = sinf(gain*in);

As gain gets larger, the output will start to fold back on itself. Very similar to the Serge wave multiplier, but with some nice sine curving, instead of the triangle wave folding found in the Serge circuit.

Plugins: http://www.valhalladsp.com

Blog: https://valhalladsp.com/blog/

KVR Subforum: http://www.kvraudio.com/forum/viewforum.php?f=146

Blog: https://valhalladsp.com/blog/

KVR Subforum: http://www.kvraudio.com/forum/viewforum.php?f=146

- KVRist
- 296 posts since 21 Jun, 2013

- KVRist
- 66 posts since 13 Apr, 2016

Wow, thank you. That's very cool. Both the demo animation and the actual function.

"apply triangle"...is that a known function? Never heard of it and it really beats the hell out of the 18 ugly lines of code I threw together:

"apply triangle"...is that a known function? Never heard of it and it really beats the hell out of the 18 ugly lines of code I threw together:

- Code: Select all
`float fold(float x)`

{

float sign = 1.0f;

if(x < 0.0f)

sign = -1.0;

x *= sign;

if(x > threshold)

{

const float remainder = std::fmod(x, threshold);

const int numFolds = (int)std::floor(x / threshold);

float y;

if(numFolds % 2 == 0)

y = remainder;

else

y = threshold - remainder;

return y * sign;

}

return x * sign;

}

- KVRAF
- 4758 posts since 11 Feb, 2006, from Helsinki, Finland

Oh... that round() trick is really neat, saves some remapping when compared to using fmod(). Have to try to remember it.

<- plugins | forum

- KVRist
- 296 posts since 21 Jun, 2013

mystran wrote:Oh... that round() trick is really neat, saves some remapping when compared to using fmod(). Have to try to remember it.

- Code: Select all
`//Range (-0.5,0.5)`

__m128 fold(__m128 x)

{

__m128i int_round = _mm_cvtps_epi32(x);

__m128 frac = _mm_sub_ps(x,_mm_cvtepi32_ps(int_round));

return _mm_xor_ps(frac,_mm_castsi128_ps(_mm_slli_epi32(int_round,31)));

}

Here's another. Not plain C, but i guess you know sse2

- KVRist
- 296 posts since 21 Jun, 2013

joshb wrote:"apply triangle"...is that a known function? Never heard of it and it really beats the hell out of the 18 ugly lines of code I threw together:

Have a look at:

https://en.wikipedia.org/wiki/Triangle_wave

- KVRist
- 124 posts since 10 Oct, 2014

Polynomial integration/differentiation can be used to limit aliasing.

With this method, instead of using a punctual sample, you get a mean value over a sampling interval.

This method can be combined with x2 oversampling.

Here is a simplified code snippet from an Axoloti object.

With this method, instead of using a punctual sample, you get a mean value over a sampling interval.

This method can be combined with x2 oversampling.

Here is a simplified code snippet from an Axoloti object.

- Code: Select all
`//init code`

float x0 = 0, x1 = 0, y0 = 0, y1 = 0;

//sample rate code

x1 = x0; y1 = y0;

x0 = input * drive; // input drive

float f0 = x0+16.5f;

int i0 = (int)f0; //rounding

if(i0 & 1){

f0 = 2 * (f0 - i0) - 1.0f; //wavefold segment

y0 = 0.25f*(f0*f0-1); // and its smooth integral

} else {

f0 = -2 * (f0 - i0) + 1.0f; //wavefold segment

y0 = -0.25f*(f0*f0-1); // and its smooth integral

}

float x1_x0 = x1 - x0;

if(fabs(x1_x0) > 0.001f){ // if the interval is large enough,

out = (y1 - y0) / (x1_x0); // we differentiate

}else{ // else we take the

out = f0; // direct value

}

- KVRAF
- 11806 posts since 7 Dec, 2004

While there is a very narrow focus on abs(), it is important to recognize that abs() is merely one possible non-linear function, while any non-linear function can be used to create this effect.

http://xhip.net/effects/?p=Multiplier

https://soundcloud.com/xhip/multiplier

abs() is an infinite order non-linearity while it is also possible to use low order (2nd, 3rd) to approximate it very well. These can be trivially anti-aliased because they generate a limited number of harmonics. (N^2 = at most 2x the bandwidth.)

The famous "Serge wave multiplier" used a diode clamp (NOT APPROXIMATED BY TANH()!) as the non-linear function.

Search for past threads on the topic, I'm not going to go into detail just repeating what has already been said.

http://xhip.net/effects/?p=Multiplier

https://soundcloud.com/xhip/multiplier

abs() is an infinite order non-linearity while it is also possible to use low order (2nd, 3rd) to approximate it very well. These can be trivially anti-aliased because they generate a limited number of harmonics. (N^2 = at most 2x the bandwidth.)

The famous "Serge wave multiplier" used a diode clamp (NOT APPROXIMATED BY TANH()!) as the non-linear function.

Search for past threads on the topic, I'm not going to go into detail just repeating what has already been said.

Free plug-ins for Windows, MacOS and Linux. Xhip Synthesizer v8.0 and Xhip Effects Bundle v6.7.