int heighthalf = height / 2;
int channels = this->audioFile->sfinfo.channels;
int i, q = 0;
int frames = this->audioFile->sfinfo.frames;
int resolution = (to - from) / width;
painter.
setBrush(QBrush(QColor::fromRgb(230,
230,
230,
255), Qt
::SolidPattern));
painter.drawRect(-10, -10, width + 10, height + 10);
painter.
setPen(QColor::fromRgb(69,
102,
99,
255));
float pos = 0.0;
float neg = 0.0;
int left = 0;
for (i = 0; left < width && from + i < frames; i++) {
double t = this->audioFile->getFrame(from + i, 0);
if (t <= 1.0 && t >= -1.0) {
if (t > 0.0) {
if (t > pos)
pos = t;
} else {
if (t < neg)
neg = t;
}
}
if (q >= resolution) {
neg = -neg;
QPoint currentpos
= QPoint(left, heighthalf
- (pos
* heighthalf
));
QPoint currentneg
= QPoint(left, heighthalf
+ (neg
* heighthalf
));
painter.
drawLine(currentpos,
QPoint(left, heighthalf
));
// THESE TWO LINES ARE (WHAT I THINK) THE BOTTLENECK painter.
drawLine(currentneg,
QPoint(left, heighthalf
));
q = 0;
pos = 0;
neg = 0;
left++;
} else {
q++;
}
}
painter.
setPen(QPen(QColor::fromRgb(69,
102,
99,
60)));
painter.drawLine(0, heighthalf + heighthalf / 2, width, heighthalf + heighthalf / 2);
painter.drawLine(0, heighthalf / 2, width, heighthalf / 2);
painter.
setPen(QPen(QColor::fromRgb(56,
84,
90,
255)));
painter.drawLine(0, heighthalf, width, heighthalf);
int heighthalf = height / 2;
int channels = this->audioFile->sfinfo.channels;
int i, q = 0;
int frames = this->audioFile->sfinfo.frames;
int resolution = (to - from) / width;
QPainter painter(canvas);
painter.setBrush(QBrush(QColor::fromRgb(230, 230, 230, 255), Qt::SolidPattern));
painter.drawRect(-10, -10, width + 10, height + 10);
painter.setPen(QColor::fromRgb(69, 102, 99, 255));
float pos = 0.0;
float neg = 0.0;
int left = 0;
for (i = 0; left < width && from + i < frames; i++) {
double t = this->audioFile->getFrame(from + i, 0);
if (t <= 1.0 && t >= -1.0) {
if (t > 0.0) {
if (t > pos)
pos = t;
} else {
if (t < neg)
neg = t;
}
}
if (q >= resolution) {
neg = -neg;
QPoint currentpos = QPoint(left, heighthalf - (pos * heighthalf));
QPoint currentneg = QPoint(left, heighthalf + (neg * heighthalf));
painter.drawLine(currentpos, QPoint(left, heighthalf)); // THESE TWO LINES ARE (WHAT I THINK) THE BOTTLENECK
painter.drawLine(currentneg, QPoint(left, heighthalf));
q = 0;
pos = 0;
neg = 0;
left++;
} else {
q++;
}
}
painter.setPen(QPen(QColor::fromRgb(69, 102, 99, 60)));
painter.drawLine(0, heighthalf + heighthalf / 2, width, heighthalf + heighthalf / 2);
painter.drawLine(0, heighthalf / 2, width, heighthalf / 2);
painter.setPen(QPen(QColor::fromRgb(56, 84, 90, 255)));
painter.drawLine(0, heighthalf, width, heighthalf);
To copy to clipboard, switch view to plain text mode
Bookmarks