sc

package module
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2017 License: GPL-2.0 Imports: 21 Imported by: 0

README

sc

Package sc provides a way to interface directly with the supercollider server from Go programs.

Go Report Card

Why

Supercollider has a well-deserved reputation for being difficult to learn. I believe that sclang is a big reason for this. I also believe that Go is quite easy to learn, hence replacing sclang with Go makes a lot of sense to me.

Who

See https://github.com/scgolang/sc/blob/master/AUTHORS

What this is not

sc is not intended for livecoding (for more about livecoding see http://en.wikipedia.org/wiki/Live_coding). I may decide someday to support some livecoding-esque features, but for now the goal is to be able to build music applications that use supercollider as the audio engine.

Install

First, and most importantly, you must have supercollider installed (see http://supercollider.github.io/download.html).

Next, you must install go (see https://golang.org/dl).

Then

go get github.com/scgolang/sc

Test

There are a handful of synthdef files that are necessary for the tests.

These synthdef files are created by sclang, so you have to

make test

instead of

go test

Also, there are tests that attempt to connect to scsynth on port 57120 (see client_test.go).

If you do not have scsynth running the test will hang, so run

scsynth -u 57120

Usage

Find godocs at http://godoc.org/github.com/scgolang/sc. Also, take a look at some of the example programs here: https://github.com/scgolang/examples.

The list of supported ugens is here: https://github.com/scgolang/sc/blob/master/UGENS.md

Develop

See https://github.com/scgolang/sc/blob/master/CONTRIBUTING and https://github.com/scgolang/sc/blob/master/HACKING.md.

Roadmap

See https://github.com/scgolang/sc/milestones

Thanks

This project is hugely indebted to

Documentation

Overview

Package sc is a SuperCollider client for Go.

Index

Examples

Constants

View Source
const (

	// BufferFlagNormalize causes the peak amplitude of the buffer
	// to be normalized to 1.0 when using the Gen method.
	BufferFlagNormalize = 0x01
	// BufferFlagWavetable causes the buffer to be written in wavetable
	// format when using the Gen method, so that it can be used by
	// interpolating oscillators
	BufferFlagWavetable = 0x02
	// BufferFlagClear causes the buffer to be cleared before new
	// partials are written using the Gen method. Otherwise new partials
	// are summed with the existing contents of the buffer.
	BufferFlagClear = 0x04
	// BufferRoutineSine1 generates a buffer with a series of sine partials.
	// The args of this routine are the amplitudes of the partials.
	BufferRoutineSine1 = "sine1"
	// BufferRoutineSine2 is similar to BufferRoutineSine1 except that the
	// args are pairs of frequency and amplitude (i.e. you can specify the
	// frequency of each partial).
	BufferRoutineSine2 = "sine2"
	// BufferRoutineSine3 is similar to BufferRoutineSine1 except that the
	// args are triplets of frequency, amplitude, and phase (i.e. you can
	// specify the frequency and phase of each partial).
	BufferRoutineSine3 = "sine3"
	// BufferRoutineCheby generates a buffer that contains a series of
	// chebyshev polynomials which can be defined as
	//     cheby(n) = amplitude * cos(n * acos(x))
	// The first arg specifies the amplitude for n = 1, the second arg
	// specifies the amplitude for n = 2, and so on.
	// To eliminate DC offset when used as a waveshaper, the wavetable is
	// offset so that the center value is zero.
	BufferRoutineCheby = "cheby"
)
View Source
const (
	DumpOff      = 0
	DumpParsed   = 1
	DumpContents = 2
	DumpAll      = 3
)

Arguments to dumpOSC command. See http://doc.sccode.org/Reference/Server-Command-Reference.html#/dumpOSC

View Source
const (
	AddToHead  = int32(0)
	AddToTail  = int32(1)
	AddBefore  = int32(2)
	AddAfter   = int32(3)
	AddReplace = int32(4)
)

Arguments to s_new command. See http://doc.sccode.org/Reference/Server-Command-Reference.html#/s_new

View Source
const (
	// RootNodeID is what sclang uses as the root node ID. See http://doc.sccode.org/Classes/RootNode.html.
	RootNodeID = int32(0)

	// DefaultGroupID is what sclang uses for the default group ID. See http://doc.sccode.org/Reference/default_group.html.
	DefaultGroupID = int32(1)

	// DefaultLocalAddr is the listening address for DefaultClient.
	DefaultLocalAddr = "0.0.0.0:57110"

	// DefaultScsynthAddr is the remote address for DefaultClient.
	DefaultScsynthAddr = "0.0.0.0:57120"

	// DefaultConnectTimeout is the default timeout for connecting to scsynth.
	DefaultConnectTimeout = time.Second
)
View Source
const (
	// CurveStep is a flat envelope segment.
	CurveStep = C(0)
	// CurveLinear is a linear envelope segment.
	CurveLinear = C(1)
	// CurveExp is an exponential envelope segment.
	CurveExp = C(2)
	// CurveSine is a sinusoidal shaped envelope segment.
	CurveSine = C(3)
	// CurveWelch is a sinusoidal segment shaped like the sides of a welch window.
	CurveWelch = C(4)
	// CurveCustom is an undocumented (on doc.sccode.org) envelope segment shape.
	CurveCustom = C(5)
	// CurveSquared is a squared envelope segment.
	CurveSquared = C(6)
	// CurveCubed is a cubed envelope segment.
	CurveCubed = C(7)
)
View Source
const (
	GrainBufHanningEnv   = -1
	GrainBufNoInterp     = 1
	GrainBufLinearInterp = 2
	GrainBufCubicInterp  = 4
)

Envelope shapes for grain amp envelope.

View Source
const (
	IR = 0
	KR = 1
	AR = 2
)

Ugen rates.

  • IR is initialization rate.
  • KR is control rate.
  • AR is audio rate.

See http://doc.sccode.org/Tutorials/Mark_Polishook_tutorial/08_Rates.html.

View Source
const (
	DoNothing = iota
	Pause
	FreeEnclosing
	FreePreceding
	FreeFollowing
	FreePrecedingGroup
	FreeFollowingGroup
	FreeAllPreceding
	FreeAllFollowing
	FreeAndPausePreceding
	FreeAndPauseFollowing
	DeepFreePreceding
	DeepFreeFollowing
	FreeAllInGroup
)

UGen done actions, see http://doc.sccode.org/Reference/UGen-doneActions.html

View Source
const DefaultServerPort = 57120

DefaultServerPort is the default listening port for scsynth.

View Source
const GrainBufDefaultMaxGrains = 512

GrainBufDefaultMaxGrains is the default value of MaxGrains.

View Source
const ServerPath = "/usr/bin/scsynth:/usr/local/bin/scsynth"

ServerPath is the path the scsynth executable on linux systems.

Variables

View Source
var ErrNoScsynth = errors.New("Please install scsynth somewhere in your PATH.")

ErrNoScsynth happens when you try to start a SuperCollider server but do not have an scsynth executable in your PATH.

View Source
var (
	ErrTimeout = errors.New("timeout error")
)

Common errors.

Functions

func CheckRate

func CheckRate(rate int8)

CheckRate causes a panic if rate is not IR, KR, or AR.

func Midicps

func Midicps(note float32) float32

Midicps converts midi note values to frequency in Hz

func Play

func Play(c *Client, f UgenFunc) error

Play corresponds to http://doc.sccode.org/Classes/Function.html#-play. It wraps the provided UgenFunc in a synthdef, sends this synthdef to a server instance with DefaultClient, then creates a new synth from the synthdef.

Types

type AllpassC

type AllpassC struct {
	// In is the input signal
	In Input
	// MaxDelay is maximum delay time in seconds.
	// This is used to initialize the delay buffer.
	MaxDelay Input
	// Delay time in seconds
	Delay Input
	// Decay time for the echoes to decay by 60dB.
	// If this is negative then the feedback coefficient will
	// be negative, thus emphasizing only odd harmonics
	// at a lower octave.
	Decay Input
}

AllpassC allpass delay with cubic interpolation

func (AllpassC) Rate

func (apc AllpassC) Rate(rate int8) Input

Rate creates a new ugen at a specific rate. If rate is an unsupported value this method will cause a runtime panic.

type AllpassL

type AllpassL struct {
	// In is the input signal
	In Input
	// MaxDelay is maximum delay time in seconds.
	// This is used to initialize the delay buffer.
	MaxDelay Input
	// Delay time in seconds
	Delay Input
	// Decay time for the echoes to decay by 60dB.
	// If this is negative then the feedback coefficient will
	// be negative, thus emphasizing only odd harmonics
	// at a lower octave.
	Decay Input
}

AllpassL allpass delay with linear interpolation

func (AllpassL) Rate

func (apl AllpassL) Rate(rate int8) Input

Rate creates a new ugen at a specific rate. If rate is an unsupported value this method will cause a runtime panic.

type AllpassN

type AllpassN struct {
	// In is the input signal
	In Input
	// MaxDelay is maximum delay time in seconds.
	// This is used to initialize the delay buffer.
	MaxDelay Input
	// Delay time in seconds
	Delay Input
	// Decay time for the echoes to decay by 60dB.
	// If this is negative then the feedback coefficient will
	// be negative, thus emphasizing only odd harmonics
	// at a lower octave.
	Decay Input
}

AllpassN allpass delay with no interpolation

func (AllpassN) Rate

func (apn AllpassN) Rate(rate int8) Input

Rate creates a new ugen at a specific rate. If rate is an unsupported value this method will cause a runtime panic.

type BLowPass

type BLowPass struct {
	// In is the input signal.
	In Input
	// Freq is frequency in Hz.
	Freq Input
	// RQ is the reciprocal of Q, bandwidth / cutoff.
	RQ Input
}

BLowPass is a lowpass filter based on the Second Order Section biquad UGen.

func (BLowPass) Rate

func (blp BLowPass) Rate(rate int8) Input

Rate creates a new ugen at a specific rate. If rate is an unsupported value this method will cause a runtime panic.

type BPF

type BPF struct {
	// In is the input signal
	In Input
	// Freq cutoff in Hz
	Freq Input
	// RQ Reciprocal of Q
	RQ Input
}

BPF a resonant low pass filter

func (BPF) Rate

func (bpf BPF) Rate(rate int8) Input

Rate creates a new ugen at a specific rate. If rate is an unsupported value this method will cause a runtime panic.

type BRF

type BRF struct {
	// In is the input signal
	In Input
	// Freq cutoff in Hz
	Freq Input
	// RQ Reciprocal of Q
	RQ Input
}

BRF a second order band reject filter

func (BRF) Rate

func (brf BRF) Rate(rate int8) Input

Rate creates a new ugen at a specific rate. If rate is an unsupported value this method will cause a runtime panic.

type Balance2

type Balance2 struct {
	// L is the left input signal
	L Input
	// R is the right input signal
	R Input
	// Pos stereo position where -1 is hard left and +1 is hard right
	Pos Input
	// Level gain [0, 1]
	Level Input
}

Balance2 equal power panner

func (Balance2) Rate

func (bal Balance2) Rate(rate int8) Input

Rate creates a new ugen at a specific rate. If rate is an unsupported value this method will cause a runtime panic.

type Blip

type Blip struct {
	// Freq frequency in Hz
	Freq Input
	// Harm the number of harmonics
	Harm Input
}

Blip band-limited impulse generator

func (Blip) Rate

func (blip Blip) Rate(rate int8) Input

Rate creates a new ugen at a specific rate. If rate is an unsupported value this method will cause a runtime panic.

type BrownNoise

type BrownNoise struct{}

BrownNoise generates noise whose spectrum falls off in power by 6 dB per octave

func (BrownNoise) Rate

func (brown BrownNoise) Rate(rate int8) Input

Rate creates a new ugen at a specific rate. If rate is an unsupported value this method will cause a runtime panic.

type Buffer

type Buffer struct {
	Num int32
	// contains filtered or unexported fields
}

Buffer is a client-side representation of an scsynth audio buffer

func (*Buffer) Gen

func (buffer *Buffer) Gen(routine string, flags int, args ...float32) error

Gen generates a buffer using a routine. A runtime panic will occur if routine is not one of the BufferRoutine constants.

type C

type C float32

C wraps a float32 and implements the Input interface.

func (C) Add

func (c C) Add(val Input) Input

Add adds another input to the constant.

func (C) Max added in v0.1.3

func (c C) Max(other Input) Input

Max returns the maximum of one input and another.

func (C) Mul

func (c C) Mul(val Input) Input

Mul multiplies the constant by another input.

func (C) MulAdd

func (c C) MulAdd(mul, add Input) Input

MulAdd multiplies and adds at the same time.

func (C) SoftClip added in v0.1.3

func (c C) SoftClip() Input

SoftClip clips the constant to the range [-0.5, 0.5]

type COsc

type COsc struct {
	// BufNum the number of a buffer filled in wavetable format
	BufNum Input
	// Freq frequency in Hz
	Freq Input
	// Beats beat frequency in Hz
	Beats Input
}

COsc is a chorusing wavetable lookup oscillator. Produces sum of 2 signals at

freq +- (beats / 2)

Due to summing, the peak amplitude is twice that of the wavetable.

func (COsc) Rate

func (cosc COsc) Rate(rate int8) Input

Rate creates a new ugen at a specific rate. If rate is an unsupported value this method will cause a runtime panic. There will also be a runtime panic if BufNum is nil.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client manages all communication with scsynth

func DefaultClient

func DefaultClient() (*Client, error)

DefaultClient returns the default sc client.

func NewClient

func NewClient(network, local, scsynth string, timeout time.Duration) (*Client, error)

NewClient creates a new SuperCollider client. The client will bind to the provided address and port to receive messages from scsynth.

func (*Client) AddDefaultGroup

func (c *Client) AddDefaultGroup() (*Group, error)

AddDefaultGroup adds the default group.

func (*Client) AllocBuffer

func (c *Client) AllocBuffer(frames, channels int) (*Buffer, error)

AllocBuffer allocates a buffer on the server

func (*Client) Close

func (c *Client) Close() error

Close closes the client.

func (*Client) Connect

func (c *Client) Connect(addr string, timeout time.Duration) error

Connect connects to an scsynth instance via UDP.

func (*Client) DumpOSC

func (c *Client) DumpOSC(level int32) error

DumpOSC sends a /dumpOSC message to scsynth level should be DumpOff, DumpParsed, DumpContents, DumpAll

func (*Client) FreeAll

func (c *Client) FreeAll(gids ...int32) error

FreeAll frees all nodes in a group

func (*Client) Group

func (c *Client) Group(id, action, target int32) (*Group, error)

Group creates a group.

func (*Client) NextSynthID

func (c *Client) NextSynthID() int32

NextSynthID gets the next available ID for creating a synth

func (*Client) QueryGroup

func (c *Client) QueryGroup(id int32) (*Group, error)

QueryGroup g_queryTree for a particular group.

func (*Client) ReadBuffer

func (c *Client) ReadBuffer(path string, num int32) (*Buffer, error)

ReadBuffer tells the server to read an audio file and load it into a buffer

func (*Client) SendDef

func (c *Client) SendDef(def *Synthdef) error

SendDef sends a synthdef to scsynth. This method blocks until a /done message is received indicating that the synthdef was loaded

func (*Client) Status

func (c *Client) Status(timeout time.Duration) (*ServerStatus, error)

Status gets the status of scsynth with a timeout. If the status request times out it returns ErrTimeout.

func (*Client) Synth

func (c *Client) Synth(defName string, id, action, target int32, ctls map[string]float32) (*Synth, error)

Synth creates a synth node.

func (*Client) Synths added in v0.1.3

func (c *Client) Synths(args []SynthArgs) error

Synths creates multiple synth nodes at once with an OSC bundle.

type ClipNoise

type ClipNoise struct{}

ClipNoise generates noise whose values are either -1 or 1. This produces the maximum energy for the least peak to peak amplitude.

func (ClipNoise) Rate

func (cn ClipNoise) Rate(rate int8) Input

Rate creates a new ugen at a specific rate. If rate is an unsupported value this method will cause a runtime panic.

type Comb

type Comb struct {
	// Interpolation determines the type of interpolation.
	Interpolation Interpolation
	// In the input signal
	In Input
	// MaxDelayTime maximum delay time in seconds, which is used
	// to initialize the delay buffer size.
	MaxDelayTime Input
	// DelayTime delay time in seconds
	DelayTime Input
	// DecayTime time for the echoes to decay by 60dB.
	// If this time is negative then the feedback coefficient will be
	// negative, thus emphasizing only odd harmonics an octave lower.
	DecayTime Input
}

Comb is a delay line with cubic interpolation.

func (Comb) Rate

func (comb Comb) Rate(rate int8) Input

Rate creates a new ugen at a specific rate. If an In signal is not provided this method will trigger a runtime panic. If Interpolation is an unsupported value, then this method will trigger a runtime panic.

type Control

type Control struct {
	// contains filtered or unexported fields
}

Control represents a synth control. See http://doc.sccode.org/Classes/Control.html.

func (*Control) Add

func (ctl *Control) Add(val Input) Input

Add adds another input to the Control.

func (*Control) Inputs

func (ctl *Control) Inputs() []Input

Inputs returns the inputs for the Control.

func (*Control) Max added in v0.1.3

func (ctl *Control) Max(other Input) Input

Max computes the maximum of the Control and another UGen.

func (*Control) Mul

func (ctl *Control) Mul(val Input) Input

Mul multiplies another input by the Control.

func (*Control) MulAdd

func (ctl *Control) MulAdd(mul, add Input) Input

MulAdd multiplies and adds inputs to the Control.

func (*Control) Name

func (ctl *Control) Name() string

Name returns the name of the Control.

func (*Control) Outputs

func (ctl *Control) Outputs() []Output

Outputs returns the outputs for the Control.

func (*Control) Rate

func (ctl *Control) Rate() int8

Rate returns the rate of the Control.

func (*Control) SoftClip added in v0.1.3

func (ctl *Control) SoftClip() Input

SoftClip adds distortion to the Control.

func (*Control) SpecialIndex

func (ctl *Control) SpecialIndex() int16

SpecialIndex returns the special index of the Control.

type Crackle

type Crackle struct {
	Chaos Input
}

Crackle is a noise generator based on a chaotic function.

func (Crackle) Rate

func (crackle Crackle) Rate(rate int8) Input

Rate creates a new ugen at a specific rate. If rate is an unsupported value this method will cause a runtime panic.

type Decay

type Decay struct {
	// In is the input signal
	In Input
	// Decay 60dB decay time in seconds
	Decay Input
}

Decay is an exponential decay.

func (Decay) Rate

func (decay Decay) Rate(rate int8) Input

Rate creates a new ugen at a specific rate. If an In signal is not provided this method will trigger a runtime panic.

type Decay2

type Decay2 struct {
	// In is the input signal
	In Input
	// Attack 60dB attack time in seconds
	Attack Input
	// Decay 60dB decay time in seconds
	Decay Input
}

Decay2 is just like Decay, except it rounds off the attack by subtracting one Decay from another. This fixes the sharp attacks and clicks that can sometimes occur with Decay.

func (Decay2) Rate

func (decay2 Decay2) Rate(rate int8) Input

Rate creates a new ugen at a specific rate. If an In signal is not provided this method will trigger a runtime panic.

type Delay

type Delay struct {
	// Interpolation determines the type of interpolation.
	Interpolation Interpolation
	// In the input signal
	In Input
	// MaxDelayTime maximum delay time in seconds, which is used
	// to initialize the delay buffer size.
	MaxDelayTime Input
	// DelayTime delay time in seconds
	DelayTime Input
}

Delay is a simple delay line.

func (Delay) Rate

func (delay Delay) Rate(rate int8) Input

Rate creates a new ugen at a specific rate. If an In signal is not provided this method will trigger a runtime panic.

type DetectSilence added in v0.1.3

type DetectSilence struct {
	In   Input // The input signal.
	Amp  Input // Amplitude threshold.
	Time Input // The minimum duration for which amplitude must be below Amp before Done triggers.
	Done int   // UGen done-action.
}

DetectSilence evaluates Done when input falls below a certain threshold.

func (DetectSilence) Rate added in v0.1.3

func (ds DetectSilence) Rate(rate int8) Input

Rate creates a new ugen at a specific rate. If rate is an unsupported value this method will cause a runtime panic.

type Dust

type Dust struct {
	// Density is the average number of impulses per second
	Density Input
}

Dust generates random impulses from 0 to +1

func (Dust) Rate

func (dust Dust) Rate(rate int8) Input

Rate creates a new ugen at a specific rate. If rate is an unsupported value this method will cause a runtime panic.

type Dust2

type Dust2 struct {
	// Density is the average number of impulses per second
	Density Input
}

Dust2 generates random impulses from -1 to +1

func (Dust2) Rate

func (dust2 Dust2) Rate(rate int8) Input

Rate creates a new ugen at a specific rate. If rate is an unsupported value this method will cause a runtime panic.

type Env

type Env struct {
	// Levels is the array of levels
	Levels []Input
	// Times is the array of durations (in seconds).
	// The length of this array should be one less than the
	// Levels array.
	Times []Input
	// Curve determines the shape of each envelope segment.
	// This could be a string, a float, a slice of strings, or a slice of floats.
	Curve       interface{}
	ReleaseNode Input
	LoopNode    Input
}

Env is a specification for a breakpoint envelope

func (Env) Inputs

func (env Env) Inputs() []Input

Inputs returns the array of inputs that defines the Env.

type EnvADSR

type EnvADSR struct {
	A, D, S, R, Peak, Curve, Bias Input
}

EnvADSR represents the ever-popular ADSR envelope

func (EnvADSR) Inputs

func (adsr EnvADSR) Inputs() []Input

Inputs returns the array of inputs that defines the Env.

type EnvASR

type EnvASR struct {
	A, S, R, Curve Input
}

EnvASR is an attack-sustain-release envelope

func (EnvASR) Inputs

func (asr EnvASR) Inputs() []Input

Inputs returns the array of inputs that defines the Env.

type EnvCutoff

type EnvCutoff struct {
	R, Level, CurveType Input
}

EnvCutoff creates an envelope with no attack segment. It simply sustains at the peak level until released.

func (EnvCutoff) Inputs

func (cutoff EnvCutoff) Inputs() []Input

Inputs returns the array of inputs that defines the Env.

type EnvDADSR

type EnvDADSR struct {
	Delay, A, D, S, R, Peak, Curve, Bias Input
}

EnvDADSR is EnvADSR with its onset delayed by D seconds

func (EnvDADSR) Inputs

func (dadsr EnvDADSR) Inputs() []Input

Inputs returns the array of inputs that defines the Env.

type EnvGen

type EnvGen struct {
	// Env determines the shape of the envelope
	Env Envelope
	// Gate triggers the envelope and holds it open while > 0
	Gate Input
	// LevelScale scales the levels of the breakpoints
	LevelScale Input
	// LevelBias offsets the levels of the breakpoints
	LevelBias Input
	// TimeScale scales the durations of the segments
	TimeScale Input
	// Done is the ugen done action
	Done int
}

EnvGen plays back breakpoint envelopes. The envelopes must implement the Envelope interface. The envelope and the arguments for LevelScale, LevelBias, and TimeScale are polled when the EnvGen is triggered and remain constant for the duration of the envelope.

func (EnvGen) Rate

func (envgen EnvGen) Rate(rate int8) Input

Rate creates a new ugen at a specific rate. If rate is an unsupported value this method will cause a runtime panic.

type EnvLinen

type EnvLinen struct {
	Attack, Sustain, Release, Level Input
	Curve                           interface{}
}

EnvLinen creates a new envelope which has a trapezoidal shape

func (EnvLinen) Inputs

func (linen EnvLinen) Inputs() []Input

Inputs returns the array of inputs that defines the Env.

type EnvPairs

type EnvPairs struct {
	Pairs Pairs
	Curve interface{}
}

EnvPairs creates a new envelope from coordinates/pairs

func (EnvPairs) Inputs

func (pairs EnvPairs) Inputs() []Input

Inputs returns the array of inputs that defines the Env.

type EnvPerc

type EnvPerc struct {
	Attack, Release, Level, Curve Input
}

EnvPerc creates a new envelope that has a percussive shape

func (EnvPerc) Inputs

func (perc EnvPerc) Inputs() []Input

Inputs returns the array of inputs that defines the Env.

type EnvSine

type EnvSine struct {
	Dur, Level Input
}

EnvSine creates a new envelope which has a hanning window shape

func (EnvSine) Inputs

func (sine EnvSine) Inputs() []Input

Inputs returns the array of inputs that defines the Env.

type EnvTLC

type EnvTLC []TLC

EnvTLC creates a new envelope from an array of (time, level, curve) triplets This is renamed from Env.xyc. The Curve value of the last triplet is ignored.

func (EnvTLC) Inputs

func (tlc EnvTLC) Inputs() []Input

Inputs returns the array of inputs that defines the Env.

func (EnvTLC) Len

func (tlc EnvTLC) Len() int

func (EnvTLC) Less

func (tlc EnvTLC) Less(i, j int) bool

func (EnvTLC) Swap

func (tlc EnvTLC) Swap(i, j int)

type EnvTriangle

type EnvTriangle struct {
	Dur, Level Input
}

EnvTriangle creates a new envelope that has a triangle shape

func (EnvTriangle) Inputs

func (tri EnvTriangle) Inputs() []Input

Inputs returns the array of inputs that defines the Env.

type Envelope

type Envelope interface {
	// InputsArray provides EnvGen with the data it needs
	// to get a list of inputs.
	Inputs() []Input
}

Envelope is an interface that should be implemented by types that define envelopes for EnvGen.

type FSinOsc

type FSinOsc struct {
	// Freq is frequency in Hz
	Freq Input
	// Phase is the initial phase offset
	Phase Input
}

FSinOsc is a very fast sine wave generator implemented using a ringing filter. This generates a much cleaner sine wave than a table lookup oscillator and is a lot faster. However, the amplitude of the wave will vary with frequency. Generally the amplitude will go down as you raise the frequency and go up as you lower the frequency.

func (FSinOsc) Rate

func (fso FSinOsc) Rate(rate int8) Input

Rate creates a new ugen at a specific rate. If rate is an unsupported value this method will cause a runtime panic.

type Formlet

type Formlet struct {
	// In the input signal
	In Input
	// Freq resonant frequency in Hz
	Freq Input
	// AttackTime 60 dB attack time in seconds
	AttackTime Input
	// DecayTime 60 dB decay time in seconds
	DecayTime Input
}

Formlet is a resonant filter whose impulse response is like that of a sine wave with a Decay2 envelope over it. The great advantage to this filter over FOF is that there is no limit to the number of overlapping grains since the grain is just the impulse response of the filter.

func (Formlet) Rate

func (formlet Formlet) Rate(rate int8) Input

Rate creates a new ugen at a specific rate. If an In signal is not provided this method will trigger a runtime panic.

type FreeVerb

type FreeVerb struct {
	// In the input signal
	In Input
	// Mix dry/wet balance [0, 1]
	Mix Input
	// Room room size [0, 1]
	Room Input
	// Damp high frequency damping [0, 1]
	Damp Input
}

FreeVerb reverb implemented with faust

func (FreeVerb) Rate

func (fv FreeVerb) Rate(rate int8) Input

Rate creates a new ugen at a specific rate. If an In signal is not provided this method will trigger a runtime panic.

type Gate

type Gate struct {
	// In is the input signal.
	In Input
	// Trig is the rigger signal. The output is held fixed when this is non-positive.
	Trig Input
}

Gate allows an input signal value to pass when gate is positive, otherwise holds last value.

func (Gate) Rate

func (gate Gate) Rate(rate int8) Input

Rate creates a new ugen at a specific rate. If an In signal is not provided this method will trigger a runtime panic.

type GrainBuf

type GrainBuf struct {
	// NumChannels is the number of channels to output.
	// If 1, mono is returned and pan is ignored.
	NumChannels int
	// Trigger is a KR or AR trigger to start a new grain.
	// If AR, grains after the start of the synth are
	// sample-accurate.
	Trigger Input
	// Dur is the size of the grain (in seconds)
	Dur Input
	// BufNum is the buffer holding a mono audio signal
	BufNum Input
	// Speed is the playback speed of the grain
	Speed Input
	// Pos is the position in the audio buffer where
	// the grain will start. This is in the range [0, 1].
	Pos Input
	// Interp is the interpolation method used for
	// pitch-shifting grains.
	// GrainBufNoInterp is no interpolation,
	// GrainBufLinearInterp is linear,
	// and GrainBufCubicInterp is cubic.
	Interp Input
	// Pan determines where to position the output in a stereo
	// field. If NumChannels = 1, no panning is done. If
	// NumChannels = 2, behavior is similar to Pan2. If
	// NumChannels > 2, behavior is the same as PanAz.
	Pan Input
	// EnvBuf is the buffer number containing a signal to use
	// for each grain's amplitude envelope. If set to
	// GrainBufHanningEnv, a built-in Hanning envelope is used.
	EnvBuf Input
	// MaxGrains is the maximum number of overlapping grains
	// that can be used at a given time. This value is set
	// when you initialize GrainBuf and can't be modified.
	// Default is 512, but lower values may result in more
	// efficient use of memory.
	MaxGrains Input
}

GrainBuf is a table-lookup sinewave oscillator

func (GrainBuf) Rate

func (gb GrainBuf) Rate(rate int8) Input

Rate creates a new ugen at a specific rate. If rate is an unsupported value this method will cause a runtime panic. There will also be a runtime panic if BufNum is nil.

type GrainFM

type GrainFM struct {
	// NumChannels is the number of channels to output.
	// If 1, mono is returned and pan is ignored.
	NumChannels int
	// Trigger is a KR or AR trigger to start a new grain.
	// If AR, grains after the start of the synth are
	// sample-accurate.
	Trigger Input
	// Dur is the size of the grain (in seconds)
	Dur Input
	// CarFreq the carrier frequency of the grain generator's internal oscillator
	CarFreq Input
	// ModFreq the modulator frequency of the grain generator's internal oscillator
	ModFreq Input
	// ModIndex the index of modulation
	ModIndex Input
	// Pan determines where to position the output in a stereo
	// field. If NumChannels = 1, no panning is done. If
	// NumChannels = 2, behavior is similar to Pan2. If
	// NumChannels > 2, behavior is the same as PanAz.
	Pan Input
	// EnvBuf is the buffer number containing a signal to use
	// for each grain's amplitude envelope. If set to
	// GrainBufHanningEnv, a built-in Hanning envelope is used.
	EnvBuf Input
	// MaxGrains is the maximum number of overlapping grains
	// that can be used at a given time. This value is set
	// when you initialize GrainFM and can't be modified.
	// Default is 512, but lower values may result in more
	// efficient use of memory.
	MaxGrains Input
}

GrainFM is a table-lookup sinewave oscillator

func (GrainFM) Rate

func (gfm GrainFM) Rate(rate int8) Input

Rate creates a new ugen at a specific rate. If rate is an unsupported value this method will cause a runtime panic. There will also be a runtime panic if BufNum is nil.

type GrayNoise

type GrayNoise struct {
}

GrayNoise generates noise which results from flipping random bits in a word. This type of noise has a high RMS level relative to its peak to peak level. The spectrum is emphasized towards lower frequencies.

func (GrayNoise) Rate

func (gn GrayNoise) Rate(rate int8) Input

Rate creates a new ugen at a specific rate. If rate is an unsupported value this method will cause a runtime panic.

type Group

type Group struct {
	Node     `json:"node" xml:"node"`
	Children []*Node `json:"children" xml:"children>child"`
	// contains filtered or unexported fields
}

Group is a group of synth nodes

func (*Group) Free

func (g *Group) Free() error

Free frees all the nodes in a group. TODO

func (*Group) FreeAll

func (g *Group) FreeAll() error

FreeAll frees all the nodes in a group recursively. TODO

func (*Group) Synth

func (g *Group) Synth(defName string, id, action int32, ctls map[string]float32) (*Synth, error)

Synth adds a synth to a group

func (*Group) Synths added in v0.1.3

func (g *Group) Synths(args []SynthArgs) error

Synths creates multiple synth nodes at once with an OSC bundle.

func (*Group) WriteJSON

func (g *Group) WriteJSON(w io.Writer) error

WriteJSON writes a JSON representation of a group to an io.Writer

func (*Group) WriteXML

func (g *Group) WriteXML(w io.Writer) error

WriteXML writes an XML representation of a group to an io.Writer

type Impulse

type Impulse struct {
	// Freq frequency in Hz
	Freq Input
	// Phase offset in cycles [0, 1]
	Phase Input
}

Impulse non-band-limited single-sample impulses

func (Impulse) Rate

func (impulse Impulse) Rate(rate int8) Input

Rate creates a new ugen at a specific rate. If rate is an unsupported value this method will cause a runtime panic.

type Input

type Input interface {
	// Max returns the max of one signal and another.
	Max(other Input) Input

	// Mul multiplies one Input by another.
	Mul(val Input) Input

	// Add adds one Input to another.
	Add(val Input) Input

	// MulAdd multiplies and adds an Input using two others.
	MulAdd(mul, add Input) Input

	// SoftClip distorts a signal with a perfectly linear range from -0.5 to 0.5
	SoftClip() Input
}

Input is implemented by any value that can serve as a ugen input. This includes synthdef parameters, constants, and other ugens.

func Mix

func Mix(rate int8, inputs []Input) Input

Mix will mix an array of channels down to a single channel.

func Sum3

func Sum3(rate int8, in1, in2, in3 Input) Input

Sum3 sums three signals. Should be used via Mix.

func Sum4

func Sum4(rate int8, in1, in2, in3, in4 Input) Input

Sum4 sums four signals. Should be used via Mix.

func UgenInput

func UgenInput(name string, rate int8, specialIndex int16, numOutputs int, inputs ...Input) Input

UgenInput creates a ugen suitable for use as an input to other ugens. It will return either a single-channel ugen or a multi-channel ugen.

type Inputs

type Inputs []Input

Inputs is a slice of Input.

func Multi

func Multi(inputs ...Input) Inputs

Multi does multichannel expansion. See http://doc.sccode.org/Guides/Multichannel-Expansion.html.

func (Inputs) Add

func (ins Inputs) Add(val Input) Input

Add adds an input to all the inputs.

func (Inputs) InputArray

func (ins Inputs) InputArray() []Input

InputArray provides access to the list of inputs.

func (Inputs) Max added in v0.1.3

func (ins Inputs) Max(other Input) Input

Max returns Inputs that contain the max of all the inputs and the provided Input.

func (Inputs) Mul

func (ins Inputs) Mul(val Input) Input

Mul multiplies all the inputs by another input.

func (Inputs) MulAdd

func (ins Inputs) MulAdd(mul, add Input) Input

MulAdd performs a multiplication and addition on all the inputs.

func (Inputs) SoftClip added in v0.1.3

func (ins Inputs) SoftClip() Input

SoftClip adds distortion to the inputs.

type Integrator

type Integrator struct {
	// In is the input signal
	In Input
	// Coef is the leak coefficient
	Coef Input
}

Integrator integrates an input signal with a leak. The formula used is

out(0) = in(0) + (coef * out(-1))

func (Integrator) Rate

func (integrator Integrator) Rate(rate int8) Input

Rate creates a new ugen at a specific rate. If an In signal is not provided this method will trigger a runtime panic.

type Interpolation

type Interpolation int

Interpolation is a smoothing strategy for delay lines. Possible values are

  • InterpolationNone
  • InterpolationLinear
  • InterpolationCubic
const (
	InterpolationNone Interpolation = iota
	InterpolationLinear
	InterpolationCubic
)

Interpolation types.

type Klank added in v0.1.3

type Klank struct {
	// Spec is three float slices (which should all have the same length).
	// The first slice is the filter frequencies.
	// The second slice is the filter amplitudes.
	// The third slice is the 60dB decay times in seconds for the filters.
	Spec [3][]float32

	In         Input // In is the excitation input to the resonant filter bank.
	FreqScale  Input // FreqScale is a scale factor multiplied by all frequencies at initialization time.
	FreqOffset Input // FreqOffset is an offset added to all frequencies at initialization time.
	DecayScale Input // DecayScale is a scale factor multiplied by all ring times at initialization time.
}

Klank is a bank of fixed frequency resonators which can be used to simulate the resonant modes of an object. Each mode is given a ring time, which is the time for the mode to decay by 60 dB.

func (Klank) Rate added in v0.1.3

func (k Klank) Rate(rate int8) Input

Rate creates a new ugen at a specific rate. If rate is an unsupported value this method will cause a runtime panic. If In is nil this method will cause a runtime panic.

type LFCub

type LFCub struct {
	// Freq frequency in Hz
	Freq Input
	// Iphase initial phase offset
	Iphase Input
}

LFCub is a sine-like shape made of two cubic pieces. It is smoother than LFPar.

func (LFCub) Rate

func (lfcub LFCub) Rate(rate int8) Input

Rate creates a new ugen at a specific rate. If rate is an unsupported value this method will cause a runtime panic.

type LFDNoise added in v0.1.3

type LFDNoise struct {
	Interpolation Interpolation
	Freq          Input
}

LFDNoise generates random values at a rate given by the freq argument, with two differences: no time quantization, and fast recovery from low freq values.

func (LFDNoise) Rate added in v0.1.3

func (lfdn LFDNoise) Rate(rate int8) Input

Rate creates a new ugen at a specific rate. If rate is an unsupported value this method will cause a runtime panic.

type LFNoise

type LFNoise struct {
	Interpolation NoiseInterpolation
	Freq          Input
}

LFNoise generates random values at a rate given by the nearest integer division of the sample rate by the Freq input. The values will be interpolated according to the Interpolation input.

func (LFNoise) Rate

func (lfnoise LFNoise) Rate(rate int8) Input

Rate creates a new ugen at a specific rate. If rate is an unsupported value this method will cause a runtime panic.

type LFPulse

type LFPulse struct {
	// Freq in Hz
	Freq Input
	// Iphase initial phase offset in cycles (0..1)
	Iphase Input
	// Width pulse width duty cycle from 0 to 1
	Width Input
}

LFPulse a non-band-limited pulse oscillator

func (LFPulse) Rate

func (lfpulse LFPulse) Rate(rate int8) Input

Rate creates a new ugen at a specific rate. If rate is an unsupported value this method will cause a runtime panic.

type LFSaw

type LFSaw struct {
	// Freq frequency in Hz
	Freq Input
	// Iphase initial phase offset in cycles:
	// for efficiency this is in the rage [0, 2]
	Iphase Input
}

LFSaw a non-band-limited sawtooth oscillator output ranges from -1 to +1

func (LFSaw) Rate

func (lfsaw LFSaw) Rate(rate int8) Input

Rate creates a new ugen at a specific rate. If rate is an unsupported value this method will cause a runtime panic.

type LFTri

type LFTri struct {
	// Freq is the approximate rate at which to
	// generate random values
	Freq Input
	// Iphase initial phase offset in the range [0, 4]
	Iphase Input
}

LFTri is a non-band-limited triangle oscillator. Output is [-1, 1].

func (LFTri) Rate

func (lftri LFTri) Rate(rate int8) Input

Rate creates a new ugen at a specific rate. If rate is an unsupported value this method will cause a runtime panic.

type Limiter

type Limiter struct {
	In    Input // The signal to be processed.
	Level Input // The peak output amplitude level to which to normalize the input.
	Dur   Input // The buffer delay time. Shorter times will produce smaller delays and quicker transient response times, but may introduce amplitude modulation artifacts.
}

Limiter limits the input amplitude to the given level. Limiter will not overshoot like Compander will, but it needs to look ahead in the audio. Thus there is a delay equal to twice the value of the dur parameter. Limiter, unlike Compander, is completely transparent for an in range signal. The Rate method of Limiter will panic if In is nil.

func (Limiter) Rate

func (limiter Limiter) Rate(rate int8) Input

Rate creates a new ugen at a specific rate. If rate is an unsupported value this method will cause a runtime panic.

type Line

type Line struct {
	Start Input
	End   Input
	Dur   Input
	Done  int
}

Line generates a line from the start value to the end value

func (Line) Rate

func (line Line) Rate(rate int8) Input

Rate creates a new ugen at a specific rate. If rate is an unsupported value this method will cause a runtime panic.

type MouseX

type MouseX struct {
	// Min is the value of this ugen's output when the
	// mouse is at the left edge of the screen
	Min Input
	// Max is the value of this ugen's output when the
	// mouse is at the right edge of the screen
	Max Input
	// Warp is the mapping curve. 0 is linear, 1 is exponential
	Warp Input
	// Lag factor to dezipper cursor movements
	Lag Input
}

MouseX allpass delay with cubic interpolation

func (MouseX) Rate

func (m MouseX) Rate(rate int8) Input

Rate creates a new ugen at a specific rate. If rate is an unsupported value this method will cause a runtime panic.

type MouseY

type MouseY struct {
	// Min is the value of this ugen's output when the
	// mouse is at the left edge of the screen
	Min Input
	// Max is the value of this ugen's output when the
	// mouse is at the right edge of the screen
	Max Input
	// Warp is the mapping curve. 0 is linear, 1 is exponential
	Warp Input
	// Lag factor to dezipper cursor movements
	Lag Input
}

MouseY allpass delay with cubic interpolation

func (MouseY) Rate

func (m MouseY) Rate(rate int8) Input

Rate creates a new ugen at a specific rate. If rate is an unsupported value this method will cause a runtime panic.

type MultiInput

type MultiInput interface {
	Input
	InputArray() []Input
}

MultiInput is the interface of an input that causes cascading multi-channel expansion. See http://doc.sccode.org/Guides/Multichannel-Expansion.html

type MultiNode

type MultiNode struct {
	// contains filtered or unexported fields
}

MultiNode is a MultiInput that consists of ugens.

func NewMultiNode

func NewMultiNode(nodes ...*UgenNode) *MultiNode

NewMultiNode creates a new MultiNode.

func (*MultiNode) Add

func (mn *MultiNode) Add(val Input) Input

Add adds an input to all the ugens.

func (*MultiNode) InputArray

func (mn *MultiNode) InputArray() []Input

InputArray returns the ugens as a slice of Inputs.

func (*MultiNode) Max added in v0.1.3

func (mn *MultiNode) Max(other Input) Input

Max returns the maximum of one Input and another.

func (*MultiNode) Mul

func (mn *MultiNode) Mul(val Input) Input

Mul multiplies all the ugens by an input.

func (*MultiNode) MulAdd

func (mn *MultiNode) MulAdd(mul, add Input) Input

MulAdd does both multiplication and addition on all the ugen nodes.

func (*MultiNode) Nodes

func (mn *MultiNode) Nodes() []*UgenNode

Nodes returns the slice of Ugen nodes.

func (*MultiNode) SoftClip added in v0.1.3

func (mn *MultiNode) SoftClip() Input

SoftClip adds distortion to the MultiNode.

type Node

type Node struct {
	ID int32 `json:"id" xml:"id,attr"`
}

Node is a node in a graph

type NoiseInterpolation

type NoiseInterpolation int

NoiseInterpolation defines different types of interpolation for LFNoise ugens.

const (
	NoiseStep NoiseInterpolation = iota
	NoiseLinear
	NoiseQuadratic
)

Noise interpolation types.

type Out

type Out struct {
	Bus      Input
	Channels Input
}

Out writes a signal to a bus.

func (Out) Rate

func (out Out) Rate(rate int8) *UgenNode

Rate creates a new ugen at a specific rate. If rate is an unsupported value this method will cause a runtime panic.

type Output

type Output int8

Output is a ugen output.

func (Output) Rate

func (o Output) Rate() int8

Rate returns the rate of the output.

func (Output) Write

func (o Output) Write(w io.Writer) error

Write writes the output to an io.Writer.

type PMOsc

type PMOsc struct {
	// CarFreq is the carrier frequency in Hz.
	CarFreq Input
	// ModFreq is the modulator frequency in Hz.
	ModFreq Input
	// PMIndex in the modulation index in radians.
	PMIndex Input
	// ModPhase is a modulation input for the modulator's phase in radians.
	ModPhase Input
}

PMOsc is a phase modulation sine-wave oscillator pair.

func (PMOsc) Rate

func (pmosc PMOsc) Rate(rate int8) Input

Rate creates a new ugen at a specific rate. If rate is an unsupported value this method will cause a runtime panic.

type Pairs

type Pairs [][2]float32

Pairs are pairs of floats: the first float is time, the second is level. They get sorted by time.

func (Pairs) Len

func (p Pairs) Len() int

func (Pairs) Less

func (p Pairs) Less(i, j int) bool

func (Pairs) Swap

func (p Pairs) Swap(i, j int)

type Pan2

type Pan2 struct {
	// In is the input signal.
	In Input

	// Pos is the pan position, -1 is hard left, +1 is hard right.
	Pos Input

	// Level is a control rate level input.
	Level Input
}

Pan2 is a two-channel equal power panner. It takes the square root of the linear scaling factor going from 1 (left or right) to 0.5.sqrt (~=0.707) in the center, which is about 3dB reduction. With linear panning (LinPan2) the signal is lowered as it approaches center using a straight line from 1 (left or right) to 0.5 (center) for a 6dB reduction in the middle. A problem inherent to linear panning is that the perceived volume of the signal drops in the middle. Pan2 solves this.

func (Pan2) Rate

func (pan Pan2) Rate(rate int8) Input

Rate creates a new ugen at a specific rate. If rate is an unsupported value this method will cause a runtime panic.

type Param

type Param interface {
	// Name returns the name of the synthdef param
	Name() string
	// Index returns the index of the synthdef param
	Index() int32
	// InitialValue returns the initial value of the synthdef param
	InitialValue() float32
}

Param is the interface of a single synthdef parameter.

type ParamName

type ParamName struct {
	Name  string `json:"name,omitempty"`
	Index int32  `json:"index"`
}

ParamName represents a parameter name of a synthdef

func (*ParamName) Write

func (pn *ParamName) Write(w io.Writer) error

type Params

type Params interface {
	// Add adds a named parameter to a synthdef, with an initial value
	Add(name string, initialValue float32) Input
	// List returns a list of the params that have been added to a synthdef
	List() []Param
	// Control returns a Ugen that should be used as the first ugen
	// of any synthdef that has parameters
	Control() Ugen
}

Params is an interface that allows you to add parameters to a synthdef.

type PinkNoise

type PinkNoise struct {
}

PinkNoise generates noise whose spectrum falls off in power by 3 dB per octave. This gives equal power over the span of each octave. This version gives 8 octaves of pink noise.

func (PinkNoise) Rate

func (pink PinkNoise) Rate(rate int8) Input

Rate creates a new ugen at a specific rate. If rate is an unsupported value this method will cause a runtime panic.

type PlayBuf

type PlayBuf struct {
	// NumChannels number of playback channels
	NumChannels int
	// BufNum buffer to use
	BufNum Input
	// Speed is the playback speed: 1.0 for original speed,
	// 2.0 for Chipmunks, 0.5 for DJ Screw
	Speed Input
	// Trigger when this input changes from negative to positive
	// playback will jump to the beginning of the buffer
	Trigger Input
	// Start is the sample frame to start playback
	Start Input
	// Loop 1 is on, 0 is off
	Loop Input
	// Done action to take when done playing buffer.
	// See http://doc.sccode.org/Reference/UGen-doneActions.html
	Done int
}

PlayBuf plays back a sample from memory. If Buf is nil a runtime panic will occur.

func (PlayBuf) Rate

func (playbuf PlayBuf) Rate(rate int8) Input

Rate creates a new ugen at a specific rate. If rate is an unsupported value this method will cause a runtime panic. There will also be a runtime panic if BufNum is nil.

type Pulse

type Pulse struct {
	// Freq in Hz
	Freq Input
	// Width pulse width duty cycle from 0 to 1
	Width Input
}

Pulse band-limited pulse wave generator with pulse width modulation.

func (Pulse) Rate

func (pulse Pulse) Rate(rate int8) Input

Rate creates a new ugen at a specific rate. If rate is an unsupported value this method will cause a runtime panic.

type RLPF

type RLPF struct {
	// In is the input signal
	In Input
	// Freq cutoff in Hz
	Freq Input
	// RQ Reciprocal of Q
	RQ Input
}

RLPF a resonant low pass filter

func (RLPF) Rate

func (rlpf RLPF) Rate(rate int8) Input

Rate creates a new ugen at a specific rate. If rate is an unsupported value this method will cause a runtime panic.

type Rand added in v0.1.3

type Rand struct {
	Lo, Hi Input
}

Rand generates a single random float value in uniform distribution from Lo to Hi. It generates this when the SynthDef first starts playing, and remains fixed for the duration of the synth's existence.

func (Rand) Rate added in v0.1.3

func (rand Rand) Rate(rate int8) Input

Rate creates a new ugen at a specific rate. If rate is an unsupported value this method will cause a runtime panic.

type Saw

type Saw struct {
	Freq Input
}

Saw is a band-limited sawtooth wave generator.

func (Saw) Rate

func (saw Saw) Rate(rate int8) Input

Rate creates a new ugen at a specific rate. If rate is an unsupported value this method will cause a runtime panic.

type Select

type Select struct {
	Which  Input
	Inputs []Input
}

Select selects an output from an array of inputs.

func (Select) Rate

func (sel Select) Rate(rate int8) Input

Rate creates a new ugen at a specific rate. If rate is an unsupported value this method will cause a runtime panic.

type Server

type Server struct {
	*exec.Cmd

	Network      string
	Port         int
	StartTimeout time.Duration
}

Server represents a running instance of scsynth.

func (*Server) Start

func (s *Server) Start(timeout time.Duration) (io.ReadCloser, io.ReadCloser, error)

Start starts a new instance of scsynth. If the server doesn't print a line containing ServerReadyMessage within the timeout then ErrTimeout is returned.

func (*Server) Stop

func (s *Server) Stop() error

Stop stops a running server.

type ServerStatus

type ServerStatus struct {
	NumUgens          int32   `json:"numUgens"`
	NumSynths         int32   `json:"numSynths"`
	NumGroups         int32   `json:"numGroups"`
	NumSynthdefs      int32   `json:"numSynthdefs"`
	AvgCPU            float32 `json:"avgCPU"`
	PeakCPU           float32 `json:"peakCPU"`
	NominalSampleRate float32 `json:"nominalSampleRate"`
	ActualSampleRate  float32 `json:"actualSampleRate"`
}

ServerStatus represents the reply to the /status command.

type SinOsc

type SinOsc struct {
	// Freq is frequency in Hz
	Freq Input
	// Phase is the initial phase offset
	Phase Input
}

SinOsc is a table-lookup sinewave oscillator

func (SinOsc) Rate

func (sin SinOsc) Rate(rate int8) Input

Rate creates a new ugen at a specific rate. If rate is an unsupported value this method will cause a runtime panic.

type Synth

type Synth struct {
	DefName string `json:"defName"`
	ID      int32  `json:"id"`
	// contains filtered or unexported fields
}

Synth encapsulates a synth node.

func PlayDef

func PlayDef(def *Synthdef) (*Synth, error)

PlayDef plays a synthdef by sending the synthdef using DefaultClient, then immediately creating a synth node from the def.

func (*Synth) Get

func (s *Synth) Get(controlName string) (float32, error)

Get the value of a synth control.

func (*Synth) Set

func (s *Synth) Set(ctls map[string]float32) error

Set the value of a synth control.

type SynthArgs added in v0.1.3

type SynthArgs struct {
	DefName string
	ID      int32
	Action  int32
	Target  int32
	Ctls    map[string]float32
}

SynthArgs contains the arguments necessary to create a synth that is part of a group.

type Synthdef

type Synthdef struct {
	// Name is the name of the synthdef
	Name string `json:"name" xml:"Name,attr"`

	// Constants is a list of constants that appear in the synth def
	Constants []float32 `json:"constants" xml:"Constants>Constant"`

	// InitialParamValues is an array of initial values for synth params
	InitialParamValues []float32 `json:"initialParamValues" xml:"InitialParamValues>initialParamValue"`

	// ParamNames contains the names of the synth parameters
	ParamNames []ParamName `json:"paramNames" xml:"ParamNames>ParamName"`

	// Ugens is the list of ugens that appear in the synth def.
	// The root of the ugen graph will always be last.
	Ugens []*ugen `json:"ugens" xml:"Ugens>Ugen"`

	// Variants is the list of variants contained in the synth def
	Variants []*Variant `json:"variants" xml:"Variants>Variant"`
	// contains filtered or unexported fields
}

Synthdef defines the structure of synthdef data as defined in http://doc.sccode.org/Reference/Synth-Definition-File-Format.html

func NewSynthdef

func NewSynthdef(name string, graphFunc UgenFunc) *Synthdef

NewSynthdef creates a synthdef by traversing a ugen graph

Example
NewSynthdef("SineTone", func(p Params) Ugen {
	bus := C(0)
	sine := SinOsc{}.Rate(AR)
	return Out{bus, sine}.Rate(AR)
}).WriteJSON(os.Stdout)
Output:

{"name":"SineTone","constants":[440,0],"initialParamValues":[],"paramNames":[],"ugens":[{"name":"SinOsc","rate":2,"specialIndex":0,"inputs":[{"ugenIndex":-1,"outputIndex":0},{"ugenIndex":-1,"outputIndex":1}],"outputs":[2]},{"name":"Out","rate":2,"specialIndex":0,"inputs":[{"ugenIndex":-1,"outputIndex":1},{"ugenIndex":0,"outputIndex":0}],"outputs":[]}],"variants":[]}

func ReadSynthdef

func ReadSynthdef(r io.Reader) (*Synthdef, error)

ReadSynthdef reads a synthdef from an io.Reader

func (*Synthdef) Bytes

func (def *Synthdef) Bytes() ([]byte, error)

Bytes writes a synthdef to a byte array

func (*Synthdef) CompareToDef

func (def *Synthdef) CompareToDef(other *Synthdef) (bool, error)

CompareToDef compare this synthdef to another.

func (*Synthdef) CompareToFile

func (def *Synthdef) CompareToFile(path string) (bool, error)

CompareToFile compares this synthdef to another one stored on disk.

func (*Synthdef) Write

func (def *Synthdef) Write(w io.Writer) error

Write writes a binary representation of a synthdef to an io.Writer. The binary representation written by this method is the data that scsynth expects at its /d_recv endpoint.

func (*Synthdef) WriteGraph

func (def *Synthdef) WriteGraph(w io.Writer) error

WriteGraph writes a dot-formatted representation of a synthdef's ugen graph to an io.Writer. See http://www.graphviz.org/content/dot-language.

func (*Synthdef) WriteJSON

func (def *Synthdef) WriteJSON(w io.Writer) error

WriteJSON writes a json-formatted representation of a synthdef to an io.Writer.

func (*Synthdef) WriteXML

func (def *Synthdef) WriteXML(w io.Writer) error

WriteXML writes an xml-formatted representation of a synthdef to an io.Writer.

type TLC

type TLC struct {
	Time, Level float32
	Curve       interface{}
}

TLC (time, level, curve) triplet

type Ugen

type Ugen interface {
	// Name returns the name of the ugen node
	Name() string
	// Rate returns the rate of the ugen node
	Rate() int8
	// SpecialIndex returns the special index of the ugen node
	SpecialIndex() int16
	// Inputs returns the inputs of the ugen node.
	// Inputs can be
	// (1) Constant (float32)
	// (2) Control (synthdef param)
	// (3) Ugen
	Inputs() []Input
	// Outputs returns the outputs of the ugen node
	Outputs() []Output
}

Ugen defines the interface between synthdefs and ugens.

func NewControl

func NewControl(numOutputs int) Ugen

NewControl creates a new Control.

type UgenFunc

type UgenFunc func(p Params) Ugen

UgenFunc is a func that is used to define a ugen graph.

type UgenNode

type UgenNode struct {
	// contains filtered or unexported fields
}

UgenNode represents a node in a ugen graph.

func BinOpAdd

func BinOpAdd(rate int8, x, y Input, numOutputs int) *UgenNode

BinOpAdd creates a BinaryOpUGen that represents addition.

func BinOpMax added in v0.1.3

func BinOpMax(rate int8, x, y Input, numOutputs int) *UgenNode

BinOpMax creates a BinaryOpUgen that represents the maximum of two signals.

func BinOpMul

func BinOpMul(rate int8, x, y Input, numOutputs int) *UgenNode

BinOpMul creates a BinaryOpUGen that represents multiplication.

func MulAdd

func MulAdd(rate int8, in, mul, add Input, numOutputs int) *UgenNode

MulAdd creates a MulAdd ugen.

func NewUgenNode

func NewUgenNode(name string, rate int8, specialIndex int16, numOutputs int, inputs ...Input) *UgenNode

NewUgenNode is a factory function for creating new UgenNode instances. Panics if rate is not AR, KR, or IR. Panics if numOutputs <= 0.

func UnaryOpSoftClip added in v0.1.3

func UnaryOpSoftClip(rate int8, in Input, numOutputs int) *UgenNode

UnaryOpSoftClip adds distortion to a ugen.

func (*UgenNode) Add

func (un *UgenNode) Add(val Input) Input

Add adds an input to a ugen node.

func (*UgenNode) Inputs

func (un *UgenNode) Inputs() []Input

Inputs returns the inputs of the ugen node.

func (*UgenNode) IsOutput

func (un *UgenNode) IsOutput()

IsOutput initializes the outputs array of the ugen node.

func (*UgenNode) Max added in v0.1.3

func (un *UgenNode) Max(other Input) Input

Max computes the maximum of one Input and another.

func (*UgenNode) Mul

func (un *UgenNode) Mul(val Input) Input

Mul multiplies the ugen node by an input.

func (*UgenNode) MulAdd

func (un *UgenNode) MulAdd(mul, add Input) Input

MulAdd multiplies and adds inputs to a ugen node.

func (*UgenNode) Name

func (un *UgenNode) Name() string

Name returns the name of the ugen node.

func (*UgenNode) Outputs

func (un *UgenNode) Outputs() []Output

Outputs returns the outputs of the ugen node.

func (*UgenNode) Rate

func (un *UgenNode) Rate() int8

Rate returns the rate of the ugen node.

func (*UgenNode) SoftClip added in v0.1.3

func (un *UgenNode) SoftClip() Input

SoftClip adds distortion to a ugen.

func (*UgenNode) SpecialIndex

func (un *UgenNode) SpecialIndex() int16

SpecialIndex returns the special index of the ugen node.

type Variant

type Variant struct {
	Name               string    `json:"name,omitempty"`
	InitialParamValues []float32 `json:"initialParamValues"`
}

Variant provides a way to create synthdef presets.

func (*Variant) Write

func (variant *Variant) Write(w io.Writer) error

Write writes a variant to an io.Writer.

type WhiteNoise

type WhiteNoise struct {
}

WhiteNoise generates noise whose spectrum has equal power at all frequencies.

func (WhiteNoise) Rate

func (white WhiteNoise) Rate(rate int8) Input

Rate creates a new ugen at a specific rate. If rate is an unsupported value this method will cause a runtime panic.

type XLine

type XLine struct {
	Start Input
	End   Input
	Dur   Input
	Done  int
}

XLine generates an exponential curve from the start value to the end value. Both the start and end values must be non-zero and have the same sign.

func (XLine) Rate

func (xline XLine) Rate(rate int8) Input

Rate creates a new ugen at a specific rate. If rate is an unsupported value this method will cause a runtime panic.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL