-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcodec.cpp
155 lines (142 loc) · 3.57 KB
/
codec.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
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
/*
Copyright (C) 2019-2021 Doug McLain
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "codec.h"
#ifdef USE_FLITE
extern "C" {
extern cst_voice * register_cmu_us_slt(const char *);
extern cst_voice * register_cmu_us_kal16(const char *);
extern cst_voice * register_cmu_us_awb(const char *);
}
#endif
Codec::Codec(QString callsign, char module, QString hostname, QString host, int port, bool ipv6, QString vocoder, QString modem, QString audioin, QString audioout) :
m_module(module),
m_hostname(hostname),
m_tx(false),
m_ttsid(0),
m_audioin(audioin),
m_audioout(audioout),
m_rxwatchdog(0),
#ifdef Q_OS_WIN
m_rxtimerint(19),
#else
m_rxtimerint(20),
#endif
m_txtimerint(19),
m_vocoder(vocoder),
m_modemport(modem),
m_modem(nullptr),
m_ambedev(nullptr),
m_hwrx(false),
m_hwtx(false),
m_ipv6(ipv6)
{
m_modeinfo.callsign = callsign;
m_modeinfo.gwid = 0;
m_modeinfo.srcid = 0;
m_modeinfo.dstid = 0;
m_modeinfo.host = host;
m_modeinfo.port = port;
m_modeinfo.count = 0;
m_modeinfo.frame_number = 0;
m_modeinfo.frame_total = 0;
m_modeinfo.streamid = 0;
m_modeinfo.stream_state = STREAM_IDLE;
#ifdef USE_FLITE
flite_init();
voice_slt = register_cmu_us_slt(nullptr);
voice_kal = register_cmu_us_kal16(nullptr);
voice_awb = register_cmu_us_awb(nullptr);
#endif
}
Codec::~Codec()
{
}
void Codec::in_audio_vol_changed(qreal v)
{
m_audio->set_input_volume(v);
}
void Codec::out_audio_vol_changed(qreal v)
{
m_audio->set_output_volume(v);
}
void Codec::send_connect()
{
m_modeinfo.status = CONNECTING;
if(m_ipv6 && (m_modeinfo.host != "none")){
qDebug() << "Host == " << m_modeinfo.host;
QList<QHostAddress> h;
QHostInfo i;
h.append(QHostAddress(m_modeinfo.host));
i.setAddresses(h);
hostname_lookup(i);
}
else{
QHostInfo::lookupHost(m_modeinfo.host, this, SLOT(hostname_lookup(QHostInfo)));
}
}
void Codec::start_tx()
{
//std::cerr << "Pressed TX buffersize == " << audioin->bufferSize() << std::endl;
qDebug() << "start_tx() " << m_ttsid << " " << m_ttstext;
if(m_hwtx){
m_ambedev->clear_queue();
}
m_txcodecq.clear();
m_tx = true;
m_txcnt = 0;
m_ttscnt = 0;
m_rxtimer->stop();
m_modeinfo.streamid = 0;
m_modeinfo.stream_state = TRANSMITTING;
#ifdef USE_FLITE
if(m_ttsid == 1){
tts_audio = flite_text_to_wave(m_ttstext.toStdString().c_str(), voice_kal);
}
else if(m_ttsid == 2){
tts_audio = flite_text_to_wave(m_ttstext.toStdString().c_str(), voice_awb);
}
else if(m_ttsid == 3){
tts_audio = flite_text_to_wave(m_ttstext.toStdString().c_str(), voice_slt);
}
#endif
if(!m_txtimer->isActive()){
if(m_ttsid == 0){
m_audio->set_input_buffer_size(640);
m_audio->start_capture();
//audioin->start(&audio_buffer);
}
m_txtimer->start(m_txtimerint);
}
}
void Codec::stop_tx()
{
m_tx = false;
}
void Codec::deleteLater()
{
if(m_modeinfo.status == CONNECTED_RW){
m_udp->disconnect();
m_ping_timer->stop();
send_disconnect();
delete m_audio;
if(m_hwtx){
delete m_ambedev;
}
if(m_modem){
delete m_modem;
}
}
m_modeinfo.count = 0;
QObject::deleteLater();
}