Skip to content

Commit 51e2ef3

Browse files
committed
Bug Fix: 24-bit samples no longer produce erroneous values for samples with values of 1.0
1 parent e7af11c commit 51e2ef3

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

AudioFile.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ bool AudioFile<T>::saveToWaveFile (std::string filePath)
954954
}
955955
else if (bitDepth == 24)
956956
{
957-
int32_t sampleAsIntAgain = (int32_t) (samples[channel][i] * (T)8388608.);
957+
int32_t sampleAsIntAgain = (int32_t) (samples[channel][i] * (T)8388607.);
958958

959959
uint8_t bytes[3];
960960
bytes[2] = (uint8_t) (sampleAsIntAgain >> 16) & 0xFF;
@@ -1064,7 +1064,7 @@ bool AudioFile<T>::saveToAiffFile (std::string filePath)
10641064
}
10651065
else if (bitDepth == 24)
10661066
{
1067-
int32_t sampleAsIntAgain = (int32_t) (samples[channel][i] * (T)8388608.);
1067+
int32_t sampleAsIntAgain = (int32_t) (samples[channel][i] * (T)8388607.);
10681068

10691069
uint8_t bytes[3];
10701070
bytes[0] = (uint8_t) (sampleAsIntAgain >> 16) & 0xFF;
@@ -1322,7 +1322,7 @@ int32_t AudioFile<T>::sampleToTwentyFourBitInt (T sample)
13221322
if (std::is_floating_point<T>::value)
13231323
{
13241324
sample = clamp (sample, -1., 1.);
1325-
return static_cast<int32_t> (sample * 8388608.);
1325+
return static_cast<int32_t> (sample * 8388607.);
13261326
}
13271327
else
13281328
{

0 commit comments

Comments
 (0)