本文整理匯總了Golang中github.com/kierdavis/gosound/sound.Context.AppendStream方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.AppendStream方法的具體用法?Golang Context.AppendStream怎麽用?Golang Context.AppendStream使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/kierdavis/gosound/sound.Context
的用法示例。
在下文中一共展示了Context.AppendStream方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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
}