Skip to content

Commit 6f6b8e5

Browse files
author
Brian Sorahan
committed
add Limiter
1 parent 26fe766 commit 6f6b8e5

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

limiter.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package sc
2+
3+
// Limiter limits the input amplitude to the given level.
4+
// Limiter will not overshoot like Compander will,
5+
// but it needs to look ahead in the audio.
6+
// Thus there is a delay equal to twice the value of the dur parameter.
7+
// Limiter, unlike Compander, is completely transparent for an in range signal.
8+
// The Rate method of Limiter will panic if In is nil.
9+
type Limiter struct {
10+
In Input // The signal to be processed.
11+
Level Input // The peak output amplitude level to which to normalize the input.
12+
Dur Input // The buffer delay time. Shorter times will produce smaller delays and quicker transient response times, but may introduce amplitude modulation artifacts.
13+
}
14+
15+
func (limiter *Limiter) defaults() {
16+
if limiter.In == nil {
17+
panic("Limiter needs an input")
18+
}
19+
if limiter.Level == nil {
20+
limiter.Level = C(1)
21+
}
22+
if limiter.Dur == nil {
23+
limiter.Dur = C(0.01)
24+
}
25+
}
26+
27+
// Rate creates a new ugen at a specific rate.
28+
// If rate is an unsupported value this method will cause a runtime panic.
29+
func (limiter Limiter) Rate(rate int8) Input {
30+
CheckRate(rate)
31+
(&limiter).defaults()
32+
return UgenInput("Limiter", rate, 0, 1, limiter.In, limiter.Level, limiter.Dur)
33+
}

0 commit comments

Comments
 (0)