the WMA file only works with WaveOut () standard.
With other DriverOut, I receive an error message from WMAStream function Read
(GetNextSample).
Tested with your NAudio Demo 1.6
This is an example of using the class Biquad Filter
I do not use the primary function "Transform" the class BiQuadFilter
using NAudio.Dsp;using System;namespace NAudio.Effects {publicclass EqFilterX { BiQuadFilter2 bqf; float[] sIn = newfloat[0]; // Sample In [n]float[] sIn1 = newfloat[0]; // Sample In [n-1]float[] sIn2 = newfloat[0]; // Sample In [n-2]float[] sOut = newfloat[0]; // Sample Out [n] float[] sOut1 = newfloat[0]; // Sample Out [n-1]float[] sOut2 = newfloat[0]; // Sample Out [n-2]public EqFilterX() : this(BiQuadFilterType.LowPassFilter, 100.0f, 1.0f, 1.0f, false) { }public EqFilterX(BiQuadFilterType filtertype, float frequency, float q, float gain, bool bypass) { Bypass = bypass; FilterType = filtertype; Frequency = frequency; Q = q; dBGain = gain; OnParamChanges(); } ///<summary>/// Type de Filter///</summary>public BiQuadFilterType FilterType { get; set; }///<summary>/// CenterFrequence or Frequence ///</summary>publicfloat Frequency { get; set; }///<summary>/// Q or Shelf Slope or BandWidth///</summary>publicfloat Q { get; set; }///<summary>/// Gain///</summary>publicfloat dBGain { get; set; }///// <summary>///// Numbre of channel///// </summary>//public int ChannelMax { get; set; }publicoverridevoid OnParamChanges() { sIn = newfloat[ChannelMax]; // Sample In [n] sIn1 = newfloat[ChannelMax]; // Sample In [n-1] sIn2 = newfloat[ChannelMax]; // Sample In [n-2] sOut = newfloat[ChannelMax]; // Sample Out [n] sOut1 = newfloat[ChannelMax]; // Sample Out [n-1] sOut2 = newfloat[ChannelMax];switch (FilterType) {case BiQuadFilterType.AllPassFilter: bqf = BiQuadFilter2.AllPassFilter(SampleRate, Frequency, Q);break;case BiQuadFilterType.BandPassFilterConstantPeakGain: bqf = BiQuadFilter2.BandPassFilterConstantPeakGain(SampleRate, Frequency, Q);break;case BiQuadFilterType.BandPassFilterConstantSkirtGain: bqf = BiQuadFilter2.BandPassFilterConstantSkirtGain(SampleRate, Frequency, Q);break;case BiQuadFilterType.HighPassFilter: bqf = BiQuadFilter2.HighPassFilter(SampleRate, Frequency, Q);break;case BiQuadFilterType.HighShelf:// Q = Shelf slope bqf = BiQuadFilter2.HighShelf(SampleRate, Frequency, Q, dBGain);break;case BiQuadFilterType.LowPassFilter: bqf = BiQuadFilter2.LowPassFilter(SampleRate, Frequency, Q);break;case BiQuadFilterType.LowShelf:// Q = Shelf slope bqf = BiQuadFilter2.LowShelf(SampleRate, Frequency, Q, dBGain);break;case BiQuadFilterType.NotchFilter: bqf = BiQuadFilter2.NotchFilter(SampleRate, Frequency, Q);break;case BiQuadFilterType.PeakingEQ: bqf = BiQuadFilter2.PeakingEQ(SampleRate, Frequency, Q, dBGain);break;default:break; } }publicoverridevoid Sample(reffloat sample, refint channel) { sIn[channel] = sample; sOut[channel] = (float)((bqf.b0 / bqf.a0) * sIn[channel] + (bqf.b1 / bqf.a0) * sIn1[channel] + (bqf.b2 / bqf.a0) * sIn2[channel] - (bqf.a1 / bqf.a0) * sOut1[channel] - (bqf.a2 / bqf.a0) * sOut2[channel]); sIn2[channel] = sIn1[channel]; sIn1[channel] = sIn[channel]; sOut2[channel] = sOut1[channel]; sOut1[channel] = sOut[channel]; if (Bypass == false) sample = sOut[channel]; }
simply declare the class.
Initialize filters (Frequency, SampleRate, Gain, Q, Type, ...) and call the function "OnParamChanges"
Then in a loop passes each sample in the function "Sample"
This example is an excerpt from one of my class "Effects".
it is possible to use Eq's different for channels.
Of course you need to adapt this example.
@markheath Your project is a very nice one. Really what i need.
thanks
Hi,
Thanks for the quick response.
Unfortunately, I don't have much knowledge in sound programming, filters and all the fourier stuff (pardon).
I need to generate a white noise filtered between 800-1200Hz for a 1 sec period.
What would be the easiest way to do it?
How can I use the EqFilterX class? How do I need to set the parameters? Can you attach a sample code?
By the way, where can I find the BiQuadFilter2 class? and what is the difference from the NAudio BiQuadFilter class?
Thanks again,
Ron
Hello,
gloupsss BiQuadFilter2 is exactly the same as BiQuadFilter
BiQuadFilter is located in the DSP library NAudio
If it's urgent I can make an example of you (depending on my available time), or you can just wait to be the complement of Mark.
Actually, it's quite urgent.
A simple example would be great !!!
Thanks a lot :-)
Here I have an example.
Well I took an existing generator and add LowPassFilter & HighPassFilter for Pink Noise & WhiteNoise and duration
I did some test with an analyzer (SmaartLive). this example seems correct
I use as a reference the dll NAudio 1.6.
If you want a more powerful filter, you will have to use FFT.
And not enough time to make an example.
example is available in WeTranfert here ::
https://www.wetransfer.com/dl/N7a9W05a/dede49dd367271447614f812590cb0b1eb5b5db0d9fb2020662074973bd5768975ff26506369f74
Publisher Visual Studio Express 2012
use a Pcm16BitToSampleProvider to turn your BufferedWaveProvider into a SampleProvider
I don't see the question to your answer.
Thanks ManuN I will check it out ...
Hi,
I use this code to generate a wav stream. it works fine but how do i generate wav for example with 5 seconds length? this is my first time i'm using this dll.
Slinger
private DirectSoundOut output = null; private BlockAlignReductionStream stream = null; privatevoid button3_Click(object sender, EventArgs e) // start tone { WaveTone tone = new WaveTone(2000, 0.5); // �������, ��������� stream = new BlockAlignReductionStream(tone); output = new DirectSoundOut(); output.Init(stream); output.Play(); } privatevoid button4_Click(object sender, EventArgs e) // stop tone { if (output != null) output.Stop(); } publicclass WaveTone : WaveStream { privatedouble frequency; privatedouble amplitude; privatedouble time; public WaveTone(double f, double a) { this.time = 0; this.frequency = f; this.amplitude = a; } publicoverridelong Position { get; set; } publicoverridelong Length { get { returnlong.MaxValue;} } publicoverride WaveFormat WaveFormat { get { returnnew WaveFormat(44100, 16, 1); } } publicoverrideint Read(byte[] buffer, int offset, int count) { int samples = count / 2; for (int i = 0; i < samples; i++) { double sine = amplitude * Math.Sin(Math.PI * 2 * frequency * time); time += 1.0 / 44100; short truncated = (short)Math.Round(sine * (Math.Pow(2,15) - 1)); buffer[i * 2] = (byte)(truncated & 0x00ff); buffer[i * 2 + 1] = (byte)((truncated & 0xff00) >> 8); } return count; } } // public class WaveTone : WaveStream