Skip to content

Commit

Permalink
🐛 Fix the out of range bug
Browse files Browse the repository at this point in the history
  • Loading branch information
AutumnSky1010 committed Dec 4, 2024
1 parent ea42889 commit d651507
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/SoundMaker/Sounds/TrackBaseSound.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public MonauralWave GenerateMonauralWave()
// 最大の終了時インデクスを取得する
var maxEndIndex = _tracksTimeMap
.SelectMany(pair => pair.Value)
.Sum(track => track.EndIndex);
.Max(track => track.EndIndex);

var wave = new double[maxEndIndex + 1];

Expand All @@ -229,7 +229,7 @@ public MonauralWave GenerateMonauralWave()
var trackWave = track.GenerateWave();
for (int i = track.StartIndex; i <= track.EndIndex; i++)
{
wave[i] += trackWave[i];
wave[i] += trackWave[i - track.StartIndex];
}
}
}
Expand All @@ -255,7 +255,7 @@ public StereoWave GenerateStereoWave()
// 最大の終了時インデクスを取得する
var maxEndIndex = _tracksTimeMap
.SelectMany(pair => pair.Value)
.Sum(track => track.EndIndex);
.Max(track => track.EndIndex);

var right = new double[maxEndIndex + 1];
var left = new double[maxEndIndex + 1];
Expand All @@ -268,8 +268,8 @@ public StereoWave GenerateStereoWave()
var pan = (track.Pan + 1) / 2.0f;
for (int i = track.StartIndex; i <= track.EndIndex; i++)
{
right[i] += trackWave[i] * pan;
left[i] += trackWave[i] * (1 - pan);
right[i] += trackWave[i - track.StartIndex] * pan;
left[i] += trackWave[i - track.StartIndex] * (1 - pan);
}
}
}
Expand Down

0 comments on commit d651507

Please sign in to comment.