Fix corruption at the end of WAV playback

This commit is contained in:
Sergeanur
2021-09-20 15:13:15 +03:00
parent 89390a85c3
commit a7b92ebede
2 changed files with 14 additions and 7 deletions
+12 -6
View File
@@ -210,6 +210,7 @@ class CWavFile : public IDecoder
tFormatHeader m_FormatHeader;
uint32 m_DataStartOffset; // TODO: 64 bit?
uint32 m_DataSize;
uint32 m_nSampleCount;
uint32 m_nSamplesPerBlock;
@@ -301,6 +302,7 @@ public:
}
m_DataStartOffset = ftell(m_pFile);
m_DataSize = DataHeader.Size;
m_nSampleCount = DataHeader.Size / m_FormatHeader.BlockAlign * m_nSamplesPerBlock;
m_bIsOpen = true;
@@ -363,7 +365,8 @@ public:
if (m_FormatHeader.AudioFormat == WAVEFMT_PCM)
{
// just read the file and sort the samples
uint32 size = fread(buffer, 1, GetBufferSize(), m_pFile);
uint32 bytesLeft = m_DataSize - (ftell(m_pFile) - m_DataStartOffset);
uint32 size = fread(buffer, 1, Min(GetBufferSize(), bytesLeft), m_pFile);
if (m_FormatHeader.NumChannels == 2)
SortStereoBuffer.SortStereo(buffer, size);
return size;
@@ -391,7 +394,8 @@ public:
{
// read the file
uint8 *pAdpcmBuf = m_pAdpcmBuffer;
if (fread(m_pAdpcmBuffer, 1, m_FormatHeader.BlockAlign, m_pFile) == 0)
uint32 bytesLeft = m_DataSize - (ftell(m_pFile) - m_DataStartOffset);
if (fread(m_pAdpcmBuffer, 1, Min(m_FormatHeader.BlockAlign, bytesLeft), m_pFile) == 0)
return 0;
// get the first sample in adpcm block and initialise the decoder(s)
@@ -1448,11 +1452,13 @@ void CStream::SetVolume(uint32 nVol)
void CStream::SetPan(uint8 nPan)
{
m_nPan = Clamp((int8)nPan - 63, 0, 63);
SetPosition(0, (m_nPan - 63) / 64.0f, 0.0f, Sqrt(1.0f - SQR((m_nPan - 63) / 64.0f)));
int iPan = nPan;
iPan = Clamp(iPan - 63, 0, 63);
SetPosition(0, (iPan - 63) / 64.0f, 0.0f, -Sqrt(1.0f - SQR((iPan - 63) / 64.0f)));
m_nPan = Clamp((int8)nPan + 64, 64, 127);
SetPosition(1, (m_nPan - 63) / 64.0f, 0.0f, Sqrt(1.0f - SQR((m_nPan - 63) / 64.0f)));
iPan = nPan;
iPan = Clamp(iPan + 64, 64, 127);
SetPosition(1, (iPan - 63) / 64.0f, 0.0f, -Sqrt(1.0f - SQR((iPan - 63) / 64.0f)));
m_nPan = nPan;
}
+2 -1
View File
@@ -856,9 +856,9 @@ cSampleManager::Initialise(void)
alcMakeContextCurrent(ALContext);
const char* ext=(const char*)alGetString(AL_EXTENSIONS);
ASSERT(strstr(ext,"AL_SOFT_loop_points")!=NULL);
if ( strstr(ext,"AL_SOFT_loop_points")==NULL )
{
ASSERT(strstr(ext, "AL_SOFT_loop_points") != NULL);
Terminate();
return FALSE;
}
@@ -1749,6 +1749,7 @@ cSampleManager::StartPreloadedStreamedFile(uint8 nStream)
if ( stream->IsOpened() )
{
stream->SetPosMS(0);
stream->Start();
}
}