To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / NoteHypothesis.h @ 32:c88a9972975b

History | View | Annotate | Download (2.24 KB)

1
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
2
/* Copyright Chris Cannam - All Rights Reserved */
3

    
4
#ifndef _NOTE_HYPOTHESIS_H_
5
#define _NOTE_HYPOTHESIS_H_
6

    
7
#include "base/RealTime.h"
8
#include <vector>
9

    
10
namespace Turbot {
11

    
12
/**
13
 * An agent used to test an incoming series of instantaneous pitch
14
 * estimates to see whether they fit a consistent single-note
15
 * relationship. Contains rules specific to testing note pitch and
16
 * timing.
17
 */
18

    
19
class NoteHypothesis
20
{
21
public:
22
    enum State {
23

    
24
        /// Just constructed, will provisionally accept any estimate
25
        New,
26

    
27
        /// Accepted at least one estimate, but not enough evidence to satisfy
28
        Provisional,
29

    
30
        /// Could not find enough consistency in offered estimates
31
        Rejected,
32

    
33
        /// Have accepted enough consistent estimates to satisfy hypothesis
34
        Satisfied,
35

    
36
        /// Have been satisfied, but evidence has now changed: we're done
37
        Expired
38
    };
39
    
40
    /**
41
     * Construct an empty hypothesis. This will be in New state and
42
     * will provisionally accept any estimate.
43
     */
44
    NoteHypothesis();
45

    
46
    /**
47
     * Destroy the hypothesis
48
     */
49
    ~NoteHypothesis();
50

    
51
    struct Estimate {
52
        double freq;
53
        RealTime time;
54
        double confidence;
55
    };
56
    typedef std::vector<Estimate> Estimates;
57

    
58
    /**
59
     * Test the given estimate to see whether it is consistent with
60
     * this hypothesis, and adjust the hypothesis' internal state
61
     * accordingly. If the estimate is not inconsistent with the
62
     * hypothesis, return true.
63
     */
64
    bool accept(Estimate);
65

    
66
    /**
67
     * Return the current state of this hypothesis.
68
     */
69
    State getState() const;
70

    
71
    /**
72
     * If the hypothesis has been satisfied (i.e. is in Satisfied or
73
     * Expired state), return the series of estimates that it
74
     * accepted. Otherwise return an empty list
75
     */
76
    Estimates getAcceptedEstimates() const;
77

    
78
    struct Note {
79
        double freq;
80
        RealTime time;
81
        RealTime duration;
82
    };
83
    
84
    /**
85
     * Return a single note roughly matching this hypothesis
86
     */
87
    Note getAveragedNote() const;
88
    
89
private:
90
    bool isWithinTolerance(Estimate) const;
91
    bool isOutOfDateFor(Estimate) const;
92
    bool isSatisfied() const;
93
    double getMeanFrequency() const;
94
    
95
    State m_state;
96
    Estimates m_pending;
97
};
98

    
99
}
100

    
101
#endif