资源简介
个人原创。仅供参考学习。工具支持本地文件和接收网络pcm音频数据播放
代码片段和文件信息
#include “curveplot.h“
CurvePlot::CurvePlot(QWidget *parent) :
QWidget(parent)
{
Margin = QMargin(0);
Background = QColor(255 255 255 2);
Pen = QPen(QBrush(QColor(89 254 222)) 1);
PenSpect = QPen(QBrush(QColor(34 106 217)) 15);
iAdjustVal = 0;
}
void CurvePlot::outPut()
{
int w = width() - Margin.Left - Margin.Right;
int h = height() - Margin.Top - Margin.Bottom;
pixmap = QPixmap(w h);
pixmap.fill(Background);
// QPainter painter(&pixmap);
// painter.setPen(Pen);
// painter.drawLine(QPoint(Margin.Left height()/2) QPoint(Margin.Left + w height()/2));
update();
}
void CurvePlot::transformPointsSpect(QVector&data int w int h QVector &points)
{ // 获取极值
float max = data[0] min = data[0] sec = data[0];
for (int i= 1; i< data.size(); i++)
{
if (max < data[i]) {
sec = max;
max = data[i];
}
if (sec < data[i])
sec = data[i];
if (min > data[i])
min = data[i];
}
// 转化成当前屏幕的内的坐标大小
max = sec;
max += iAdjustVal;
min -= iAdjustVal;
float diffVal = max - min;
for (int i= 0; i< data.size(); i++) {
if (data[i] * 20 > diffVal)
points.append(QPointF(i * w / data.size() * 10 h - (data[i] - min) / diffVal * h));
else
points.append(QPointF(i * w / data.size() * 10 h - 1));
}
}
void CurvePlot::transformPoints(QVector&data int w int h QVector &points)
{ // 获取极值
float max = data[0] min = data[0];
for (int i= 1; i< data.size(); i++)
{
if (max < data[i])
max = data[i];
if (min > data[i])
min = data[i];
}
// 转化成当前屏幕的内的坐标大小
max += iAdjustVal;
min -= iAdjustVal;
float diffVal = max - min;
for (int i= 0; i< data.size(); i++)
points.append(QPointF(i * w / data.size() h - (data[i] - min) / diffVal * h));
}
void CurvePlot::outPut(QVector&data)
{
int w = width() - Margin.Left - Margin.Right;
int h = height() - Margin.Top - Margin.Bottom;
pixmap = QPixmap(w h);
pixmap.fill(Background);
QPainter painter(&pixmap);
QVector points;
transformPoints(data w h points);
painter.setPen(Pen);
int step = points.size()*2/w;
for (int i= 0; i< points.size()-1; i+=step)
painter.drawLine(points[i] points[i] + QPoint(0 h - points[i].y()*2));
update();
}
void CurvePlot::outPutSpect(QVector &data)
{
int w = width() - Margin.Left - Margin.Right;
int h = height() - Margin.Top - Margin.Bottom;
pixmap = QPixmap(w h);
pixmap.fill(Background);
QPainter painter(&pixmap);
QVector points;
transformPointsSpect(data w h points);
painter.setPen(PenSpect);
int cnt = points.size()/10;
for (int i= 0; i< cnt; i++)
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 549 2017-01-08 11:30 audioTool\audioTool.pro
文件 23704 2017-04-01 20:55 audioTool\audioTool.pro.user
文件 13385 2017-01-07 12:04 audioTool\audioTool.pro.user.3.2-pre1
文件 3603 2017-01-08 00:05 audioTool\curveplot.cpp
文件 1200 2016-04-04 09:42 audioTool\curveplot.h
文件 21662 2017-01-08 11:21 audioTool\icon\music.ico
文件 32 2017-01-08 11:31 audioTool\icon.rc
文件 24182 2010-05-02 02:07 audioTool\lib\libzplay.lib
文件 34716 2010-05-05 22:41 audioTool\libzplay.h
文件 183 2017-01-07 15:14 audioTool\main.cpp
文件 10943 2017-01-08 11:12 audioTool\mainwindow.cpp
文件 2199 2017-01-07 22:21 audioTool\mainwindow.h
文件 23420 2017-01-08 11:28 audioTool\mainwindow.ui
文件 98 2017-01-08 11:24 audioTool\res.qrc
目录 0 2017-01-08 11:24 audioTool\icon
目录 0 2017-01-07 19:17 audioTool\lib
目录 0 2017-04-01 20:55 audioTool
----------- --------- ---------- ----- ----
159876 17
- 上一篇:满屏玫瑰花
- 下一篇:《支付信息保护技术规范》
评论
共有 条评论