样本值数组中的createPeriodicWave [英] createPeriodicWave from an array of sample values

查看:48
本文介绍了样本值数组中的createPeriodicWave的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一条曲线(例如正弦曲线),该曲线以均匀的间隔采样到Float32Array中,称为 samples .该曲线是通过 value 进行采样的.如果在屏幕上放置 samples (经过四舍五入),我们将得到如下内容:

I have a curve -- say, a sine curve -- that is sampled at uniform intervals into a Float32Array, called samples. The curve is sampled by value. If samples (with some rounding) was put on the screen, we would get something like the following:

 1.0 |    x           x
 0.5 |  x   x       x   x
 0.0 | x     x     x     x     x
-0.5 |        x   x       x   x
-1.0 |          x           x

samples 数组的内容与这些数字相似:

And the contents of the samples array is something along these numbers:

0, 0.5, 1, 0.5, 0, -0.5, -1, -0.5, 0, ...

如您所见,曲线由每个给定样本的曲线的表示.我想根据这些样本值创建一个 PeriodicWave ,可以使用 AudioContext.createPeriodicWave()完成.

As you can see, the curve is represented by the value of the curve at each given sample. I would like to create a PeriodicWave from these sample values, which can be done by using AudioContext.createPeriodicWave().

但是,此方法接受以下参数而不是采样值:

However, this method accepts the following arguments instead of sampled values:

  • 实数:一系列余弦项(传统上是A项).
  • imag :一系列正弦项(传统上是B项).
  • real: An array of cosine terms (traditionally the A terms).
  • imag: An array of sine terms (traditionally the B terms).

对于一个采样值数组,我不太确定这些值是什么意思.如何从采样值转换为余弦项和正弦项?

I'm not quite sure what these values mean in regard to an array of sampled values. How can I make a conversion from sampled values to cosine terms and sine terms?

采样的曲线不一定是正弦波或余弦波.它可以是任意形状.

推荐答案

如果您真的只想获取波形,则只需使用AudioBufferSource并将其循环(作为AudioBuffer)即可.

If you really just want to take a waveform, then just use an AudioBufferSource and loop it (as an AudioBuffer).

PeriodicWaves有所不同-它们是一种通过更改每个谐波的相对系数来谐波控制振荡器波形的方法.如果在"imag"数组的第二个插槽中创建的PeriodicWave仅值为"1",则将得到一个正弦波.同样,您可以通过控制较高的谐波来创建方波,三角波或锯齿波-请参见 https://en.wikipedia.org/wiki/Non-sinusoidal_waveform .这些浪潮最终可能会变得非常丰富-

PeriodicWaves are something different - they're a way of controlling the waveform of the Oscillator harmonically, by changing the relative coefficients of each harmonic. If you created a PeriodicWave with only the value "1" in the second slot of the "imag" array, you would get a sine wave. Likewise, you can create square, triangle, or sawtooth waves by controlling the higher harmonics - see https://en.wikipedia.org/wiki/Non-sinusoidal_waveform. These waves can end up being pretty rich -

如果要将其转换为PeriodicWave,则需要使用FFT算法将其转换为PeriodicWave使用的相对谐波强度集( https://github.com/corbanbrook/dsp.js/).

If you want to turn it into a PeriodicWave, you need to turn it into the set of relative harmonic strengths used by PeriodicWave, using an FFT algorithm (https://en.wikipedia.org/wiki/Discrete_Fourier_transform is a decent introduction). There are libraries on the net to do this, like DSP.js (https://github.com/corbanbrook/dsp.js/).

(以前称为Wavetable,但这也令人困惑.也许应该将其重命名为HarmonicWaveTable?)

(This used to be called Wavetable, but that was confusing too. Maybe it should have been renamed HarmonicWaveTable?)

这篇关于样本值数组中的createPeriodicWave的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆