Update to experimental state in master :D #2
@@ -113,19 +113,9 @@ void OsciWidget::darkenFrame()
|
|||||||
//m_pixmap.fill(Qt::black);
|
//m_pixmap.fill(Qt::black);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OsciWidget::updateDrawBuffer()
|
|
||||||
|
void OsciWidget::drawBuffer(SampleBuffer::iterator &bufferPos, const SampleBuffer::iterator &end)
|
||||||
{
|
{
|
||||||
// If there is no new data do not update
|
|
||||||
if(m_buffer.empty()) return;
|
|
||||||
|
|
||||||
if (m_pixmap.size() != size())
|
|
||||||
{
|
|
||||||
m_pixmap = QPixmap(size());
|
|
||||||
m_pixmap.fill(Qt::black);
|
|
||||||
}
|
|
||||||
|
|
||||||
darkenFrame();
|
|
||||||
|
|
||||||
QPainter painter(&m_pixmap);
|
QPainter painter(&m_pixmap);
|
||||||
painter.translate(m_pixmap.width()/2, m_pixmap.height()/2);
|
painter.translate(m_pixmap.width()/2, m_pixmap.height()/2);
|
||||||
painter.scale(m_factor * m_pixmap.width() / 2.0, m_factor * m_pixmap.height() / 2.0);
|
painter.scale(m_factor * m_pixmap.width() / 2.0, m_factor * m_pixmap.height() / 2.0);
|
||||||
@@ -136,18 +126,9 @@ void OsciWidget::updateDrawBuffer()
|
|||||||
pen.setColor(QColor(0, 255, 0));
|
pen.setColor(QColor(0, 255, 0));
|
||||||
painter.setPen(pen);
|
painter.setPen(pen);
|
||||||
|
|
||||||
|
for (;bufferPos < end; ++bufferPos)
|
||||||
// persistance time is the time it needs to decay to 1/e ~ 36,7%
|
|
||||||
|
|
||||||
auto duration = 1000*(m_bufferTimer.elapsed()-m_lastTime);
|
|
||||||
auto framesOffset = framesForDuration(duration);
|
|
||||||
//qDebug() << framesOffset << m_buffer.size()-framesOffset << m_bufferOffset - m_buffer.begin();
|
|
||||||
|
|
||||||
//m_bufferBegin = m_buffer.begin();
|
|
||||||
auto bufferEnd = m_buffer.begin() + framesOffset;
|
|
||||||
for (;m_bufferOffset < bufferEnd && m_bufferOffset != m_buffer.end(); ++m_bufferOffset)
|
|
||||||
{
|
{
|
||||||
const auto &frame = *m_bufferOffset;
|
const auto &frame = *bufferPos;
|
||||||
|
|
||||||
const QPointF p{
|
const QPointF p{
|
||||||
float(frame.first) / std::numeric_limits<qint16>::max(),
|
float(frame.first) / std::numeric_limits<qint16>::max(),
|
||||||
@@ -156,23 +137,45 @@ void OsciWidget::updateDrawBuffer()
|
|||||||
|
|
||||||
const QLineF line(m_lastPoint, p);
|
const QLineF line(m_lastPoint, p);
|
||||||
|
|
||||||
// the time of one sample is 1/samplerate
|
|
||||||
// the brightness
|
|
||||||
auto beamOpacity = std::min(1.0, 1. / ((line.length() * m_lightspeed) + 1));
|
auto beamOpacity = std::min(1.0, 1. / ((line.length() * m_lightspeed) + 1));
|
||||||
|
|
||||||
|
|
||||||
double time = 1000.0 * std::distance(m_bufferOffset, bufferEnd) / 44100.0;
|
double time = 1000.0 * std::distance(bufferPos, end) / 44100.0;
|
||||||
auto beamDecay = exp(-time/m_decayTime);
|
auto beamDecay = exp(-time/m_decayTime);
|
||||||
//qDebug() << time << beamDecay;
|
|
||||||
|
|
||||||
painter.setOpacity(beamDecay*beamOpacity);
|
painter.setOpacity(beamDecay*beamOpacity);
|
||||||
|
|
||||||
painter.drawLine(m_lastPoint, p);
|
painter.drawLine(m_lastPoint, p);
|
||||||
|
|
||||||
m_lastPoint = p;
|
m_lastPoint = p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OsciWidget::resizeDrawBuffer()
|
||||||
|
{
|
||||||
|
if (m_pixmap.size() != size())
|
||||||
|
{
|
||||||
|
m_pixmap = QPixmap(size());
|
||||||
|
m_pixmap.fill(Qt::black);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void OsciWidget::updateDrawBuffer()
|
||||||
|
{
|
||||||
|
// If there is no new data do not update
|
||||||
|
if(m_buffer.empty()) return;
|
||||||
|
|
||||||
|
resizeDrawBuffer();
|
||||||
|
darkenFrame();
|
||||||
|
// persistance time is the time it needs to decay to 1/e ~ 36,7%
|
||||||
|
|
||||||
|
auto duration = 1000*(m_bufferTimer.elapsed()-m_lastTime);
|
||||||
|
size_t framesOffset = framesForDuration(duration);
|
||||||
|
//qDebug() << framesOffset << m_buffer.size()-framesOffset << m_bufferOffset - m_buffer.begin();
|
||||||
|
|
||||||
|
auto bufferEnd = m_buffer.begin() + std::min(framesOffset, m_buffer.size());
|
||||||
|
drawBuffer(m_bufferOffset, bufferEnd);
|
||||||
|
}
|
||||||
|
|
||||||
void OsciWidget::timerEvent(QTimerEvent *event)
|
void OsciWidget::timerEvent(QTimerEvent *event)
|
||||||
{
|
{
|
||||||
QWidget::timerEvent(event);
|
QWidget::timerEvent(event);
|
||||||
|
@@ -48,8 +48,9 @@ private:
|
|||||||
float m_decayTime{25.0};
|
float m_decayTime{25.0};
|
||||||
float m_lightspeed{35.f};
|
float m_lightspeed{35.f};
|
||||||
|
|
||||||
std::vector<SamplePair> m_buffer;
|
typedef std::vector<SamplePair> SampleBuffer;
|
||||||
std::vector<SamplePair>::iterator m_bufferOffset;
|
SampleBuffer m_buffer;
|
||||||
|
SampleBuffer::iterator m_bufferOffset;
|
||||||
|
|
||||||
int m_frameCounter{0}, m_callbacksCounter{0}, m_samplesCounter{0};
|
int m_frameCounter{0}, m_callbacksCounter{0}, m_samplesCounter{0};
|
||||||
QElapsedTimer m_statsTimer;
|
QElapsedTimer m_statsTimer;
|
||||||
@@ -60,4 +61,6 @@ private:
|
|||||||
QPointF m_lastPoint;
|
QPointF m_lastPoint;
|
||||||
QPixmap m_pixmap;
|
QPixmap m_pixmap;
|
||||||
void darkenFrame();
|
void darkenFrame();
|
||||||
|
void drawBuffer(SampleBuffer::iterator &bufferPos, const SampleBuffer::iterator &end);
|
||||||
|
void resizeDrawBuffer();
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user