使用生成的波形数据在.NET中播放声音波形、声音、数据、NET

2023-09-03 09:05:44 作者:薄荷再凉不及我心

我怎么能起到基础上,我的.NET程序从用户的输入和数学函数产生波形数据的声音?通过波形数据我的意思是SPL(声pressure水平)在固定间隔时间序列(可能是44.1千赫)值。我presume,这需要某种形式的流媒体缓冲安排。

How can I play a sound based on waveform data that my .NET program is generating from user input and mathematical functions? By "waveform data" I mean SPL (sound pressure level) values in a fixed interval time-series (probably 44.1 kHz). I presume that this requires some kind of streaming buffer arrangement.

请注意,这必须是活/实时性,所以只创建一个.wav文件,然后播放,这将是不够的。 VB.NET是preferred,但是C#是可以接受的。

Note, that this has to be live/real-time, so just creating a .wav file and then playing that will not be sufficient. VB.NET is preferred, but C# is acceptable also.

只是为了澄清:我所寻找的是一个简单的工作code例如

Just to clarify: What I am looking for is a simple working code example.

推荐答案

您可以使用做到这一点 n音讯。您创建一个流源自的WaveStream,并在其被覆盖的阅读方法,你回到你的样品,你可以在飞行中产生。您可以在使用的声卡,让你掌控延迟缓冲区的大小控制。

You can do this using NAudio. You create a stream that derives from WaveStream and in its overriden Read method, you return your samples which you can generate on the fly. You have control over the size of the buffers used by the soundcard which gives you control over the latency.