當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Context.Add方法代碼示例

本文整理匯總了Golang中github.com/kierdavis/gosound/sound.Context.Add方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.Add方法的具體用法?Golang Context.Add怎麽用?Golang Context.Add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/kierdavis/gosound/sound.Context的用法示例。


在下文中一共展示了Context.Add方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Generate

func Generate(ctx sound.Context) (left, right chan float64) {
	treble := SequenceTreble(ctx).Play()
	bass := SequenceBass(ctx).Play()

	trebleLeft, trebleRight := ctx.Fork2(treble)
	bassLeft, bassRight := ctx.Fork2(bass)

	left = ctx.TakeDuration(
		ctx.Add(
			ctx.Mul(trebleLeft, ctx.Const(0.3)),
			ctx.Mul(bassLeft, ctx.Const(0.4)),
		),
		NoteDuration*NumBars*3+time.Second*2,
		true,
	)

	right = ctx.TakeDuration(
		ctx.Add(
			ctx.Mul(trebleRight, ctx.Const(0.4)),
			ctx.Mul(bassRight, ctx.Const(0.3)),
		),
		NoteDuration*NumBars*3+time.Second*2,
		true,
	)

	return left, right
}
開發者ID:kierdavis,項目名稱:gosound-demos,代碼行數:27,代碼來源:arp2.go

示例2: genBassArpeggio

func genBassArpeggio(ctx sound.Context, scale music.Scale, n int) (stream chan float64) {
	var parts []chan float64

	root := scale.Root

	for i := 0; i < n; i++ {
		note := scale.Root
		nextNote(&scale, root)

		if rand.Float64() < 0.05 {
			part := ctx.TakeDuration(
				ctx.Mul(
					ctx.Const(note.Frequency()),
					ctx.Add( // Add a slight vibrato effect
						ctx.Mul(
							ctx.Sine(ctx.Const(24)),
							ctx.Const(0.01),
						),
						ctx.Const(1.0),
					),
				),
				time.Second*3/8,
				false,
			)

			parts = append(parts, part)

		} else if rand.Float64() < 0.05 {
			part1 := ctx.TakeDuration(
				ctx.Const(note.Frequency()),
				time.Second/8,
				false,
			)

			part2 := ctx.TakeDuration(
				ctx.Const(note.Frequency()),
				time.Second/8,
				false,
			)

			parts = append(parts, part1)
			parts = append(parts, ctx.TakeDuration(ctx.Silence(), time.Second/8, false))
			parts = append(parts, part2)

		} else {
			part := ctx.TakeDuration(
				ctx.Const(note.Frequency()),
				time.Second/8,
				false,
			)

			parts = append(parts, part)
			parts = append(parts, ctx.TakeDuration(ctx.Silence(), time.Second/4, false))
		}
	}

	return ctx.Append(parts...)
}
開發者ID:kierdavis,項目名稱:gosound-demos,代碼行數:58,代碼來源:arp1.go

示例3: FilterFormant

func FilterFormant(ctx sound.Context, input chan float64, centre, q, gain float64) (output chan float64) {
	lowerCutoff := (centre - (centre / q)) / 0.772
	upperCutoff := (centre + (centre / q)) / 1.29

	input, formant := ctx.Fork2(input)
	formant = filter.Chebyshev(ctx, formant, filter.HighPass, lowerCutoff, 0.5, 2)
	formant = filter.Chebyshev(ctx, formant, filter.LowPass, upperCutoff, 0.5, 2)
	formant = ctx.Mul(formant, ctx.Const(gain-1.0))
	return ctx.Add(input, formant)
}
開發者ID:kierdavis,項目名稱:gosound-demos,代碼行數:10,代碼來源:karplusstrongdemo.go

示例4: playBassSynth

func playBassSynth(ctx sound.Context, freqInput chan float64) (stream chan float64) {
	return ctx.Add(
		ctx.Mul(
			ctx.Square(
				freqInput,
				ctx.Const(0.8),
			),
		),
	)
}
開發者ID:kierdavis,項目名稱:gosound-demos,代碼行數:10,代碼來源:arp1.go

示例5: PlayBassNote

func PlayBassNote(ctx sound.Context, freqInput chan float64, duration time.Duration) (stream chan float64) {
	return ctx.TakeDuration(
		ctx.Add(
			ctx.Mul(
				ctx.Square(
					freqInput,
					ctx.Const(0.8),
				),
			),
		),
		duration,
		true,
	)
}
開發者ID:kierdavis,項目名稱:gosound-demos,代碼行數:14,代碼來源:arp2.go

示例6: playMelodySynth

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),
		),
	)
}
開發者ID:kierdavis,項目名稱:gosound-demos,代碼行數:19,代碼來源:arp1.go

示例7: PlayTrebleNote

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,
	)
}
開發者ID:kierdavis,項目名稱:gosound-demos,代碼行數:23,代碼來源:arp2.go

示例8: KarplusStrong

// input should be finite and preferably short (e.g. one cycle of a triangle wave)
func KarplusStrong(ctx sound.Context, input chan float64, delaySamples uint, cutoff float64, decay float64) (output chan float64) {
	feedback := make(chan float64, ctx.StreamBufferSize)

	// Mix the input with the feedback.
	output = ctx.Add(input, feedback)

	// Fork off a copy of the output.
	output, outputCopy := ctx.Fork2(output)

	// The copy is first passed through a delay line...
	outputCopy = delay(ctx, outputCopy, delaySamples)

	// ...then filtered...
	//outputCopy = filter.Chebyshev(ctx, outputCopy, filter.LowPass, cutoff, 0.5, 2)
	outputCopy = filter.RC(ctx, outputCopy, filter.LowPass, cutoff)

	// ...and finally attenuated slightly.
	outputCopy = ctx.Mul(outputCopy, ctx.Const(decay))

	// The filtered output copy is fed back into the system.
	go pipe(outputCopy, feedback)

	return output
}
開發者ID:kierdavis,項目名稱:gosound-demos,代碼行數:25,代碼來源:karplusstrongdemo.go

示例9: Generate

func Generate(ctx sound.Context) (left, right chan float64) {
	rand.Seed(time.Now().UnixNano())

	melodyParts := make(chan chan float64)
	bassParts := make(chan chan float64)

	go func() {
		for {
			var octave int
			x := rand.Float64()
			if x < 0.3 {
				octave = 4
			} else {
				octave = 5
			}

			root := music.MakeNote(music.D, octave)
			scale := music.Scale{Root: root, Intervals: music.HarmonicMinor}

			var n int
			x = rand.Float64()
			if x < 0.2 {
				n = 3
			} else if x < 0.4 {
				n = 6
			} else if x < 0.6 {
				n = 12
			} else if x < 0.8 {
				n = 18
			} else {
				n = 24
			}

			melodyParts <- genMelodyArpeggio(ctx, scale, n)
		}
	}()

	go func() {
		for {
			var octave int
			x := rand.Float64()
			if x < 0.3 {
				octave = 3
			} else {
				octave = 2
			}

			root := music.MakeNote(music.D, octave)
			scale := music.Scale{Root: root, Intervals: music.HarmonicMinor}

			var n int
			x = rand.Float64()
			if x < 0.2 {
				n = 3
			} else if x < 0.4 {
				n = 6
			} else if x < 0.6 {
				n = 9
			} else if x < 0.8 {
				n = 12
			} else {
				n = 18
			}

			bassParts <- genBassArpeggio(ctx, scale, n)
		}
	}()

	melody := playMelodySynth(ctx, ctx.AppendStream(melodyParts))
	bass := playBassSynth(ctx, ctx.AppendStream(bassParts))

	melodyLeft, melodyRight := ctx.Fork2(melody)
	bassLeft, bassRight := ctx.Fork2(bass)

	left = ctx.TakeDuration(
		ctx.Add(
			ctx.Mul(melodyLeft, ctx.Const(0.4)),
			ctx.Mul(bassLeft, ctx.Const(0.6)),
		),
		time.Second*300,
		true,
	)

	right = ctx.TakeDuration(
		ctx.Add(
			ctx.Mul(melodyRight, ctx.Const(0.6)),
			ctx.Mul(bassRight, ctx.Const(0.4)),
		),
		time.Second*300,
		true,
	)

	return left, right
}
開發者ID:kierdavis,項目名稱:gosound-demos,代碼行數:94,代碼來源:arp1.go


注:本文中的github.com/kierdavis/gosound/sound.Context.Add方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。