# Script for natural room dynamics in wet libraries



## FriFlo (Feb 26, 2013)

Hi guys,

in the Sptifire Sable release thread there was a lot of discussion about wet libraries in general. Thinking about it IMO the biggest disadvantage of such a library is lacking realism when using a CC (e.g. Mod Wheel) for dynamics. For example, if you do smoe kind of pfp move over a short time, the room always follows the close sound immediately. In a real recording, you would hear the reverberation of the forte in the last piano for a little bit of time decaying.
What all wet libraries offer is a release sample for different dynamic levels. I thought, this could be a way to fix it:
When you are at the dynamic peak, a release sample of that maximum dynamic gets faded in, so you would basically hear room decay of the loud note during the beginning of the quiet one. I hope you get, what I mean! 
I thought about a script figuring out, at what speed the mod wheel gets turned down and let it decide, wether a release sample would be appropriate or not, determined by speed and amount of send byte 2 decrease. Then I thought, maybe this might lead to many unwanted results, as no script could ever really understand the intended performance of a player. So, i came up with a real easy method: There would just be an empty key or a pedal CC that tells the script to fire a release sample for all currently held notes. I am pretty sure, that would not be a gigantic effort to script (even I might do it).
On the other hand, Guy Roland insisted, he would like to see a script, that figures it out by itself. He added, there could be a 0db release sample get fired at a certain threshold, that gets faded in by the script, according to the amount and time of dynamics decrease. I am not sure, if something like that could offer satisfying results. Not sure either, if it would sound anywhere near real ...
Hence, my question: Has something like that been tried? How difficult might it be to script it?


----------



## Simon Ravn (Feb 26, 2013)

Without knowing it, I can imagine it will be really tough to make a script know when it is appropriate to use a release sample in this situation or not - also, I am not sure it will sound good. There are so many variables here; what state of x-fading are the different layers in, which release samples should be used, at what speed does it make sense to do this at all etc. In any case, release samples will in some settings be "fired off" left and right and I don't think that will have a good impact on sound. I think it could clutter up the sound a lot - and then we are not even discussion how much extra noise it will introduce, how it will affect your systems performance etc.

I think there are some limitations we will have to accept like these, and personally I would rather have a "semi wet" recording that still relies on a final hall reverb/ambience of my choice, than having something that doesn't require reverb at all - for the reasons you describe. And Air IS a studio - it makes perfect sense for me to use some combination of Spitfires mic choices and then add my hall reverb in the end.


----------



## Guy Rowland (Feb 26, 2013)

Simon Ravn @ Tue Feb 26 said:


> Without knowing it, I can imagine it will be really tough to make a script know when it is appropriate to use a release sample in this situation or not - also, I am not sure it will sound good. There are so many variables here; what state of x-fading are the different layers in, which release samples should be used, at what speed does it make sense to do this at all etc. In any case, release samples will in some settings be "fired off" left and right and I don't think that will have a good impact on sound. I think it could clutter up the sound a lot - and then we are not even discussion how much extra noise it will introduce, how it will affect your systems performance etc



Hmm, I'm nowhere near as pessimistic as you, but ultimately the only way to find out is to try it. I think you can make intelligent guesses at the answers to most of your questions / scenarios. For example, I think it's only really an issue when dialling down from F quickly, so the only releases you'd probably need are the F ones. My idea of them fading in dependent on speed rather than just triggering should stop them sounding like they are just fired off.

I'd love to hear a test on this. I don't program myself, but I'd have thought the scripting wouldn't be too complex. There are two elements really (chosing guesswork figures for an example - if CC1> 100 and falls, then trigger the release sample at zero level, then if the rate of change is quick, fade up the release triggers. Dunno, perhaps that is hard, a Kontakt expert might enlighten me!


----------



## Sasje (Feb 26, 2013)

On the first glance it doesn't seem that difficult. I think you can get away fairly well with using fade_in() and fade_out(). And it's easy to get the CC value to script it. You can do it on a modwheel action, or simply register a listener that checks every _n _ms and does something.

Can you post a less cryptic/descriptive and a more functional explanation? in steps? maybe I can write something if you would like.


----------



## FriFlo (Feb 26, 2013)

If you would try this, I suggest starting with something like that:

First condition: any number of notes held (array, to determine which ones)
Second condition: Mod wheel gets turned down from a value between roughly 100-127 (max value)
-> note_on to release (velocity of the peak mod wheel value) sample, playing at 0db.
If mod wheel reaches a value of <max value> - 20 within 300 milliseconds (<fp_time>, fade into the release sample. fade_in time could be dependent on <fp_time> ...
As a start i would recommend something like a mod wheel controlled timpani rolls patch with stage miking (Spitfire percussion or Project sam, ...). Of course, the library would need recorded release samples (the reverberation in the hall, after the instrument was stopped).


----------



## FriFlo (Feb 26, 2013)

Well, I changed my mind: Timpani wouldn't do it, unless it is a recorded release of the hall alone (without the drum itself decaying). Better starting point would be something like a dyn controlled brass patch (like symphobia or spitfire albion).


----------



## Sasje (Feb 26, 2013)

Not sure if this is as you want, and haven't tested it. It's a bit difficult if I don't have an instrument to work on, so I'm just guessing here.

It basically uses two groups in the group editor: 0 & 1. Group 0 contains the samples, group 1 contains the release samples. If you press a key it should play a note in group 0. On a modwheel action below 20 AND when you release a key, it will fade in the release. At least, that's how the code below should work. A timer also runs which keeps track on how long a note was held. Currently it does nothing with that information.



```
on init
	declare const $C := 8
	declare $release :=0
	declare $counter :=0
	declare $note
	set_listener($NI_SIGNAL_TIMER_BEAT, $C)
end on

on note 

	$counter :=0
	disallow_group($ALL_GROUPS) 
	set_event_par_arr($EVENT_ID,$EVENT_PAR_ALLOW_GROUP,1,0)
	ignore_event($EVENT_ID) 
	play_note($EVENT_NOTE,$EVENT_VELOCITY,0,-1)
 
	while($NOTE_HELD = 1) 
		$counter := $counter+1
		wait(100000)
		end while
	end on

on listener
	message($counter)
end on

on controller 
	if(%CC[1] <= 20)
	$release := 1
	else
	$release := 0
	end if
end on

on release
	if($release = 1)
		disallow_group($ALL_GROUPS) 
		set_event_par_arr($EVENT_ID,$EVENT_PAR_ALLOW_GROUP,1,1)
		ignore_event($EVENT_ID) 
		$note := play_note($EVENT_NOTE,$EVENT_VELOCITY,0,-1) 
		fade_in ($note,1000000) 
	end if
end on
```

I'm sorry if it isn't what you meant. Have had a long day at work. But I think it can be of use, with a little tweaking, no? :D


----------



## FriFlo (Feb 26, 2013)

Sasje, thank you for your effort. Right now, I am afraid I don't have the time to really dig deep into this. I can write multiscripts, but I never wrote a instrument script. The midi-commands are completely different there and I would need a lot of time to get behind that and all the parameters I never used so far.
I did test the script, though. I am not sure what it does, but it does not, what I described, I am afraid ... 

Let's wait and see ... maybe I find some time to do it myself! Or someone else does ...


----------



## Sasje (Feb 27, 2013)

Okay, it does control the release sample with the modwheel. If I understand it correctly, you just need to adjust the value on which it will release a release-sample. Correct? 

I just tried it with two groups, and it seems it does just that:

1. hold a key
2. turn down the modwheel (which determines if a release sample should be played)
3. release key
4. release sample is played.

With this, I managed to get a release sample on a Piano that played throughout me playing higher notes. Emulating the effect of "ringing on" i.e. "more dynamics" on release, throughout the other notes. I thought that was the point?

Btw, I am not sure what you mean by a 0db sample? what does it needs to do, if you can just fade in a release with a wait() statement? :D


----------



## FriFlo (Feb 27, 2013)

I am sorry, Sasje! I should have explained this a little better, as it is quite complicated and special:

1) The problem: If you have orchestral samples that are dynamically controlled by modwheel (or other CC), they have a certain amount of dynamic layers (let's say 3 for the sake of an example). These are all played on note on events and the controller dynamically fades between those samples. When this patch is recorded with a stage microphone setting (I called these "wet" libraries), they always have dedicated release samples that capture the decay of the hall. In most cases, there are as many release samples, as there are dynamic layers, so in our example that would be 3 again.

Now, imagine a trombone playing a slow crescendo and at peak rapidly going piano - all in one blow: Two things would combine to your listening experience of that in an orchestral hall. you would hear the direct sound from the trombone and you would hear the reverberation of the hall. Now try doing that with a "wet" sample library! While a single fff note would sound perfectly (well, almost) like a real recording of the same player (Sample of the fff-recording and at the end a release sample of the decaying reverb of that note), in the case of my example it would sound quite different! Here is why: when the crescendo builds up, everything is ok, as the direct sound from the trombone gets louder. But than, at the fp moment we have a problem: The complete sound fades to piano immediately (including the reverb of the hall), while in reality, you would hear the the reverb of the fff note decaying (and for a moment even concealing) the direct sound from the trombone playing quietly.
This problem would not be there with a library recorded dry, but there are other reasons for some people to prefer wet libraries. 

2) My idea to solve this issue: In my example there is only one moment, where this becomes really obvious to the ear and that is the fp - the moment where the virtual trombone player would pull down his mod wheel more or less abruptly. If there would be a way to fire a release sample of the same note at the moment of peak volume, this should - at least in theory- come very close to the sound of the real player recorded. When i have the time, I will try this out first, because the sonic result can easily be tested without any scripting at all. However, there could be different ways of including this in a script ...

3) The easy way: Even I could script this with a little practice, i suppose. I would use the note_held condition to determine which notes are currently active. I would declare an empty key on the keyboard (not within playing range) as a trigger and this trigger would cause release samples (not note offs!!!) of the according pitches with the current mod wheel velocity immediately. So ... your script is kind of close to that, but not quite the same, as you see. It might be interesting for other applications, though!

4) The hard (and good?) way: Of course it sucks, having to trigger that manually. So, I thought, maybe a script could figure it out for you automatically, but this is were it gets ugly! o/~ 
IMO something like this could work: A script figures out, when a certain threshold of mod wheel is reached - let's say 100 (condition one). Then it figures out when there is a turn of direction of at least 20 steps down within a certain amount of time (e.g. 200ms)(condition 2). At this moment, a release sample of all currently held notes is triggered (again: NOT a note off, as the note is supposed to play on). The release sample should probably have some kind of short attack phase, to blend better with the continuing note - just speculation!
I hope you understand, this would - at least in theory -lead to the same aural sensation as the real player doing it on a recording. That is the holy-grail-script we thought about ...

Cheers,

Fritz.


----------



## Sasje (Mar 2, 2013)

Hi Fritz,

It comes close to what my script currently does.  We can change it a little bit, and I think it then will work. It is easy to figure out what the modwheel is doing. Then we just need to get a timer listening and play the appropriate releases when it needs to. Should be a small correction to the script.


----------



## Pzy-Clone (Mar 29, 2013)

You guys are looking for complicated solutions to a simple problem..., just stick a max lag number of 4999 on the release trail groups envelope crossfades. Problem solved


----------

