예제 #1
0
func playMelodySynth(ctx sound.Context, freqInput chan float64) (stream chan float64) {
	freqInput1, freqInput2 := ctx.Fork2(freqInput)

	return ctx.Add(
		ctx.Mul(
			ctx.Square(
				freqInput1,
				ctx.Const(0.5),
			),
			ctx.Const(0.75),
		),
		ctx.Mul(
			ctx.Saw(
				ctx.Mul(freqInput2, ctx.Const(2)),
			),
			ctx.Const(0.25),
		),
	)
}
예제 #2
0
func PlayTrebleNote(ctx sound.Context, freqInput chan float64, duration time.Duration) (stream chan float64) {
	freqInput1, freqInput2 := ctx.Fork2(freqInput)

	return ctx.TakeDuration(
		ctx.Add(
			ctx.Mul(
				ctx.Square(
					freqInput1,
					ctx.Const(0.5),
				),
				ctx.Const(0.75),
			),
			ctx.Mul(
				ctx.Saw(
					ctx.Mul(freqInput2, ctx.Const(2)),
				),
				ctx.Const(0.25),
			),
		),
		duration,
		true,
	)
}
예제 #3
0
func KarplusStrongSaw(ctx sound.Context, frequency, cutoff, decay float64) (output chan float64) {
	delaySamples := uint((1.0 / frequency) * ctx.SampleRate)
	wave := ctx.Saw(ctx.Const(frequency))
	input := ctx.Take(wave, delaySamples, true)
	return KarplusStrong(ctx, input, delaySamples, cutoff, decay)
}