Beispiel #1
0
 public void DataAvailable(double[] L, double [] R)
 {
     if ((buf_wr + 1) % buffers == buf_rd)
     {
         overflow += L.Length;
         return;
     }
     for (int i = 0; i < L.Length; i++)
     {
         if (buffer[buf_wr].add(L[i], R[i]))
         {
             // Buffer Full
             buffer[buf_wr].resetFill();
             if (buf_last >= 0)
             {
                 fftx.run(buffer[buf_last].wavel, buffer[buf_wr].wavel, buffer[buf_wr].fftl1, 0);
                 fftx.run(buffer[buf_last].waver, buffer[buf_wr].waver, buffer[buf_wr].fftr1, 1);
             }
             fftx.run(null, buffer[buf_wr].fft1, 2);
             fftx.run(buffer[buf_wr].wavel, buffer[buf_wr].fftl2, 0);
             fftx.run(buffer[buf_wr].waver, buffer[buf_wr].fftr2, 1);
             fftx.run(null, buffer[buf_wr].fft2, 2);
             // Inc or overflow
             buf_last = buf_wr;
             if ((buf_wr + 1) % buffers == buf_rd)
             {
                 overflow += L.Length - i;
                 return;
             }
             buf_wr = (buf_wr + 1) % buffers;
         }
     }
 }
Beispiel #2
0
        private void RecorderOnDataAvailable(object sender, WaveInEventArgs waveInEventArgs)
        {
            int bnext = (buf_wr + 1) % buffers;
            int blast = (buf_wr + buffers - 1) % buffers;

            if (bnext == buf_rd)
            {
                // Overflow
                overflow++;
                return;
            }

            if (testtone)
            {
                //Test Tones instead of the audio signal - for calibration or testing
                double w   = 2 * Math.PI * testtone_freq;
                double tau = 1 / testtone_freq;
                for (int i = 0; i < 2400; i++)
                {
                    double t = (double)i / 48000.0 + testtone_ofs;
                    int    v = (int)Math.Floor(Math.Sin(w * t) * 32767.0 * testtone_amp + 0.5);
                    buffer[buf_wr].wavel[i] = v;
                    buffer[buf_wr].waver[i] = -v;
                    buffer[buf_wr].wave[i]  = v - v;
                }
                testtone_ofs = (double)2400.0 / 48000.0 + testtone_ofs;
                testtone_ofs = testtone_ofs - Math.Floor(testtone_ofs / tau) * tau;
                // testtone_ofs = 0;
            }
            else
            {
                for (int i = 0; i < 2400; i++)
                {
                    buffer[buf_wr].wavel[i] = BitConverter.ToInt16(waveInEventArgs.Buffer, i * 4);
                    buffer[buf_wr].waver[i] = BitConverter.ToInt16(waveInEventArgs.Buffer, i * 4 + 2);
                    buffer[buf_wr].wave[i]  = buffer[buf_wr].wavel[i] + buffer[buf_wr].waver[i];
                }
            }

            fftx.run(buffer[blast].wavel, buffer[buf_wr].wavel, buffer[buf_wr].fftl1, 0);
            fftx.run(buffer[blast].waver, buffer[buf_wr].waver, buffer[buf_wr].fftr1, 1);
            fftx.run(null, buffer[buf_wr].fft1, 2);

            fftx.run(buffer[buf_wr].wavel, buffer[buf_wr].fftl2, 0);
            fftx.run(buffer[buf_wr].waver, buffer[buf_wr].fftr2, 1);
            fftx.run(null, buffer[buf_wr].fft2, 2);

            buf_wr = bnext;
        }