在 C# 中生成正弦扫描
我想在 C# 中生成正弦扫描,我可以在其中定义起始频率、结束频率和扫描持续时间。我研究过播放缓冲区的声音库,例如 DirectSound 和 ASIO。但由于缓冲区大小限制,当扫描持续时间足够长以填充多个缓冲区时,我无法弄清楚如何控制扫描持续时间。任何示例或指南都会非常有帮助。
I want to generate a sine sweep in C# where I am able to define the start frequency, end frequency, and the duration of the sweep. I've looked at sound libraries such as DirectSound and ASIO that play a buffer. But I haven't been able to figure out how to control the duration of the sweep when the duration of the sweep is long enough to fill more than one buffer due to the buffer size limitation. Any samples or guides would be extremely helpful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您对正在运行的程序感到满意,而无需自己编写程序,请查看音频测试文件生成器 。
这个小窗口 EXE 能够生成具有给定开始和结束频率的线性正弦扫描。
If you want to write it by your own, you have to fill the buffer using:
sin(2*pi * f * n/sample_rate)
其中
f
是当前正弦频率(您想要扫描),以 Hz 为单位n
是缓冲区的样本索引sample_rate
是以 Hz 为单位的采样率f=10Hz 的示例。
If you are satisfied with an running program without writing it yourself take a look at The Audio Test File Generator.
This small windows EXE is able to generate a linear sine sweep with a given start and end frequency.
If you want to write it by your own, you have to fill the buffer using:
sin(2*pi * f * n/sample_rate)
where
f
is the current sine frequency (you want to sweep) in Hzn
is the sample index of the buffersample_rate
is the sample rate in HzAn example with f=10Hz.
ulrichb 已经说明了所有必要的信息,但最近我不得不用 C# 在 .Net 中构建一个正弦扫描发生器。
对我来说看起来很酷,我将把代码留在这里,也许对其他人有用。
numberofSamples:缓冲区大小。
scanDuration:从低频到高频所需的时间。
lowFreq:起始频率
highFreq:结束频率
deltaTime:1 / 采样率(获取 1 个样本所需的时间)
该函数从低频进展到高频,在每次采样后将频率增加一定量。
ulrichb has already stated all necessary information but recently I had to build a sine sweep generator in .Net with C#.
It looked cool to me, I'll leave the code here, maybe it will be useful for others.
numberofSamples: Buffer size.
sweepDuration: Time takes to go from low frequency to high frequency.
lowFreq: Start frequency
highFreq: End Frequency
deltaTime: 1 / sampling rate (time taken to take 1 sample)
The function progresses from low frequency to high frequency increasing the frequency by a certain amount after each sample.