# Adding a constant background noise to my kontakt instrument



## CFrentzen (Oct 23, 2011)

Hey there,

I am building a kontakt patch for a virtual clavinet. Because of a constant noise (the original instrument produces this while not being played) I want to have this sound in my patch, too.
How do I include this noise (for example with an extra wav-file) into my patch?
Maybe it would be cool to have a knob for turning it on / off on the front panel.

Is there somebody who is good at skripting? Would be nice if you could help me out. I only have little experience with skripting.

Btw - I am using several groups because I have attack and release sample groups. These are turned on and off with each key that is pressed. Maybe this constant noise sample could be in a separate group and won't be turned off.

Thanks for your help. I can also give you my skript as far as it is now, so it would be easier to see how my additional function could be included.

Thanks!

Chris


----------



## Sforzando (Oct 23, 2011)

Don't know if it's the sound you're looking for, but you could use a Lo-Fi filter in the Instrument FX racks, and turn the Noise knob up, or you can assign it to a CC, so that it's automateable. You can even modify the way the noise sounds with the N. Color knob. You should turn the Bits and S-rate off, so that they don't modify the sound of the instrument itself.


----------



## CFrentzen (Oct 23, 2011)

Thanks for your quick reply! I tried it, but unfortunately the noise somehow seems to be linked to the keys. I have to press a key to make it start. And it affects the sound of the samples, because they still seem to be processed through this Lo-Fi effect. 

Btw - the noise from the instrument sounds different. I would prefer using a recorded sound.


----------



## djdarko (Oct 24, 2011)

Record the noise and map it to an area of the keyboard where you won't have any instrument notes, then using the wave editor- edit the sample so that it loops.

I'm not sure how efficient this would be for playing live but it should work fine mapped in DAW midi playback.


----------



## sonaht (Oct 24, 2011)

Hello,

I remember somebody had asked this before and there was a script made for it(which I saved for later use). I do not remember who wrote this script but here it is in case it helps you.

It has an on/off switch as well as level 

Best,
Thanos

*on init*
make_perfview
````
pgs_create_key(PLAYNOTE,1) _{Create a key(sortof like array) named PLAYNOTE with 1 element}_
````
*declare* ui_knob $Noise_Vol (0,631000,1)
*declare* ui_button $Noise_On_Off
````
*declare* !text[2]
!text[0] := "Line Noise Off"
!text[1] := "Line Noise On"
````set_text($Noise_On_Off,!text[$Noise_On_Off]) _{Smart Naming of Button Noise On/Off}_
````
*declare* $noteID _{Needed Later}_

````
````
set_knob_unit($Noise_Vol,$KNOB_UNIT_DB)
set_knob_defval($Noise_Vol,315000)
````
$Noise_Vol := get_engine_par($ENGINE_PAR_VOLUME,find_group("Line Noise"),-1,-1) _{Get the volume level to update the knob}_
````
make_persistent($Noise_Vol)
make_persistent($Noise_On_Off)
````
read_persistent_var($Noise_On_Off)
````

````set_text($Noise_Vol,"Level")
````
pgs_set_key_val(PLAYNOTE,0,$Noise_On_Off) _{Assign the value of $Noise_On_Off (0 or 1) to the FIRST element of the key/array "PLAYNOTE"}_
````
set_knob_label($Noise_Vol,get_engine_par_disp($ENGINE_PAR_VOLUME,find_group("Line Noise"),-1,-1))
````
message("")
*end on*

*on ui_control* ($Noise_Vol)
set_engine_par($ENGINE_PAR_VOLUME,$Noise_Vol,find_group("Line Noise"),-1,-1)
set_knob_label($Noise_Vol,get_engine_par_disp($ENGINE_PAR_VOLUME,find_group("Line Noise"),-1,-1))
*end on*

*on ui_control* ($Noise_On_Off)
pgs_set_key_val(PLAYNOTE,0,$Noise_On_Off)
````set_text($Noise_On_Off,!text[$Noise_On_Off])
*end on*

*on pgs_changed*
*if* (pgs_get_key_val(PLAYNOTE,0) = 1)_{If the button is pressed}_
$noteID := play_note(60,127,0,-1) _{Assign the playnote notenumber, velocity, sampleOffset, and -1(duration as played) to $noteID}_
_{set_event_par_arr($noteID,$EVENT_PAR_ALLOW_GROUP,0,-1)}_
set_event_par_arr($noteID,$EVENT_PAR_ALLOW_GROUP,1,find_group("Line Noise"))_{Allow group "Line Noise" to play}_
*else*
note_off($noteID)
*end if*
*end on*


----------



## CFrentzen (Oct 25, 2011)

Thanks for the script! That looks really good. But it doesn't work in my editor. I have Kontakt 3. It highlights the first "pgs_create_key[...]" by saying "end on expected". But putting in a end on (neither before nor after the line) doesn't work. Do I need Kontakt 4 for this script?


----------



## sonaht (Oct 25, 2011)

Hi Philip,

It should work in Kontakt 3 too. If not then yes it definately works in K4. However the script was pasted from Nils KSE editor so it contains those ''' characters before each line. That's the source of your problems. YOu cannot just paste it directly into Kontakt's editor. 

You either have to remove the ' ' ' characters or just simply download the KSE editor : 
http://www.nilsliberg.se/ksp/

and paste the code in there. Then pressing F5 will compile the code and paste it into your clipboard for you to paste into Kontakt's editor directly. Then it should work.

Hope this helps.

Best,
Thanos


----------



## CFrentzen (Oct 25, 2011)

I know about the '''' etc. - I removed it manually. I also tried the compiler in Nils Liberg's Editor. It doesn't work. Maybe I need Kontakt 4. 

Do you think there might be another way of solving this thing?


----------



## polypx (Oct 25, 2011)

Weren't PGS made available only in Kontakt 4?


----------



## mbietenholz (Oct 26, 2011)

Something like this should work in any version of Kontakt. (I'm on a linux box doing it from memory, so don't shoot me if syntax is not quite right. However, I *do* have scripts that do this kind of thing and work in K2).

First, get your noise sample. Map it some note on the keyboard you don't use otherwise (example below uses note # 12). Set sample to loop until end.

Now the script - this is just a simple latch for that one note. A first keypress starts the note, which then ignores the key-up and just continues to play until there is a second keypress of that note.

I'll leave it to you to add volume control knobs etc for noise.

-----------------script ----------------------------

{ sorry about lack of indentation, it was indented when I typed it, but vi-control seems to strip whitespace from start of lines :-( }

on init
declare $noise_on := 0
declare $noise_note := 12 {whichever note your noise is mapped to}
end on

on note
if ($EVENT_NOTE = $noise_note)
if ($noise_on = 0) 
{noise is not yet playing; start noise-note normally}
$noise_on = $EVENT_ID
else 
{noise is already playing, ignore this event and end the one that is already playing}
ignore_event($EVENT_ID)
note_off($noise_on)
$noise_on := 0
end if
end if
end on

on release
if (($EVENT_NOTE = $noise_note) and ( $noise_on # 0))
ignore_even($EVENT_ID)
end if
end on


----------

