1 回答
TA贡献1887条经验 获得超5个赞
buffer我需要直接写入buffer数组元素,而不是尝试设置为新数组(这毫无意义),以便它们可以在函数调用之外使用。我真的不喜欢这样做,也许是为了解决我看不到的问题,但显然我正在使用的库就是这样做的。
private class SampleSource : ISampleSource
{
public long Position { get; set; }
public WaveFormat WaveFormat { get; private set; }
public bool CanSeek => true;
public long Length => _data.Length;
private float[] _data;
private long readPoint = 0;
public SampleSource(float[][] samples, int sampleRate, int bits, int channels)
{
WaveFormat = new WaveFormat(sampleRate, bits, channels);
if (samples.Length <= 0) return;
_data = new float[samples[0].Length * samples.Length];
int cchannels = samples.Length;
int sampleLength = samples[0].Length;
for (var i = 0; i < sampleLength; i += cchannels)
for (var n = 0; n < cchannels; n++)
_data[i + n] = samples[n][i / cchannels];
}
public int Read(float[] buffer, int offset, int count)
{
/*THIS IS THE CHANGED FUNCTION*/
if (_data.Length < Position + count)
count = (int) (_data.Length - Position);
for (var i = 0; i < count; i++)
buffer[i] = _data[i + Position + offset];
Position += count;
return count;
}
public void Dispose() =>_data = null;
}
- 1 回答
- 0 关注
- 201 浏览
添加回答
举报