Mercurial > hg > silvet
comparison src/NoteHypothesis.h @ 181:10e7c3ff575e noteagent
Experimental branch toward note-agent stuff (not actually plumbed in yet)
author | Chris Cannam |
---|---|
date | Fri, 23 May 2014 12:40:18 +0100 |
parents | |
children | e1718e64a921 |
comparison
equal
deleted
inserted
replaced
179:825193ef09d2 | 181:10e7c3ff575e |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 /* | |
4 Silvet | |
5 | |
6 A Vamp plugin for note transcription. | |
7 Centre for Digital Music, Queen Mary University of London. | |
8 This file Copyright 2012 Chris Cannam. | |
9 | |
10 This program is free software; you can redistribute it and/or | |
11 modify it under the terms of the GNU General Public License as | |
12 published by the Free Software Foundation; either version 2 of the | |
13 License, or (at your option) any later version. See the file | |
14 COPYING included with this distribution for more information. | |
15 */ | |
16 | |
17 #ifndef NOTE_HYPOTHESIS_H | |
18 #define NOTE_HYPOTHESIS_H | |
19 | |
20 #include "AgentHypothesis.h" | |
21 | |
22 #include <set> | |
23 #include <vector> | |
24 | |
25 /** | |
26 * An AgentHypothesis which tests a series of instantaneous pitch | |
27 * estimates to see whether they fit a single-note relationship. | |
28 * Contains rules specific to testing note pitch and timing. | |
29 */ | |
30 | |
31 class NoteHypothesis : public AgentHypothesis | |
32 { | |
33 public: | |
34 /** | |
35 * Construct an empty hypothesis. This will be in New state and | |
36 * will provisionally accept any estimate. | |
37 */ | |
38 NoteHypothesis(); | |
39 | |
40 /** | |
41 * Destroy the hypothesis | |
42 */ | |
43 ~NoteHypothesis(); | |
44 | |
45 virtual bool accept(Observation); | |
46 virtual State getState() const; | |
47 virtual Observations getAcceptedObservations() const; | |
48 | |
49 struct Note { | |
50 Note() : freq(0), time(), duration() { } | |
51 Note(double _f, Vamp::RealTime _t, Vamp::RealTime _d) : | |
52 freq(_f), time(_t), duration(_d) { } | |
53 bool operator==(const Note &e) const { | |
54 return e.freq == freq && e.time == time && e.duration == duration; | |
55 } | |
56 double freq; | |
57 Vamp::RealTime time; | |
58 Vamp::RealTime duration; | |
59 }; | |
60 | |
61 /** | |
62 * Return the mean frequency of the accepted observations | |
63 */ | |
64 double getMeanFrequency() const; | |
65 | |
66 /** | |
67 * Return a single note roughly matching this hypothesis | |
68 */ | |
69 Note getAveragedNote() const; | |
70 | |
71 /** | |
72 * Return the time of the first accepted observation | |
73 */ | |
74 Vamp::RealTime getStartTime() const; | |
75 | |
76 /** | |
77 * Return the difference between the start time and the end of the | |
78 * final accepted observation | |
79 */ | |
80 Vamp::RealTime getDuration() const; | |
81 | |
82 /** | |
83 * Convert the given sequence of accepted hypotheses into a | |
84 * sampled series of pitches (in Hz), returned at regular | |
85 * intervals determined by the given start time, end time, and | |
86 * interval. The range is [start,end], i.e. the end time is | |
87 * included. The interval must be greater than zero. | |
88 * | |
89 * Unvoiced samples are returned as 0Hz. | |
90 */ | |
91 static std::vector<double> sample(const std::set<NoteHypothesis> &, | |
92 Vamp::RealTime startTime, | |
93 Vamp::RealTime endTime, | |
94 Vamp::RealTime interval); | |
95 | |
96 /** | |
97 *!!! No! Not equally spaced, should be able to be anything [ordered] | |
98 | |
99 * Given a series of equally spaced observations, return a series | |
100 * of the same number of pitches (in Hz) calculated by running an | |
101 * AgentFeeder<NoteHypothesis> on the observations and flattening | |
102 * and sampling the resulting accepted hypotheses. | |
103 * | |
104 * The result should contain only pitches that contributed to | |
105 * recognised notes in the input observations, with the remaining | |
106 * (unvoiced) samples returned as 0Hz. | |
107 * | |
108 * If the input observations are not equally spaced, the result is | |
109 * undefined. | |
110 *!!! (what about rounding errors from RealTime to frame and vice versa?) | |
111 *!!! (should provide a Timebase?) | |
112 *!!! update docs for updated api | |
113 */ | |
114 static std::vector<double> winnow(const Observations &, | |
115 Vamp::RealTime startTime, | |
116 Vamp::RealTime endTime, | |
117 Vamp::RealTime interval); | |
118 | |
119 //!!! | |
120 bool operator==(const NoteHypothesis &other) const { | |
121 return m_state == other.m_state && m_pending == other.m_pending; | |
122 } | |
123 | |
124 bool operator<(const NoteHypothesis &other) const { | |
125 return getStartTime() < other.getStartTime(); | |
126 } | |
127 | |
128 private: | |
129 bool isWithinTolerance(Observation) const; | |
130 bool isOutOfDateFor(Observation) const; | |
131 bool isSatisfied() const; | |
132 | |
133 State m_state; | |
134 Observations m_pending; | |
135 }; | |
136 | |
137 #endif |