diff --git a/Exchange/DereTore.Exchange.Audio.HCA/HcaAudioStream.cs b/Exchange/DereTore.Exchange.Audio.HCA/HcaAudioStream.cs index 03b4bc6..dc48c0a 100644 --- a/Exchange/DereTore.Exchange.Audio.HCA/HcaAudioStream.cs +++ b/Exchange/DereTore.Exchange.Audio.HCA/HcaAudioStream.cs @@ -143,7 +143,7 @@ public override long Length { var waveDataBlockSize = _decoder.GetMinWaveDataBufferSize(); totalLength += waveDataBlockSize * hcaInfo.BlockCount; if (HasLoop && audioParams.SimulatedLoopCount > 0) { - var loopedBlockCount = hcaInfo.LoopEnd - hcaInfo.LoopStart + 1; + var loopedBlockCount = hcaInfo.LoopEnd - hcaInfo.LoopStart; totalLength += waveDataBlockSize * loopedBlockCount * audioParams.SimulatedLoopCount; } _length = totalLength; @@ -201,7 +201,7 @@ private void EnsureSoundDataDecodedWithLoops(long waveDataOffset, int byteCount) var audioParams = _audioParams; var decodedSize = (waveDataOffset - headerSize) / waveBlockSize * waveBlockSize; // For those before or in the loop range... - if (audioParams.InfiniteLoop || startBlockIndex <= hcaInfo.LoopEnd + (hcaInfo.LoopEnd - hcaInfo.LoopStart + 1) * audioParams.SimulatedLoopCount) { + if (audioParams.InfiniteLoop || startBlockIndex <= hcaInfo.LoopEnd - 1 + (hcaInfo.LoopEnd - hcaInfo.LoopStart) * audioParams.SimulatedLoopCount) { var blockIndex = startBlockIndex; var executed = false; while (true) { @@ -218,7 +218,7 @@ private void EnsureSoundDataDecodedWithLoops(long waveDataOffset, int byteCount) EnsureDecodeOneBlock(blockIndex); decodedSize += waveBlockSize; ++blockIndex; - if (blockIndex > hcaInfo.LoopEnd) { + if (blockIndex > hcaInfo.LoopEnd - 1) { blockIndex = hcaInfo.LoopStart; } executed = true; @@ -228,10 +228,10 @@ private void EnsureSoundDataDecodedWithLoops(long waveDataOffset, int byteCount) if (audioParams.InfiniteLoop) { return; } - var endBlockIndex = hcaInfo.LoopEnd + (hcaInfo.LoopEnd - hcaInfo.LoopStart + 1) * audioParams.SimulatedLoopCount; + var endBlockIndex = hcaInfo.LoopEnd - 1 + (hcaInfo.LoopEnd - hcaInfo.LoopStart) * audioParams.SimulatedLoopCount; var startOfAfterLoopRegion = endBlockIndex * waveBlockSize; if (waveDataEnd >= startOfAfterLoopRegion) { - for (var blockIndex = hcaInfo.LoopEnd + 1; blockIndex < hcaInfo.BlockCount && decodedSize < waveDataEnd; ++blockIndex) { + for (var blockIndex = hcaInfo.LoopEnd; blockIndex < hcaInfo.BlockCount && decodedSize < waveDataEnd; ++blockIndex) { EnsureDecodeOneBlock(blockIndex); decodedSize += waveBlockSize; } @@ -261,7 +261,7 @@ private long MapPosToNonLoopedWaveStreamPos(long requestedPosition) { var waveBlockSize = _decoder.GetMinWaveDataBufferSize(); var headerSize = _headerSize; var relativeDataPosition = requestedPosition - headerSize; - var endLoopDataPosition = (hcaInfo.LoopEnd + 1) * waveBlockSize; + var endLoopDataPosition = (hcaInfo.LoopEnd) * waveBlockSize; if (relativeDataPosition < endLoopDataPosition) { return requestedPosition; } diff --git a/Exchange/DereTore.Exchange.Audio.HCA/HcaDecoder.cs b/Exchange/DereTore.Exchange.Audio.HCA/HcaDecoder.cs index 0848261..44eb0f0 100644 --- a/Exchange/DereTore.Exchange.Audio.HCA/HcaDecoder.cs +++ b/Exchange/DereTore.Exchange.Audio.HCA/HcaDecoder.cs @@ -88,7 +88,7 @@ public int WriteWaveHeader(byte[] stream, AudioParams audioParams) { var totalBlockCount = hcaInfo.BlockCount; if (hcaInfo.LoopFlag) { - totalBlockCount += (hcaInfo.LoopEnd - hcaInfo.LoopStart + 1) * audioParams.SimulatedLoopCount; + totalBlockCount += (hcaInfo.LoopEnd - hcaInfo.LoopStart) * audioParams.SimulatedLoopCount; } wavData.DataSize = totalBlockCount * 0x80 * 8 * wavRiff.FmtSamplingSize; wavRiff.RiffSize = (uint)(0x1c + (hcaInfo.Comment != null ? wavNote.NoteSize : 0) + Marshal.SizeOf(wavData) + wavData.DataSize); diff --git a/Exchange/DereTore.Exchange.Audio.HCA/HcaHelper.cs b/Exchange/DereTore.Exchange.Audio.HCA/HcaHelper.cs index e777a00..ae233c2 100644 --- a/Exchange/DereTore.Exchange.Audio.HCA/HcaHelper.cs +++ b/Exchange/DereTore.Exchange.Audio.HCA/HcaHelper.cs @@ -91,7 +91,7 @@ public static uint CalculateLengthInSamples(HcaInfo hcaInfo, uint loopCount, boo return uint.MaxValue; } var totalBlockCount = hcaInfo.BlockCount; - totalBlockCount += (hcaInfo.LoopEnd - hcaInfo.LoopStart + 1) * loopCount; + totalBlockCount += (hcaInfo.LoopEnd - hcaInfo.LoopStart) * loopCount; return totalBlockCount * hcaInfo.ChannelCount * 0x80 * 8; } @@ -104,7 +104,7 @@ public static float CalculateLengthInSeconds(HcaInfo hcaInfo, uint loopCount, bo return float.MaxValue; } var totalBlockCount = hcaInfo.BlockCount; - totalBlockCount += (hcaInfo.LoopEnd - hcaInfo.LoopStart + 1) * loopCount; + totalBlockCount += (hcaInfo.LoopEnd - hcaInfo.LoopStart) * loopCount; return totalBlockCount * 0x80 * 8 / (float)hcaInfo.SamplingRate; }