实时显示采集的波形,振幅,二维码,wifi,电量,内存等功能。
window版下载地址:

安装qt:
1.命令行输入:sudo apt-get install samba//安装samba

2.命令行输入:sudo apt-get install qt5-default //安装qt5

3.命令行输入:sudo apt-get install qtcreator //安装qtcreator

qmake
make 编译

#include "qaudiowave.h"
#include "qpainter.h"
#include <QDebug>
#define SCALE_HEIGHY 20
#define MIN(x,y) (x)<(y)?(x):(y)
#define MAX(x,y) (x)>(y)?(x):(y)

QAudioWave::QAudioWave(QWidget *parent) : QWidget(parent)
{
qRegisterMetaType<QVector<QPointF> >("QVector<QPointF> ");//注册数据类型
foreground = QColor(255, 184, 255);
background = QColor(40, 40, 40);
girdLineGround = QColor(255, 255, 255);
everyLineColor = QColor(139,105 ,20);
scaleLineColor = QColor(0, 0, 0);
girdLineWidth = 0.5;

recordPassageway = PASSAGEWAY_1;
everyLineColor = QColor(139,105 ,20);

QPalette palette(this->palette());
palette.setColor(QPalette::Background,"#ffffff");
this->setPalette(palette);


QList<QAudioDeviceInfo> devicelist = QAudioDeviceInfo::availableDevices(QAudio::Mode::AudioInput);
for(int i = 0; i < devicelist.size(); i++){
qDebug()<<"++++++++++++++++++++"<<devicelist.at(i).deviceName();
}

QAudioFormat formatAudio;
formatAudio.setSampleRate(8000);
formatAudio.setChannelCount(1);
formatAudio.setSampleSize(8);
formatAudio.setCodec("audio/pcm");
formatAudio.setByteOrder(QAudioFormat::LittleEndian);
formatAudio.setSampleType(QAudioFormat::UnSignedInt);
//打印可用设备
QList<QAudioDeviceInfo> list = QAudioDeviceInfo::availableDevices(QAudio::AudioInput);
qDebug()<<list.at(0).deviceName();

QAudioDeviceInfo inputDevices = QAudioDeviceInfo::defaultInputDevice();
m_audioInput = new QAudioInput(inputDevices,formatAudio, this);

m_device = new XYSeriesIODevice(this);
m_device->open(QIODevice::WriteOnly);
connect(m_device,SIGNAL(sendPaintPoints(QVector<QPointF> )),this,SLOT(acceptPaintPoints(QVector<QPointF>)));
connect(m_device,SIGNAL(sendAmplitudeData(QByteArray )),this,SIGNAL(sendAmplitudeData(QByteArray )));

m_audioInput->start(m_device);
}

QAudioWave::~QAudioWave()
{
}

void QAudioWave::paintEvent(QPaintEvent *)
{
//绘制准备工作,启用反锯齿
QPainter painter(this);
painter.setRenderHints(QPainter::Antialiasing);
//绘制背景
drawBg(&painter);
//绘制数据
drawData(&painter);
}

void QAudioWave::drawBg(QPainter *painter)
{
painter->fillRect(this->rect(), background);
}

void QAudioWave::drawData(QPainter *painter)
{
QPen pen;
pen.setColor(QColor(0x4B,0xF3,0xA7)); //波形图画笔
painter->setPen(pen); //设置画笔
painter->drawLines(paintPoints);
}

void QAudioWave::resizeEvent(QResizeEvent *event)
{
Q_UNUSED(event);
m_device->acceptResizeWidth(this->width());
m_device->acceptResizeHeight(this->height());
}

void QAudioWave::thisUpdate()
{
this->update();
}

void QAudioWave::acceptPaintPoints(QVector<QPointF> points)
{
paintPoints.clear();
paintPoints = points ;
this->thisUpdate ();
}

void QAudioWave::setDisplayWaveTime(int value)
{
m_device->setDisplayWaveTime(value);
}