This repository was archived by the owner on Mar 18, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +23
-6
lines changed
Expand file tree Collapse file tree 2 files changed +23
-6
lines changed Original file line number Diff line number Diff line change @@ -54,7 +54,7 @@ func (m *MixBuffer) MixInSample(d SampleMixIn) {
5454 pos := d .MixPos
5555 for i := 0 ; i < d .MixLen ; i ++ {
5656 sdata := d .Sample .GetSample ()
57- samp := d . StaticVol . Apply ( sdata ... )
57+ samp := sdata . ApplyInSitu ( d . StaticVol )
5858 mixed := d .VolMatrix .Apply (samp ... )
5959 for c , s := range mixed {
6060 (* m )[c ][pos ] += s
Original file line number Diff line number Diff line change @@ -62,17 +62,34 @@ func (v Volume) Apply(samp ...Volume) Matrix {
6262 return o
6363}
6464
65- // Apply takes a volume matrix and multiplies it my incoming volumes
65+ // Apply takes a volume matrix and multiplies it by incoming volumes
6666func (m Matrix ) Apply (samp ... Volume ) Matrix {
6767 o := make (Matrix , len (m ))
68- for _ , s := range samp {
69- for i , v := range s .Apply (m ... ) {
70- o [i ] += v
71- }
68+ v := Matrix (samp ).Sum ()
69+ for i , s := range v .Apply (m ... ) {
70+ o [i ] = s
7271 }
7372 return o
7473}
7574
75+ // ApplyInSitu takes a volume matrix and multiplies it by incoming volumes
76+ func (m Matrix ) ApplyInSitu (samp ... Volume ) Matrix {
77+ v := Matrix (samp ).Sum ()
78+ for i , s := range v .Apply (m ... ) {
79+ m [i ] = s
80+ }
81+ return m
82+ }
83+
84+ // Sum sums all the elements of the Matrix and returns the resulting Volume
85+ func (m Matrix ) Sum () Volume {
86+ var v Volume
87+ for _ , s := range m {
88+ v += s
89+ }
90+ return v
91+ }
92+
7693func (v Volume ) withOverflowProtection () float64 {
7794 val := float64 (v )
7895 if math .Abs (val ) <= 1.0 {
You can’t perform that action at this time.
0 commit comments