-
-
Notifications
You must be signed in to change notification settings - Fork 143
/
Copy pathsilence_remover.cpp
53 lines (45 loc) · 1.03 KB
/
silence_remover.cpp
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
// Copyright (C) 2016 Lukas Lalinsky
// Distributed under the MIT license, see the LICENSE file for details.
#include <cassert>
#include <algorithm>
#include "debug.h"
#include "silence_remover.h"
namespace chromaprint {
const short kSilenceWindow = 55; // 5 ms as 11025 Hz
SilenceRemover::SilenceRemover(AudioConsumer *consumer, int threshold)
: m_start(true),
m_threshold(threshold),
m_average(kSilenceWindow),
m_consumer(consumer)
{
}
bool SilenceRemover::Reset(int sample_rate, int num_channels)
{
if (num_channels != 1) {
DEBUG("chromaprint::SilenceRemover::Reset() -- Expecting mono audio signal.");
return false;
}
m_start = true;
return true;
}
void SilenceRemover::Consume(const int16_t *input, int length)
{
if (m_start) {
while (length) {
m_average.AddValue(std::abs(*input));
if (m_average.GetAverage() > m_threshold) {
m_start = false;
break;
}
input++;
length--;
}
}
if (length) {
m_consumer->Consume(input, length);
}
}
void SilenceRemover::Flush()
{
}
}; // namespace chromaprint