summaryrefslogtreecommitdiff
path: root/libs/vamp-plugins/EBUr128.cpp
blob: c84d9df1d5fc7197a41d29b12af9076033472d05 (plain)
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */

/*
    Vamp

    An API for audio analysis and feature extraction plugins.

    Centre for Digital Music, Queen Mary, University of London.
    Copyright 2006 Chris Cannam.

    Permission is hereby granted, free of charge, to any person
    obtaining a copy of this software and associated documentation
    files (the "Software"), to deal in the Software without
    restriction, including without limitation the rights to use, copy,
    modify, merge, publish, distribute, sublicense, and/or sell copies
    of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be
    included in all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
    ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
    CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
    WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

*/

#include "EBUr128.h"

using std::string;
using std::vector;
using std::cerr;
using std::endl;


VampEBUr128::VampEBUr128(float inputSampleRate)
    : Plugin(inputSampleRate)
    , m_stepSize(0)
{
}

VampEBUr128::~VampEBUr128()
{
}

string
VampEBUr128::getIdentifier() const
{
    return "ebur128";
}

string
VampEBUr128::getName() const
{
    return "EBU R128 Loudness";
}

string
VampEBUr128::getDescription() const
{
    return "Loudness measurements according to the EBU Recommendation 128";
}

string
VampEBUr128::getMaker() const
{
    return "Harrison Consoles";
}

int
VampEBUr128::getPluginVersion() const
{
    return 2;
}

string
VampEBUr128::getCopyright() const
{
    return "GPL version 2 or later";
}

bool
VampEBUr128::initialise(size_t channels, size_t stepSize, size_t blockSize)
{
    if (channels < getMinChannelCount() ||
	channels > getMaxChannelCount()) return false;

    m_stepSize = std::min(stepSize, blockSize);
    m_channels = channels;

    ebu.init (m_channels, m_inputSampleRate);

    return true;
}

void
VampEBUr128::reset()
{
    ebu.reset ();
}

VampEBUr128::OutputList
VampEBUr128::getOutputDescriptors() const
{
    OutputList list;

    OutputDescriptor zc;
    zc.identifier = "loundless";
    zc.name = "Integrated loudness";
    zc.description = "Integrated Loudness";
    zc.unit = "LUFS";
    zc.hasFixedBinCount = true;
    zc.binCount = 0;
    zc.hasKnownExtents = false;
    zc.isQuantized = false;
    zc.sampleType = OutputDescriptor::OneSamplePerStep;
    list.push_back(zc);

    zc.identifier = "range";
    zc.name = "Integrated Loudness Range";
    zc.description = "Dynamic Range of the Audio";
    zc.unit = "LU";
    zc.hasFixedBinCount = true;
    zc.binCount = 0;
    zc.hasKnownExtents = false;
    zc.isQuantized = false;
    zc.sampleType = OutputDescriptor::OneSamplePerStep;
    list.push_back(zc);

    zc.identifier = "histogram";
    zc.name = "Loudness Histogram";
    zc.description = "Dynamic Range of the audio";
    zc.unit = "";
    zc.hasFixedBinCount = false;
    zc.binCount = 0;
    zc.hasKnownExtents = false;
    zc.isQuantized = false;
    zc.sampleType = OutputDescriptor::OneSamplePerStep;
    list.push_back(zc);

    return list;
}

VampEBUr128::FeatureSet
VampEBUr128::process(const float *const *inputBuffers,
                      Vamp::RealTime timestamp)
{
    if (m_stepSize == 0) {
	cerr << "ERROR: VampEBUr128::process: "
	     << "VampEBUr128 has not been initialised"
	     << endl;
	return FeatureSet();
    }

    ebu.integr_start (); // noop if already started
    ebu.process (m_stepSize, inputBuffers);

    return FeatureSet();
}

VampEBUr128::FeatureSet
VampEBUr128::getRemainingFeatures()
{
    FeatureSet returnFeatures;

    Feature loudness;
    loudness.hasTimestamp = false;
    loudness.values.push_back(ebu.integrated());
    returnFeatures[0].push_back(loudness);

    Feature range;
    range.hasTimestamp = false;
    range.values.push_back(ebu.range_max () - ebu.range_min ());
    returnFeatures[1].push_back(range);

    Feature hist;
    hist.hasTimestamp = false;
    const int * hist_S = ebu.histogram_S();
    for (int i = 110; i < 650; ++i) {
	hist.values.push_back(hist_S[i]);
    }
    returnFeatures[2].push_back(hist);

    return returnFeatures;
}