andrew@0: /* andrew@0: * AudioAnalysis.cpp andrew@0: * audioFileLoader4 andrew@0: * andrew@0: * Created by Andrew on 14/08/2011. andrew@0: * Copyright 2011 QMUL. All rights reserved. andrew@0: * andrew@0: */ andrew@0: andrew@0: #include "AudioAnalysis.h" andrew@0: andrew@0: andrew@1: AudioAnalysis::AudioAnalysis(){ andrew@1: chromoGramm.initialise(FRAMESIZE,2048); andrew@1: andrew@1: scrollWidth = 1600; andrew@1: andrew@1: } andrew@1: andrew@1: andrew@1: andrew@1: void AudioAnalysis::drawEnergyVectorFromPointer(){ andrew@1: DoubleVector* energyVec; andrew@1: energyVec = &energyVector; andrew@1: //xxx above andrew@1: andrew@1: ofSetColor(0xFF0066); andrew@1: float screenHeight = ofGetHeight() ; andrew@1: float screenWidth = ofGetWidth(); andrew@1: float heightFactor = 8; andrew@1: int i, j, startingFrame; andrew@1: startingFrame = currentPlayingFrame / scrollWidth;//i.e. number of scroll widths in andrew@1: startingFrame *= scrollWidth; andrew@1: andrew@1: for (i = 0; i < scrollWidth - 1; i++){ andrew@1: j = i + startingFrame; andrew@1: if (j < (*energyVec).size()) andrew@1: ofLine(i*screenWidth/scrollWidth, screenHeight - ((*energyVec)[j]*screenHeight/heightFactor), andrew@1: screenWidth*(i+1)/scrollWidth, screenHeight - ((*energyVec)[j+1]*screenHeight/heightFactor)); andrew@1: andrew@1: } andrew@1: } andrew@1: andrew@1: void AudioAnalysis::drawSpectralDifference(){ andrew@1: DoubleMatrix* dMatrix; andrew@1: dMatrix = &chromaMatrix; andrew@1: //get rid of these! andrew@1: andrew@1: int matrixSize = (*dMatrix).size(); andrew@1: if (matrixSize > 0){ andrew@1: andrew@1: float screenHeight = ofGetHeight() ; andrew@1: float screenWidth = ofGetWidth(); andrew@1: float heightFactor = 8; andrew@1: double difference; andrew@1: int i, j, startingFrame; andrew@1: startingFrame = currentPlayingFrame / scrollWidth;//i.e. number of scroll widths in andrew@1: startingFrame *= scrollWidth;//starting frame in terms of energy frames andrew@1: startingFrame /= CHROMA_CONVERSION_FACTOR; //in terms of chroma frames andrew@1: andrew@1: float chromoLength = scrollWidth/CHROMA_CONVERSION_FACTOR; andrew@1: for (i = 1; i < chromoLength; i++){//changed to add 1 andrew@1: j = i + startingFrame; andrew@1: for (int y = 0;y < 12;y++){ andrew@1: andrew@1: if (j < matrixSize) andrew@1: difference = (*dMatrix)[j][11-y] - (*dMatrix)[j-1][11-y]; andrew@1: else andrew@1: difference = 0; andrew@1: andrew@1: if (difference < 0) andrew@1: difference = 0;//half wave rectify andrew@1: andrew@1: ofSetColor(0,0,255 * difference);//, 0; andrew@1: ofRect(i*screenWidth/chromoLength,y*screenHeight/12,screenWidth/chromoLength,screenHeight/12); andrew@1: }//end y andrew@1: }//end i andrew@1: andrew@1: }///end if matrix has content andrew@1: else{ andrew@1: printf("Error - please load audio first"); andrew@1: } andrew@1: andrew@1: } andrew@1: andrew@1: andrew@0: /* andrew@0: void testApp::initialiseVariables(){ andrew@0: andrew@0: energyIndex = 0; andrew@0: // frameIndex = 0; andrew@0: chromaIndex = 0; andrew@0: chromoGramm.initialise(FRAMESIZE,2048);//framesize 512 and hopsize 2048 andrew@0: } andrew@0: andrew@0: andrew@0: //-------------------------------------------------------------- andrew@0: void testApp::draw(){ andrew@0: switch (screenToDraw){ andrew@0: case 0: andrew@0: if (drawSpectralDifferenceFunction) andrew@0: drawSpectralDifference(&chromaMatrix); andrew@0: else andrew@0: drawDoubleMatrix(&chromaMatrix); andrew@0: andrew@0: drawEnergyVectorFromPointer(&firstEnergyVector); andrew@0: break; andrew@0: case 1: andrew@0: // audioHolder.drawAudioVectorMillis(1000, 1000+audioScale); andrew@0: audioHolder.drawAudioVectorSamples(audioHolder.playPosition, audioHolder.playPosition+audioHolder.audioScaleSamples); andrew@0: break; andrew@0: } andrew@0: andrew@0: andrew@0: andrew@0: //ofSetColor(255,0,0); andrew@0: //drawEnergyVectorFromPointer(&audioVector); andrew@0: andrew@0: ofSetColor(0xFFFFFF); andrew@0: ofLine(audioPosition*width, 0, audioPosition*width, height); andrew@0: andrew@0: ofDrawBitmapString(soundFileName,80,480); andrew@0: andrew@0: } andrew@0: andrew@0: andrew@0: void testApp::drawEnergyVectorFromPointer(DoubleVector* energyVec){ andrew@0: andrew@0: ofSetColor(0xFF0066); andrew@0: float screenHeight = ofGetHeight() ; andrew@0: float screenWidth = ofGetWidth(); andrew@0: float heightFactor = 8; andrew@0: int i, j, startingFrame; andrew@0: startingFrame = currentPlayingFrame / scrollWidth;//i.e. number of scroll widths in andrew@0: startingFrame *= scrollWidth; andrew@0: andrew@0: for (i = 0; i < scrollWidth - 1; i++){ andrew@0: j = i + startingFrame; andrew@0: if (j < (*energyVec).size()) andrew@0: ofLine(i*screenWidth/scrollWidth, screenHeight - ((*energyVec)[j]*screenHeight/heightFactor), andrew@0: screenWidth*(i+1)/scrollWidth, screenHeight - ((*energyVec)[j+1]*screenHeight/heightFactor)); andrew@0: andrew@0: } andrew@0: } andrew@0: andrew@0: void testApp::drawSpectralDifference(DoubleMatrix* dMatrix){ andrew@0: int matrixSize = (*dMatrix).size(); andrew@0: if (matrixSize > 0){ andrew@0: andrew@0: float screenHeight = ofGetHeight() ; andrew@0: float screenWidth = ofGetWidth(); andrew@0: float heightFactor = 8; andrew@0: double difference; andrew@0: int i, j, startingFrame; andrew@0: startingFrame = currentPlayingFrame / scrollWidth;//i.e. number of scroll widths in andrew@0: startingFrame *= scrollWidth;//starting frame in terms of energy frames andrew@0: startingFrame /= CHROMA_CONVERSION_FACTOR; //in terms of chroma frames andrew@0: andrew@0: float chromoLength = scrollWidth/CHROMA_CONVERSION_FACTOR; andrew@0: for (i = 1; i < chromoLength; i++){//changed to add 1 andrew@0: j = i + startingFrame; andrew@0: for (int y = 0;y < 12;y++){ andrew@0: andrew@0: if (j < matrixSize) andrew@0: difference = (*dMatrix)[j][11-y] - (*dMatrix)[j-1][11-y]; andrew@0: else andrew@0: difference = 0; andrew@0: andrew@0: if (difference < 0) andrew@0: difference = 0;//half wave rectify andrew@0: andrew@0: ofSetColor(0,0,255 * difference);//, 0; andrew@0: ofRect(i*screenWidth/chromoLength,y*screenHeight/12,screenWidth/chromoLength,screenHeight/12); andrew@0: }//end y andrew@0: }//end i andrew@0: andrew@0: }///end if matrix has content andrew@0: else{ andrew@0: printf("Error - please load audio first"); andrew@0: } andrew@0: andrew@0: } andrew@0: andrew@0: andrew@0: void testApp::drawDoubleMatrix(DoubleMatrix* dMatrix){ andrew@0: //used to draw the chromagram matrix andrew@0: int matrixSize = (*dMatrix).size(); andrew@0: if (matrixSize > 0){ andrew@0: andrew@0: float screenHeight = ofGetHeight() ; andrew@0: float screenWidth = ofGetWidth(); andrew@0: float heightFactor = 8; andrew@0: int i, j, startingFrame; andrew@0: startingFrame = currentPlayingFrame / scrollWidth;//i.e. number of scroll widths in andrew@0: startingFrame *= scrollWidth;//starting frame in terms of energy frames andrew@0: startingFrame /= CHROMA_CONVERSION_FACTOR; //in terms of chroma frames andrew@0: andrew@0: float chromoLength = scrollWidth/CHROMA_CONVERSION_FACTOR; andrew@0: for (i = 0; i < chromoLength; i++){ andrew@0: j = i + startingFrame; andrew@0: for (int y = 0;y < 12;y++){ andrew@0: andrew@0: if (j < matrixSize) andrew@0: ofSetColor(0,0,255 * (*dMatrix)[j][11-y]); andrew@0: else andrew@0: ofSetColor(0,0,0); andrew@0: andrew@0: ofRect(i*screenWidth/chromoLength,y*screenHeight/12,screenWidth/chromoLength,screenHeight/12); andrew@0: }//end y andrew@0: }//end i andrew@0: andrew@0: }///end if matrix has content andrew@0: else{ andrew@0: printf("Error - please load audio first"); andrew@0: } andrew@0: andrew@0: andrew@0: } andrew@0: andrew@0: andrew@0: andrew@0: andrew@0: andrew@0: */ andrew@0: andrew@0: