Exemple #1
0
 public InverseRealFft(int fftSize)
 {
     FftSize    = fftSize;
     Waveform   = new AlignedArrayDouble(16, fftSize);
     Spectrum   = new AlignedArrayComplex(16, fftSize);
     InverseFft = FftwPlanRC.Create(Waveform, Spectrum, DftDirection.Backwards, PlannerFlags.Estimate);
 }
Exemple #2
0
        public AudioIn(int sampleRate, int device, int bufferSize)
        {
            if (device > WaveIn.DeviceCount)
            {
                throw new Exception();
            }

            this.sampleRate = sampleRate;
            this.bufferSize = bufferSize;
            audioDataTrue   = new short[bufferSize + 20286];
            tempOdd         = new double[audioDataTrue.Length];
            tempTrue        = new double[audioDataTrue.Length];

            realIn = new PinnedArray <double>(audioDataTrue.Length);
            comOut = new FftwArrayComplex(DFT.GetComplexBufferSize(realIn.GetSize()));
            fft    = FftwPlanRC.Create(realIn, comOut, DftDirection.Forwards);

            waveInDevices            = WaveIn.DeviceCount;
            waveEvent                = new WaveInEvent();
            waveEvent.DeviceNumber   = device;
            waveEvent.DataAvailable += OnWaveIn;
            channels             = WaveIn.GetCapabilities(device).Channels;
            waveEvent.WaveFormat = new WaveFormat(sampleRate, 1);

            string path = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "/NetworkSave01.json";

            // Load Neural network
            if (File.Exists(path))
            {
                Console.WriteLine("exists");
                network = NeuralNetwork.LoadNetwork(path);
            }
            else
            {
                throw new FileNotFoundException();
            }

            //network.PrintWeights();

            waveEvent.StartRecording();
        }
        static void Main(string[] args)
        {
            try
            {
                TcpClient tcpClient = new TcpClient("127.0.0.1", 10000);
                Console.WriteLine("Connected");

                StreamReader reader = new StreamReader(tcpClient.GetStream());
                StreamWriter writer = new StreamWriter(tcpClient.GetStream());
                string       s      = "";

                using (var timeDomain = new PinnedArray <double>(inputSize))
                    using (var frequencyDomain = new FftwArrayComplex(DFT.GetComplexBufferSize(timeDomain.GetSize())))
                        using (var fft = FftwPlanRC.Create(timeDomain, frequencyDomain, DftDirection.Forwards))
                        {
                            while (!(s = reader.ReadLine()).Equals("Quit") || (s == null))
                            {
                                string result = "";

                                if (IsValidJson(s))
                                {
                                    result = ProcessMessage(s, timeDomain, frequencyDomain, fft);
                                }

                                writer.WriteLine(result);
                                writer.Flush();
                                GC.Collect();
                            }
                            reader.Close();
                            writer.Close();
                            tcpClient.Close();
                        }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                Console.WriteLine(e.InnerException);
                Console.WriteLine(e.Message);
                throw;
            }
        }