void populateFFT(void) { printf("INFO: Compute FFT\n"); fftN = (sampleSize/2); fftWidthx = 8.0; fftWidthy = 4.0; fftDepth = 12.0; computeFFT(); colorizeFFT(); scaleFFT(); }
void MainWindow::slotDraw() { QVector<int> v(th->getCounter()) ; std::cout << v.size() << std::endl ; for (int i = 0 ; i < v.size() ; i++) std::cout << "\t" << v.at(i) << std::endl ; drawSignal() ; computeFFT() ; drawFreq() ; }
// _______________________________________________________ void KeyWordDetector::performFFT() { // Apply the windowing on the vector //applyWindowing(vReal, window, WINDOW_LENGTH, true); // Apply the windowing on the vector // TODO: Seems to work way better without windowing (but why?) /* for (int i = 0; i < WINDOW_LENGTH/2; i++) { vReal[i] *= window[i]; vReal[WINDOW_LENGTH - (i + 1)] *= window[i]; } */ // Padd with 0s at the end if FFT size is not the same as windowLength and reset imaginary vector for (size_t i = 0; i < FFT_SIZE; i++) { if (i >= WINDOW_LENGTH) vReal[i] = 0; vImag[i] = 0; } // Compute FFT (is done inPlace) computeFFT(vReal, vImag, FFT_SIZE); // Get the magnitude of the complex value (inPlace) //complexToMagnitude(vReal, vImag, FFT_SIZE); // Get the magnitude of the complex value and store in powerSpec complexToMagnitude(vReal, vImag, powerSpec, FFT_SIZE); #ifdef DEBUG_KD_MAJOR_FREQUENCY // Compute the major peak for DEBUG_KDging double peak = majorPeak(vReal, FFT_SIZE, SAMPLING_RATE); Serial.print("Major peak at: "); Serial.print(peak); Serial.println("Hz"); #endif #ifdef DEBUG_KD_FFT printV(vReal, FFT_SIZE, false); Serial.print("\n"); #endif }
// run ffts, keep certain results, combine into feature descriptor void Auvsi_Fft::computeFeatureDescriptor() { clearFeatureDescriptor(); Complex * currentColumn; // current values to compute Complex * currentResults; // current FFT results if (!COMPUTE_ROW) { // compute each column // loop through columns for (int i = 0; i < inputImage.size().width; i++) { currentColumn = getColumn(i); // get column currentResults = computeFFT(currentColumn, HEIGHT_INPUT); // take fft of column addToFeatureDescriptor(currentResults, i); // add results to feature descriptor } } // we are done! }
// _______________________________________________________ void KeyWordDetector::noiseFloorCalculation() { // Padd with 0s at the end if FFT size is not the same as windowLength and reset imaginary vector for (size_t i = 0; i < FFT_SIZE; i++) { if (i >= WINDOW_LENGTH) vReal[i] = 0; vImag[i] = 0; } // Compute FFT (is done inPlace) computeFFT(vReal, vImag, FFT_SIZE); // Get the magnitude of the complex value (inPlace) //complexToMagnitude(vReal, vImag, FFT_SIZE); // Get the magnitude of the complex value and store in powerSpec complexToMagnitude(vReal, vImag, powerSpec, FFT_SIZE); // Update old noise floor value for (int i = 0; i < FFT_SIZE/2; i++) { noiseFloor[i] = (1.0-NOISE_FLOOR_LOWPASS)*noiseFloor[i] + (NOISE_FLOOR_LOWPASS)*powerSpec[i]; } }
void SignalProcessorAudioProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages) { ////////////////////////////////////////////////////////////////// // MIDI processing takes place here ! ////////////////////////////////////////////////////////////////// // Audio processing takes place here ! // If the signal is defined by the user as mono, no need to check the second channel int numberOfChannels = (monoStereo==false) ? 1 : getNumInputChannels(); for (int channel = 0; channel < numberOfChannels; channel++) { const float* channelData = buffer.getReadPointer (channel); //Only read one value out of nbOfSamplesToSkip, it's faster this way for (int i=0; i<buffer.getNumSamples(); i+=nbOfSamplesToSkip) { // Signal average: The objective is to get an average of the signal's amplitude -> use the absolute value signalSum += std::abs(channelData[i]); // Note: Possible optimization to be done using the mean square of the vector. // extern void vDSP_measqv } // Instant signal value if (sendSignalInstantVal == true) { for (int i=0; i<buffer.getNumSamples(); i+=1) { if (instantSigValNbOfSamplesSkipped >= instantSigValNbOfSamplesToSkip) { sendSignalInstantValMsg(channelData[i]); instantSigValNbOfSamplesSkipped = 0; } else { instantSigValNbOfSamplesSkipped += 1; } } } } nbBufValProcessed += buffer.getNumSamples(); samplesSinceLastTimeInfoTransmission += buffer.getNumSamples(); if (sendFFT == true) { // For the FFT, only check the left channel (mono), it's not very useful the work twice. This could be changed in the future if a case where this is needed were to appear for (int i=0; i<buffer.getNumSamples(); i+=1) { // Move the available buffer in the processed data buffer (for FFT) *(fftBuffer + fftBufferIndex) = *(buffer.getReadPointer(0) + i); fftBufferIndex += 1; if (fftBufferIndex >= N) { computeFFT(); } } } //Must be calculated before the instant signal, or else the beat effect will be minimized signalAverageEnergy = denormalize(((signalAverageEnergy * (averageEnergyBufferSize-1)) + signalInstantEnergy) / averageEnergyBufferSize); signalInstantEnergy = signalSum / (averagingBufferSize * numberOfChannels); if (sendImpulse == true) { // Fade the beat detection image (variable used by the editor) if (beatIntensity > 0.1) { beatIntensity = std::max(0.1, beatIntensity - 0.05); } else { beatIntensity = 0.1; } } else { beatIntensity = 0; } // If the instant signal energy is thresholdFactor times greater than the average energy, consider that a beat is detected if (signalInstantEnergy > signalAverageEnergy*thresholdFactor) { //Set the new signal Average Energy to the value of the instant energy, to avoid having bursts of false beat detections signalAverageEnergy = signalInstantEnergy; if (sendImpulse == true) { //Send the impulse message (which was pre-generated earlier) sendImpulseMsg(); } } if (nbBufValProcessed >= averagingBufferSize) { if (sendSignalLevel == true) { sendSignalLevelMsg(); } nbBufValProcessed = 0; signalSum = 0; } if (samplesSinceLastTimeInfoTransmission >= timeInfoCycle) { // Ask the host for the current time if (sendTimeInfo == true) { sendTimeinfoMsg(); } else { // Don't send the current time, set the GUI info to a default value lastPosInfo.resetToDefault(); } samplesSinceLastTimeInfoTransmission = 0; } }