コード例 #1
0
ファイル: filter.go プロジェクト: lamproae/sigourney
func main() {
	fs := audio.NewSin()
	fs.Input("pitch", audio.Value(-0.4))
	fm := audio.NewMul()
	fm.Input("a", audio.Value(0.2))
	fm.Input("b", fs)

	s := audio.NewSquare()
	s.Input("pitch", audio.Value(-0.1))
	f := audio.NewFilter()
	f.Input("in", s)
	f.Input("freq", fm)

	debug.View(debug.Render(debug.Process(f, 10)))
}
コード例 #2
0
ファイル: ui.go プロジェクト: rakyll/sigourney
func (u *UI) Handle(m *Message) error {
	switch a := m.Action; a {
	case "new":
		u.newObject(m.Name, m.Kind, m.Value)
	case "connect":
		return u.connect(m.From, m.To, m.Input)
	case "disconnect":
		return u.disconnect(m.From, m.To, m.Input)
	case "set":
		o, ok := u.objects[m.Name]
		if !ok {
			return errors.New("unknown object: " + m.Name)
		}
		o.Value = m.Value
		v := audio.Value(m.Value)
		o.proc = v
		u.engine.Lock()
		o.dup.SetSource(v)
		u.engine.Unlock()
	case "destroy":
		return u.destroy(m.Name)
	case "save":
		return u.save(m.Name)
	case "load":
		if err := u.engine.Stop(); err != nil {
			return err
		}
		for name := range u.objects {
			if name != "engine" {
				if err := u.destroy(name); err != nil {
					return err
				}
			}
		}
		if err := u.load(m.Name); err != nil {
			return err
		}
		return u.engine.Start()
	case "setDisplay":
		o, ok := u.objects[m.Name]
		if !ok {
			return errors.New("bad Name: " + m.Name)
		}
		for k, v := range m.Display {
			if o.Display == nil {
				o.Display = make(map[string]interface{})
			}
			o.Display[k] = v
		}
	default:
		return fmt.Errorf("unrecognized Action:", a)
	}
	return nil
}
コード例 #3
0
ファイル: ui.go プロジェクト: nilslice/sigourney
func (u *UI) Set(name string, v float64) error {
	o, ok := u.objects[name]
	if !ok {
		return errors.New("unknown object: " + name)
	}
	o.Value = v
	av := audio.Value(v)
	o.proc = av
	u.engine.Lock()
	o.dup.SetSource(av)
	u.engine.Unlock()
	return nil
}
コード例 #4
0
ファイル: ui.go プロジェクト: lamproae/sigourney
func (o *Object) init() {
	var p interface{}
	switch o.Kind {
	case "clip":
		p = audio.NewClip()
	case "delay":
		p = audio.NewDelay()
	case "engine":
		p = audio.NewEngine()
	case "env":
		p = audio.NewEnv()
	case "mul":
		p = audio.NewMul()
	case "noise":
		p = audio.NewNoise()
	case "quant":
		p = audio.NewQuant()
	case "rand":
		p = audio.NewRand()
	case "saw":
		p = audio.NewBandLimitedSaw()
	case "sin":
		p = audio.NewSin()
	case "skip":
		p = audio.NewSkip()
	case "sequencer":
		p = audio.NewStep()
	case "square":
		p = audio.NewBandLimitedSquare()
	case "sum":
		p = audio.NewSum()
	case "triangle":
		p = audio.NewBandLimitedTriangle()
	case "value":
		p = audio.Value(o.Value)
	case "gate":
		p = midi.NewGate()
	case "note":
		p = midi.NewNote()
	default:
		panic("bad kind: " + o.Kind)
	}
	var dup *audio.Dup
	if proc, ok := p.(audio.Processor); ok {
		dup = audio.NewDup(proc)
	}
	o.proc = p
	o.dup = dup
	o.output = make(map[dest]*audio.Output)
}
コード例 #5
0
ファイル: ui.go プロジェクト: rakyll/sigourney
func NewObject(name, kind string, value float64) *Object {
	var p interface{}
	switch kind {
	case "clip":
		p = audio.NewClip()
	case "engine":
		p = audio.NewEngine()
	case "env":
		p = audio.NewEnv()
	case "mul":
		p = audio.NewMul()
	case "rand":
		p = audio.NewRand()
	case "sin":
		p = audio.NewSin()
	case "square":
		p = audio.NewSquare()
	case "sum":
		p = audio.NewSum()
	case "value":
		p = audio.Value(value)
	case "note":
		p = audio.NewMidiNote()
	case "gate":
		p = audio.NewMidiGate()
	default:
		panic("bad kind: " + kind)
	}
	var dup *audio.Dup
	if proc, ok := p.(audio.Processor); ok {
		dup = audio.NewDup(proc)
	}
	return &Object{
		Name:  name,
		Kind:  kind,
		Value: value,
		Input: make(map[string]string),

		proc:   p,
		dup:    dup,
		output: make(map[dest]*audio.Output),
	}
}
コード例 #6
0
ファイル: ui.go プロジェクト: nilslice/sigourney
func (u *UI) Disconnect(from, to, input string) error {
	f, ok := u.objects[from]
	if !ok {
		return errors.New("unknown From: " + from)
	}
	t, ok := u.objects[to]
	if !ok {
		return errors.New("unknown To: " + to)
	}

	u.engine.Lock()
	f.output[dest{to, input}].Close()
	t.proc.(audio.Sink).Input(input, audio.Value(0))
	u.engine.Unlock()

	delete(f.output, dest{to, input})
	delete(t.Input, input)

	return nil
}
コード例 #7
0
ファイル: demo.go プロジェクト: rakyll/sigourney
func demo() error {
	e := audio.NewEngine()
	e.Input("in", audio.NewSin())
	if err := e.Start(); err != nil {
		return err
	}
	time.Sleep(time.Second)
	if err := e.Stop(); err != nil {
		return err
	}

	u, err := ui.New()
	if err != nil {
		return err
	}
	for _, m := range []*ui.Message{
		{Action: "new", Name: "sin1", Kind: "sin"},
		{Action: "new", Name: "sin2", Kind: "sin"},
		{Action: "new", Name: "sum1", Kind: "sum"},
		{Action: "new", Name: "mul1", Kind: "mul"},
		{Action: "new", Name: "mul2", Kind: "mul"},
		{Action: "new", Name: "val1", Kind: "value", Value: 0.1},
		{Action: "connect", From: "sin1", To: "engine", Input: "in"},
		{Action: "connect", From: "mul1", To: "sin1", Input: "pitch"},
		{Action: "connect", From: "sin2", To: "mul1", Input: "a"},
		{Action: "connect", From: "val1", To: "mul1", Input: "b"},
		{Action: "connect", From: "val1", To: "sin2", Input: "pitch"},
	} {
		if err := u.Handle(m); err != nil {
			return err
		}
	}
	time.Sleep(time.Second)
	for _, m := range []*ui.Message{
		{Action: "set", Name: "val1", Value: 0.15},
	} {
		if err := u.Handle(m); err != nil {
			return err
		}
	}
	time.Sleep(time.Second)
	if err := u.Close(); err != nil {
		return err
	}

	e = audio.NewEngine()

	sinMod := audio.NewSin()
	sinMod.Input("pitch", audio.Value(-0.1))

	sinModMul := audio.NewMul()
	sinModMul.Input("a", sinMod)
	sinModMul.Input("b", audio.Value(0.1))

	sin := audio.NewSin()
	sin.Input("pitch", sinModMul)

	envMod := audio.NewSin()
	envMod.Input("pitch", audio.Value(-1))

	envModMul := audio.NewMul()
	envModMul.Input("a", envMod)
	envModMul.Input("b", audio.Value(0.02))

	envModSum := audio.NewSum()
	envModSum.Input("a", envModMul)
	envModSum.Input("b", audio.Value(0.021))

	sin2 := audio.NewSin()
	sin2.Input("pitch", audio.Value(-0.6))

	env := audio.NewEnv()
	env.Input("trig", sin2)
	env.Input("att", audio.Value(0.0001))
	env.Input("dec", envModSum)

	mul := audio.NewMul()
	mul.Input("a", sin)
	mul.Input("b", env)

	mulMul := audio.NewMul()
	mulMul.Input("a", mul)
	mulMul.Input("b", audio.Value(0.5))

	e.Input("in", mulMul)

	if err := e.Start(); err != nil {
		return err
	}

	os.Stdout.Write([]byte("Press enter to stop...\n"))
	os.Stdin.Read([]byte{0})

	return e.Stop()
}
コード例 #8
0
ファイル: sine.go プロジェクト: lamproae/sigourney
func main() {
	s := audio.NewSin()
	s.Input("pitch", audio.Value(-0.3))
	debug.View(debug.Render(debug.Process(s, 5)))
}
コード例 #9
0
ファイル: demo.go プロジェクト: lamproae/sigourney
func demo() error {
	e := audio.NewEngine()
	e.Input("in", audio.NewSin())
	if err := e.Start(); err != nil {
		return err
	}
	time.Sleep(time.Second)
	if err := e.Stop(); err != nil {
		return err
	}

	e = audio.NewEngine()

	sinMod := audio.NewSin()
	sinMod.Input("pitch", audio.Value(-0.1))

	sinModMul := audio.NewMul()
	sinModMul.Input("a", sinMod)
	sinModMul.Input("b", audio.Value(0.1))

	sin := audio.NewSin()
	sin.Input("pitch", sinModMul)

	envMod := audio.NewSin()
	envMod.Input("pitch", audio.Value(-1))

	envModMul := audio.NewMul()
	envModMul.Input("a", envMod)
	envModMul.Input("b", audio.Value(0.02))

	envModSum := audio.NewSum()
	envModSum.Input("a", envModMul)
	envModSum.Input("b", audio.Value(0.021))

	sin2 := audio.NewSin()
	sin2.Input("pitch", audio.Value(-0.6))

	env := audio.NewEnv()
	env.Input("trig", sin2)
	env.Input("att", audio.Value(0.0001))
	env.Input("dec", envModSum)

	mul := audio.NewMul()
	mul.Input("a", sin)
	mul.Input("b", env)

	mulMul := audio.NewMul()
	mulMul.Input("a", mul)
	mulMul.Input("b", audio.Value(0.5))

	e.Input("in", mulMul)

	if err := e.Start(); err != nil {
		return err
	}

	os.Stdout.Write([]byte("Press enter to stop...\n"))
	os.Stdin.Read([]byte{0})

	return e.Stop()
}