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; } }
static void ExampleR2C() { double[] input = new double[97]; var rand = new Random(); for (int i = 0; i < input.Length; i++) { input[i] = rand.NextDouble(); } using (var pinIn = new PinnedArray <double>(input)) using (var output = new FftwArrayComplex(DFT.GetComplexBufferSize(pinIn.GetSize()))) { DFT.FFT(pinIn, output); for (int i = 0; i < output.Length; i++) { Console.WriteLine(output[i]); } } }