简体   繁体   English

如何将网络音频振荡器从(-1,1)缩放为(x,y)

[英]how to scale web audio oscillator from (-1,1) to (x,y)

I would like to map the signal of an oscillator from (-1,1) to (x,y) For what I've understand so far, gain nodes can be used for that. 我想将振荡器的信号从(-1,1)映射到(x,y)。到目前为止,我了解到可以使用增益节点。

if i connect my oscillator to a gain node that value is 1, I've get back my signal in the range (0,2) 如果我将振荡器连接到值为1的增益节点,我的信号将返回(0,2)

if I feed this signal into another gain at value 0.25 i've get back a signal in range (0,0.5) 如果我将此信号馈入另一个值为0.25的增益中,我会返回一个范围为(0,0.5)的信号

but how to do if I want my signal to be in the range (0.5, 1) ? 但是,如果我希望信号在(0.5,1)范围内怎么办?

I'm wandering why we cannot simply map a function over a signal. 我在徘徊为什么我们不能简单地将函数映射到信号上。

like signal.map(function(x){return x + 0.5}) 像signal.map(function(x){return x + 0.5})

For the specific scenario you mention ("[what] if I want my signal to be in the range (0.5, 1)?"), you should connect your (0,0.5) signal into the same node as a ConstantSourceNode: 对于您提到的特定场景(“ [如果我希望我的信号在(0.5,1)范围内?”)?),您应该将(0,0.5)信号连接到ConstantConstantNode所在的节点中:

var constant = new ConstantSourceNode( { offset: 0.5 } );
constant.connect( /* same node as your signal */ );

For the more general case - like, you want to do non-linear mapping - use a WaveShaperNode. 对于更一般的情况-例如,您要进行非线性映射-请使用WaveShaperNode。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM