Welcome to %s forums

BrainModular Users Forum

Login Register

Usine has a convolution reverb

Discussions about add-ons, announcements
Post Reply
caco
Member
Posts: 306
Contact:

Unread post by caco » 12 Jul 2011, 09:59

Csound can pretty much do anything so how about a convolution reverb for Usine. I never got around to adding this to the c4u download so I thought I may as well post the Csound script here. Note that you will need Csound installed on your system as well as my c4u addon for this to work. To use it just save the script as a text file called 'convolution.csd' into the c4u directory, load it into the c4u addon and have fun :)

The only thing you need to change in the script is the file path to your impulse response. Also, the dry/wet mix can be controlled using c4u's param 1.

I have also documented all the code so you can see how it works but feel free to ask if you have any questions. It also shows how CPU efficient Csound is as this convolution reverb uses less than 5% CPU on my system!

[c]
;Martin Eastwood, 2011
;Using CSound to do convolution reverb in Usine

;Note we are using two instruments here
;- instr1 gets the input and makes it global
;- instr2 is the actual convolution reverb
;the reason for this is that we could then potentially have any number of
;instruments feeding their data to the globals and then run it all through
;just one reverb - kind of like having one reverb on your master bus. Therefore using
;less CPU than having a reverb per csound instrument!

;To keep the example simple the reverb sums the signal to mono rather than running in stereo

<CsoundSynthesizer>

<CsOptions>

</CsOptions>

<CsInstruments>
sr = 44100 ;Csound's samplerate, should be set to match Usine's
ksmps = 1024 ;sets the number of samples in a control period. CSound's Equivalent to Usine's BLOC size
nchnls = 2 ;Number of audio channels in/out of CSound. At the moment Usine only reads channels one and/or two so set to either 1 or 2 for mono/stereo
0dbfs = 1 ;Maximum amplitude of data output by CSound. Data is automatically scaled by Usine

;set this macro to the location of your impulse response. Make sure you keep the #" "# around the file path
#define impulse #"C:\l960brite_stage&hall.wav"#

ga1 init 0 ; preallocate global audio variable
ga2 init 0 ; preallocate global audio variable

instr 1 ; Instrument 1 begins here
ga1 inch 1 ; get audio in from Csound's first input and make global
ga2 inch 2 ; get audio in from Csound's second input and make global
endin

instr 2 ; Instrument 2 begins here
kdrywet chnget "param1" ;get dry/wet param
ipartitionsize = 4096 ; convolution partition size
ilatency = (ksmps < ipartitionsize ? ipartitionsize + ksmps : ipartitionsize)/sr ; claculate latency of pconvolve opcode
arev1, arev2 pconvolve (ga1+ga2)*0.5, $impulse, 4096 ;do the convolution
adry1 delay ga1, ilatency ;delay dry signal by latency of the convolution to keep in sync
adry2 delay ga2, ilatency ;delay dry signal by latency of the convolution to keep in sync
amix1 = (adry1 * (1. - kdrywet)) + ((arev1 * kdrywet)*0.15) ;mix dry / wet signals
amix2 = (adry2 * (1. - kdrywet)) + ((arev2 * kdrywet)*0.15) ;mix dry / wet signals
outs amix1, amix2 ; send to CSound's outputs
ga1 = 0 ; zero globals for safety
ga2 = 0 ; zero globals for safety
endin


</CsInstruments>

<CsScore>
;ins strt dur
i1 0 40000
i2 0 40000

e ; indicates the end of the score

</CsScore>

</CsoundSynthesizer>

[/c]

waolelaid
Member
Posts: 339
Location: Ecouen 95
Contact:

Unread post by waolelaid » 12 Jul 2011, 22:02

Hi caco , you wrote : " The only thing you need to change in the script is the file path to your impulse response "
how can i know the path of my impulse response ?
for you it's this line #define impulse #"C:\l960brite_stage&hall.wav"#
where C:\l960brite_stage&hall.wav , is in Csound folder ?
tell me if i make a mistake
thanx to share it''s real good one
cheers
Avant l'effet on croit à d'autres causes qu'après
Friedrich Nietzsche

caco
Member
Posts: 306
Contact:

Unread post by caco » 12 Jul 2011, 22:48

In my example the file is called l960brite_stage&hall.wav and it is located in the root directory of the C drive hence C:

If the impulse response you wished to use was called my_impulse.wav and was located in a folder called Impulses then the line would be #define impulse #"C:\Impulses\my_impulse.wav"#. The bit between the last two # symbols is just the name and location of your chosen file. Hope this makes it clearer for you :)

When I get chance I will create an example patch for people to download as this should make it easier for people.

User avatar
senso
Site Admin
Posts: 4424
Location: France
Contact:

Unread post by senso » 13 Jul 2011, 00:11

it's a great script.
I'll try it asap.

User avatar
nay-seven
Site Admin
Posts: 5684
Location: rennes France
Contact:

Unread post by nay-seven » 13 Jul 2011, 10:54

Sounds good !
I've made a test and I've to limit the param1 to not down in the red..
maybe it's from the impulses files..?
here the example ( copy the dir IMreverbs1 to your C: ,and csd files in Csound dir of course

caco
Member
Posts: 306
Contact:

Unread post by caco » 13 Jul 2011, 17:15

How bizarre, that shouldn't happen. I have ammended my code above to scale the wet output.

waolelaid
Member
Posts: 339
Location: Ecouen 95
Contact:

Unread post by waolelaid » 13 Jul 2011, 20:05

Hi , i've installed Csound 5.13.1-gnu-win32-d.exe
it is in C:ProgramCsounddocmanualexamplesimpulse.aiff
is it this file ? i don't find a file called "impulse response"
and last newbie question what is "impulse response"
excuse me
thanx
Avant l'effet on croit à d'autres causes qu'après
Friedrich Nietzsche

caco
Member
Posts: 306
Contact:

Unread post by caco » 13 Jul 2011, 20:40

waolelaid - now that you have installed Csound you also need to install my Csound4Usine addon too. Once that is installed try downloading the free impulse responses from Voxengo - http://www.voxengo.com/impulses/

Next, save the script from above in a text file called convolution.csd in the same location as the example files included with the csound4usine addon.

Alter the file path in the script to the location of one of the impulses you downloaded from Voxengo and then load the convolution.csd file into the csound4usine addon and you have a convolution reverb. Csund4Usine's param1 can then control the dry/wet mix too

waolelaid
Member
Posts: 339
Location: Ecouen 95
Contact:

Unread post by waolelaid » 16 Jul 2011, 20:34

Hi caco excuse me i'm a little bit late
in fact i didn't know what were "impulse responses"
i understood now and i try it tonight with the Nay's exemple
it works fine but i can't go more than 2 for the dry/wet
otherwise i'm in the red and i found the sound a litlle muted
i also try the reverb.csd and it works well
i also wanted to build the patch of the wiki "first approach of Csound"
but i've not the Csoud wiki example 1.csd where can i get it ?
i think i'm going to try another one tonight
very very interesting
thanx :D
Avant l'effet on croit à d'autres causes qu'après
Friedrich Nietzsche

caco
Member
Posts: 306
Contact:

Unread post by caco » 16 Jul 2011, 21:18

Glad you got it working :)

I have amended the code above to stop it going into the red so try changing the script to match that one. If you want to try some other basic examples to learn from then as well as the wiki there is an article of mine recently published in the csound journal that may provide you a good tutorial http://www.csounds.com/journal/issue15/Usine.html

waolelaid
Member
Posts: 339
Location: Ecouen 95
Contact:

Unread post by waolelaid » 17 Jul 2011, 03:10

thanx for the link i printed the tutorial
i'm going to have fun tonight
cheers :D
Avant l'effet on croit à d'autres causes qu'après
Friedrich Nietzsche

User avatar
oli_lab
Member
Posts: 1261
Location: Brittany, France
Contact:

Unread post by oli_lab » 16 Aug 2011, 09:30

Would it be complicated to have more than 6 "parameters" inputs ?

it would be great as I found param inputs more straightforward than the OSC business.

say for a basic FM operator you need at least 7 parammeters...

anyway, using the synthesis power of CSound inside usine is really cool ! thanks for that.

I had a go with CsoundVST but its not working with usine...works great with Puredata but.

Olivar
http://oli-lab.org

Win11 Ryzen9/32GB RAM - RME MADIFACE - SSL alpha link 4-16 - OSC capable interfaces

follow OLI_LAB adventures on Mastodon
@olivar_premier@mastodon.social

caco
Member
Posts: 306
Contact:

Unread post by caco » 16 Aug 2011, 09:55

I agree that in many ways the 'parameter' inputs are more straightforward to use than OSC. However their data needs scaling to 0-1 while values sent by OSC do not need scaling so in some ways OSC can be easier too.

I have been wondering about having more 'parameter' inputs though, how many do you think the user module should have? Do consider though that each additional parameter does add slightly more CPU usage to the module.

I also think it may be nice to have more audio inputs/outputs too. Since both Csound and Usine are good for surround sound it would be nice to be able to use them together like that.

At some point when I have free time there will likely be a v2 of the user module so I am happy to hear suggestions :)

User avatar
senso
Site Admin
Posts: 4424
Location: France
Contact:

Unread post by senso » 16 Aug 2011, 10:13

let's go for suggestions!
add a Query (included in the SDK) to be able to choose between several types; for example
- 2 audio in/out 4 params
- 2 audio in/out 8 params
- 8 audio in/out 8 params
etc..

User avatar
oli_lab
Member
Posts: 1261
Location: Brittany, France
Contact:

Unread post by oli_lab » 16 Aug 2011, 10:26

Hi,
for number of input, let me play with it a while to have a clearer idea....

Could it be set when opening the module just like with mixer module in usine ?

also something cool would be to reload from the file each time we hit the reqtart button :jthat will make things easier when tweaking the csound script while using usine

as i understand, all the csound modules are one instance of csound, so audio busses can be made general in csound and be passed on to various usine's modules for surround purpose

all this sounds really good !

Cheers
http://oli-lab.org

Win11 Ryzen9/32GB RAM - RME MADIFACE - SSL alpha link 4-16 - OSC capable interfaces

follow OLI_LAB adventures on Mastodon
@olivar_premier@mastodon.social

caco
Member
Posts: 306
Contact:

Unread post by caco » 16 Aug 2011, 13:30

Yes I think the most likely possibilities are Usine's TestQuery system, a config file or maybe just parsing the csound .csd file for the number of audio channels etc.

caco
Member
Posts: 306
Contact:

Unread post by caco » 12 Sep 2011, 14:17

Still thinking about updates to c4u and another possible issue is the range of the params 1-6. Currently they are all limited to 0-1, which in many ways is simpler but in some ways difficult as data may need scaling to go in and out of c4u.

Does anyone have preferences on whether it should stay 0-1 or be unrestricted, e.g upto +/- 3.4 x 10^38? I am tempted to just make it unrestricted I think but I may have to do a few tests first.

lalo
Member
Posts: 200
Location: italy
Contact:

Unread post by lalo » 13 Sep 2011, 02:11

hi caco! i'd really like to have more parameters ( a max of 64 ? ) and more input/outputs ( 16/16 ? )
thanks for your great work.
a.

caco
Member
Posts: 306
Contact:

Unread post by caco » 13 Sep 2011, 09:14

Yes definately 16 audio inputs/outputs as some of the Csound opcodes require this many audio chanels, such as vbap16move. Also thinking of adding at least 64 parameters too. This will all be user definable using Usine's Test Query System so when you add the module you can select eg 4 in/out with 4 params, 8 in/out with 16 params etc.


caco
Member
Posts: 306
Contact:

Unread post by caco » 13 Sep 2011, 15:35

New vesion coming along nicely :)

I have kind of settled on 2,4,8 and16 audio inputs/outputs each with either 4,8,16,32,64 or 128 parameters. Is this enough combinations or does anybody want more?

I am also going to update the example patches as well. Anybody have any ideas for examples they want to see??

Floego
Member
Posts: 319
Location: Venezuela
Contact:

Unread post by Floego » 13 Sep 2011, 16:13

Caco, have you found a solution for the OSC port assignation conflict when using many csound modules in different tracks? :)

caco
Member
Posts: 306
Contact:

Unread post by caco » 13 Sep 2011, 16:20

Yes, don't use OSC :)

You will be able to have 128 generic parameters per module so you can avoid using OSC unless you need more than 128 parameters..

Floego
Member
Posts: 319
Location: Venezuela
Contact:

Unread post by Floego » 13 Sep 2011, 16:31

Really good news! thanks :)

headphoner
Member
Posts: 225
Contact:

Unread post by headphoner » 28 Sep 2011, 09:52

Hi,

Nice news.

I have an idea for an example partikkel;)

caco
Member
Posts: 306
Contact:

Unread post by caco » 28 Sep 2011, 10:37

Yes, a Usine version of partikkel is on my to-do list for the future :)

The new version of c4u is coming along very nicely, it can now have either 2,4,8 or 16 audio inputs/outputs with either 4,8,16,32,64 or 128 parameters. Also the parameters are no longer required to be in the range 0-1 making it a lot easier to create patches.

There should be a new version of Csound along in a week or two so once that is available I will compile against it and release c4u. In the meantime I am updating the example patches. If anyone has any particular examples they want to see then just let me know.

User avatar
nay-seven
Site Admin
Posts: 5684
Location: rennes France
Contact:

Unread post by nay-seven » 28 Sep 2011, 10:42

cool news !!

woodslanding
Member
Posts: 1327
Contact:

Unread post by woodslanding » 28 Sep 2011, 22:35

caco wrote:If anyone has any particular examples they want to see then just let me know.
Well, one thing I've been looking for forever is a spectral gate. Don't know if that's a job for csound or not....
Custom Ryzen 5900x MATX build, Win10, Fireface UFX, touchscreen
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify

caco
Member
Posts: 306
Contact:

Unread post by caco » 29 Sep 2011, 14:43

woodslanding wrote:
caco wrote:If anyone has any particular examples they want to see then just let me know.
Well, one thing I've been looking for forever is a spectral gate. Don't know if that's a job for csound or not....
So, do you mean an effect that gates any frequency bins whose amplitude is below a given threshold. If so, one of Csound's strengths is spectral processing so this shouldn't be too much of a problem to do for you :)

woodslanding
Member
Posts: 1327
Contact:

Unread post by woodslanding » 29 Sep 2011, 19:06

I only know it from Logic, but if I had to guess from how it sounds, I'd say that's what's happening.....
Custom Ryzen 5900x MATX build, Win10, Fireface UFX, touchscreen
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify

Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests