DitherFloat update

This commit is contained in:
Chris Johnson 2019-02-19 08:35:31 -05:00
parent e5da517d26
commit 83f022409a
15 changed files with 234 additions and 158 deletions

View file

@ -14,8 +14,7 @@ DitherFloat::DitherFloat(audioMasterCallback audioMaster) :
{
A = 0.0;
B = 1.0;
fpNShapeL = 0.0;
fpNShapeR = 0.0;
fpd = 17;
//this is reset: values being initialized only once. Startup values, whatever they are.
_canDo.insert("plugAsChannelInsert"); // plug-in can be used as a channel insert effect.

View file

@ -53,8 +53,7 @@ private:
char _programName[kVstMaxProgNameLen + 1];
std::set< std::string > _canDo;
long double fpNShapeL;
long double fpNShapeR;
uint32_t fpd;
//default stuff
float A;

View file

@ -67,16 +67,15 @@ void DitherFloat::processReplacing(float **inputs, float **outputs, VstInt32 sam
long double inputSampleR = *in2 + (gain-1);
//stereo 32 bit dither, made small and tidy.
//begin stereo 32 bit floating point dither
int expon; frexpf((float)inputSampleL, &expon);
long double dither = (rand()/(RAND_MAX*7.737125245533627e+25))*pow(2,expon+62) * blend; //remove 'blend' for real use, it's for the demo;
inputSampleL += (dither-fpNShapeL); fpNShapeL = dither;
fpd ^= fpd<<13; fpd ^= fpd>>17; fpd ^= fpd<<5;
inputSampleL += (fpd*3.4e-36l*pow(2,expon+62)* blend); //remove 'blend' for real use, it's for the demo;
frexpf((float)inputSampleR, &expon);
dither = (rand()/(RAND_MAX*7.737125245533627e+25))*pow(2,expon+62) * blend; //remove 'blend' for real use, it's for the demo;
inputSampleR += (dither-fpNShapeR); fpNShapeR = dither;
//end 32 bit dither
fpd ^= fpd<<13; fpd ^= fpd>>17; fpd ^= fpd<<5;
inputSampleR += (fpd*3.4e-36l*pow(2,expon+62)* blend); //remove 'blend' for real use, it's for the demo;
//end stereo 32 bit floating point dither
inputSampleL = (float)inputSampleL; //equivalent of 'floor' for 32 bit floating point
@ -154,15 +153,14 @@ void DitherFloat::processDoubleReplacing(double **inputs, double **outputs, VstI
//stereo 32 bit dither, made small and tidy.
//begin stereo 32 bit floating point dither
int expon; frexpf((float)inputSampleL, &expon);
long double dither = (rand()/(RAND_MAX*7.737125245533627e+25))*pow(2,expon+62) * blend; //remove 'blend' for real use, it's for the demo;
inputSampleL += (dither-fpNShapeL); fpNShapeL = dither;
fpd ^= fpd<<13; fpd ^= fpd>>17; fpd ^= fpd<<5;
inputSampleL += (fpd*3.4e-36l*pow(2,expon+62)* blend); //remove 'blend' for real use, it's for the demo;
frexpf((float)inputSampleR, &expon);
dither = (rand()/(RAND_MAX*7.737125245533627e+25))*pow(2,expon+62) * blend; //remove 'blend' for real use, it's for the demo;
inputSampleR += (dither-fpNShapeR); fpNShapeR = dither;
//end 32 bit dither
fpd ^= fpd<<13; fpd ^= fpd>>17; fpd ^= fpd<<5;
inputSampleR += (fpd*3.4e-36l*pow(2,expon+62)* blend); //remove 'blend' for real use, it's for the demo;
//end stereo 32 bit floating point dither
inputSampleL = (float)inputSampleL; //equivalent of 'floor' for 32 bit floating point