fix loading of 64-bit float samples
This commit is contained in:
parent
3145ccddcb
commit
1a68d0efe7
|
@ -313,12 +313,18 @@ std::vector<DivSample*> DivEngine::sampleFromFile(const char* path) {
|
|||
logD("sample is 32-bit float");
|
||||
buf=new float[si.channels*si.frames];
|
||||
sampleLen=sizeof(float);
|
||||
} else if ((si.format&SF_FORMAT_SUBMASK)==SF_FORMAT_DOUBLE) {
|
||||
logD("sample is 64-bit float");
|
||||
buf=new float[si.channels*si.frames];
|
||||
sampleLen=sizeof(double);
|
||||
} else {
|
||||
logD("sample is 16-bit signed");
|
||||
buf=new short[si.channels*si.frames];
|
||||
sampleLen=sizeof(short);
|
||||
}
|
||||
if ((si.format&SF_FORMAT_SUBMASK)==SF_FORMAT_PCM_U8 || (si.format&SF_FORMAT_SUBMASK)==SF_FORMAT_FLOAT) {
|
||||
if ((si.format&SF_FORMAT_SUBMASK)==SF_FORMAT_PCM_U8 ||
|
||||
(si.format&SF_FORMAT_SUBMASK)==SF_FORMAT_FLOAT ||
|
||||
(si.format&SF_FORMAT_SUBMASK)==SF_FORMAT_DOUBLE) {
|
||||
if (sf_read_raw(f,buf,si.frames*si.channels*sampleLen)!=(si.frames*si.channels*sampleLen)) {
|
||||
logW("sample read size mismatch!");
|
||||
}
|
||||
|
@ -361,6 +367,19 @@ std::vector<DivSample*> DivEngine::sampleFromFile(const char* path) {
|
|||
sample->data16[index++]=averaged;
|
||||
}
|
||||
delete[] (float*)buf;
|
||||
} else if ((si.format&SF_FORMAT_SUBMASK)==SF_FORMAT_DOUBLE) {
|
||||
for (int i=0; i<si.frames*si.channels; i+=si.channels) {
|
||||
double averaged=0.0f;
|
||||
for (int j=0; j<si.channels; j++) {
|
||||
averaged+=((double*)buf)[i+j];
|
||||
}
|
||||
averaged/=si.channels;
|
||||
averaged*=32767.0;
|
||||
if (averaged<-32768.0) averaged=-32768.0;
|
||||
if (averaged>32767.0) averaged=32767.0;
|
||||
sample->data16[index++]=averaged;
|
||||
}
|
||||
delete[] (double*)buf;
|
||||
} else {
|
||||
for (int i=0; i<si.frames*si.channels; i+=si.channels) {
|
||||
int averaged=0;
|
||||
|
|
Loading…
Reference in a new issue