Cabbage Logo
Back to Cabbage Site

Tryed to hack Iain's powershape example, but

Hi,

I try to hack the Iain McCurdy powershape example and add it into one simply synth, but I don’t understand why doesn’t works… what I wrong?

<Cabbage>
form caption("Untitled") size(400, 300), colour(58, 110, 182), pluginid("def1")
hslider bounds(5, 18,290, 40),  channel("amount"), range(0.1, 1000, 1, 0.25,0.001)
hslider bounds(5,108,290, 40),  channel("level"),  range(0, 50, 0.5, 0.25,0.000001) 
keyboard bounds(8, 158, 381, 95)
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d --midi-key-cps=4 --midi-velocity-amp=5
</CsOptions>
<CsInstruments>
ksmps = 32
nchnls = 2
0dbfs = 1
giwave ftgen 1, 0, 4096, 10, 1
instr 1
    kporttime	linseg	0,0.001,0.05
	gkshape		chnget	"amount"
	gkshape		portk	gkshape,kporttime
	gklevel		chnget	"level"
	gklevel		portk	gklevel,kporttime
    kEnv        madsr .1, .2, .6, 1
    asigL       oscili p5*kEnv, p4, 1
    asigR       = asigL
	aL 		    powershape 	asigL, gkshape, 0dbfs
	aR 		    powershape 	asigR, gkshape, 0dbfs
	alevel		interp		gklevel
			    outs	aL * alevel, aR * alevel
endin
</CsInstruments>
<CsScore>
f0 z
</CsScore>
</CsoundSynthesizer>

same results with the pdclip.csd example…

thanks guys!!!

What are you expecting to happen? Both of these instruments depend on audio input. You will also need to press a key on the keyboard to start them as there are no score events for them in the CsScore section…

Hi Big Rory! Thanks for your fast reply!!!

I would like to understand how to “distort” with powershape opcode (or with pdclip opcode) the audio that is generated with the simply startup synth… (it is clear that the synth must play it from the keyboard…)

[quote=“rorywalsh, post:2, topic:1493”]
as there are no score events for them in the CsScore section…
[/quote] what did I miss?

Big Thanks!!

Do you have widgets to control the various parts of Iain’s instruments? I’ll take a look. Can you post the full .csd rather than just snippets.

This is the entire file. I begin to learn how Csound works and how works with Cabbage. The simple Synth is a beautiful starting point… but: the audio signal that it generate, how is routed inside the powershape opcode?

I’ll explain:
the first part of the code is the Cabbage GUI;
then the Options/settings for Cabbage and Csound
then the instr1 that is divided in 3 macro parts:
1 the section of reading values generated from GUI;
2 the audio generation section (oscili and envelope);
3 the waveshaping section with powershape opcode.

The audio is generated correctly from synth, but the problems begin when I try to move the sliders “amount” and “level” and I don’t understand why… Similar is for pdclip.csd example…

I don’t see any file? Anyhow, I’ve attached a quick hack of the PowerShape example.
synthClip.csd (2.3 KB)
This one works for me, although if you give it too much ‘amount’ it will stop making audio. I guess the signal get too hot, but I don’t know. I didn’t study the code. Post your file anyway so I can see where exactly you went wrong.

sorry, the code that I posted… now I try your example…

Sorry, when i checked first there were only bits of the code. Anyhow, it works fine for me, so long as you don’t crank ‘amount’ up too much…?

No problem…
My example works similar…

Seems to be the audio doesn’t work correctly… when I crank ‘amount’ up 1/4 the entire"amount" range, the sound disappears

I’d need to stud the code, but it might just be a restriction Iain added so users don’t blow their ears up!

when I use the integrated sine oscillator provided in the Iain’s example, the audio distorted is beautiful!!! I would like to distort in similar mode the audio that is generated with one synth…

Thanks for your support!!!

You might take a look at Waveshaping synthesis. It uses a simple sinusoidal input, but can create some very complex and interesting timbres. With some careful planning you can also avoid any kind of aliasing.

Hi, thank you, the Csound Flossmanual is one beautiful resource!!! :wink:

This is my latest experiment with Iain’s Powershape example hack test: for control the instrument via MIDI keyboard I need to set the flags, and change the oscili line with these 2 row of code:

-+rtmidi=NULL -M0 -m0d --midi-key-cps=4 --midi-velocity-amp=5

asigL oscili 1,cpsoct(koct),gisine

BUT is in this moment that the audio will stopped and doesn’t works…

This is my last Iain’s powershape example hacked…

> <Cabbage>
> form caption("Powershape") size(400,260), pluginid("pshp") style("legacy")
> hslider bounds(  5, 18,290, 40),          colour("white"), trackercolour("white"), channel("amount"), range(0.1, 1000, 1, 0.25,0.001)
> label   bounds(129, 50, 40, 11), text("Amount"), fontcolour("white")
> hslider bounds(  5,108,290, 40),          colour("white"), trackercolour("white"),  channel("level"),  range(0, 50, 0.5, 0.25,0.000001)    
> label   bounds(135,140, 27, 11), text("Level"), fontcolour("white")
> keyboard bounds(8, 158, 381, 95)
> </Cabbage>
> <CsoundSynthesizer>
> <CsOptions>
> -d -n -+rtmidi=NULL -M0 -m0d --midi-key-cps=4 --midi-velocity-amp=5
> </CsOptions>
> <CsInstruments>
> 0dbfs		=	1
> gisine	ftgen	0,0,4096,10,1
> instr	1
> 	kporttime	linseg	0,0.001,0.05				; portamento time ramps up from zero
> 	gkshape		chnget	"amount"				; READ WIDGETS...
> 	gkshape		portk	gkshape,kporttime
> 	gklevel		chnget	"level"					;
> 	gklevel		portk	gklevel,kporttime
> 	gkTestTone	chnget	"TestTone"
> 	 koct	rspline	4,8,0.2,0.5						
> 	 asigL		oscili	1,p3,gisine			; ...generate a tone
> 	ifullscale	=	0dbfs	;DEFINE FULLSCALE AMPLITUDE VALUE
> 	aL 		powershape 	asigL, gkshape, ifullscale	;CREATE POWERSHAPED SIGNAL
> 	alevel		interp		gklevel
> 			outs		aL * alevel, aL * alevel		;WAVESET OUTPUT ARE SENT TO THE SPEAKERS
> endin
> </CsInstruments>
> <CsScore>
> i 1 0 [3600*24*7]
> </CsScore>
> </CsoundSynthesizer>

Please help me! thanks

The code you posted doesn’t modify the oscil line at all. And what’s all the >'s :joy: When you add those MIDI flags it usually means instrument one will sound when a note is pressed on the keyboard.

What’s the idea here with using the output of a line generator to generate the frequency? I thought you might have used p4? Here’s an example of what I think you are looking for?

<Cabbage>
form caption("Powershape") size(400,260), pluginid("pshp") style("legacy")
hslider bounds(  5, 18,290, 40),          colour("white"), trackercolour("white"), channel("amount"), range(0.1, 1000, 1, 0.25,0.001)
label   bounds(129, 50, 40, 11), text("Amount"), fontcolour("white")
hslider bounds(  5,108,290, 40),          colour("white"), trackercolour("white"),  channel("level"),  range(0, 50, 0.5, 0.25,0.000001)    
label   bounds(135,140, 27, 11), text("Level"), fontcolour("white")
keyboard bounds(8, 158, 381, 95)
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-d -n -+rtmidi=NULL -M0 -m0d --midi-key-cps=4 --midi-velocity-amp=5
</CsOptions>
<CsInstruments>
0dbfs		=	1
gisine	ftgen	0,0,4096,10,1
instr	1
	kporttime	linseg	0,0.001,0.05				; portamento time ramps up from zero
	gkshape		chnget	"amount"				; READ WIDGETS...
	gkshape		portk	gkshape,kporttime
	gklevel		chnget	"level"					;
	gklevel		portk	gklevel,kporttime
	gkTestTone	chnget	"TestTone"
	 koct	rspline	4,8,0.2,0.5						
	 asigL	oscili	1,p4,gisine
	ifullscale	=	0dbfs	;DEFINE FULLSCALE AMPLITUDE VALUE
	aL 		powershape 	asigL, gkshape, ifullscale	;CREATE POWERSHAPED SIGNAL
	alevel		interp		gklevel
			outs		aL * alevel, aL * alevel		;WAVESET OUTPUT ARE SENT TO THE SPEAKERS
endin
</CsInstruments>
<CsScore>
f0 z
</CsScore>
</CsoundSynthesizer>

Hi…

I’m sorry for the last post. My problems are only one: the oscili line:[quote=“Slivovitz84, post:14, topic:1493”]
asigL oscili 1,p3,gisine
[/quote]

It’s wrong … what you posted is right:[quote=“rorywalsh, post:15, topic:1493”]
asigL oscili 1,p4,gisine
[/quote]

…p3 instead of p4… I don’t have see this bug! :sweat_smile:

AND the line [quote=“rorywalsh, post:15, topic:1493”]
koct rspline 4,8,0.2,0.5
[/quote]

is another line that I have not deleted… is unuseful… :sweat_smile: (This is Csound NOOB section, right?)

And all the characters “>”? I simply copy / paste the code from Cabbage into this forum, and I click on the “Blockquote” and “Preformatted Text” buttons to give the code formatting … (I also press the “Preformatted Text” button otherwise all parts<xxx> of the code are lost …) but have I done something wrong? …

Yes, your correction is right: simply the audio output from the oscil is routed into the powershape opcode for waveshaping… But, If this way is the correct way I don’t know, but now works…

thank you…

</Cabbage>
form caption("Powershape") size(400,260), pluginid("pshp") style("legacy")
hslider bounds(  5, 18,290, 40),          colour("white"), trackercolour("white"), channel("amount"), range(0.1, 1000, 1, 0.25,0.001)
label   bounds(129, 50, 40, 11), text("Amount"), fontcolour("white")
hslider bounds(  5,108,290, 40),          colour("white"), trackercolour("white"),  channel("level"),  range(0, 500, 0.5, 0.25,0.000001)    
label   bounds(135,140, 27, 11), text("Level"), fontcolour("white")
keyboard bounds(8, 158, 381, 95)
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-d -n -+rtmidi=NULL -M0 -m0d --midi-key-cps=4 --midi-velocity-amp=5
</CsOptions>
<CsInstruments>
0dbfs		=	1
gisine	ftgen	0,0,4096,10,1
instr	1
	kporttime	linseg	0,0.001,0.05				; portamento time ramps up from zero
	gkshape		chnget	"amount"				; READ WIDGETS...
	gkshape		portk	gkshape,kporttime
	gklevel		chnget	"level"					;
	gklevel		portk	gklevel,kporttime				
	 asigL		oscili	1,p4,gisine			; ...generate a tone
	ifullscale	=	0dbfs	;DEFINE FULLSCALE AMPLITUDE VALUE
	aL 		powershape 	asigL, gkshape, ifullscale	;CREATE POWERSHAPED SIGNAL
	alevel		interp		gklevel
			outs		aL * alevel, aL * alevel		;WAVESET OUTPUT ARE SENT TO THE SPEAKERS
endin
</CsInstruments>
<CsScore>
i 1 0 [3600*24*7]
</CsScore>
</CsoundSynthesizer>

It’s certainly one way of doing it and I think it also sounds great. The biggest drawback with this type of approach is aliasing when playing higher notes. Waveshaping is a big topic. Many commercial waveshaper use over sampling to avoid aliasing. This is possible with Csound, but it’s quite complex.

Sorry for my late input into a thread that bears my name.

I think you spotted that it’s best if the amplitude of the input oscillator is a constant 1 for powershape otherwise the sound will disappear if shape amount is high. You can apply an amplitude envelope after the powershaping.

Below is my own quick version of a synth using this opcode.
PowershapeSynth.csd (1.9 KB)

Aliasing is indeed a problem as higher notes are played. My solution here was to use keyboard scaling to suppress the shaping amount as higher and higher notes are played.

If shape amount changes quickly - e.g. by using an envelope as I am doing here - then ksmps will need to be low to prevent quantisation artefacts. A better solution would be to place powershape in a UDO with its own local setksmps value.

<Cabbage>
form caption("Powershape Synth") size(500, 180), colour(58, 110, 182), pluginid("def1")
rslider bounds(5,5,70,70), channel("att"), range(0.001,2,0.05,0.5), text("Att.")
rslider bounds(75,5,70,70), channel("dec"), range(0.001,2,1,0.5), text("Dec.")
rslider bounds(145,5,70,70), channel("rel"), range(0.001,2,0.1,0.5), text("Rel.")
rslider bounds(215,5,70,70), channel("amt"), range(1,5000,1000), text("Amount")
rslider bounds(285,5,70,70), channel("dtn"), range(0,50,1,0.5), text("Detune")
rslider bounds(355,5,70,70), channel("semi"), range(-24,0,-12,1,1), text("Semitone")
keyboard bounds(5,80, 490, 95)
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d --midi-key-cps=4 --midi-velocity-amp=5
</CsOptions>
<CsInstruments>
ksmps = 2  ; ksmps needs to be low if kShape will be changing quickly
nchnls = 2
0dbfs = 1

giScl  ftgen  0,0,128,-5,500,96,0.01,32,0.00001 ; keyboard scaling. MIDI notes are mapped to values in this table

instr 1
; shape amount attack and release times
iAtt    chnget   "att"
iDec    chnget   "dec"
iRel    chnget   "rel"
iAmt    chnget   "amt"
kDtn    chnget   "dtn"
kSemi   chnget   "semi"

; read MIDI note number
iNum    notnum

; read a keyboard scaling value. High numbers greater than 1 for low notes, low numbers close to zero
iScl    table    iNum, giScl

; envelope peak is dictated by velcity and and keyboard scaling value
kShape  expseg  1, iAtt, 1+(iAmt*p5^3*iScl), iDec, 1, 1, 1

; create two oscillators. NB amplitude must be 1
a1      poscil 1, p4*cent(kDtn)
a2      poscil 1, p4*cent(-kDtn)*semitone(kSemi)

; powershape both oscillators
a1      powershape a1, kShape
a2      powershape a2, kShape

; amplitude envelope
aEnv    expsegr    1, iRel, 0.001
aMix    =          (a1 + a2) * aEnv * p5 * 0.5
        outs       aMix, aMix
endin

</CsInstruments>
<CsScore>
f0 z
</CsScore>
</CsoundSynthesizer>