Ejemplo n.º 1
0
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)
}
Ejemplo n.º 2
0
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),
	}
}
Ejemplo n.º 3
0
func main() {
	flag.Usage = func() {
		fmt.Fprint(os.Stderr, usage)
		flag.PrintDefaults()
		os.Exit(2)
	}
	flag.Parse()
	if flag.NArg() != 1 {
		flag.Usage()
	}
	p, err := drum.DecodeFile(flag.Arg(0))
	if err != nil {
		log.Fatalf("cannot decode splice file: %v", err)
	}
	if *showInfo {
		fmt.Print(p)
		return
	}
	patches, err := readPatches(p, *sampleDir)
	if err != nil {
		log.Fatalf("cannot read sample patches: %v", err)
	}
	drumMod, err := drummachine.New(p, patches)
	if err != nil {
		log.Fatalf("cannot make new drum machine: %v", err)
	}

	portaudio.Initialize()
	defer portaudio.Terminate()

	portmidi.Initialize()
	defer portmidi.Terminate()

	e := audio.NewEngine()
	e.Input("in", drumMod)
	if err := e.Start(); err != nil {
		panic(err)
	}
	select {}
}
Ejemplo n.º 4
0
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()
}
Ejemplo n.º 5
0
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()
}