Fetch the repository succeeded.
package effects
import (
"math"
"gitee.com/wulalade/hwpack/music/beep"
)
// Volume adjusts the volume of the wrapped Streamer in a human-natural way. Human's perception of
// volume is roughly logarithmic to gain and thus the natural way to adjust volume is exponential.
//
// Natural Base for the exponentiation is somewhere around 2. In order to adjust volume along
// decibells, pick 10 as the Base and set Volume to dB/10. However, adjusting volume along decibells
// is nowhere as natural as with bases around 2.
//
// Volume of 0 means no change. Negative Volume will decrease the perceived volume and positive will
// increase it.
//
// With exponential gain it's impossible to achieve the zero volume. When Silent field is set to
// true, the output is muted.
type Volume struct {
Streamer beep.Streamer
Base float64
Volume float64
Silent bool
}
// Stream streams the wrapped Streamer with volume adjusted according to Base, Volume and Silent
// fields.
func (v *Volume) Stream(samples [][2]float64) (n int, ok bool) {
n, ok = v.Streamer.Stream(samples)
gain := 0.0
if !v.Silent {
gain = math.Pow(v.Base, v.Volume)
}
for i := range samples[:n] {
samples[i][0] *= gain
samples[i][1] *= gain
}
return n, ok
}
// Err propagates the wrapped Streamer's errors.
func (v *Volume) Err() error {
return v.Streamer.Err()
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。