private void OnChangeFrequency(ChangeFrequency obj) { var interval = FrequencyUtils.TimeSpanFromFrequency(obj.Frequency); // (Konrad) We should delay the execution by the new interval. Runner.Timer.Change(interval, interval); }
// دزیافت نمونه های صوتی از کارت صدا private void NewInputSamplesArrivedEvent(short[] data) { // تیدیل داده های نمونه به فرکانسهای صوتی FrequencyUtils.ProcessForierTransfer(data, NewFourierFrequencyArrived, (int)MainForm.FftPeechInterval ); }
public void ExecuteUpdate() { // (Konrad) User requested an update now, so we can just change the interval // to start right away, and execute again in whatever time it was supposed to // execute afterwards var interval = FrequencyUtils.TimeSpanFromFrequency(Program.Settings.Frequency); Program.Runner.Timer.Change(TimeSpan.Zero, interval); }
public void ChangeFrequency(Frequency frequency) { // (Konrad) Update Service Settings. Program.Settings.Frequency = frequency; // (Konrad) We should delay the execution by the new interval. var interval = FrequencyUtils.TimeSpanFromFrequency(frequency); Program.Runner.Timer.Change(interval, interval); }
public UpdateRunner(ZombieSettings settings, ZombieModel model) { // (Konrad) We can launch the updater immediately. var interval = FrequencyUtils.TimeSpanFromFrequency(settings.CheckFrequency); Timer = new Timer(x => { try { model.GetLatestRelease(settings); } catch (Exception e) { _logger.Fatal(e.Message); } }, null, TimeSpan.Zero, interval); }
public void Listen() { byte[] audioBuffer = new byte[_bufferSizeInBytes]; int numberOfReadBytes = _audioRecorder.Read(audioBuffer, 0, _bufferSizeInBytes); double[] x = new double[audioBuffer.Length]; for (int i = 0; i < x.Length; i++) { x[i] = audioBuffer[i] / 32768.0; } double frequency = FrequencyUtils.FindFundamentalFrequency(x, RECORDER_SAMPLERATE, MinFreq, MaxFreq); //Fire event for passing back the recorded value. FinishedSampling(this, new FinishedSampalingEventArgs() { Frequency = new Hz((float)frequency * 2), //Volume = max_magnitude }); }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == Microsoft.Xna.Framework.Input.ButtonState.Pressed) { this.Exit(); } if (Keyboard.GetState().IsKeyDown(Keys.P)) { pausar(); } if (bytesRead < buffer.Length) { // public int GetData (byte[] buffer,int offset,int count) // this method is really bad explained in msdn I almost had to do reverse engineering, // it basically takes the whole recording // and put the data in the buffer array starting in position offset and getting also the data from postion // offset, and maximal until position count, this way it fills gradualy the buffer array bytesRead += Microphone.Default.GetData(buffer, bytesRead, (buffer.Length - bytesRead)); // in this case it just put in the buffer the last data obtained since last getdata called, // put it in buffer starting in pos 0, so you have to know the size of new data doing the difference // to know until where is the new data, this could be very useful, but I decided to use // samples of half second and then restart the buffer so is not necessary // //int old = bytesRead; //bytesRead += Microphone.Default.GetData(buffer); //dif = bytesRead - old; //dif-1 is the pos of last current element in buffer } else { isMicrophoneRecording = true; //short[] ensayo = (short[])buffer; double MinFreq = 60; double MaxFreq = 1300; int SampleRate = 44100; // Scaling the samples to send to external method double[] scaledBuffer = new double[buffer.Length]; for (int i = 0; i < scaledBuffer.Length; i++) { // 255 is maximal number in byte type scaledBuffer[i] = buffer[i] / 255.0; } // external method to find frequency // this can be replaced for any method with next description: // it must receive an array of scaleted samples of wav file and return the frequency frequency = FrequencyUtils.FindFundamentalFrequency(scaledBuffer, SampleRate, MinFreq, MaxFreq); if (frequency > 0) { frequency2Note(frequency, out closestFrequency, out noteName); Console.WriteLine(frequency.ToString("f2") + " " + closestFrequency.ToString("f2") + " " + noteName); interpCont.verificarNotaDetectada(noteName); } bytesRead = 0; isMicrophoneRecording = false; } // TODO: Add your update logic here UpdateSprite(gameTime); //base.Update(gameTime); }