#This work is licensed under the
#Creative Commons Attribution-Share Alike 3.0 United States License.
#To view a copy of this license, visit
#http://creativecommons.org/licenses/by-sa/3.0/us/ or send a letter to
#Creative Commons,
#171 Second Street, Suite 300,
#San Francisco, California, 94105, USA.

INPUT decorrelated_sample,correlated,decorrelation_weight,decorrelation_delta;
OUTPUT "an updated decorrelation weight value";
VAR decorrelated_sample "decorrelated sample";
VAR correlated "correlated sample";
VAR decorrelation_weight "decorrelation weight";
VAR decorrelation_delta "decorrelation delta";
if (decorrelated_sample == 0) or (correlated == 0) {
    return decorrelation_weight;
} elif (decorrelated_sample > 0) and (correlated > 0) /*both positive*/ {
    return decorrelation_weight + decorrelation_delta;
} elif (decorrelated_sample > 0) and (correlated < 0) /*one positive*/ {
    return decorrelation_weight - decorrelation_delta;
} elif (decorrelated_sample < 0) and (correlated > 0) /*one positive*/ {
    return decorrelation_weight - decorrelation_delta;
} elif (decorrelated_sample < 0) and (correlated < 0) /*both negative*/ {
    return decorrelation_weight + decorrelation_delta;
}
