add basic VAMP plugin for EBUr128 analysis
[ardour.git] / libs / vamp-plugins / EBUr128.cpp
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
2
3 /*
4     Vamp
5
6     An API for audio analysis and feature extraction plugins.
7
8     Centre for Digital Music, Queen Mary, University of London.
9     Copyright 2006 Chris Cannam.
10
11     Permission is hereby granted, free of charge, to any person
12     obtaining a copy of this software and associated documentation
13     files (the "Software"), to deal in the Software without
14     restriction, including without limitation the rights to use, copy,
15     modify, merge, publish, distribute, sublicense, and/or sell copies
16     of the Software, and to permit persons to whom the Software is
17     furnished to do so, subject to the following conditions:
18
19     The above copyright notice and this permission notice shall be
20     included in all copies or substantial portions of the Software.
21
22     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23     EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24     MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
26     ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
27     CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28     WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30 */
31
32 #include "EBUr128.h"
33
34 using std::string;
35 using std::vector;
36 using std::cerr;
37 using std::endl;
38
39
40 VampEBUr128::VampEBUr128(float inputSampleRate)
41     : Plugin(inputSampleRate)
42     , m_stepSize(0)
43 {
44 }
45
46 VampEBUr128::~VampEBUr128()
47 {
48 }
49
50 string
51 VampEBUr128::getIdentifier() const
52 {
53     return "ebur128";
54 }
55
56 string
57 VampEBUr128::getName() const
58 {
59     return "EBU R128 Loudness";
60 }
61
62 string
63 VampEBUr128::getDescription() const
64 {
65     return "Loudness measurements according to the EBU Recommendation 128";
66 }
67
68 string
69 VampEBUr128::getMaker() const
70 {
71     return "Harrison Consoles";
72 }
73
74 int
75 VampEBUr128::getPluginVersion() const
76 {
77     return 2;
78 }
79
80 string
81 VampEBUr128::getCopyright() const
82 {
83     return "GPL version 2 or later";
84 }
85
86 bool
87 VampEBUr128::initialise(size_t channels, size_t stepSize, size_t blockSize)
88 {
89     if (channels < getMinChannelCount() ||
90         channels > getMaxChannelCount()) return false;
91
92     m_stepSize = std::min(stepSize, blockSize);
93     m_channels = channels;
94
95     ebu.init (m_channels, m_inputSampleRate);
96
97     return true;
98 }
99
100 void
101 VampEBUr128::reset()
102 {
103     ebu.reset ();
104 }
105
106 VampEBUr128::OutputList
107 VampEBUr128::getOutputDescriptors() const
108 {
109     OutputList list;
110
111     OutputDescriptor zc;
112     zc.identifier = "loundless";
113     zc.name = "Integrated loudness";
114     zc.description = "Integrated loudness";
115     zc.unit = "LUFS";
116     zc.hasFixedBinCount = true;
117     zc.binCount = 0;
118     zc.hasKnownExtents = false;
119     zc.isQuantized = false;
120     zc.sampleType = OutputDescriptor::OneSamplePerStep;
121     list.push_back(zc);
122
123     zc.identifier = "range";
124     zc.name = "Integrated loudness Range";
125     zc.description = "Dynamic Range of the audio";
126     zc.unit = "LU";
127     zc.hasFixedBinCount = true;
128     zc.binCount = 0;
129     zc.hasKnownExtents = false;
130     zc.isQuantized = false;
131     zc.sampleType = OutputDescriptor::OneSamplePerStep;
132     list.push_back(zc);
133
134     return list;
135 }
136
137 VampEBUr128::FeatureSet
138 VampEBUr128::process(const float *const *inputBuffers,
139                       Vamp::RealTime timestamp)
140 {
141     if (m_stepSize == 0) {
142         cerr << "ERROR: VampEBUr128::process: "
143              << "VampEBUr128 has not been initialised"
144              << endl;
145         return FeatureSet();
146     }
147
148     ebu.integr_start (); // noop if already started
149     ebu.process (m_stepSize, inputBuffers);
150
151     return FeatureSet();
152 }
153
154 VampEBUr128::FeatureSet
155 VampEBUr128::getRemainingFeatures()
156 {
157     FeatureSet returnFeatures;
158
159     Feature loudness;
160     loudness.hasTimestamp = false;
161     loudness.values.push_back(ebu.integrated());
162     returnFeatures[0].push_back(loudness);
163
164     Feature range;
165     range.hasTimestamp = false;
166     range.values.push_back(ebu.range_max () - ebu.range_min ());
167     returnFeatures[1].push_back(range);
168
169     return returnFeatures;
170 }