Example #1
0
Histogram::Histogram(QString histogramStr)
{
  float kernelizedValues[MAX_HISTOGRAM_SIZE];
  float normalizedValues[MAX_HISTOGRAM_SIZE];

  // encountered weirdness when using memset here...?
  for (int i = 0; i < MAX_HISTOGRAM_SIZE; ++i) {
    normalizedValues[i] = 0.f;
    kernelizedValues[i] = 0.f;
  }

  int count = 0;
  m_min = MAX_HISTOGRAM_INDEX;
  m_max = MIN_HISTOGRAM_INDEX;

  parseHistogram(histogramStr, kernelizedValues, count);

  qDebug() << "parsed" << histogramStr << "count" << count;
  normalizeValues(kernelizedValues, normalizedValues, count);

  m_min -= kernelHalfWidth;
  m_max += kernelHalfWidth;

  int length = m_max - m_min + 1;
  if (length > MAX_HISTOGRAM_INDEX)
    length = MAX_HISTOGRAM_INDEX;

  if (m_min < MIN_HISTOGRAM_INDEX)
    m_min = MIN_HISTOGRAM_INDEX;

  if (m_max >= MAX_HISTOGRAM_INDEX)
    m_max = MAX_HISTOGRAM_INDEX-1;

  m_normalizedValues = new float [length];

  // memcpy??
  for (int i = 0; i < length; ++i)
    m_normalizedValues[i] = normalizedValues[m_min - MIN_HISTOGRAM_INDEX + i];
}
//--------------------------------------------------------------
void openniTracking::updateOpenCV(){

	cleanImage.setFromPixels(depthRangeMaskScaled.getPixels(), _width, _height);

	//////////////////////////////////////////////
	cleanImage.erode(ciErode);
	cleanImage.dilate(ciDilate);
	cleanImage.blur(ciBlur);
	//////////////////////////////////////////////

	//////////////////////////////////////////////
	// motion detection
	calculateMotion();
	//////////////////////////////////////////////

	//////////////////////////////////////////////
	// find contours
	if(computeContourFinder){
		runningBlobs = contourFinder.findContours(cleanImage, minBlobArea, maxBlobArea, MAX_NUM_CONTOURS_TO_FIND, false, false);
		if(runningBlobs > 0 && runningBlobs < MAX_NUM_CONTOURS_TO_FIND){
			computeContourAnalysis();
			blobTracker.trackBlobs(contourFinder.blobs);
		}
	}
	//////////////////////////////////////////////

	//////////////////////////////////////////////
	// motion trigger areas
	if(computeContourFinder && computeTriggerAreas){
		if(numPixelsChanged > onHorizon){
			// if first blob is inside area...
			// this is useful when working with laser tracking
			triggerAreas.isPointInside(box[0].center.x,box[0].center.y);
			if(lastAreaON != triggerAreas.areaON){
				if(actualArea != triggerAreas.areaON){
					actualArea = triggerAreas.areaON;
					// actualArea activated
					triggerState[actualArea] = !triggerState[actualArea];
				}

				lastTime = ofGetElapsedTimeMillis();

			}
			lastAreaON = triggerAreas.areaON;
		}
		if(numPixelsChanged < offHorizon){
			if(lastAreaON != -1){
				silencePeriod = ofGetElapsedTimeMillis();
				// actualArea deactivated after (silencePeriod-lastTime);
			}
			lastAreaON = -1;
		}

	}
	//////////////////////////////////////////////

	//////////////////////////////////////////////
	// apply kalman filter (if selected) to every output value
	// smoothing & normalize numerical variable
	// (prepare it for sending via OSC)
	kalmanFilterValues();
	smoothingValues();
	normalizeValues();
	//////////////////////////////////////////////

}
//---------------------------------------------------------------
void audioInputChannel::captureChannel(float *input){
	
	/////////////////////
	// mute/unmute channel
	if(_mute){
		_internalMute = 0.0f;
	}else{
		_internalMute = 1.0f;
	}
	/////////////////////
	
	/////////////////////
	// capture channel
	for (unsigned int i = 0; i < bufferSize; i++){
		chRaw[i] = input[i*numChannels + chID] * (_volume*_internalMute);
	}
	/////////////////////
	
	// autocorrelation + normalization
	doAutoCorrelation();
	
	// get volume
	detectVolume();
	
	// get pitch
	detectPitch();
	
	// parametric eq [normalized radial basis function network]
	updateFilter();
	
	/////////////////////
	// FFT analysis
	fft_mutex.lock();
	if(noiseRec){
		fft->setSignal(autoCorrelationNorm);
		memcpy(fftBins, fft->getAmplitude(), sizeof(float) * fft->getBinSize());
		for(unsigned int i = 0; i < fft->getBinSize(); i++){
			noiseFilterStep[i] += fftBins[i];
			noiseFilter[i] = noiseFilterStep[i]/bufferRecCounter;
		}
		bufferRecCounter++;
		
	}else{
		fft->setSignal(autoCorrelation);
		memcpy(fftBins, fft->getAmplitude(), sizeof(float) * fft->getBinSize());
		
		fft_StrongestBinValue	= 0.0f;
		
		for(unsigned int j=0;j<BARK_SCALE_CRITICAL_BANDS;j++){
			barkBins[j] = 0.0f;
		}
		
		for(unsigned int i = 0; i < fft->getBinSize(); i++){
			// apply noise and parametric eq to fft bins
			binsFiltered[i] = fftBins[i] * (1.0 - (noiseFilter[i]*reduxFactor));
			binsFiltered[i] *= (gaussianFilter[i] + 1.0f);
			// storing strongest bin for pitch detection
			if(binsFiltered[i] > fft_StrongestBinValue){
				fft_StrongestBinValue = binsFiltered[i];
				fft_StrongestBinIndex = i;
			}
			// calculate bark scale bins from fft bins
			updateBarkScale(i);
			
		}
	}
	fft->setPolar(binsFiltered, fft->getPhase());
	fft->clampSignal();
	memcpy(chClean, fft->getSignal(), sizeof(float) * fft->getSignalSize());
	fft_mutex.unlock();
	/////////////////////
	
	//////////////////////////////////////////////
	// apply kalman filter (if selected) to every output value
	// smoothing & normalize numerical variable
	// (prepare it for sending via OSC)
	kalmanFilterValues();
	smoothingValues();
	normalizeValues();
	//////////////////////////////////////////////
		
}
Example #4
0
void Stick::setX(int x)
{
  this -> x = normalizeValues(x);
}
Example #5
0
void Stick::setY(int y)
{
  this -> y = (-1)*normalizeValues(y);
}