-
-
Notifications
You must be signed in to change notification settings - Fork 143
/
Copy pathaudio_processor.h
72 lines (54 loc) · 1.55 KB
/
audio_processor.h
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
// Copyright (C) 2010-2016 Lukas Lalinsky
// Distributed under the MIT license, see the LICENSE file for details.
#ifndef CHROMAPRINT_AUDIO_PROCESSOR_H_
#define CHROMAPRINT_AUDIO_PROCESSOR_H_
#include "utils.h"
#include "audio_consumer.h"
#include <vector>
struct AVResampleContext;
namespace chromaprint
{
class AudioProcessor : public AudioConsumer
{
public:
AudioProcessor(int sample_rate, AudioConsumer *consumer);
virtual ~AudioProcessor();
int target_sample_rate() const
{
return m_target_sample_rate;
}
void set_target_sample_rate(int sample_rate)
{
m_target_sample_rate = sample_rate;
}
AudioConsumer *consumer() const
{
return m_consumer;
}
void set_consumer(AudioConsumer *consumer)
{
m_consumer = consumer;
}
//! Prepare for a new audio stream
bool Reset(int sample_rate, int num_channels);
//! Process a chunk of data from the audio stream
void Consume(const int16_t *input, int length);
//! Process any buffered input that was not processed before and clear buffers
void Flush();
private:
CHROMAPRINT_DISABLE_COPY(AudioProcessor);
int Load(const int16_t *input, int length);
void LoadMono(const int16_t *input, int length);
void LoadStereo(const int16_t *input, int length);
void LoadMultiChannel(const int16_t *input, int length);
void Resample();
std::vector<int16_t> m_buffer;
size_t m_buffer_offset;
std::vector<int16_t> m_resample_buffer;
int m_target_sample_rate;
int m_num_channels;
AudioConsumer *m_consumer;
struct AVResampleContext *m_resample_ctx;
};
};
#endif