Mercurial > hg > drum-timing-analyser
comparison DrumTimingLoader_OF/ofxAudioFileLoader/AudioFile.cpp @ 0:82352cfc0b23
Added files from ISMIR groove drum timing work
author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
---|---|
date | Mon, 01 Oct 2012 22:24:32 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:82352cfc0b23 |
---|---|
1 /* | |
2 * audioFile.cpp | |
3 * audioFileLoader3 | |
4 * | |
5 * Created by Andrew on 31/07/2011. | |
6 * Copyright 2011 QMUL. All rights reserved. | |
7 * | |
8 */ | |
9 | |
10 #include "AudioFile.h" | |
11 | |
12 const double samplingFrequency = 44100.0; | |
13 | |
14 AudioFile::AudioFile(){ | |
15 audioScaleSamples = 44100; | |
16 playPosition = 0; | |
17 | |
18 } | |
19 | |
20 void AudioFile::drawAudioVectorMillis(double startTimeMillis, double endTimeMillis){ | |
21 | |
22 ofBackground(255); | |
23 double startTimeSamples = startTimeMillis * samplingFrequency / 1000.0; | |
24 double endTimeSamples = endTimeMillis * samplingFrequency / 1000.0; | |
25 double screenHeight = ofGetHeight() ; | |
26 double screenWidth = ofGetWidth(); | |
27 | |
28 ofSetColor(255,0,0); | |
29 double numberOfSamples = endTimeSamples - startTimeSamples; | |
30 double samplesPerPixel = numberOfSamples / screenWidth; | |
31 string samplesString = "millis : sps "; | |
32 samplesString += ofToString(samplesPerPixel, 2); | |
33 samplesString += " , \n"; | |
34 | |
35 int lastSampleIndex = (int) startTimeSamples; | |
36 | |
37 for (int i = 1;i < screenWidth;i++){// && startTimeSamples + samplesPerPixel * i < endTimeSamples;i += 1){ | |
38 int sampleIndex = (int) min((startTimeSamples + samplesPerPixel * i), (double) length-1); | |
39 //if (sampleIndex < 0) | |
40 // sampleIndex = 0; | |
41 ofLine(i-1, screenHeight - (1-audioVector[sampleIndex])*screenHeight/2.0 , i, screenHeight - (1-audioVector[lastSampleIndex])*screenHeight/2.0); | |
42 samplesString += ofToString(audioVector[i])+" , \n"; | |
43 lastSampleIndex = sampleIndex; | |
44 | |
45 } | |
46 ofDrawBitmapString(samplesString, 20,20); | |
47 | |
48 ofSetColor(100,100,100); | |
49 ofLine(screenWidth/2, 0, screenWidth/2, screenHeight); | |
50 | |
51 | |
52 } | |
53 | |
54 | |
55 | |
56 void AudioFile::drawAudioVectorSamples(double startTimeSample, double endTimeSample){ | |
57 | |
58 ofBackground(255); | |
59 screenHeight = ofGetHeight() ; | |
60 double screenWidth = ofGetWidth(); | |
61 | |
62 ofSetColor(255,0,0); | |
63 double numberOfSamples = endTimeSample - startTimeSample; | |
64 double samplesPerPixel = numberOfSamples / screenWidth; | |
65 | |
66 double halfHeight = screenHeight/2; | |
67 | |
68 int lastSampleIndex = (int) startTimeSample; | |
69 /* | |
70 for (int i = 1;i < screenWidth;i++){// && startTimeSamples + samplesPerPixel * i < endTimeSamples;i += 1){ | |
71 int sampleIndex = (int) (startTimeSample + samplesPerPixel * i); | |
72 ofLine(i-1, screenHeight - (1-audioVector[sampleIndex])*screenHeight/2.0 , i, screenHeight - (1-audioVector[lastSampleIndex])*screenHeight/2.0); | |
73 lastSampleIndex = sampleIndex; | |
74 | |
75 } | |
76 */ | |
77 double firstXpos = halfHeight; | |
78 double firstYpos = getPosition(startTimeSample);//screenHeight - ((1-audioVector[startTimeSample])*screenHeight/2.0); | |
79 | |
80 int stepSize = 1;//(int) samplesPerPixel); optimize !! XXX | |
81 for (int sampleIndex = startTimeSample+1;sampleIndex < min(endTimeSample, (double) length);sampleIndex+= stepSize){ | |
82 | |
83 double secondXpos = (sampleIndex - startTimeSample) * screenWidth/numberOfSamples; | |
84 double secondYpos = getPosition(sampleIndex);//screenHeight - ((1-audioVector[sampleIndex])*screenHeight/2.0); | |
85 ofLine(firstXpos, firstYpos, secondXpos, secondYpos); | |
86 | |
87 if (numberOfSamples < 100) | |
88 ofCircle(secondXpos, secondYpos, 2); | |
89 | |
90 firstXpos = secondXpos; | |
91 firstYpos = secondYpos; | |
92 | |
93 | |
94 } | |
95 | |
96 string samplesString = "samples: sps " + ofToString(samplesPerPixel, 2); | |
97 samplesString += ", number of smaplers " + ofToString(numberOfSamples, 2); | |
98 samplesString += " , \n"; | |
99 | |
100 | |
101 string textString; | |
102 textString = ofToString(playPosition, 1); | |
103 ofDrawBitmapString(textString, 20, 20); | |
104 ofDrawBitmapString(samplesString, 20, 60); | |
105 | |
106 ofSetColor(0,0,255); | |
107 ofLine(0, halfHeight, screenWidth, halfHeight); | |
108 | |
109 } | |
110 /* | |
111 double testApp::getXposition(int index, int startTimeSampleIndex){ | |
112 if (index >= 0 && index < audioVector.size()) | |
113 return (index - startTimeSampleIndex) * screenWidth/numberOfSamples; | |
114 } | |
115 */ | |
116 double AudioFile::getPosition(int index){ | |
117 if (index >= 0 && index < audioVector.size()) | |
118 return screenHeight - ((1-audioVector[index])*screenHeight/2.0); | |
119 else | |
120 return screenHeight /2 ; | |
121 } | |
122 | |
123 |