Mercurial > hg > multitrack-audio-matcher
view src/AudioEventMatcher.cpp @ 2:179c09199b3c
bayesian vector now adding gaussians for kick onsets
author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
---|---|
date | Tue, 31 Jan 2012 21:34:19 +0000 |
parents | 852173ca8365 |
children | 5e188c0035b6 |
line wrap: on
line source
/* * AudioEventMatcher.cpp * MultipleAudioMathcher * * Created by Andrew on 31/01/2012. * Copyright 2012 QMUL. All rights reserved. * */ #include "AudioEventMatcher.h" const int matchWindowWidth = 6000; AudioEventMatcher::AudioEventMatcher(){ bayesTempoWindow.setToRelativeSize(0, 0.6, 1, 0.2); bayesPositionWindow.setToRelativeSize(0, 0.8, 1, 0.2); setArraySizes(); } void AudioEventMatcher::setArraySizes(){ bayesianStruct.resetSpeedSize(200); bayesianStruct.setRelativeSpeedScalar(0.01); bayesianStruct.setSpeedPrior(1.0); bayesianStruct.relativeSpeedPrior.getMaximum(); bayesianStruct.resetSize(matchWindowWidth); bayesianStruct.setPositionDistributionScalar(1); } void AudioEventMatcher::draw(){ //ofRect(20, 20, 300, 200); recordedTracks.drawTracks(); ofSetColor(255); // bayesianStruct.relativeSpeedPrior.drawVector(0, 200, bayesTempoWindow); double screenWidthMillis = recordedTracks.loadedAudioFiles[0].fileLoader.onsetDetect.framesToMillis(recordedTracks.loadedAudioFiles[0].fileLoader.onsetDetect.amplitudeNumber); bayesianStruct.likelihood.drawVector(0, screenWidthMillis, bayesTempoWindow); } void AudioEventMatcher::newPitchEvent(const double& pitchIn, const double& timeIn){ liveInput.addPitchEvent(pitchIn, timeIn); recordedTracks.matchNewPitchEvent(0, pitchIn, timeIn); } void AudioEventMatcher::newKickEvent(const double& timeIn){ matchNewOnsetEvent(0, timeIn); } void AudioEventMatcher::newSnareEvent(const double& timeIn){ matchNewOnsetEvent(0, timeIn); } //Needs just to set bounds for the matching process, not have TimeIn void AudioEventMatcher::matchNewOnsetEvent(const int& channel, const double& timeIn){ //start at beginning but OPTIMISE later double likelihoodToNoise = 0.5; double likelihoodWidth = 40; bayesianStruct.likelihood.offset = bayesianStruct.prior.offset; bayesianStruct.likelihood.zero();//set to zero double quantity = 1;//likelihoodToNoiseRatio / numberOfMatches; int numberOfMatchesFound = 0; double startTime = bayesianStruct.likelihood.offset; double endTime = bayesianStruct.likelihood.offset + matchWindowWidth; if (channel <= recordedTracks.numberOfAudioTracks){ for (int i = 0;i < recordedTracks.loadedAudioFiles[channel].fileLoader.onsetDetect.chromaOnsets.size();i++){ double millisTime = recordedTracks.loadedAudioFiles[channel].fileLoader.onsetDetect.chromaOnsets[i].millisTime; if (millisTime >= startTime && millisTime <= endTime){ bayesianStruct.likelihood.addGaussianShapeFromRealTime(millisTime, likelihoodWidth, quantity); numberOfMatchesFound++; printf("Adding Gaussian for onset at time %f offset %f\n", millisTime, bayesianStruct.likelihood.offset); } } } bayesianStruct.likelihood.renormalise(); //bayesStruct.likelihood.addConstant((1-likelihoodToNoiseRatio)/bayesStruct.likelihood.length); } void AudioEventMatcher::windowResized(const int& w, const int& h){ recordedTracks.windowResized(w,h); }