func (s *song) Sing() float64 { s.n-- if s.n < 0 { s.n = int(s.Params.SampleRate / 20) for i, t := range s.tones { if t.Smoother.Value() < -16 { s.removeTone(i) break } } for len(s.tones) < 6 { s.addTone() print(".") } for _, t := range s.tones { t.dAmp = math.Max(-8, math.Min(8, t.dAmp+4*(rand.NormFloat64()+1/t.amp)/20)) // t.dAmp *= .98 t.amp = math.Min(0, t.amp+t.dAmp/20) } // c := s.complexity() // for _, t := range s.tones { // t.amp += math.Log2(1 / c) // } } x := 0.0 for _, t := range s.tones { x += t.sing() } return audio.Saturate(x) }
func main() { flag.Parse() if *random { *seed = time.Now().UnixNano() fmt.Println("seed =", *seed) } if *seed != math.MinInt64 { *random = true } rand.Seed(*seed) portaudio.Initialize() defer portaudio.Terminate() p := audio.Params{SampleRate: 48000} m := audio.MultiVoice{} audio.Init(&m, p) // for _, x := range [][2]float64{{1, 1}, {2, 1}, {3, 1}, {4, 1}, {5, 1}, {3, 2}, {4, 3}, {5, 4}, {7, 4}, {6, 5}, {7, 5}, {8, 5}, {9, 5}} { for xy := 1; xy <= 60; xy++ { for x := 2; x <= int(math.Sqrt(float64(xy))); x++ { if y := xy / x; x*y == xy && relPrime(x, y) { x, y, xy := float64(x), float64(y), float64(xy) c := math.Exp(-xy * math.Log2(y/x) / 12) f := y / x phase := 0.0 if *random { phase = rand.Float64() } m.Add(newSineBeat(.5*c, 128*f, 1/xy, phase, .1/f)) } } } s, err := portaudio.OpenDefaultStream(0, 1, p.SampleRate, 512, func(out []float32) { for i := range out { out[i] = float32(audio.Saturate(m.Sing())) } }) if err != nil { panic(err) } s.Start() fmt.Println("Press Enter to stop.") fmt.Scanln() s.Stop() }
func (s *song) Sing() float64 { s.EventDelay.Step() return audio.Saturate(s.MultiVoice.Sing() / 4) }
func (t *tone) sing() float64 { return t.attenuate * math.Exp2(t.Smoother.Smooth(t.amp)) * audio.Saturate(2*t.Osc.Sing()) }
func (v *sineVoice) Sing() float64 { return audio.Saturate(2*v.Osc.Sing()) * v.Env.Sing() * v.amp }
func (s *song) Sing() float64 { s.EventDelay.Step() x := audio.Saturate(s.MultiVoice.Sing()) return audio.Saturate((2*x + s.Reverb.Filter(x)) / 3) }
func (s *sines) Sing() float64 { return math.Exp2(s.Amplitude.Sing()) * audio.Saturate(s.MultiVoice.Sing()*math.Exp2(s.Distortion.Sing())) }
func (v *sineVoice) Sing() float64 { v.Sine.Freq(math.Exp2(v.Pitch.Sing())) g := math.Exp2(v.Amp.Sing()) * v.Env.Sing() return g * audio.Saturate(2*v.Sine.Sing()) }