Example #1
0
func SequenceBass(ctx sound.Context) (seq *sound.Sequencer) {
	melody := GenerateBassMelody()
	seq = sound.NewSequencer(ctx)

	var pos time.Duration

	for i := 0; i < NumBars; i++ {
		if rand.Float64() < 0.05 {
			freqInput := ctx.Const((<-melody).Frequency())
			note := PlayBassNote(ctx, freqInput, NoteDuration*3)
			seq.Add(pos, note)

		} else if rand.Float64() < 0.05 {
			freqInput1, freqInput2 := ctx.Fork2(ctx.Const((<-melody).Frequency()))
			note1 := PlayBassNote(ctx, freqInput1, NoteDuration)
			note2 := PlayBassNote(ctx, freqInput2, NoteDuration)
			seq.Add(pos, note1)
			seq.Add(pos+NoteDuration*2, note2)

		} else {
			freqInput := ctx.Const((<-melody).Frequency())
			note := PlayBassNote(ctx, freqInput, NoteDuration)
			seq.Add(pos, note)
		}

		pos += NoteDuration * 3
	}

	return seq
}
Example #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
}