@@ -307,7 +307,7 @@ dsp::wav::LoadReturnCode ReadDataChunk(std::ifstream& wavFile, WaveFileData& wfd
307307 if (audioFormat == AUDIO_FORMAT_IEEE)
308308 {
309309 if (wfd.fmtChunk .bitsPerSample == 32 )
310- dsp::wav::_LoadSamples32 (wavFile, wfd.dataChunk .size , audio);
310+ dsp::wav::_LoadSamples32FloatingPoint (wavFile, wfd.dataChunk .size , audio);
311311 else
312312 {
313313 std::cerr << " Error: Unsupported bits per sample for IEEE files: " << wfd.fmtChunk .bitsPerSample << std::endl;
@@ -321,7 +321,7 @@ dsp::wav::LoadReturnCode ReadDataChunk(std::ifstream& wavFile, WaveFileData& wfd
321321 else if (wfd.fmtChunk .bitsPerSample == 24 )
322322 dsp::wav::_LoadSamples24 (wavFile, wfd.dataChunk .size , audio);
323323 else if (wfd.fmtChunk .bitsPerSample == 32 )
324- dsp::wav::_LoadSamples32 (wavFile, wfd.dataChunk .size , audio);
324+ dsp::wav::_LoadSamples32FixedPoint (wavFile, wfd.dataChunk .size , audio);
325325 else
326326 {
327327 std::cerr << " Error: Unsupported bits per sample for PCM files: " << wfd.fmtChunk .bitsPerSample << std::endl;
@@ -456,10 +456,25 @@ int dsp::wav::_ReadSigned24BitInt(std::ifstream& stream)
456456 return value;
457457}
458458
459- void dsp::wav::_LoadSamples32 (std::ifstream& wavFile, const int chunkSize, std::vector<float >& samples)
459+ void dsp::wav::_LoadSamples32FloatingPoint (std::ifstream& wavFile, const int chunkSize, std::vector<float >& samples)
460460{
461461 // NOTE: 32-bit is float.
462462 samples.resize (chunkSize / 4 ); // 32 bits (4 bytes) per sample
463463 // Read the samples from the file into the array
464464 wavFile.read (reinterpret_cast <char *>(samples.data ()), chunkSize);
465465}
466+
467+ void dsp::wav::_LoadSamples32FixedPoint (std::ifstream& wavFile, const int chunkSize, std::vector<float >& samples)
468+ {
469+ // Allocate an array to hold the samples
470+ std::vector<int > tmp (chunkSize / 4 ); // 32 bits (4 bytes) per sample
471+
472+ // Read the samples from the file into the array
473+ wavFile.read (reinterpret_cast <char *>(tmp.data ()), chunkSize);
474+
475+ // Copy into the return array
476+ const float scale = 1.0 / ((double )(1 << 31 )); // 2^31 for 32-bit fixed point
477+ samples.resize (tmp.size ());
478+ for (auto i = 0 ; i < samples.size (); i++)
479+ samples[i] = scale * ((float )tmp[i]);
480+ }
0 commit comments