view src/timeWarp.h @ 0:572c856e38ac

Starting up openFrameworks project for audio time warping. The ofxFileReader goes in addons of your OF folder, the libraries and source (chromogram, fftw and source code src+ timewarp) are probably best kept in the repository, then dragged into the project afresh. That way, as we update the repository, the code that the openFrameworks project looks for will be updated.
author Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk>
date Tue, 17 May 2011 08:48:58 +0100
parents
children 6842ff391568
line wrap: on
line source
/*
 *  timeWarp.h
 *  chromaReader13
 *
 *  Created by Andrew on 16/05/2011.
 *  Copyright 2011 QMUL. All rights reserved.
 *
 */

#ifndef _TIME_WARP
#define _TIME_WARP


#include "ofMain.h"
#include "chromaGram.h"
#include "ChordDetect.h"
#include "sndfile.h"
#include "ofxFileDialogOSX.h"


#define FRAMESIZE 512
#define ENERGY_LENGTH 80000
#define CHROMA_LENGTH 12000
#define CHROMA_CONVERSION_FACTOR 16 //16 times as many frames in energy as in chroma
//length in terms of frames (at 512 samples per frame - there are 90 per second) => 900: 10 seconds

class timeWarp : public ofBaseApp{
	
public:
	
	/*
	void setup();
	void update();
	void draw();
	
	void keyPressed  (int key);
	void keyReleased(int key);
	void mouseMoved(int x, int y );
	void mouseDragged(int x, int y, int button);
	void mousePressed(int x, int y, int button);
	void mouseReleased(int x, int y, int button);
	void windowResized(int w, int h);
	
	void audioRequested 	(float * input, int bufferSize, int nChannels);
	void loadSndfile();
	 */
	 
	double getEnergyOfFrame();
	void putEnergyInFrame();

//	void drawChromoGram();
//	void loadFirstAudioFile();
	void initialiseVariables();

	//variables
	typedef std::vector<double> DoubleVector;
	typedef std::vector<DoubleVector> DoubleMatrix;
	
	DoubleMatrix chromaMatrix;
	DoubleMatrix secondMatrix;
	DoubleMatrix* matrixPtr;
	
//	void drawDoubleMatrix(DoubleMatrix* dMatrix);//DoubleMatrix* dMatrix); WOULD BE NICE TO USE POINTER BUT NOT WORKING YET
//	void drawSpectralDifference(DoubleMatrix* dMatrix);
	
	DoubleVector firstEnergyVector;
	DoubleVector secondEnergyVector;	
		
	DoubleMatrix similarityMatrix;

	void calculateSimilarityMatrix();
	
//	bool drawSimilarity;
//	void drawSimilarityMatrix();
//	void printSimilarityMatrix(int sizeToPrint);
	
	DoubleMatrix alignmentMeasureMatrix;	
	DoubleVector minimumAlignmentPath;
	
//	void drawAlignmentPath(int startingChromaXFrame, int startingChromaYFrame);
	int findStartWidthFrame();	  
	
//	void printScoreForRow(int row, int max);
	
//	int numberOfScrollWidthsForFirstFile;
//	int numberOfScrollWidthsForSecondFile;	
//	void checkIfAudioPositionExceedsWidthForFirstFile();
	
	typedef std::vector<int> IntVector;
	typedef std::vector<IntVector> IntMatrix;
	
//	void updateAlignmentPathIndex(int idenifier);
	
	IntMatrix backwardsAlignmentPath;
	int backwardsAlignmentIndex;
	
	bool findPreviousMinimumInBackwardsPath();
	bool testForNewAlignmentMinimum(double *previousMinimum, int i, int j);	
	
	void calculateAlignmentMatrix();
	double getDistance(int i, int j);
	void printAlignmentMatrix();
	double getMinimum(int i, int j, float newValue);
	bool extendAlignmentUp();
	bool extendAlignmentAlong();
	void calculateMinimumAlignmentPath();
	int findMinimumOfVector(DoubleVector *d);
//	void swapBetweenPlayingFilesUsingAlignmentMatch();
//	int findMatchFromAlignment(bool whichFileToTest);
	
//	void drawEnergyVectorFromPointer(DoubleVector* energyVec);
	
//	void processAudioToDoubleMatrix(Chromagram* chromaG, DoubleMatrix* myDoubleMatrix, DoubleVector* energyVector);
	
	
	
	
	Chromagram chromoGramm;
	Chromagram secondChromoGramm;
	
	
	
//	void loadNewAudio(string soundFileName);
//	void loadSecondAudio(string soundFileName);
	
//	void loadSoundFiles();
//	void openFileDialogBox();
//	void loadLibSndFile(const char * filename);
//	bool getFilenameFromDialogBox(string* fileNameToSave);
//	void openNewAudioFileWithdialogBox();		
	
	//int* firstAudioLength, secondAudioLength;
	
//	string soundFileName, secondFileName;
	
//	float screenHeight, screenWidth;

	
//	bool moveOn;
//	bool drawSpectralDifferenceFunction;

	float frame[FRAMESIZE]; 
	
	float diagonalPenalty;
	
//	int frameIndex;
	
//	float chromoGramVector[CHROMA_LENGTH][12];
//	int rootChord[CHROMA_LENGTH];
	
//	int energyIndex;
//	int totalFrames;
	
//	int scrollWidth;// 1600
//	float chromoLength;
	
//	bool audioPlaying, audioPaused;
//	bool drawSecondMatrix;
	
/*

	
	//------------------- for the simple sine wave synthesis
	float 	targetFrequency;
	float 	phase;
	float 	phaseAdder;
	float 	phaseAdderTarget;
	
	string sndfileInfoString, textString;
	int xIndex;
	
	bool firstAudioFilePlaying;
	ofSoundPlayer  loadedAudio;
	ofSoundPlayer secondAudio;
	ofSoundPlayer *playingAudio;
	
 */
//	float audioPosition;
//	float width, height;
//	int chromaIndex;	
//	int totalNumberOfFrames;
//	int currentPlayingFrame;
//	int currentChromaFrame ;
	
//	string chordString;
	
	//Chromagram* chromoGrammPtr;
	
	
	
	
//	string userInfoString;
//	ChordDetect chord;
	//sndfile part
//	SNDFILE *infile; // define input and output sound files
//	SF_INFO sfinfo ; // struct to hold info about sound file
	
	
};

#endif