From 45de876614cf68c8a7d7032f334c414dafdefcd8 Mon Sep 17 00:00:00 2001 From: indigo-san Date: Tue, 12 Sep 2023 22:39:29 +0900 Subject: [PATCH 1/2] =?UTF-8?q?Pcm.Compound=E3=83=A1=E3=82=BD=E3=83=83?= =?UTF-8?q?=E3=83=89=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Beutl.Engine/Media/Music/Pcm.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Beutl.Engine/Media/Music/Pcm.cs b/src/Beutl.Engine/Media/Music/Pcm.cs index bf94e24cd..b690a5372 100644 --- a/src/Beutl.Engine/Media/Music/Pcm.cs +++ b/src/Beutl.Engine/Media/Music/Pcm.cs @@ -138,10 +138,14 @@ public void Compound(int start, Pcm 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 Resamples(int frequency) From 9f30c68c047cfbf24873c90549284265ef0508fb Mon Sep 17 00:00:00 2001 From: indigo-san Date: Tue, 12 Sep 2023 22:41:11 +0900 Subject: [PATCH 2/2] Fix Pcm.Compound --- src/Beutl.Engine/Media/Music/Pcm.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Beutl.Engine/Media/Music/Pcm.cs b/src/Beutl.Engine/Media/Music/Pcm.cs index b690a5372..cf25b87fa 100644 --- a/src/Beutl.Engine/Media/Music/Pcm.cs +++ b/src/Beutl.Engine/Media/Music/Pcm.cs @@ -131,7 +131,7 @@ public void Compound(Pcm 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 sound)