audio - C# How does the following code for Low Pass Filter run? -
i have following c# code low pass filter found on naudio site:
public void setvalues(isampleprovider sourceprovider,int cutofffreq) { this.sourceprovider = sourceprovider; this.cutofffreq = cutofffreq; filter_lowpass(); } private void filter_lowpass() { channels = sourceprovider.waveformat.channels; filters = new biquadfilter[channels]; (int n = 0; n < channels; n++) if (filters[n] == null) filters[n] = biquadfilter.lowpassfilter(44100, cutofffreq, 1); else filters[n].setlowpassfilter(44100, cutofffreq, 1); } public waveformat waveformat { { return sourceprovider.waveformat; } } public int read(float[] buffer, int offset, int count) { int samplesread = sourceprovider.read(buffer, offset, count); (int = 0; < samplesread; i++) buffer[offset + i] = filters[(i % channels)].transform(buffer[offset + i]); return samplesread; }
where read function being called?
why need it?
i calling function filter_lowpass way:
myfilter.setvalues(audiofilereader, currentcutoff); waveout.init(myfilter);
if want multiply each of samples constant value after passing through low pass filter, write code?
naudio using pull model here. waveout
going demanded samples sound card going call upstream myfilter.read()
, in turn going call audiofilereader.read()
.
if want add gain either create new isampleprovider following same pattern or inline low pass filter's read function:
public int read(float[] buffer, int offset, int count) { int samplesread = sourceprovider.read(buffer, offset, count); (int = 0; < samplesread; i++) buffer[offset + i] = gain * filters[(i % channels)].transform(buffer[offset + i]); // ^^^^ return samplesread; }
Comments
Post a Comment