Beispiel #1
0
func main() {
	maxfreq := flag.Float64("maxfreq", 440, "max freq for sweep")
	// sinchg := flag.Float64("sinchgrate", 15, "chg rate for sin wav")
	bufsize := flag.Int("bufsize", 4096, "buffer size")
	t := flag.Int64("time", 15000, "milliseconds")
	flag.Parse()
	fmt.Println("start!")
	var s0 ugen.UGen = ugen.NewSin(float32(*maxfreq), 0, 0, 1)
	// var s1 ugen.UGen = ugen.NewSin(1004, 0, 0, 1)
	// var s2 ugen.UGen = ugen.NewSin(1008, 0, 0, 1)
	// var s3 ugen.UGen = ugen.NewSin(1016, 0, 0, 1)
	// var sp ugen.UGen = ugen.NewSin(float32(*sinchg), 0, 440, float32(*maxfreq - 440))

	// ml := ugen.NewMixer(4,2)
	//
	// ml.SetInput(0, ugen.NewSpreaderWithUGen(2, s0))
	// ml.SetInput(1, ugen.NewSpreaderWithUGen(2, s1))
	// ml.SetInput(2, ugen.NewSpreaderWithUGen(2, s2))
	// ml.SetInput(3, ugen.NewSpreaderWithUGen(2, s3))

	// ml.ParamChannel() <- ugen.ParamValue{0, 0.05}
	// ml.ParamChannel() <- ugen.ParamValue{1, 0.05}
	// ml.ParamChannel() <- ugen.ParamValue{2, 0.05}
	// ml.ParamChannel() <- ugen.ParamValue{3, 0.05}

	// var ps = ugen.NewAudioParam()
	// ps.SetUGenSource(0, sp, 0)
	// ps.SetDest(0, s0, 0)

	var o = ugen.NewPortAudioOutput(2)
	var op = ugen.OutputParams{SampleRate: 44100, BufferSize: *bufsize}

	// o.SetInput(0, ml)
	o.SetInput(0, ugen.NewSpreaderWithUGen(2, s0))
	//	ps.Start(op)
	o.Start(op)
	go func() {
		t := time.Tick(time.Second)
		for {
			<-t
			ugen.LogRecycleStats()
			// ugen.LogStackTrace()
		}
	}()
	fmt.Println("sleeping!")
	time.Sleep(time.Duration(*t) * time.Millisecond)
	fmt.Println("stopping!")
	o.Stop()
	// ps.Stop()
}
Beispiel #2
0
func main() {
	maxfreq := flag.Float64("maxfreq", 440, "max freq for sweep")
	sinchg := flag.Float64("sinchgrate", 15, "chg rate for sin wav")
	bufsize := flag.Int("bufsize", 4096, "buffer size")
	t := flag.Int64("time", 15000, "milliseconds")
	filename := flag.String("filename", "tableout.wav", "output filename")
	flag.Parse()
	tables := flag.Args()

	fmt.Println("start!")
	var sp ugen.UGen = ugen.NewSin(float32(*sinchg), 0, 440, float32(*maxfreq-440))
	var ps = ugen.NewAudioParam()
	ps.SetUGenSource(0, sp, 0)

	var o = ugen.NewSndfileOut(*filename, sndfile.Info{Channels: 2, Format: sndfile.SF_FORMAT_WAV | sndfile.SF_FORMAT_PCM_24}, 1, true)
	var op = ugen.OutputParams{SampleRate: 44100, BufferSize: *bufsize}

	custombuf := make([]float32, 8192)

	go func() {
		t := time.Tick(time.Second)
		for {
			<-t
			ugen.LogRecycleStats()
			// ugen.LogStackTrace()
		}
	}()
TABLES:
	for _, table := range tables {
		var s0 ugen.UGen
		var err error
		switch table {
		case "sin":
			s0, err = ugen.NewTableOsc(1000, 0, 0, 1, false, ugen.SinTable, 8192, nil)
		case "tan":
			s0, err = ugen.NewTableOsc(1000, 0, 0, 1, false, ugen.TanTable, 8192, nil)
		case "pulse":
			s0, err = ugen.NewTableOsc(1000, 0, 0, 1, false, ugen.PulseTable, 8192, nil, 0.5)
		case "tri":
			s0, err = ugen.NewTableOsc(1000, 0, 0, 1, false, ugen.TriTable, 8192, nil)
		case "saw":
			s0, err = ugen.NewTableOsc(1000, 0, 0, 1, false, ugen.SawTable, 8192, nil, 0)
		case "custom":
			s0, err = ugen.NewTableOsc(1000, 0, 0, 1, false, ugen.CustomTable, 8192, custombuf)
		default:
			continue TABLES
		}

		if err != nil {
			fmt.Println(err)
			continue TABLES
		}

		spread := ugen.NewSpreaderWithUGen(2, s0)
		o.SetInput(0, spread)
		ps.SetDest(0, s0, 0)
		ps.Start(op)
		o.Start(op)
		fmt.Println("sleeping!")
		time.Sleep(time.Duration(*t) * time.Millisecond)
		fmt.Println("stopping!")
		o.Stop()
		ps.Stop()
	}
}
Beispiel #3
0
func main() {
	count := flag.Int("count", 0, "Number of sines")
	interval := flag.Float64("interval", 2, "Multiplier for each increment. If <= 1 increase arithmetically, not geometrically")
	outch := flag.Int("channels", 2, "channels in output device")
	bufsize := flag.Int("bufsize", 4096, "buffer size")
	samplerate := flag.Float64("samplerate", 44100, "sample rate")
	minfreq := flag.Float64("minfreq", 20, "starting frequency")
	maxfreq := flag.Float64("maxfreq", -1, "ending frequency")
	t := flag.Int64("time", 15000, "milliseconds")
	flag.Parse()

	freqs := make([]float32, 0)
	if *maxfreq == -1 {
		if *count <= 0 {
			fmt.Println("No maxfreq, no count. Can't read your mind, human.")
			return
		}
		if *interval > 1 {
			for f, i := float32(*minfreq), 0; i < *count; f, i = f*float32(*interval), i+1 {
				freqs = append(freqs, f)
			}
		} else {
			for f, i := float32(*minfreq), 0; i < *count; f, i = f+float32(*minfreq), i+1 {
				freqs = append(freqs, f)
			}
		}
	} else {
		if *interval > 1 {
			for f, i := float32(*minfreq), 0; i < *count && f < float32(*maxfreq); f, i = f*float32(*interval), i+1 {
				freqs = append(freqs, f)
			}
		} else {
			for f, i := float32(*minfreq), 0; i < *count && f < float32(*maxfreq); f, i = f+float32(*minfreq), i+1 {
				freqs = append(freqs, f)
			}
		}
	}

	fmt.Println("frequencies", freqs)

	mx := ugen.NewMixer(len(freqs), *outch)

	for i := 0; i < len(freqs); i++ {
		mx.SetInput(i, ugen.NewSpreaderWithUGen(*outch, ugen.NewSin(freqs[i], 0, 0, 1/float32(len(freqs)))))
	}

	fmt.Println("start!")

	var o = ugen.NewPortAudioOutput(*outch)
	var op = ugen.OutputParams{SampleRate: *samplerate, BufferSize: *bufsize}

	o.SetInput(0, mx)
	o.Start(op)
	go func() {
		t := time.Tick(time.Second)
		for {
			<-t
			ugen.LogRecycleStats()
			// ugen.LogStackTrace()
		}
	}()
	fmt.Println("sleeping!")
	time.Sleep(time.Duration(*t) * time.Millisecond)
	fmt.Println("stopping!")
	o.Stop()
}