I am currently working on a project which is using Naudio on Unity. I have done my equalizer part of code. But I realize that when the WaveOutEvent hits the silent part of the playing audio, it will stop outputting the audio even when the audio is still playing and not stopped.
When I commented on the part which transform the buffer, the problem stated above will not occur. I have restarted my Unity project and my computer but the problem is not yet solved.
public EqualizedAudio(ISampleProvider sampleProvider = null) {
equalizer = new();
if (sampleProvider != null) {
this.sampleProvider = sampleProvider;
}
filter = new BiQuadFilter[equalizer.Length];
CreateFilter();
}
private void CreateFilter() {
for (int i = 0; i < equalizer.Length; i++) {
if (filter[i] == null) {
filter[i] = BiQuadFilter.PeakingEQ(sampleProvider.WaveFormat.SampleRate,
equalizer.equalizerBands[i].CenterFrequency, equalizer.equalizerBands[i].QFactor,
equalizer.equalizerBands[i].Gain);
}
else {
filter[i].SetPeakingEq(sampleProvider.WaveFormat.SampleRate,
equalizer.equalizerBands[i].CenterFrequency, equalizer.equalizerBands[i].QFactor,
equalizer.equalizerBands[i].Gain);
}
}
}
public int Read(float[] buffer, int offset, int count) {
int sampleRead = sampleProvider.Read(buffer, offset, count);
if (updated) {
CreateFilter();
updated = false;
}
for (int i = 0; i < sampleRead; i++) {
for (int band = 0; band < equalizer.Length; band++) {
buffer[offset + i] = filter[band].Transform(buffer[offset + i]);
}
}
return sampleRead;
}
Any suggestion would be appreciated.
if your
Read
method returns 0, playback will stop. If you want playback to continue, always returncount
and fill the buffer with silence