コミットメタ情報

リビジョンabd87e301a865a1a472ad3f8085aa099c474059d (tree)
日時2018-07-28 22:31:20
作者Starg <starg@user...>
コミッターStarg

ログメッセージ

[dls] Fix audio glitches

変更サマリ

差分

--- a/timidity/dls.cpp
+++ b/timidity/dls.cpp
@@ -372,7 +372,7 @@ public:
372372
373373 pSample->data = reinterpret_cast<sample_t*>(waveInfo.pData.release());
374374 pSample->data_alloced = 1;
375- pSample->data_length = static_cast<splen_t>(waveInfo.DataLength) << FRACTION_BITS;
375+ pSample->data_length = static_cast<splen_t>(waveInfo.DataLength + 1) << FRACTION_BITS;
376376 pSample->data_type = SAMPLE_TYPE_INT16;
377377 pSample->sample_rate = static_cast<std::int32_t>(waveInfo.SamplesPerSec);
378378
@@ -409,8 +409,12 @@ public:
409409 pSample->volume = 1.0;
410410 }
411411
412- pSample->loop_start = std::clamp<splen_t>(loop.LoopStart, 0, waveInfo.DataLength) << FRACTION_BITS;
413- pSample->loop_end = std::clamp<splen_t>(loop.LoopStart + loop.LoopLength, loop.LoopStart, waveInfo.DataLength) << FRACTION_BITS;
412+ pSample->loop_start = std::clamp<splen_t>(loop.LoopStart, 0, waveInfo.DataLength - 1) << FRACTION_BITS;
413+ pSample->loop_end = std::clamp(
414+ pSample->loop_start + (static_cast<splen_t>(loop.LoopLength) << FRACTION_BITS),
415+ pSample->loop_start + (1 << FRACTION_BITS),
416+ pSample->data_length
417+ );
414418
415419 pSample->root_freq = ::freq_table[pSample->root_key];
416420 }
@@ -1465,6 +1469,11 @@ private:
14651469 waveInfo.BlockAlign = ReadUInt16(pFile.get());
14661470 waveInfo.BitsPerSample = ReadUInt16(pFile.get());
14671471
1472+ if (waveInfo.BitsPerSample != 8 && waveInfo.BitsPerSample != 16)
1473+ {
1474+ throw DLSParserException(m_FileName, "unsupported bit rate");
1475+ }
1476+
14681477 DoSkip(pFile.get(), Align2(chunkSize) - 16);
14691478 }
14701479 else
@@ -1481,7 +1490,9 @@ private:
14811490 {
14821491 std::uint32_t chunkSize = ReadUInt32(pFile.get());
14831492 listSize -= 4;
1484- waveInfo.pData.reset(reinterpret_cast<char*>(safe_malloc(chunkSize)));
1493+
1494+ std::size_t bufferSize = chunkSize + 128 * 2;
1495+ waveInfo.pData.reset(reinterpret_cast<char*>(safe_large_malloc(bufferSize)));
14851496
14861497 #ifdef LITTLE_ENDIAN
14871498 if (::tf_read(waveInfo.pData.get(), 1, chunkSize, pFile.get()) != chunkSize)
@@ -1494,6 +1505,7 @@ private:
14941505 reinterpret_cast<std::uint16_t*>(waveInfo.pData.get())[i] = ReadUInt16(pFile.get());
14951506 }
14961507 #endif
1508+ std::memset(waveInfo.pData.get() + chunkSize, 0, bufferSize - chunkSize);
14971509 waveInfo.DataLength = chunkSize;
14981510
14991511 if (chunkSize & 1)
旧リポジトリブラウザで表示