Commit e3d490c6 authored by Thomas Eschenbacher's avatar Thomas Eschenbacher
Browse files

fixed deprecation warnings about 'qrand() and qsrand()', use QRandomGenerator instead

parent 3ee20ef0
......@@ -58,6 +58,7 @@
#include <QBuffer>
#include <QByteArray>
#include <QList>
#include <QRandomGenerator>
#include <QString>
#include <QTime>
#include <QtGlobal>
......@@ -606,12 +607,11 @@ bool Kwave::OpusEncoder::open(QWidget *widget, const Kwave::FileInfo &info,
/* Extra samples that need to be read to compensate for the pre-skip */
m_extra_out = lookahead;
// set up our packet->stream encoder
// pick a random serial number; that way we can more likely build
// chained streams just by concatenation
qsrand(QTime::currentTime().msec() ^ qrand());
ogg_stream_init(&m_os, qrand());
QRandomGenerator rnd(QTime::currentTime().msec());
ogg_stream_init(&m_os, rnd.generate());
return true;
}
......
......@@ -20,6 +20,7 @@
#include <math.h>
#include <string.h>
#include <QRandomGenerator>
#include <QTime>
#include <QtGlobal>
......@@ -190,8 +191,8 @@ bool Kwave::VorbisEncoder::open(QWidget *widget, const Kwave::FileInfo &info,
// set up our packet->stream encoder
// pick a random serial number; that way we can more likely build
// chained streams just by concatenation
qsrand(QTime::currentTime().msec() ^ qrand());
ogg_stream_init(&m_os, qrand());
QRandomGenerator rnd(QTime::currentTime().msec());
ogg_stream_init(&m_os, rnd.generate());
return true;
}
......
......@@ -24,7 +24,10 @@
//***************************************************************************
Kwave::NoiseGenerator::NoiseGenerator(QObject *parent)
:Kwave::SampleSource(parent), m_buffer(blockSize()), m_noise_level(1.0)
:Kwave::SampleSource(parent),
m_random(),
m_buffer(blockSize()),
m_noise_level(1.0)
{
}
......@@ -48,13 +51,15 @@ void Kwave::NoiseGenerator::input(Kwave::SampleArray data)
m_buffer = data;
const quint32 max = m_random.max();
const quint32 m_2 = max / 2;
const double alpha = (1.0 - m_noise_level);
const double scale = (m_noise_level * 2.0) / static_cast<double>(RAND_MAX);
const double scale = (m_noise_level * 2.0) / static_cast<double>(max);
for (unsigned i = 0; i < data.size(); ++i) {
const Kwave::SampleArray &in = data;
m_buffer[i] = double2sample(
(sample2double(in[i]) * alpha) +
((qrand() - (RAND_MAX / 2)) * scale)
(qint32(m_random.generate() - m_2) * scale)
);
}
}
......
......@@ -21,6 +21,7 @@
#include "config.h"
#include <QObject>
#include <QRandomGenerator>
#include <QVariant>
#include "libkwave/SampleArray.h"
......@@ -62,6 +63,9 @@ namespace Kwave
private:
/** random generator for the noise */
QRandomGenerator m_random;
/** buffer for input */
Kwave::SampleArray m_buffer;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment