-
Notifications
You must be signed in to change notification settings - Fork 1
/
io_audio.h
74 lines (58 loc) · 1.83 KB
/
io_audio.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
72
73
74
#ifndef IO_AUDIO_H
#define IO_AUDIO_H
#include <QThread>
#include <QtMultimedia/QtMultimedia>
#include <QAudioInput>
#include <QAudioOutput>
#include <QCoreApplication>
#include <mutex>
#include <memory>
#include <atomic>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "audio_processing/audio_buffer.h"
#include "audio_processing/high_pass_filter.h"
#include "api/echo_control.h"
#include "buffer.h"
class IoAudio {
public:
explicit IoAudio();
~IoAudio();
enum class AudioMode { Audio16Khz, Audio8Khz };
enum class StatusType { Stop, Run, Destroy };
void startAudio();
bool isStarted() { return m_status == StatusType::Run; }
private:
bool initAudio(AudioMode mode = AudioMode::Audio16Khz);
bool initFormat();
bool initAec(int sampleRate);
void aecPutFarEndFrame(std::vector<uint8_t> &in, int samplesCount);
void aecProcess(std::vector<uint8_t> &in,
std::vector<uint8_t> &out, int samplesCount);
void destroyAec();
QAudioSource* m_audioSource;
QAudioSink* m_audioSink;
QIODevice* m_audioInDevice;
QIODevice* m_audioOutDevice;
QAudioDevice audio_info_in;
QAudioDevice audio_info_out;
AudioMode m_mode;
QThread* m_api_thread;
QThread* m_qobject_thread;
QCoreApplication* m_app;
Buffer _audioOutBuf;
Buffer _micBuf;
Buffer _sendToNetBuf;
Buffer _echoBuff;
std::mutex _aecLock;
std::shared_ptr<webrtc::AudioBuffer> aec_audio;
std::shared_ptr<webrtc::AudioBuffer> ref_audio;
std::shared_ptr<webrtc::HighPassFilter> hp_filter;
std::shared_ptr<webrtc::EchoControl> echo_controler;
webrtc::AudioFrame ref_frame, aec_frame;
std::atomic<StatusType> m_status;
static constexpr int MIN_SAMPLE_SIZE = 160 * 2;
static constexpr const char* const TAG = "IoAudio";
};
#endif // IO_AUDIO_H