C#-Naudio-如何将float []转换为iSampleProvider?
我正在编码我的第一个音频应用程序,并且我正在努力尝试将float []格式的缓冲区转换为IsampleProvider。我需要进一步将几片音频粘合在一起。 我该怎么做?代码:
float dt;//= 1f / nSamplesPerSec;
int nChannels = 1;
int duration = 30;
int nSamplesPerChannel;//= nSamplesPerSec * duration / 1000;
float[] buffer;
void CreateBuffer()
{
dt = 1f / nSamplesPerSec;
nSamplesPerChannel = nSamplesPerSec * duration / 1000;
d = nSamplesPerChannel * dt;
buffer = new float[nSamplesPerChannel];
float f = 800;//frequency
generate(f, 0);
}
void generate(float f, float p)
{
double koef = 0.22;
int newSamples = (int)(nSamplesPerChannel * koef);
for (int i = 0; i < nSamplesPerChannel; i++)
{
double AmpRamp = 1.0D;
buffer[i] = (float)(AmpRamp*Math.Sin(2 * Math.PI * (f * dt * i + p)));
}
}
I'm coding my first audio application, and I'm struggling for hours on trying to convert a buffer in float[] format to ISampleProvider. I need this for further gluing together several pieces of audio.
How do I do this? Code:
float dt;//= 1f / nSamplesPerSec;
int nChannels = 1;
int duration = 30;
int nSamplesPerChannel;//= nSamplesPerSec * duration / 1000;
float[] buffer;
void CreateBuffer()
{
dt = 1f / nSamplesPerSec;
nSamplesPerChannel = nSamplesPerSec * duration / 1000;
d = nSamplesPerChannel * dt;
buffer = new float[nSamplesPerChannel];
float f = 800;//frequency
generate(f, 0);
}
void generate(float f, float p)
{
double koef = 0.22;
int newSamples = (int)(nSamplesPerChannel * koef);
for (int i = 0; i < nSamplesPerChannel; i++)
{
double AmpRamp = 1.0D;
buffer[i] = (float)(AmpRamp*Math.Sin(2 * Math.PI * (f * dt * i + p)));
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Isample -provider是一个接口,因此您不能像类那样直接创建一个接口。但是,我们可以创建自己的类,该类实现Isample -provider接口,然后创建该类的实例,以用作WaveOutEvent或您需要的任何其他内容。
ISampleProvider is an interface so you can't directly create one like you would a class. However we can create our own class which implements the ISampleProvider interface then create an instance of that class to use as the source for a WaveOutEvent or anything else you need.