Silvet.h
Go to the documentation of this file.
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 
9  This program is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2 of the
12  License, or (at your option) any later version. See the file
13  COPYING included with this distribution for more information.
14 */
15 
16 #ifndef SILVET_H
17 #define SILVET_H
18 
19 #include <vamp-sdk/Plugin.h>
20 
21 #include <vector>
22 #include <string>
23 #include <set>
24 
25 #include "MedianFilter.h"
26 #include "Instruments.h"
27 
28 #ifndef MAX_EM_THREADS
29 #define MAX_EM_THREADS 8
30 #endif
31 
32 using std::string;
33 using std::vector;
34 using std::set;
35 using std::map;
36 
37 class Resampler;
38 class CQSpectrogram;
39 class FlattenDynamics;
40 
41 class Silvet : public Vamp::Plugin
42 {
43 public:
44  Silvet(float inputSampleRate);
45  virtual ~Silvet();
46 
47  string getIdentifier() const;
48  string getName() const;
49  string getDescription() const;
50  string getMaker() const;
51  int getPluginVersion() const;
52  string getCopyright() const;
53 
54  InputDomain getInputDomain() const;
55  size_t getPreferredBlockSize() const;
56  size_t getPreferredStepSize() const;
57  size_t getMinChannelCount() const;
58  size_t getMaxChannelCount() const;
59 
60  ParameterList getParameterDescriptors() const;
61  float getParameter(string identifier) const;
62  void setParameter(string identifier, float value);
63 
64  ProgramList getPrograms() const;
65  string getCurrentProgram() const;
66  void selectProgram(string name);
67 
68  OutputList getOutputDescriptors() const;
69 
70  bool initialise(size_t channels, size_t stepSize, size_t blockSize);
71  void reset();
72 
73  FeatureSet process(const float *const *inputBuffers,
74  Vamp::RealTime timestamp);
75 
76  FeatureSet getRemainingFeatures();
77 
79  LiveMode = 0,
81  };
82 
83 protected:
84  const std::vector<InstrumentPack> m_instruments;
85  const std::vector<InstrumentPack> m_liveInstruments;
86 
87  const InstrumentPack &getPack(int instrument) const {
88  if (m_mode == LiveMode) {
89  return m_liveInstruments[instrument];
90  } else {
91  return m_instruments[instrument];
92  }
93  }
94 
95  Resampler *m_resampler;
96  FlattenDynamics *m_flattener;
97  CQSpectrogram *m_cq;
98 
100 
104 
105  typedef vector<vector<double> > Grid;
106 
107  vector<MedianFilter<double> *> m_postFilter;
108  vector<map<int, double> > m_pianoRoll;
109  vector<map<int, int> > m_pianoRollShifts;
110  map<Vamp::RealTime, float> m_inputGains;
111  set<int> m_current;
112 
113  Grid preProcess(const Grid &);
114 
115  std::pair<vector<double>, vector<int> > applyEM(const InstrumentPack &pack,
116  const vector<double> &column);
117 
118  void postProcess(const vector<double> &pitches,
119  const vector<int> &bestShifts); // -> piano roll column
120 
121  struct FeatureChunk {
122  FeatureList notes;
123  FeatureList onsets;
124  FeatureList onOffsets;
125  };
126 
127  int getShiftCount() const;
128 
129  FeatureChunk noteTrack(); // notes, on/offsets
130 
131  void emitNoteAndOffset(int start, int end, int note,
132  FeatureList &noteFeatures,
133  FeatureList &onOffsetFeatures);
134 
135  void emitOnset(int start, int note,
136  FeatureList &onOffsetFeatures);
137 
138  Vamp::RealTime getColumnTimestamp(int column);
139 
140  Feature makeNoteFeature(int start, int end, int note, int shift, double strength);
141  Feature makeOnsetFeature(int start, int note, int shift, double strength);
142  Feature makeOffsetFeature(int col, int note, int shift);
143 
144  int getVelocityFor(double strength, int column);
145 
146  float getInputGainAt(Vamp::RealTime t);
147 
148  void insertTemplateFeatures(FeatureSet &);
149 
150  void transcribe(const Grid &, FeatureSet &);
151 
152  string getChromaName(int n) const;
153  string getNoteName(int n, int shift) const;
154  float getNoteFrequency(int n, int shift) const;
155 
159  Vamp::RealTime m_startTime;
161 
162  mutable int m_notesOutputNo;
163  mutable int m_onsetsOutputNo;
164  mutable int m_onOffsetsOutputNo;
165  mutable int m_fcqOutputNo;
166  mutable int m_pitchOutputNo;
167  mutable int m_templateOutputNo;
168  mutable int m_chromaOutputNo;
169 };
170 
171 #endif
int m_pitchOutputNo
Definition: Silvet.h:166
Feature makeOnsetFeature(int start, int note, int shift, double strength)
Definition: Silvet.cpp:1270
int m_blockSize
Definition: Silvet.h:156
void setParameter(string identifier, float value)
Definition: Silvet.cpp:208
set< int > m_current
Definition: Silvet.h:111
void emitOnset(int start, int note, FeatureList &onOffsetFeatures)
Definition: Silvet.cpp:1209
float getInputGainAt(Vamp::RealTime t)
Definition: Silvet.cpp:1331
int m_instrument
Definition: Silvet.h:102
Feature makeOffsetFeature(int col, int note, int shift)
Definition: Silvet.cpp:1292
size_t getPreferredStepSize() const
Definition: Silvet.cpp:128
FeatureSet getRemainingFeatures()
Definition: Silvet.cpp:623
Definition: Instruments.h:32
vector< MedianFilter< double > * > m_postFilter
Definition: Silvet.h:107
Resampler * m_resampler
Definition: Silvet.h:95
int getPluginVersion() const
Definition: Silvet.cpp:104
int m_resampledCount
Definition: Silvet.h:158
Definition: Silvet.h:80
Definition: Silvet.h:79
Feature makeNoteFeature(int start, int end, int note, int shift, double strength)
Definition: Silvet.cpp:1246
string getNoteName(int n, int shift) const
Definition: Silvet.cpp:403
const std::vector< InstrumentPack > m_liveInstruments
Definition: Silvet.h:85
OutputList getOutputDescriptors() const
Definition: Silvet.cpp:238
size_t getPreferredBlockSize() const
Definition: Silvet.cpp:122
FeatureList onOffsets
Definition: Silvet.h:124
int m_onsetsOutputNo
Definition: Silvet.h:163
Definition: Silvet.h:41
string getCopyright() const
Definition: Silvet.cpp:110
int getShiftCount() const
Definition: Silvet.cpp:678
ProgramList getPrograms() const
Definition: Silvet.cpp:220
FeatureList onsets
Definition: Silvet.h:123
string getName() const
Definition: Silvet.cpp:86
string getDescription() const
Definition: Silvet.cpp:92
CQSpectrogram * m_cq
Definition: Silvet.h:97
void reset()
Definition: Silvet.cpp:494
std::pair< vector< double >, vector< int > > applyEM(const InstrumentPack &pack, const vector< double > &column)
Definition: Silvet.cpp:823
string getMaker() const
Definition: Silvet.cpp:98
bool initialise(size_t channels, size_t stepSize, size_t blockSize)
Definition: Silvet.cpp:462
vector< map< int, int > > m_pianoRollShifts
Definition: Silvet.h:109
int m_columnCount
Definition: Silvet.h:157
vector< vector< double > > Grid
Definition: Silvet.h:105
string getChromaName(int n) const
Definition: Silvet.cpp:393
void selectProgram(string name)
Definition: Silvet.cpp:233
int m_colsPerSec
Definition: Silvet.h:103
int m_templateOutputNo
Definition: Silvet.h:167
int m_chromaOutputNo
Definition: Silvet.h:168
FlattenDynamics * m_flattener
Definition: Silvet.h:96
Vamp::RealTime m_startTime
Definition: Silvet.h:159
void transcribe(const Grid &, FeatureSet &)
Definition: Silvet.cpp:690
size_t getMaxChannelCount() const
Definition: Silvet.cpp:140
size_t getMinChannelCount() const
Definition: Silvet.cpp:134
string getCurrentProgram() const
Definition: Silvet.cpp:227
void insertTemplateFeatures(FeatureSet &)
Definition: Silvet.cpp:660
ProcessingMode
Definition: Silvet.h:78
Vamp::RealTime getColumnTimestamp(int column)
Definition: Silvet.cpp:1236
void emitNoteAndOffset(int start, int end, int note, FeatureList &noteFeatures, FeatureList &onOffsetFeatures)
Definition: Silvet.cpp:1125
int m_fcqOutputNo
Definition: Silvet.h:165
ParameterList getParameterDescriptors() const
Definition: Silvet.cpp:146
FeatureList notes
Definition: Silvet.h:122
int m_notesOutputNo
Definition: Silvet.h:162
Grid preProcess(const Grid &)
Definition: Silvet.cpp:881
string getIdentifier() const
Definition: Silvet.cpp:80
float getParameter(string identifier) const
Definition: Silvet.cpp:195
const std::vector< InstrumentPack > m_instruments
Definition: Silvet.h:84
void postProcess(const vector< double > &pitches, const vector< int > &bestShifts)
Definition: Silvet.cpp:968
InputDomain getInputDomain() const
Definition: Silvet.cpp:116
int getVelocityFor(double strength, int column)
Definition: Silvet.cpp:1313
virtual ~Silvet()
Definition: Silvet.cpp:69
Definition: Silvet.h:121
vector< map< int, double > > m_pianoRoll
Definition: Silvet.h:108
bool m_haveStartTime
Definition: Silvet.h:160
bool m_fineTuning
Definition: Silvet.h:101
int m_onOffsetsOutputNo
Definition: Silvet.h:164
float getNoteFrequency(int n, int shift) const
Definition: Silvet.cpp:431
map< Vamp::RealTime, float > m_inputGains
Definition: Silvet.h:110
ProcessingMode m_mode
Definition: Silvet.h:99
const InstrumentPack & getPack(int instrument) const
Definition: Silvet.h:87
FeatureSet process(const float *const *inputBuffers, Vamp::RealTime timestamp)
Definition: Silvet.cpp:568
Silvet(float inputSampleRate)
Definition: Silvet.cpp:54
FeatureChunk noteTrack()
Definition: Silvet.cpp:1042