diff --git a/brew/create_mol.m b/brew/create_mol.m
new file mode 100644
index 0000000..719dbcd
--- /dev/null
+++ b/brew/create_mol.m
@@ -0,0 +1,29 @@
+## Copyright (C) 2023 Jens
+##
+## This program is free software: you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation, either version 3 of the License, or
+## (at your option) any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program. If not, see .
+
+## -*- texinfo -*-
+## @deftypefn {} {@var{retval} =} brewwater_optimizer (@var{input1}, @var{input2})
+##
+## @seealso{}
+## @end deftypefn
+
+## Author: Jens
+## Created: 2023-06-08
+
+function mol = create_mol(indices, quantity, mol_masses)
+ N = length(mol_masses);
+ mol = zeros(1, N);
+ mol(indices) = quantity.*mol_masses(indices);
+endfunction
diff --git a/brew/eval_vecfit.m b/brew/eval_vecfit.m
new file mode 100644
index 0000000..3272e1c
--- /dev/null
+++ b/brew/eval_vecfit.m
@@ -0,0 +1,42 @@
+## Copyright (C) 2023 Jens
+##
+## This program is free software: you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation, either version 3 of the License, or
+## (at your option) any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program. If not, see .
+
+## -*- texinfo -*-
+## @deftypefn {} {@var{retval} =} eval_vecfit (@var{input1}, @var{input2})
+##
+## @seealso{}
+## @end deftypefn
+
+## Author: Jens
+## Created: 2023-06-10
+
+function eval_vecfit ()
+P0 = [-1 -1];
+P1 = [2 4];
+P2 = [4 2];
+
+Pp = [P0; P1; P2];
+
+T = [15 12];
+A = [0 0];
+
+Dn = 1;
+Pa = [0 0 0]';
+
+for i=1:50,
+ [A1, Pa, Dn] = vecfit(Pp,T,A,Pa,0.1.*(1-exp(-Dn)))
+end
+
+endfunction
diff --git a/brew/vecfit.m b/brew/vecfit.m
new file mode 100644
index 0000000..45b55c7
--- /dev/null
+++ b/brew/vecfit.m
@@ -0,0 +1,64 @@
+## Copyright (C) 2023 Jens
+##
+## This program is free software: you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation, either version 3 of the License, or
+## (at your option) any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program. If not, see .
+
+## -*- texinfo -*-
+## @deftypefn {} {@var{retval} =} vecfit (@var{input1}, @var{input2})
+##
+## @seealso{}
+## @end deftypefn
+
+## Author: Jens
+## Created: 2023-06-10
+
+function [P1, Pa1, D] = vecfit (Pp, Pt, P0, Pa0, step)
+
+ # A-Priory state
+ P1 = P0 + sum(Pp.*Pa0);
+
+ # Calc distance to target
+ d = (Pt-P1);
+ D = norm(d);
+ dn = d/D;
+
+ # Find best prototype
+ best_i = 0;
+ best_k = 10000;
+
+ for i=1:size(Pp)(1),
+ p = Pp(i,:);
+ pn = p/norm(p);
+ # compare d and p
+ k = norm(pn - dn);
+ if k < best_k,
+ best_k = k;
+ best_i = i;
+ end
+ end
+
+ # Calc next Pa
+ Pa1 = Pa0;
+
+ if best_i,
+ # Get value from best prototype
+ dps = step*Pp(best_i,:);
+
+ # Update point
+ P1 += dps;
+
+ # Update Point accu
+ Pa1(best_i) += step;
+ end
+
+endfunction
diff --git a/brew/vecfit.m.bak.m b/brew/vecfit.m.bak.m
new file mode 100644
index 0000000..00f5f5f
--- /dev/null
+++ b/brew/vecfit.m.bak.m
@@ -0,0 +1,62 @@
+## Copyright (C) 2023 Jens
+##
+## This program is free software: you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation, either version 3 of the License, or
+## (at your option) any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program. If not, see .
+
+## -*- texinfo -*-
+## @deftypefn {} {@var{retval} =} vecfit (@var{input1}, @var{input2})
+##
+## @seealso{}
+## @end deftypefn
+
+## Author: Jens
+## Created: 2023-06-10
+
+function [P1, dPs] = vecfit (Pt, P0, Pp, step)
+
+ d = Pt-P0;
+ D = norm(d)
+ dn = d/D;
+
+# P1 = P0 + sum(Pp0)
+
+ # Find best prototype
+ best_i = 0;
+ best_k = 10000;
+
+ for i=1:length(Pp),
+ p = Pp(i,:);
+ pn = p/norm(p);
+ # compare d and p
+ k = norm(pn - dn)
+ if k < best_k,
+ best_k = k;
+ best_i = i;
+ end
+ end
+
+ best_i
+ best_k
+
+ P1 = P0;
+ Ps1 = Pp;
+
+ if best_i,
+ ps_best = Pp(best_i,:);
+ dps_best = step*ps_best;
+ Ps1(best_i,:) = Pp(best_i,:) + dps_best;
+ P1 = P0 + dps_best;
+ end
+ dPs = Ps1 - Pp;
+
+endfunction
diff --git a/brew/water_constants.m b/brew/water_constants.m
new file mode 100644
index 0000000..c09ccce
--- /dev/null
+++ b/brew/water_constants.m
@@ -0,0 +1,32 @@
+i_H = 1;
+i_C = 2;
+i_O = 3;
+i_Na = 4;
+i_Cl = 5;
+i_Ca = 6;
+i_Mg = 7;
+i_S = 8;
+i_P = 9;
+i_SIZE = 9;
+
+M_H = 1.00794; % g/mol
+M_C = 12.0107; % g/mol
+M_O = 15.9994; % g/mol
+M_Na = 22.9897; % g/mol
+M_Cl = 35.45; % g/mol
+M_Ca = 40.078; % g/mol
+M_Mg = 24.305; % g/mol
+M_S = 32.06; % g/mol
+M_P = 30.9738; % g/mol
+
+mol_masses = zeros(1, i_SIZE);
+mol_masses(i_H) = M_H;
+mol_masses(i_C) = M_C;
+mol_masses(i_O) = M_O;
+mol_masses(i_Na) = M_Na;
+mol_masses(i_Cl) = M_Cl;
+mol_masses(i_Ca) = M_Ca;
+mol_masses(i_Mg) = M_Mg;
+mol_masses(i_S) = M_S;
+mol_masses(i_P) = M_P;
+
diff --git a/brew/water_optimizer.m b/brew/water_optimizer.m
new file mode 100644
index 0000000..555f953
--- /dev/null
+++ b/brew/water_optimizer.m
@@ -0,0 +1,74 @@
+## Copyright (C) 2023 Jens
+##
+## This program is free software: you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation, either version 3 of the License, or
+## (at your option) any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program. If not, see .
+
+## -*- texinfo -*-
+## @deftypefn {} {@var{retval} =} brewwater_optimizer (@var{input1}, @var{input2})
+##
+## @seealso{}
+## @end deftypefn
+
+## Author: Jens
+## Created: 2023-06-08
+
+function brewwater_optimizer (input1, input2)
+
+# Load constants
+water_constants()
+
+k_ve = 0.25;
+
+m_Ca_0 = 94.0; % mg/l
+m_Mg_0 = 18.1; % mg/l
+m_Na_0 = 3.6; % mg/l
+m_S_0 = 44.1; % mg/l
+m_Cl_0 = 4.6; % mg/l
+k_HCO3_0 = 5.5; % mmol/l
+
+M_CaSO4 = create_mol([i_Ca i_S i_O], [1 1 4], mol_masses)
+M_CaCl2 = create_mol([i_Ca i_Cl], [1 2], mol_masses)
+M_NaCl = create_mol([i_Na i_Cl], [1 1], mol_masses)
+M_MgSO4 = create_mol([i_Mg i_S i_O], [1 1 4], mol_masses)
+M_NaHCO3 = create_mol([i_Na i_H i_C i_O], [1 1 1 3], mol_masses)
+M_H20 = create_mol([i_H i_O], [2 1], mol_masses)
+
+m_CaSO4 = sum(M_CaSO4)
+
+mask = create_mol([i_Ca i_Mg i_S i_Cl i_Na], [1 1 1 1 1], ones(1, length(mol_masses)))
+
+m_empty = create_mol([], [], mol_masses)
+
+molare_masse_H2O = sum(M_H20)
+
+
+T = create_mol([i_Ca i_Mg i_Na i_S i_Cl], [0.05 0.01 0.02 0.05 0.10], mol_masses)
+A = create_mol([i_Ca i_Mg i_Na i_S i_Cl], [0.094 0.018 0.004 0.044 0.005], mol_masses)
+A = 4*T
+
+M_ve = create_mol([i_Ca i_Mg i_Na i_S i_Cl], [1 1 1 1 1]/1000, mol_masses)
+Pa = [0 0 0 0]';
+Pp = [M_CaSO4; M_CaCl2; M_MgSO4; -M_ve];
+
+Pa = [0]';
+Pp = [-M_ve]
+
+Dn = 1;
+while Dn > 0.05,
+ T = T
+ [A1, Pa, Dn] = vecfit(T,A,Pa,Pp, 0.1*Dn)
+end
+
+endfunction
+
+
diff --git a/compressor/cmp_eval.m b/compressor/cmp_eval.m
index eedc779..c2d706c 100644
--- a/compressor/cmp_eval.m
+++ b/compressor/cmp_eval.m
@@ -43,22 +43,23 @@ h_dly = [zeros(1, n_look_ahead-1) 1];
x_dly = filter(h_dly, 1, x);
alpha_a = 5/(time_attack*fs);
-alpha_r = 5/(time_release*fs);
+alpha_r = 5/(time_release*fs);
lev = level_detect(x, alpha_a, alpha_r);
lev_dB = max(-120, 20*log10(lev));
k_makeup_gain = 10^(gain_makeup_dB/20);
-gain1 = min(8, (1/8)./(lev+0.1));
+#gain1 = min(8, (1/8)./(lev+0.1));
[lev_out_dB, gain2_dB] = cmp_gain(R, lev_knee_dB, lev_dB);
gain2 = 10.^(gain2_dB/20);
-y1 = gain1.*x_dly * 2;
+#y1 = gain1.*x_dly * 2;
+
y2 = gain2.*x_dly * k_makeup_gain;
-audiowrite(to_filename_out(filename_in, "gain1"), gain1, fs)
-audiowrite(to_filename_out(filename_in, "gain2"), gain2, fs)
-audiowrite(to_filename_out(filename_in, "out1"), y1, fs)
+#audiowrite(to_filename_out(filename_in, "gain1"), gain1, fs)
+audiowrite(to_filename_out(filename_in, "gain2"), gain2, fs)
+#audiowrite(to_filename_out(filename_in, "out1"), y1, fs)
audiowrite(to_filename_out(filename_in, "out2"), y2, fs)
-audiowrite(to_filename_out(filename_in, "lev"), lev, fs)
+audiowrite(to_filename_out(filename_in, "lev"), lev, fs)
gain_out = [];
gain_in = [];