Skip to content

Commit

Permalink
Pcm.Compoundメソッドを修正 (#711)
Browse files Browse the repository at this point in the history
* Pcm.Compoundメソッドを修正

* Fix Pcm.Compound
  • Loading branch information
yuto-trd authored Sep 12, 2023
1 parent 78d10a1 commit d131b94
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/Beutl.Engine/Media/Music/Pcm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,21 @@ public void Compound(Pcm<T> sound)
{
if (sound.SampleRate != SampleRate) throw new Exception("Sounds with different SampleRates cannot be synthesized.");

Parallel.For(0, Math.Min(sound.NumSamples, NumSamples), i => DataSpan[i] = T.Compound(DataSpan[i], sound.DataSpan[i]));
Compound(0, sound);
}

public void Compound(int start, Pcm<T> sound)
{
if (sound.SampleRate != SampleRate) throw new Exception("Sounds with different SampleRates cannot be synthesized.");

Parallel.For(
start,
Math.Min(sound.NumSamples, NumSamples),
i => DataSpan[i] = T.Compound(DataSpan[i], sound.DataSpan[i - start]));
Parallel.For(start, NumSamples, i =>
{
int j = i - start;
if (j < sound.NumSamples)
{
DataSpan[i] = T.Compound(DataSpan[i], sound.DataSpan[j]);
}
});
}

public Pcm<T> Resamples(int frequency)
Expand Down

0 comments on commit d131b94

Please sign in to comment.