1 Star 0 Fork 15

seanpan2016/Encoder

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Intercom.cpp 2.79 KB
一键复制 编辑 原始数据 按行查看 历史
zc 提交于 2022-07-01 11:25 . 修正VAD与gain关系
#include "Intercom.h"
#include <QFile>
#include "Json.h"
Intercom::Intercom(QObject *parent) : QObject(parent),timer(this)
{
connect(&timer,SIGNAL(timeout()),this,SLOT(onTimer()));
}
void Intercom::init()
{
if(!QFile::exists("/link/config/intercom.json"))
return;
QVariantMap data;
ai=Link::create("InputAlsa");
data["path"] = "-1";
data["id"]="0d8c:0014|12d1:0010";
ai->start(data);
ao=Link::create("OutputAlsa");
ao->start(data);
res1=Link::create("Resample");
data.clear();
data["num"]=200;
data["channels"]=1;
data["samplerate"]=8000;
res1->start(data);
res2=Link::create("Resample");
res2->start();
intercom=Link::create("Intercom");
gain=Link::create("Gain");
gain->start();
ai->linkA(res1)->linkA(gain)->linkA(intercom)->linkA(res2)->linkA(ao);
server=Link::create("IntercomServer");
vmix=Link::create("VMix");
tally=Link::create("Tally");
vmix->linkE(intercom);
connect(intercom,SIGNAL(newEvent(QString,QVariant)),this,SLOT(onNewEvent(QString,QVariant)));
update(Json::loadFile("/link/config/intercom.json").toMap());
}
bool Intercom::update(QVariantMap cfg)
{
QVariantMap cfgIntercom=cfg["intercom"].toMap();
if(cfgIntercom["vad"].toInt()>0)
{
cfgIntercom["vad"]=cfgIntercom["vad"].toInt()+cfgIntercom["gain"].toInt();
}
if(cfgIntercom["enable"].toBool())
intercom->start(cfgIntercom);
else
intercom->stop();
QVariantMap cfgGain;
cfgGain["gain"]=cfgIntercom["gain"].toInt();
gain->start(cfgGain);
QVariantMap cfgServer=cfg["server"].toMap();
if(cfgServer["enable"].toBool())
server->start();
else
server->stop();
QVariantMap cfgVMix=cfg["vmix"].toMap();
if(cfgVMix["enable"].toBool())
vmix->start(cfgVMix);
else
vmix->stop();
QVariantMap cfgTally=cfg["tally"].toMap();
if(cfgTally["enable"].toBool())
{
timer.start(1000);
tally->start(cfgTally);
}
else
{
timer.stop();
tally->stop();
}
Json::saveFile(cfg,"/link/config/intercom.json");
return true;
}
bool Intercom::setTally(QVariantList list)
{
tally->invoke("setTally",list);
tallyInfo=list;
return true;
}
QVariantMap Intercom::getState()
{
QVariantMap state;
QVariantMap map=intercom->invoke("getState").toMap();
state["intercom"]=map["list"].toList();
state["talking"]=map["talking"].toBool();
state["tally"]=tallyInfo;
return state;
}
void Intercom::onTimer()
{
if(tallyInfo.isValid())
{
tally->invoke("setTally",tallyInfo);
}
}
void Intercom::onNewEvent(QString type, QVariant info)
{
if(type=="TALLY")
{
tallyInfo=info;
// qDebug()<<info;
tally->invoke("setTally",info);
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C/C++
1
https://gitee.com/seanpan2016/Encoder.git
git@gitee.com:seanpan2016/Encoder.git
seanpan2016
Encoder
Encoder
master

搜索帮助