
[英]How to play two audio files simultaneously with real time size value with NAudio
[英]NAudio Algorithm to play a sinewave whose frequency can be changed smoothly in real time [closed]
到目前为止,我已经实现了在这篇博文中找到的算法,但成功有限。
我的程序的概念是初始化正弦波,然后根据屏幕上鼠标的 position 更改频率 - 向上移动鼠标,正弦波变高,反之亦然(本质上是使用鼠标的特雷门型仪器)。
到目前为止,我实施的问题是,当正弦波的频率更新时,会发出咔哒声,而不是提供平滑的频率扫描,而是听起来像是有离散的频率水平。 我一直在 NAudio 论坛和此处搜索高低,但似乎没有其他人试图使用 NAudio 或任何其他声音模块来做这种事情 - 所有类似的程序都执行类似地使用 Kinect 等设备使用虚拟 MIDI 布线和现有的软件模块,但我想在不依赖外部软件包的情况下实现相同的概念。
我已在此处的 NAudio 论坛上发布了与此问题有关的代码部分,如您所见,我正在按照 MarkHeath 的建议在此处尝试找到解决我的问题的方法。
您需要避免 output 波形中的不连续性(这些是您听到的咔嗒声)。 最简单的方法是使用基于 LUT 的波形发生器 - 这适用于任何周期性波形(即不仅仅是纯正弦波)。 通常您使用一个定点相位累加器,它为每个新样本增加一个增量值,该增量值对应于当前 output 频率。 您可以根据需要安全地修改增量,并且波形仍然是连续的。
伪代码(一个 output 样品):
const int LUT_SIZE;
const int LUT[LUT_SIZE]; // waveform lookup table (typically 2^N, N >= 8)
Fixed index; // current index into LUT (integer + fraction)
Fixed delta; // delta controls output frequency
output_value = LUT[(int)index];
// NB: for higher quality use the fractional part of index to interpolate
// between LUT[(int)index] and LUT[(int)index + 1], rather than just
// truncating the index and using LUT[(int)index] only. Depends on both
// LUT_SIZE and required output quality.
index = (index + delta) % LUT_SIZE;
f
和采样率Fs
的delta
:
delta = FloatToFixed(LUT_SIZE * f / Fs);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.