maybe fix sample corruption when resampling 8-bit

This commit is contained in:
tildearrow 2023-01-15 17:27:16 -05:00
parent 3174638120
commit 6834b3b7db

View file

@ -827,18 +827,15 @@ bool DivSample::resampleBlep(double r) {
unsigned int posInt=0; unsigned int posInt=0;
double factor=r/(double)rate; double factor=r/(double)rate;
float* sincITable=DivFilterTables::getSincIntegralTable(); float* sincITable=DivFilterTables::getSincIntegralTable();
float s[16];
memset(s,0,16*sizeof(float)); float* floatData=new float[finalCount];
memset(floatData,0,finalCount*sizeof(float));
if (depth==DIV_SAMPLE_DEPTH_16BIT) { if (depth==DIV_SAMPLE_DEPTH_16BIT) {
memset(data16,0,finalCount*sizeof(short)); memset(data16,0,finalCount*sizeof(short));
for (int i=0; i<finalCount; i++) { for (int i=0; i<finalCount; i++) {
if (posInt<samples) { if (posInt<samples) {
int result=data16[i]+oldData16[posInt]; data16[i]=oldData16[posInt];
if (result<-32768) result=-32768;
if (result>32767) result=32767;
data16[i]=result;
} }
posFrac+=1.0; posFrac+=1.0;
@ -853,28 +850,25 @@ bool DivSample::resampleBlep(double r) {
for (int j=0; j<8; j++) { for (int j=0; j<8; j++) {
if (i-j>0) { if (i-j>0) {
float result=data16[i-j]+t1[j]*-delta; floatData[i-j]+=t1[j]*-delta;
if (result<-32768) result=-32768;
if (result>32767) result=32767;
data16[i-j]=result;
} }
if (i+j+1<finalCount) { if (i+j+1<finalCount) {
float result=data16[i+j+1]+t2[j]*delta; floatData[i+j+1]+=t2[j]*delta;
if (result<-32768) result=-32768;
if (result>32767) result=32767;
data16[i+j+1]=result;
} }
} }
} }
} }
for (int i=0; i<finalCount; i++) {
float result=floatData[i]+data16[i];
if (result<-32768) result=-32768;
if (result>32767) result=32767;
data16[i]=round(result);
}
} else if (depth==DIV_SAMPLE_DEPTH_8BIT) { } else if (depth==DIV_SAMPLE_DEPTH_8BIT) {
memset(data8,0,finalCount); memset(data8,0,finalCount);
for (int i=0; i<finalCount; i++) { for (int i=0; i<finalCount; i++) {
if (posInt<samples) { if (posInt<samples) {
int result=data8[i]+oldData8[posInt]; data8[i]=oldData8[posInt];
if (result<-128) result=-128;
if (result>127) result=127;
data8[i]=result;
} }
posFrac+=1.0; posFrac+=1.0;
@ -889,20 +883,20 @@ bool DivSample::resampleBlep(double r) {
for (int j=0; j<8; j++) { for (int j=0; j<8; j++) {
if (i-j>0) { if (i-j>0) {
float result=data8[i-j]+t1[j]*-delta; floatData[i-j]+=t1[j]*-delta;
if (result<-128) result=-128;
if (result>127) result=127;
data8[i-j]=result;
} }
if (i+j+1<finalCount) { if (i+j+1<finalCount) {
float result=data8[i+j+1]+t2[j]*delta; floatData[i+j+1]+=t2[j]*delta;
if (result<-128) result=-128;
if (result>127) result=127;
data8[i+j+1]=result;
} }
} }
} }
} }
for (int i=0; i<finalCount; i++) {
float result=floatData[i]+data16[i];
if (result<-128) result=-128;
if (result>127) result=127;
data16[i]=round(result);
}
} }
RESAMPLE_END; RESAMPLE_END;