Commit 73ee6324 authored by Thomas Eschenbacher's avatar Thomas Eschenbacher
Browse files

(fixed some compiler warnings from clan-10 about some int <-> double conversions)

parent 81df44b1
......@@ -125,7 +125,8 @@ Kwave::TopWidget::TopWidget(Kwave::App &app)
if (!status_bar) return;
QLabel *spacer = new(std::nothrow) QLabel(this);
const int frame_style = QFrame::StyledPanel | QFrame::Sunken;
const int frame_style = static_cast<int>(QFrame::StyledPanel) |
static_cast<int>(QFrame::Sunken);
status_bar->addWidget(spacer);
spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
spacer->setFrameStyle(frame_style);
......
......@@ -246,7 +246,7 @@ void Kwave::ZoomToolBar::setZoomInfo(Kwave::FileContext *context, double zoom)
double rate = (signal_manager) ? signal_manager->rate() : 0.0;
double ms = ((rate > 0) && (zoomable)) ?
(((zoomable->visibleSamples()) * 1E3) / rate) : 0.0;
((static_cast<double>(zoomable->visibleSamples()) * 1E3) / rate) : 0.0;
QString strZoom;
if ((signal_manager) && (signal_manager->tracks())) {
......
......@@ -363,7 +363,8 @@ void Kwave::OverViewWidget::calculateBitmap()
const double scale = static_cast<double>(width) /
static_cast<double>(length);
const int bitmap_width = Kwave::toInt(m_signal_length * scale);
const int bitmap_width = Kwave::toInt(
static_cast<double>(m_signal_length) * scale);
// let the bitmap be updated from the cache
QImage bitmap = m_cache.getOverView(bitmap_width, height,
......
......@@ -71,7 +71,8 @@ void Kwave::SelectTimeWidget::init(Mode mode, quint64 range,
// set range of time controls
{
quint64 t = static_cast<quint64>((m_length * 1E3) / m_rate);
quint64 t = static_cast<quint64>(
(static_cast<double>(m_length) * 1E3) / m_rate);
sbMilliseconds->setMaximum(Kwave::toInt(qMax(t, quint64(999))));
t /= 1000;
sbSeconds->setMaximum(Kwave::toInt(qMax(t, quint64(59))));
......@@ -295,7 +296,7 @@ void Kwave::SelectTimeWidget::timeChanged(int)
// limit time
quint64 max_ms = static_cast<quint64>(
ceil(((m_length - m_offset) * 1E3) / m_rate));
ceil((static_cast<double>(m_length - m_offset) * 1E3) / m_rate));
if (ms > max_ms) ms = max_ms;
quint64 t = ms;
......@@ -482,7 +483,8 @@ sample_index_t Kwave::SelectTimeWidget::timeToSamples(
case Kwave::SelectTimeWidget::byPercents:
// by percentage of whole signal
pos = static_cast<unsigned int>(rint(
static_cast<double>(length * (time / 100.0))));
static_cast<double>(length) *
(static_cast<double>(time) / 100.0)));
break;
}
......
......@@ -149,7 +149,8 @@ void Kwave::SignalView::showCursor(sample_index_t pos)
//***************************************************************************
int Kwave::SignalView::samples2pixels(sample_index_t samples) const
{
return Kwave::toInt((m_zoom > 0.0) ? (samples / m_zoom) : 0);
return Kwave::toInt((m_zoom > 0.0) ?
(static_cast<double>(samples) / m_zoom) : 0);
}
//***************************************************************************
......@@ -179,10 +180,11 @@ Kwave::SignalView::SelectionPos Kwave::SignalView::selectionPosition(int x)
Q_ASSERT(m_signal_manager);
if (!m_signal_manager) return None;
const double p = (m_zoom * x) + m_offset;
const Kwave::Selection &sel = m_signal_manager->selection();
const double p = (m_zoom * x) + static_cast<double>(m_offset);
const double tol = m_zoom * selectionTolerance();
const double first = m_signal_manager->selection().first();
const double last = m_signal_manager->selection().last();
const double first = static_cast<double>(sel.first());
const double last = static_cast<double>(sel.last());
Q_ASSERT(first <= last);
// get distance to left/right selection border
......@@ -695,7 +697,8 @@ Kwave::SignalView::PositionWidget::PositionWidget(QWidget *parent)
Q_ASSERT(m_label);
if (!m_label) return;
m_label->setFrameStyle(QFrame::Panel | QFrame::Plain);
m_label->setFrameStyle(static_cast<int>(QFrame::Panel) |
static_cast<int>(QFrame::Plain));
m_label->setPalette(QToolTip::palette()); // use same colors as a QToolTip
m_label->setFocusPolicy(Qt::NoFocus);
m_label->setMouseTracking(true);
......
......@@ -597,7 +597,7 @@ void Kwave::TrackPixmap::drawInterpolatedSignal(QPainter &p, int width,
sig = sig_buffer + (N / 2);
while (x <= width + N / 2) {
if ((x >= -N / 2) && (sample > 0) && (sample < buflen)) {
sig[x] = static_cast<float>(sample_buffer[sample] * scale_y);
sig[x] = static_cast<float>(sample_buffer[sample]) * scale_y;
}
sample++;
x = Q_LIKELY(sample >= 0) ?
......@@ -675,20 +675,20 @@ void Kwave::TrackPixmap::drawPolyLineSignal(QPainter &p, int width,
if (samples2pixels(sample - 1) <= width) {
int x1;
int x2;
float y1;
float y2;
double y1;
double y2;
x1 = samples2pixels(sample - 1);
x2 = samples2pixels(sample);
y1 = ((sample) && (sample <= buflen)) ?
Kwave::toInt(scale_y * sample_buffer[sample - 1]) : 0.0;
y2 = (sample < buflen) ?
Kwave::toInt(scale_y * sample_buffer[sample ]) : 0.0;
y1 = ((sample) && (sample <= buflen)) ? (scale_y *
static_cast<double>(sample_buffer[sample - 1])) : 0.0;
y2 = (sample < buflen) ? (scale_y *
static_cast<double>(sample_buffer[sample ])) : 0.0;
x = width - 1;
y = Kwave::toInt(static_cast<float>(x - x1) *
static_cast<float>(y2 - y1) / static_cast<float>(x2 - x1));
y = Kwave::toInt(static_cast<double>(x - x1) * (y2 - y1) /
static_cast<double>(x2 - x1));
points.append(QPoint(x, middle - y));
}
......@@ -813,7 +813,8 @@ void Kwave::TrackPixmap::convertOverlap(sample_index_t &offset,
length = 0; // out of view
return;
} else {
length = static_cast<sample_index_t>(ceil(length / m_zoom));
length = static_cast<sample_index_t>(
ceil(static_cast<double>(length) / m_zoom));
}
} else {
if (offset >= m_offset + buflen) {
......@@ -826,10 +827,11 @@ void Kwave::TrackPixmap::convertOverlap(sample_index_t &offset,
offset = (offset > m_offset) ? offset - m_offset : 0;
if (m_minmax_mode) {
// attention: round down in this mode!
sample_index_t ofs = static_cast<sample_index_t>(floor(offset / m_zoom));
double ofs_d = static_cast<double>(offset);
sample_index_t ofs = static_cast<sample_index_t>(floor(ofs_d / m_zoom));
// if offset was rounded down, increment length
if (ofs != static_cast<sample_index_t>(ceil(offset / m_zoom)))
if (ofs != static_cast<sample_index_t>(ceil(ofs_d / m_zoom)))
length++;
offset = ofs;
}
......
......@@ -180,7 +180,8 @@ QSharedPointer<Kwave::ViewItem> Kwave::TrackView::findItem(const QPoint &pos)
Q_ASSERT(m_signal_manager);
if (!m_signal_manager) return item;
const double offset = m_offset + pixels2samples(pos.x()); // [samples]
const double offset = static_cast<double>(m_offset) +
static_cast<double>(pixels2samples(pos.x()));
const double tolerance = m_zoom * selectionTolerance(); // [samples]
const double fine_pos = static_cast<double>(m_offset) +
(static_cast<double>(pos.x()) * m_zoom);
......
......@@ -287,8 +287,8 @@ void Kwave::FileProgress::updateStatistics(double rate, double rest,
"%1=number of loaded/saved megabytes, "
"%2=number of total megabytes to load or save",
"%1 MB of %2 MB done",
num1.setNum(static_cast<double>(pos / (1024.0 * 1024.0)), 'f', 1),
num2.setNum(static_cast<double>(m_size / (1024.0 * 1024.0)), 'f', 1)
num1.setNum(static_cast<double>(pos) / (1024.0 * 1024.0), 'f', 1),
num2.setNum(static_cast<double>(m_size) / (1024.0 * 1024.0), 'f', 1)
);
m_stat_bytes->setText(text);
......@@ -341,8 +341,8 @@ void Kwave::FileProgress::setBytePosition(quint64 pos)
}
// update the transfer statistics
double seconds = m_time.elapsed() / 1000.0; // [sec]
double rate = pos / seconds; // [bytes/sec]
double seconds = static_cast<double>(m_time.elapsed()) / 1000.0; // [sec]
double rate = static_cast<double>(pos) / seconds; // [bytes/sec]
double rest = 0;
if (rate > 10) {
rest = static_cast<double>(m_size - pos) / rate; // [seconds]
......
......@@ -369,9 +369,11 @@ void Kwave::MetaDataList::scalePositions(double scale)
meta[Kwave::MetaData::STDPROP_POS].toULongLong(&ok));
if (!ok) continue;
if ((pos * scale) <= SAMPLE_INDEX_MAX) {
sample_index_t scaled_pos = static_cast<sample_index_t>(
static_cast<double>(pos) * scale);
if (scaled_pos <= SAMPLE_INDEX_MAX) {
// scale position
meta[Kwave::MetaData::STDPROP_POS] = (pos * scale);
meta[Kwave::MetaData::STDPROP_POS] = scaled_pos;
} else {
// do not produce a coordinate overflow
// -> moving outside range means deleting!
......
......@@ -263,7 +263,8 @@ sample_index_t Kwave::MimeData::decode(QWidget *widget, const QMimeData *e,
// if the sample rate has to be converted, adjust the length
// right border
if (!qFuzzyCompare(src_rate, dst_rate) && (dst_rate > 1) && sig.tracks())
decoded_length = qRound(decoded_length * (dst_rate / src_rate));
decoded_length = qRound(static_cast<double>(decoded_length) *
(dst_rate / src_rate));
sample_index_t left = pos;
sample_index_t right = left + decoded_length - 1;
......
......@@ -90,8 +90,8 @@ void Kwave::MultiTrackReader::proceeded()
for (track = 0; track < n_tracks; ++track) {
Kwave::SampleReader *r = at(track);
if (r) {
sum += (r->pos() - r->first());
total += (r->last() - r->first() + 1);
sum += static_cast<qreal>(r->pos() - r->first());
total += static_cast<qreal>(r->last() - r->first() + 1);
}
}
......
......@@ -57,8 +57,8 @@ void Kwave::MultiWriter::proceeded()
for (track = 0; track < tracks; ++track) {
const Kwave::Writer *w = at(track);
if (w) {
sum += w->position() - w->first();
total += w->last() - w->first();
sum += static_cast<qreal>(w->position() - w->first());
total += static_cast<qreal>(w->last() - w->first());
}
}
emit progress(qreal(100.0) * sum / total);
......
......@@ -470,7 +470,7 @@ int Kwave::OpusDecoder::open(QWidget *widget, Kwave::FileInfo &info)
qint64 file_size = m_source->size();
qreal bitrate = 196000; // just guessed
qreal rate = rate_orig;
qreal seconds = file_size / (bitrate / 8);
qreal seconds = static_cast<qreal>(file_size) / (bitrate / 8);
sample_index_t samples = static_cast<sample_index_t>(seconds * rate);
qDebug(" OpusDecoder: estimated length: %llu samples", samples);
......@@ -688,8 +688,8 @@ void Kwave::OpusDecoder::close(Kwave::FileInfo &info)
// n_seconds = n_samples / sample_rate
// => bitrate = (n_bytes * 8) / (n_samples / sample_rate)
const double sr = Kwave::opus_next_sample_rate(m_opus_header.sample_rate);
int bitrate = Kwave::toInt(
((m_bytes_count * 8) * sr) / m_samples_written);
int bitrate = Kwave::toInt((static_cast<double>(m_bytes_count * 8) * sr) /
static_cast<double>(m_samples_written));
qDebug(" OpusDecoder: average bitrate: %d bits/sec", bitrate);
info.set(INF_BITRATE_NOMINAL, QVariant(bitrate));
......
......@@ -940,7 +940,8 @@ bool Kwave::OpusEncoder::encode(Kwave::MultiTrackReader &src,
sample_index_t length = m_info.length();
double rate = m_info.rate();
m_op.granulepos = static_cast<ogg_int64_t>(
ceil((length * 48000.0) / rate) + m_opus_header.preskip);
ceil((static_cast<double>(length) * 48000.0) / rate) +
m_opus_header.preskip);
}
ogg_stream_packetin(&m_os, &m_op);
last_segments += size_segments;
......
......@@ -149,7 +149,7 @@ int Kwave::VorbisDecoder::open(QWidget *widget, Kwave::FileInfo &info)
// get the standard properties
info.setTracks(m_vi.channels);
info.setRate(m_vi.rate);
info.setRate(static_cast<double>(m_vi.rate));
info.set(Kwave::INF_COMPRESSION, Kwave::Compression::OGG_VORBIS);
info.set(Kwave::INF_SOURCE, _(m_vc.vendor));
if ((m_vi.bitrate_nominal > 0) &&
......@@ -216,9 +216,9 @@ int Kwave::VorbisDecoder::open(QWidget *widget, Kwave::FileInfo &info)
if ((br < 0) && (m_vi.bitrate_upper > 0)) br = m_vi.bitrate_upper;
if ((br < 0) && (m_vi.bitrate_lower > 0)) br = m_vi.bitrate_lower;
qint64 file_size = m_source->size();
qreal rate = m_vi.rate;
qreal seconds = (br > 0) ? (file_size / (br / 8)) :
DEFAULT_BITRATE;
qreal rate = static_cast<qreal>(m_vi.rate);
qreal seconds = (br > 0) ?
static_cast<qreal>(file_size / (br / 8)) : DEFAULT_BITRATE;
sample_index_t samples = static_cast<sample_index_t>(seconds * rate);
qDebug(" estimated length: %llu samples", samples);
......
......@@ -156,7 +156,7 @@ void Kwave::RIFFParser::detectEndianness()
names += m_sub_chunk_names;
// average length should be approx. half of file size
double half = (m_dev.size() >> 1);
double half = static_cast<double>(m_dev.size() >> 1);
// loop over all chunk names
int count = names.count();
......
......@@ -360,7 +360,7 @@ void Kwave::DebugPlugin::run(QStringList params)
const double f_max = rate / 2.0;
const double f_min = 1;
for (unsigned int i = 0; i < m_buffer.size(); ++i, ++pos) {
double t = static_cast<double>((pos - left) / rate);
double t = static_cast<double>(pos - left) / rate;
double f = f_min + (((f_max - f_min) *
static_cast<double>(pos - left)) /
static_cast<double>(length));
......
......@@ -256,9 +256,10 @@ void Kwave::NewSignalDialog::timeChanged(int)
// update the other controls
edSamples->setValue(Kwave::toInt(samples));
slideLength->setValue(Kwave::toInt(100.0 * samples / max_samples));
slideLength->setValue(Kwave::toInt(100.0 *
static_cast<double>(samples) / static_cast<double>(max_samples)));
updateFileSize();
buttonBox->button(QDialogButtonBox::Ok)->setEnabled(samples > 0.0);
buttonBox->button(QDialogButtonBox::Ok)->setEnabled(samples > 0);
m_recursive = false;
}
......@@ -280,9 +281,10 @@ void Kwave::NewSignalDialog::samplesChanged(int)
// update the other controls
setHMS(samples);
slideLength->setValue(Kwave::toInt(100.0 * samples / max_samples));
slideLength->setValue(Kwave::toInt(100.0 *
static_cast<double>(samples) / static_cast<double>(max_samples)));
updateFileSize();
buttonBox->button(QDialogButtonBox::Ok)->setEnabled(samples > 0.0);
buttonBox->button(QDialogButtonBox::Ok)->setEnabled(samples > 0);
m_recursive = false;
}
......@@ -334,7 +336,8 @@ void Kwave::NewSignalDialog::setLengthPercentage(int percent)
if (rate() <= 0) return;
m_recursive = true;
sample_index_t samples = static_cast<sample_index_t>(maxSamples() *
sample_index_t samples = static_cast<sample_index_t>(
static_cast<double>(maxSamples()) *
static_cast<double>(percent) / 100.0);
// update the other controls
......@@ -355,7 +358,7 @@ void Kwave::NewSignalDialog::setHMS(sample_index_t &samples)
// TODO: support for 64 bit
if (samples > maxSamples()) samples = maxSamples();
int total_sec = Kwave::toInt(ceil(samples / rate));
int total_sec = Kwave::toInt(ceil(static_cast<double>(samples) / rate));
int hours = total_sec / (60*60);
int minutes = (total_sec / 60) % 60;
int seconds = total_sec % 60;
......
......@@ -440,8 +440,8 @@ int Kwave::PlayBackALSA::openDevice(const QString &device, unsigned int rate,
return err;
}
qDebug(" real rate = %u", rrate);
if (static_cast<float>(rate) * 1.05f < rrate ||
static_cast<float>(rate) * 0.95f > rrate)
if (static_cast<float>(rate) * 1.05f < static_cast<float>(rrate) ||
static_cast<float>(rate) * 0.95f > static_cast<float>(rrate))
{
qWarning("rate is not accurate (requested = %iHz, got = %iHz)",
rate, rrate);
......
......@@ -361,7 +361,7 @@ void Kwave::LevelMeter::drawContents()
p.fillRect(rect(), palette().window().color());
const unsigned int border = 4;
const unsigned int cell = 3;
const unsigned int cell = 3;
const unsigned int w = width() - (border * 2) - (cell * 2);
const unsigned int h = (height() - border) / (m_tracks ? m_tracks : 1);
......@@ -370,7 +370,8 @@ void Kwave::LevelMeter::drawContents()
for (track = 0; track < m_tracks; ++track) {
// show a bar up to the "fast" value
const unsigned int fast = Kwave::toUint(m_current_fast[track] * w);
const unsigned int fast = Kwave::toUint(m_current_fast[track] *
static_cast<float>(w));
for (unsigned int i = 0; i < w; i += cell * 2) {
QColor color;
if (i >= w_high)
......@@ -389,7 +390,8 @@ void Kwave::LevelMeter::drawContents()
}
// draw the peak value
unsigned int peak = Kwave::toUint(m_current_peak[track] * w);
unsigned int peak = Kwave::toUint(
m_current_peak[track] * static_cast<float>(w));
QColor peak_color;
if (peak >= w_high)
peak_color = m_color_high;
......
......@@ -1338,7 +1338,8 @@ void Kwave::RecordDialog::updateRecordButton()
// enabled if not disabled by status and also not limited or
// less than the limit has been recorded
new_enable = m_record_enabled && (!m_params.record_time_limited ||
(m_samples_recorded < m_params.record_time * m_params.sample_rate));
(static_cast<double>(m_samples_recorded) <
m_params.record_time * m_params.sample_rate));
if (new_enable != old_enable) btRecord->setEnabled(new_enable);
}
......
......@@ -126,7 +126,8 @@ void Kwave::SampleRatePlugin::run(QStringList params)
// calculate the new length
double ratio = m_new_rate / old_rate;
sample_index_t new_length = static_cast<sample_index_t>(length * ratio);
sample_index_t new_length =
static_cast<sample_index_t>(double(length) * ratio);
if ((new_length == length) || !new_length) return;
Kwave::MetaDataList meta = mgr.metaData().selectByRange(first, last);
......@@ -220,12 +221,12 @@ void Kwave::SampleRatePlugin::run(QStringList params)
if (length) {
if (m_whole_signal) {
// if whole signal selected -> adjust start and end
first = sample_index_t(first * ratio);
last = sample_index_t(last * ratio);
first = sample_index_t(static_cast<double>(first) * ratio);
last = sample_index_t(static_cast<double>(last) * ratio);
length = last - first + 1;
} else {
// only a portion selected -> adjust only length
length = sample_index_t(length * ratio);
length = sample_index_t(static_cast<double>(length) * ratio);
}
mgr.selectRange(first, length);
......
......@@ -355,7 +355,8 @@ void Kwave::SonagramWindow::adjustBrightness()
sum += m_histogram[i];
// cut off all parts below the cutoff ratio (e.g. 0.1%)
unsigned int cutoff = Kwave::toUint(sum * COLOR_CUTOFF_RATIO);
unsigned int cutoff = Kwave::toUint(
static_cast<double>(sum) * COLOR_CUTOFF_RATIO);
// get the last used color from the histogram
int last = 254;
......
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