Hi,
Why are you using a lookup table and not just a log10(x) and 10^(x) for the gain <-> dB conversions? That's how it should be done I think like 10x corresponding to 20dB (assuming signal gain). In your tests it is just: 2000*log10(gain) - 9630 for going to that dB-like scale.
Regards, Roderick