Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy DFT from AForge.Math doesn't work?
    primarykey
    data
    text
    <p>I tried to get fft and then get dft of a wave using this code:</p> <pre><code> string s = textBox1.Text; double[] source = SourceToDouble(s); listBox2.DataSource = source; ToPowerOfTwo(ref source); List&lt;Complex&gt; Source = DoubleToComplex(source); Complex[] sou = Source.ToArray(); FourierTransform.FFT(sou, FourierTransform.Direction.Forward); listBox1.DataSource = sou; FourierTransform.DFT(sou, FourierTransform.Direction.Forward); DoPlaySound(sou); </code></pre> <p><code>SourceToDouble(s)</code>:</p> <pre><code>private double[] SourceToDouble(string s) { List&lt;double&gt; Final = new List&lt;double&gt;(); EricOulashin.WAVFile audioFile = new EricOulashin.WAVFile(); String warning = audioFile.Open(s, WAVFile.WAVFileMode.READ); if (warning == "") { short audioSample = 0; for (int sampleNum = 0; sampleNum &lt; audioFile.NumSamples; ++sampleNum) { audioSample = audioFile.GetNextSampleAs16Bit(); Final.Add((double)audioSample); } } else { throw new Exception(warning); } return Final.ToArray(); } </code></pre> <p><code>ToPowerOfTwo(ref source)</code>:</p> <pre><code>private void ToPowerOfTwo(ref double[] source) { List&lt;long&gt; TwoPowers = GetTwoPowers(100); long pCount = 0; for (int i = 0; i &lt;= 100; i++) { if (source.Count() &lt;= TwoPowers[i]) { pCount = TwoPowers[i]; break; } } List&lt;double&gt; f = new List&lt;double&gt;(source); while (f.Count &lt; pCount) { f.Add(0.0); } //f.Add(0.0); source = f.ToArray(); } </code></pre> <p><code>DoubleToComplex(source)</code>:</p> <pre><code>private static List&lt;Complex&gt; DoubleToComplex(double[] source) { List&lt;Complex&gt; Source = new List&lt;Complex&gt;(); foreach (double dob in source) { Complex c = new Complex(dob, 0.0); Source.Add(c); } return Source; } </code></pre> <p><code>DoPlaySound(sou)</code>:</p> <pre><code> private void DoPlaySound(Complex[] c) { FourierTransform.DFT(c, FourierTransform.Direction.Forward); double wav = c[0].Re; List&lt;double&gt; Big = ToBigger(100000, new double[] { wav }); MakeWavFile(Big, "tmp.wav"); System.Media.SoundPlayer s = new SoundPlayer("tmp.wav"); s.PlayLooping(); } </code></pre> <p><strong>the problem is this: when I give a wav file to general code, after a long time the method trying to play the final wav (tmp.wav) but it isn't like the general file.</strong></p> <p><strong>Update 1:</strong></p> <p>I also tried <code>FourierTransform.DFT(sou, FourierTransform.Direction.Backward);</code> but it didn't work too!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload