Csound Csound-dev Csound-tekno Search About

[CSOUND-DEV] Simple wavefolder opcode

Date2015-10-17 17:02
FromPeter Burgess
Subject[CSOUND-DEV] Simple wavefolder opcode
Hi, I'm trying to find or make a simple wavefolding opcode, by which I mean, if the amplitude of a sample is higher than a threshold, or lower than a -threshold, it will invert the petruduing samples around the threshold/-threshold line.

I've tried knocking one up myself, but I can't use > on a-rate variables. This is what I had in mind:

instr 1

iwavethresh = 0.6

icps = cpsmidinn(p4)


aosc oscili 0.8, icps, ifn1


if (aosc > iwavethresh) then

   aosc = iwavethresh - (aosc - iwavethresh)

elseif (aosc < -iwavethresh) then

   aosc = -iwavethresh + (-aosc - iwavethresh)

endif


out aosc

endin

If ifn1 was a triangle wave with 32 elements, i would expect the first half of the output waveform of the above to look like this:

0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.5, 0.4, 0.5, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1

Pete

Date2015-10-17 17:14
Fromjpff
SubjectRe: [CSOUND-DEV] Simple wavefolder opcode
Write an udo with ksmps=1, then you can test an audio signal.  Just an 
idea....


On Sat, 17 Oct 2015, Peter Burgess wrote:

> Hi, I'm trying to find or make a simple wavefolding opcode, by which I mean,
> if the amplitude of a sample is higher than a threshold, or lower than a
> -threshold, it will invert the petruduing samples around the
> threshold/-threshold line.
> 
> I've tried knocking one up myself, but I can't use > on a-rate variables. This
> is what I had in mind:
> 
> instr 1
> 
> iwavethresh = 0.6
> 
> icps = cpsmidinn(p4)
> 
> 
> aosc oscili 0.8, icps, ifn1
> 
> 
> if (aosc > iwavethresh) then
> 
>    aosc = iwavethresh - (aosc - iwavethresh)
> 
> elseif (aosc < -iwavethresh) then
> 
>    aosc = -iwavethresh + (-aosc - iwavethresh)
> 
> endif
> 
> 
> out aosc
> 
> endin
> 
> If ifn1 was a triangle wave with 32 elements, i would expect the first half of
> the output waveform of the above to look like this:
> 
> 0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.5, 0.4, 0.5, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1
> 
> Pete
> 
>

Date2015-10-17 17:18
Fromjpff
SubjectRe: [CSOUND-DEV] Simple wavefolder opcode
or does the moirror opcode do what you want?

On Sat, 17 Oct 2015, Peter Burgess wrote:

> Hi, I'm trying to find or make a simple wavefolding opcode, by which I mean,
> if the amplitude of a sample is higher than a threshold, or lower than a
> -threshold, it will invert the petruduing samples around the
> threshold/-threshold line.
> 
> I've tried knocking one up myself, but I can't use > on a-rate variables. This
> is what I had in mind:
> 
> instr 1
> 
> iwavethresh = 0.6
> 
> icps = cpsmidinn(p4)
> 
> 
> aosc oscili 0.8, icps, ifn1
> 
> 
> if (aosc > iwavethresh) then
> 
>    aosc = iwavethresh - (aosc - iwavethresh)
> 
> elseif (aosc < -iwavethresh) then
> 
>    aosc = -iwavethresh + (-aosc - iwavethresh)
> 
> endif
> 
> 
> out aosc
> 
> endin
> 
> If ifn1 was a triangle wave with 32 elements, i would expect the first half of
> the output waveform of the above to look like this:
> 
> 0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.5, 0.4, 0.5, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1
> 
> Pete
> 
>

Date2015-10-17 17:25
FromPeter Burgess
SubjectRe: [CSOUND-DEV] Simple wavefolder opcode
That's the biscuit! Mirror's my man. Cheers john!

On Sat, Oct 17, 2015 at 5:18 PM, jpff <jpff@codemist.co.uk> wrote:
or does the moirror opcode do what you want?

On Sat, 17 Oct 2015, Peter Burgess wrote:

Hi, I'm trying to find or make a simple wavefolding opcode, by which I mean,
if the amplitude of a sample is higher than a threshold, or lower than a
-threshold, it will invert the petruduing samples around the
threshold/-threshold line.

I've tried knocking one up myself, but I can't use > on a-rate variables. This
is what I had in mind:

instr 1

iwavethresh = 0.6

icps = cpsmidinn(p4)


aosc oscili 0.8, icps, ifn1


if (aosc > iwavethresh) then

   aosc = iwavethresh - (aosc - iwavethresh)

elseif (aosc < -iwavethresh) then

   aosc = -iwavethresh + (-aosc - iwavethresh)

endif


out aosc

endin

If ifn1 was a triangle wave with 32 elements, i would expect the first half of
the output waveform of the above to look like this:

0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.5, 0.4, 0.5, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1

Pete