Esempio n. 1
0
        public unsafe override int Read(byte[] buffer, int offset, int count)
        {
            int length = count / 2;

            if (d == null || d.Length != length)
                d = new double[length];
            fixed(byte *tmp = buffer)
            {
                short *data = (short *)(tmp + offset);
                int    i;

                FFTFilter.GetNoise(d, equalizer, (uint)sampleRate);
                for (i = 0; i < length; i++)
                {
                    data[i] = (short)(d[i] * short.MaxValue);
                }
            }

            return(count);
        }
Esempio n. 2
0
            public uint cb(byte *buf, uint length)
            {
                if (s != null)
                {
                    lock (this.d) {
                        if (tmp == null || tmp.Length != (length * 2))
                        {
                            tmp = new byte[length * 2];
                        }
                        uint __tmp = (uint)s.Read(tmp, 0, (int)length);
                        fixed(byte *tmp2 = tmp)
                        {
                            //WaveOut.equalizer_process(eq, tmp2, buf);
                            short *tmp3 = (short *)(tmp2);

                            //if (_c == null || _c.Length != (int)(__tmp / 2)) _c = new Exocortex.DSP.ComplexF[(int)(__tmp / 2)];
                            if (_d == null || _d.Length != (int)(__tmp / 2))
                            {
                                _d = new double[(int)(__tmp / 2)];
                            }
                            //wave_lib2.VBFFT.to_complex(_c, (short*)(tmp2), (uint)(__tmp / 2));
                            /*//wave_lib2.VBFFT.forward(_c);*/
                            //wave_lib2.VBFFT.inverse(_c);
                            to_double(_d, tmp3, (uint)_d.Length);

                            /*wave_lib2.FFT2 f = new FFT2(_d.Length / 2);
                             * f.transform(_d, false);
                             * int j;
                             * double __tmpd = 1.0;
                             * int __tmpl=_d.Length;
                             * for (j = 0; j < __tmpl; j++)
                             * {
                             *      if (j > (__tmpl / ((double)(120.0 / 44100.0) * (double)sampleRate)))
                             *      {
                             *              __tmpd = 0.05;
                             *      }
                             *      else
                             *      {
                             *              __tmpd = 1.0;
                             *      }
                             *      _d[j] *= __tmpd;
                             *      //__tmpd /= 1.01;
                             * }
                             * double mult = 1;
                             * // multiply transforms to get convolution
                             * for (j = 0; j != _d.Length; j += 2)
                             * {
                             *      double a = _d[j] - _d[j + 1];
                             *      double b = _d[j] + _d[j + 1];
                             *      _d[j] = a * mult;
                             *      _d[j + 1] = b * mult;
                             *      //mult += 0.001;
                             * }
                             * f.transform(_d, true);*/
                            FFTFilter.Process(_d, this._eq, this.sampleRate);
                            to_short((short *)buf, _d, (uint)_d.Length);

                            /*Exocortex.DSP.Fourier.FFT(_c, Exocortex.DSP.FourierDirection.Forward);
                            *  Exocortex.DSP.Fourier.FFT(_c, Exocortex.DSP.FourierDirection.Forward);
                            *  Exocortex.DSP.Fourier.FFT(_c, Exocortex.DSP.FourierDirection.Forward);*/
                            //Exocortex.DSP.Fourier.FFT(_c, Exocortex.DSP.FourierDirection.Backward);
                            //wave_lib2.VBFFT.to_short(tmp3, _c, (uint)_c.Length);

                            /*Exocortex.DSP.Fourier.FFT(_c, Exocortex.DSP.FourierDirection.Forward);
                             * //__tmp /= 2;
                             * //System.Array.Resize<Exocortex.DSP.ComplexF>(ref _c, _c.Length / 2);
                             * Exocortex.DSP.ComplexF mult = new Exocortex.DSP.ComplexF(1, 0);
                             * int j;
                             * // multiply transforms to get convolution
                             * for (j = 0; j != _c.Length; j += 2)
                             * {
                             *      Exocortex.DSP.ComplexF a = _c[j] - _c[j + 1];
                             *      Exocortex.DSP.ComplexF b = _c[j] + _c[j + 1];
                             *      _c[j] = a * mult;
                             *      _c[j + 1] = b * mult;
                             *      //mult += 0.001;
                             * }
                             * Exocortex.DSP.Fourier.FFT(_c, Exocortex.DSP.FourierDirection.Backward);
                             * wave_lib2.VBFFT.to_short(tmp3, _c, (uint)_c.Length);*/
                            /*byte* __src = (byte*)tmp2;
                             * byte* __dst = (byte*)buf;
                             * int i;
                             * uint l = __tmp;
                             * for (i = 0; i < l; i++)
                             * {
                             *(__dst + i) = *(__src + i);
                             * }*/
                        }

                        //if (__tmp == 0) throw new Exception();
                        return(__tmp);
                    }
                }
                return(0);
            }