使用博客上的示例,我输出了一个正弦波:
public class SineWaveProvider32 : WaveProvider32{
int sample;
public SineWaveProvider32()
{
Frequency = 1000;
Amplitude = 0.25f; // let's not hurt our ears
}
public float Frequency { get; set; }
public float Amplitude { get; set; }
public override int Read(float[] buffer, int offset, int sampleCount)
{
int sampleRate = WaveFormat.SampleRate;
for (int n = 0; n < sampleCount; n++)
{
buffer[n+offset] = (float)(Amplitude * Math.Sin((2 * Math.PI * sample * Frequency) / sampleRate));
sample++;
if (sample >= sampleRate) sample = 0;
}
return sampleCount;
}
}
当我播放这个正弦波时,它是一个无限循环。想知道如何输出给定长度的声音?