-
Notifications
You must be signed in to change notification settings - Fork 556
/
Copy pathpitchcontours.h
128 lines (103 loc) · 5.03 KB
/
pitchcontours.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
* Copyright (C) 2006-2021 Music Technology Group - Universitat Pompeu Fabra
*
* This file is part of Essentia
*
* Essentia is free software: you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License as published by the Free
* Software Foundation (FSF), either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the Affero GNU General Public License
* version 3 along with this program. If not, see http://www.gnu.org/licenses/
*/
#ifndef ESSENTIA_PITCHCONTOURS_H
#define ESSENTIA_PITCHCONTOURS_H
#include "algorithmfactory.h"
namespace essentia {
namespace standard {
class PitchContours : public Algorithm {
private:
Input<std::vector<std::vector<Real> > > _peakBins;
Input<std::vector<std::vector<Real> > > _peakSaliences;
Output<std::vector<std::vector<Real> > > _contoursBins;
Output<std::vector<std::vector<Real> > > _contoursSaliences;
Output<std::vector<Real> > _contoursStartTimes;
Output<Real> _duration;
Real _sampleRate;
int _hopSize;
Real _binResolution;
Real _peakFrameThreshold;
Real _peakDistributionThreshold;
//Real _timeContinuity;
std::vector<std::vector<Real> > _salientPeaksBins;
std::vector<std::vector<Real> > _salientPeaksValues;
std::vector<std::vector<Real> > _nonSalientPeaksBins;
std::vector<std::vector<Real> > _nonSalientPeaksValues;
Real _timeContinuityInFrames;
Real _minDurationInFrames;
Real _pitchContinuityInBins;
size_t _numberFrames;
Real _frameDuration;
void removePeak(std::vector<std::vector<Real> >& peaksBins, std::vector<std::vector<Real> >& peaksValues, size_t i, int j);
int findNextPeak(std::vector<std::vector<Real> >& peaksBins, std::vector<Real>& contoursBins, size_t i, bool backward=false);
void trackPitchContour(size_t& index, std::vector<Real>& contourBins, std::vector <Real>& contourSaliences);
public:
PitchContours() {
declareInput(_peakBins, "peakBins", "frame-wise array of cent bins corresponding to pitch salience function peaks");
declareInput(_peakSaliences, "peakSaliences", "frame-wise array of values of salience function peaks");
declareOutput(_contoursBins, "contoursBins", "array of frame-wise vectors of cent bin values representing each contour");
declareOutput(_contoursSaliences, "contoursSaliences", "array of frame-wise vectors of pitch saliences representing each contour");
declareOutput(_contoursStartTimes, "contoursStartTimes", "array of start times of each contour [s]");
declareOutput(_duration, "duration", "time duration of the input signal [s]");
}
~PitchContours() {
};
void declareParameters() {
declareParameter("sampleRate", "the sampling rate of the audio signal [Hz]", "(0,inf)", 44100.);
declareParameter("hopSize", "the hop size with which the pitch salience function was computed", "(0,inf)", 128);
declareParameter("binResolution", "salience function bin resolution [cents]", "(0,inf)", 10.0);
declareParameter("peakFrameThreshold", "per-frame salience threshold factor (fraction of the highest peak salience in a frame)", "[0,1]", 0.9);
declareParameter("peakDistributionThreshold", "allowed deviation below the peak salience mean over all frames (fraction of the standard deviation)", "[0,2]", 0.9);
declareParameter("pitchContinuity", "pitch continuity cue (maximum allowed pitch change during 1 ms time period) [cents]", "[0,inf)", 27.5625);
declareParameter("timeContinuity", "time continuity cue (the maximum allowed gap duration for a pitch contour) [ms]", "(0,inf)", 100.);
declareParameter("minDuration", "the minimum allowed contour duration [ms]", "(0,inf)", 100.);
}
void configure();
void compute();
static const char* name;
static const char* category;
static const char* description;
}; // class PitchContours
} // namespace standard
} // namespace essentia
#include "streamingalgorithmwrapper.h"
namespace essentia {
namespace streaming {
class PitchContours : public StreamingAlgorithmWrapper {
protected:
Sink<std::vector<std::vector<Real> > > _peakBins;
Sink<std::vector<std::vector<Real> > > _peakSaliences;
Source<std::vector<std::vector<Real> > > _contoursBins;
Source<std::vector<std::vector<Real> > > _contoursSaliences;
Source<std::vector<Real> > _contoursStartTimes;
Source<Real> _duration;
public:
PitchContours() {
declareAlgorithm("PitchContours");
declareInput(_peakBins, TOKEN, "peakBins");
declareInput(_peakSaliences, TOKEN, "peakSaliences");
declareOutput(_contoursBins, TOKEN, "contoursBins");
declareOutput(_contoursSaliences, TOKEN, "contoursSaliences");
declareOutput(_contoursStartTimes, TOKEN, "contoursStartTimes");
declareOutput(_duration, TOKEN, "duration");
}
};
} // namespace streaming
} // namespace essentia
#endif // ESSENTIA_PITCHCONTOURS_H