Пример #1
0
func genSlideEnvelope(ctx sound.Context, from, to music.Note, duration time.Duration) (stream chan float64) {
	return ctx.LinearEnvelope(
		from.Frequency(),
		duration*1/10,
		from.Frequency(),
		duration*8/10,
		to.Frequency(),
		duration*1/10,
		to.Frequency(),
	)
}
Пример #2
0
func SequenceTreble(ctx sound.Context) (seq *sound.Sequencer) {
	melody := GenerateTrebleMelody()
	seq = sound.NewSequencer(ctx)

	var pos time.Duration

	for i := 0; i < NumBars*3; i++ {
		var freqInput chan float64
		var duration time.Duration

		if rand.Float64() < 0.01 {
			from := (<-melody).Frequency()
			to := (<-melody).Frequency()

			freqInput = ctx.LinearEnvelope(
				from,
				NoteDuration*1/5,
				from,
				NoteDuration*8/5,
				to,
				NoteDuration*1/5+time.Millisecond,
				to,
			)
			duration = NoteDuration * 2

		} else {
			freqInput = ctx.Const((<-melody).Frequency())
			duration = NoteDuration
		}

		note := PlayTrebleNote(ctx, freqInput, duration)
		seq.Add(pos, note)
		pos += duration
	}

	return seq
}