Skip to content

Commit db9f6bf

Browse files
committed
fix UnaryOpSoftClip
1 parent 2ae242e commit db9f6bf

File tree

6 files changed

+37
-38
lines changed

6 files changed

+37
-38
lines changed

binop.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ func MulAdd(rate int8, in, mul, add Input, numOutputs int) *UgenNode {
2323
return NewUgenNode("MulAdd", rate, 0, numOutputs, in, mul, add)
2424
}
2525

26-
// BinOpSoftClip adds distortion to a ugen.
27-
func BinOpSoftClip(rate int8, in Input, numOutputs int) *UgenNode {
26+
// UnaryOpSoftClip adds distortion to a ugen.
27+
func UnaryOpSoftClip(rate int8, in Input, numOutputs int) *UgenNode {
2828
CheckRate(rate)
29-
return NewUgenNode("BinaryOpUGen", rate, 43, numOutputs, in)
29+
return NewUgenNode("UnaryOpUGen", rate, 43, numOutputs, in)
3030
}

detect_silence.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ func (ds DetectSilence) Rate(rate int8) Input {
2525
}
2626
CheckRate(rate)
2727
(&ds).defaults()
28-
return UgenInput("DetectSilence", rate, 0, 1, ds.In, ds.Amp, ds.Time)
28+
return UgenInput("DetectSilence", rate, 0, 1, ds.In, ds.Amp, ds.Time, C(float32(ds.Done)))
2929
}

detectsilence_test.go

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,31 @@ package sc
33
import "testing"
44

55
func TestDetectSilence(t *testing.T) {
6+
// TODO: need a way to compare synthdef blobs where the order of the constants doesn't matter
67
t.SkipNow()
78

8-
const name = "DetectTheSilence"
9+
const name = "DetectSilence"
910

1011
def := NewSynthdef(name, func(params Params) Ugen {
1112
out := params.Add("out", 0)
1213

14+
noise := LFDNoise{
15+
Interpolation: InterpolationCubic,
16+
Freq: C(8),
17+
}.Rate(KR).Max(C(0))
18+
1319
sine := SinOsc{
14-
Freq: Rand{
15-
Lo: C(400),
16-
Hi: C(700),
17-
}.Rate(AR),
18-
}.Rate(AR)
20+
Freq: Rand{Lo: C(400), Hi: C(700)}.Rate(AR),
21+
Phase: C(0),
22+
}.Rate(AR).Mul(noise).SoftClip().Mul(C(0.3))
23+
1924
return Out{
2025
Bus: out,
21-
Channels: sine.Mul(LFDNoise{
22-
Interpolation: InterpolationCubic,
23-
Freq: C(8),
24-
}.Rate(KR)),
26+
Channels: DetectSilence{
27+
In: sine,
28+
Done: FreeEnclosing,
29+
}.Rate(AR),
2530
}.Rate(AR)
2631
})
27-
same, err := def.CompareToFile("fixtures/DetectSilence.scsyndef")
28-
if err != nil {
29-
t.Fatal(err)
30-
}
31-
if !same {
32-
t.Fatalf("synthdef different from sclang version")
33-
}
32+
compareAndWrite(t, name, def)
3433
}

multiNode.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func (mn *MultiNode) MulAdd(mul, add Input) Input {
6161
func (mn *MultiNode) SoftClip() Input {
6262
a := make([]*UgenNode, len(mn.nodes))
6363
for i, n := range mn.nodes {
64-
a[i] = BinOpSoftClip(n.Rate(), n, n.numOutputs)
64+
a[i] = UnaryOpSoftClip(n.Rate(), n, n.numOutputs)
6565
}
6666
return &MultiNode{a}
6767
}

param.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func (p *param) MulAdd(mul, add Input) Input {
8585
}
8686

8787
func (p *param) SoftClip() Input {
88-
return BinOpSoftClip(KR, p, 1)
88+
return UnaryOpSoftClip(KR, p, 1)
8989
}
9090

9191
func newParam(name string, index int32, initialValue float32) *param {

ugenNode.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@ package sc
22

33
// UGen done actions, see http://doc.sccode.org/Reference/UGen-doneActions.html
44
const (
5-
DoNothing = 0
6-
Pause = 1
7-
FreeEnclosing = 2
8-
FreePreceding = 3
9-
FreeFollowing = 4
10-
FreePrecedingGroup = 5
11-
FreeFollowingGroup = 6
12-
FreeAllPreceding = 7
13-
FreeAllFollowing = 8
14-
FreeAndPausePreceding = 9
15-
FreeAndPauseFollowing = 10
16-
DeepFreePreceding = 11
17-
DeepFreeFollowing = 12
18-
FreeAllInGroup = 13
5+
DoNothing = iota
6+
Pause
7+
FreeEnclosing
8+
FreePreceding
9+
FreeFollowing
10+
FreePrecedingGroup
11+
FreeFollowingGroup
12+
FreeAllPreceding
13+
FreeAllFollowing
14+
FreeAndPausePreceding
15+
FreeAndPauseFollowing
16+
DeepFreePreceding
17+
DeepFreeFollowing
18+
FreeAllInGroup
1919
// I do not understand the difference between the last and
2020
// next-to-last options [bps]
2121
)
@@ -87,7 +87,7 @@ func (un *UgenNode) MulAdd(mul, add Input) Input {
8787

8888
// SoftClip adds distortion to a ugen.
8989
func (un *UgenNode) SoftClip() Input {
90-
return BinOpSoftClip(un.rate, un, un.numOutputs)
90+
return UnaryOpSoftClip(un.rate, un, un.numOutputs)
9191
}
9292

9393
// NewUgenNode is a factory function for creating new UgenNode instances.

0 commit comments

Comments
 (0)