Skip to content

Commit cf99a8c

Browse files
committed
Correctly calculate frame counts when reading WAV files
1 parent 7b2d1e9 commit cf99a8c

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/Editor/LoadWav.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,10 @@ int WavLoader::readFrames(int frames, short* buffer)
5555
{
5656
int numFramesToRead = min(numFramesLeft, frames);
5757
numFramesLeft -= numFramesToRead;
58-
file.read(reinterpret_cast<char*>(buffer), bytesPerSample * numChannels * numFramesToRead);
59-
return static_cast<int>(file.gcount());
58+
59+
std::streamsize bytesPerFrame = static_cast<std::streamsize>(bytesPerSample) * numChannels;
60+
file.read(reinterpret_cast<char*>(buffer), bytesPerFrame * numFramesToRead);
61+
return static_cast<int>(file.gcount() / bytesPerFrame);
6062
}
6163

6264
}; // anonymous namespace

0 commit comments

Comments
 (0)