diff --git a/app/audio/audiomanager.cpp b/app/audio/audiomanager.cpp index 25b871b37..433efbbe6 100644 --- a/app/audio/audiomanager.cpp +++ b/app/audio/audiomanager.cpp @@ -48,21 +48,6 @@ AudioManager *AudioManager::instance() void AudioManager::RefreshDevices() { - if (!is_refreshing_outputs_) { - QFutureWatcher< QList >* output_watcher = new QFutureWatcher< QList >(); - connect(output_watcher, &QFutureWatcher< QList >::finished, this, &AudioManager::OutputDevicesRefreshed); - output_watcher->setFuture(QtConcurrent::run(QAudioDeviceInfo::availableDevices, QAudio::AudioOutput)); - - is_refreshing_outputs_ = true; - } - - if (!is_refreshing_inputs_) { - QFutureWatcher< QList >* input_watcher = new QFutureWatcher< QList >(); - connect(input_watcher, &QFutureWatcher< QList >::finished, this, &AudioManager::InputDevicesRefreshed); - input_watcher->setFuture(QtConcurrent::run(QAudioDeviceInfo::availableDevices, QAudio::AudioInput)); - - is_refreshing_inputs_ = true; - } } bool AudioManager::IsRefreshingOutputs() @@ -209,16 +194,6 @@ void AudioManager::SetInputDevice(PaDeviceIndex device) input_device_ = device; } -const QList &AudioManager::ListInputDevices() -{ - return input_devices_; -} - -const QList &AudioManager::ListOutputDevices() -{ - return output_devices_; -} - AudioManager::AudioManager() : is_refreshing_inputs_(false), is_refreshing_outputs_(false), diff --git a/app/audio/audiomanager.h b/app/audio/audiomanager.h index 7c2fa9882..ca0f2429e 100644 --- a/app/audio/audiomanager.h +++ b/app/audio/audiomanager.h @@ -22,7 +22,6 @@ #define AUDIOMANAGER_H #include -#include #include #include #include @@ -68,9 +67,6 @@ public: void SetInputDevice(PaDeviceIndex device); - const QList& ListInputDevices(); - const QList& ListOutputDevices(); - signals: void OutputListReady(); @@ -87,9 +83,6 @@ private: void CloseOutputStream(); - QList input_devices_; - QList output_devices_; - bool is_refreshing_inputs_; bool is_refreshing_outputs_; diff --git a/app/common/CMakeLists.txt b/app/common/CMakeLists.txt index 2dd2eaf62..2938ad229 100644 --- a/app/common/CMakeLists.txt +++ b/app/common/CMakeLists.txt @@ -28,6 +28,7 @@ set(OLIVE_SOURCES common/crashpadutils.h common/debug.cpp common/debug.h + common/decibel.h common/define.h common/ffmpegutils.cpp common/ffmpegutils.h diff --git a/app/common/decibel.h b/app/common/decibel.h new file mode 100644 index 000000000..61d57f276 --- /dev/null +++ b/app/common/decibel.h @@ -0,0 +1,89 @@ +/*** + + Olive - Non-Linear Video Editor + Copyright (C) 2021 Olive Team + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +***/ + +#ifndef DECIBEL_H +#define DECIBEL_H + +#include +#include + +namespace olive { + +class Decibel +{ +public: + static double fromLinear(double linear) + { + return double(20.0) * std::log10(linear); + } + + static double toLinear(double decibel) + { + double to_linear = std::pow(double(10.0), decibel / double(20.0)); + + // Minimum threshold that we figure is close enough to 0 that we may as well just return 0 + if (to_linear < 0.000001) { + return 0; + } else { + return to_linear; + } + } + + static double fromLogarithmic(double logarithmic) + { + if (logarithmic < 0.001) + return -200.0; + else if (logarithmic > 0.99) + return 0; + else + return 20.0 * std::log10(-std::log(1 - logarithmic) / LOG100); + } + + static double toLogarithmic(double decibel) + { + if (qFuzzyIsNull(decibel)) { + return 1; + } else { + return 1 - std::exp(-std::pow(10.0, decibel / 20.0) * LOG100); + } + } + + static double LinearToLogarithmic(double linear) + { + return 1 - std::exp(-linear * LOG100); + } + + static double LogarithmicToLinear(double logarithmic) + { + if (logarithmic > 0.99) { + return 1; + } else { + return -std::log(1 - logarithmic) / LOG100; + } + } + +private: + static constexpr double LOG100 = 4.60517018599; + +}; + +} + +#endif // DECIBEL_H diff --git a/app/dialog/preferences/tabs/preferencesaudiotab.cpp b/app/dialog/preferences/tabs/preferencesaudiotab.cpp index 57c3027b5..4c0d4536b 100644 --- a/app/dialog/preferences/tabs/preferencesaudiotab.cpp +++ b/app/dialog/preferences/tabs/preferencesaudiotab.cpp @@ -179,20 +179,20 @@ void PreferencesAudioTab::RefreshDevices() void PreferencesAudioTab::RetrieveOutputList() { - PopulateComboBox(audio_output_devices_, + /*PopulateComboBox(audio_output_devices_, AudioManager::instance()->IsRefreshingOutputs(), AudioManager::instance()->ListOutputDevices(), - Config::Current()["AudioOutput"].toString()); + Config::Current()["AudioOutput"].toString());*/ UpdateRefreshButtonEnabled(); } void PreferencesAudioTab::RetrieveInputList() { - PopulateComboBox(audio_input_devices_, + /*PopulateComboBox(audio_input_devices_, AudioManager::instance()->IsRefreshingInputs(), AudioManager::instance()->ListInputDevices(), - Config::Current()["AudioInput"].toString()); + Config::Current()["AudioInput"].toString());*/ UpdateRefreshButtonEnabled(); } @@ -209,7 +209,7 @@ void PreferencesAudioTab::UpdateRefreshButtonEnabled() && audio_input_devices_->isEnabled()); } -void PreferencesAudioTab::PopulateComboBox(QComboBox *cb, bool still_refreshing, const QList &list, const QString& preferred) +/*void PreferencesAudioTab::PopulateComboBox(QComboBox *cb, bool still_refreshing, const QList &list, const QString& preferred) { cb->clear(); @@ -237,6 +237,6 @@ void PreferencesAudioTab::PopulateComboBox(QComboBox *cb, bool still_refreshing, } } -} +}*/ } diff --git a/app/dialog/preferences/tabs/preferencesaudiotab.h b/app/dialog/preferences/tabs/preferencesaudiotab.h index 740d4a602..b2cbcbd34 100644 --- a/app/dialog/preferences/tabs/preferencesaudiotab.h +++ b/app/dialog/preferences/tabs/preferencesaudiotab.h @@ -21,7 +21,6 @@ #ifndef PREFERENCESAUDIOTAB_H #define PREFERENCESAUDIOTAB_H -#include #include #include @@ -72,7 +71,7 @@ private: void UpdateRefreshButtonEnabled(); - static void PopulateComboBox(QComboBox* cb, bool still_refreshing, const QList& list, const QString &preferred); + //static void PopulateComboBox(QComboBox* cb, bool still_refreshing, const QList& list, const QString &preferred); }; diff --git a/app/render/audioparams.cpp b/app/render/audioparams.cpp index 1654ef084..24246429b 100644 --- a/app/render/audioparams.cpp +++ b/app/render/audioparams.cpp @@ -67,26 +67,6 @@ bool AudioParams::operator!=(const AudioParams &other) const return !(*this == other); } -QAudioFormat::SampleType AudioParams::GetQtSampleType(AudioParams::Format format) -{ - switch (format) { - case kFormatUnsigned8: - return QAudioFormat::UnSignedInt; - case kFormatSigned16: - case kFormatSigned32: - case kFormatSigned64: - return QAudioFormat::SignedInt; - case kFormatFloat32: - case kFormatFloat64: - return QAudioFormat::Float; - case kFormatInvalid: - case kFormatCount: - break; - } - - return QAudioFormat::Unknown; -} - qint64 AudioParams::time_to_bytes(const double &time) const { return time_to_bytes_per_channel(time) * channel_count(); diff --git a/app/render/audioparams.h b/app/render/audioparams.h index d28105c40..a8f5f1496 100644 --- a/app/render/audioparams.h +++ b/app/render/audioparams.h @@ -21,7 +21,6 @@ #ifndef AUDIOPARAMS_H #define AUDIOPARAMS_H -#include #include #include #include @@ -184,8 +183,6 @@ public: bool operator==(const AudioParams& other) const; bool operator!=(const AudioParams& other) const; - static QAudioFormat::SampleType GetQtSampleType(Format format); - static const QVector kSupportedChannelLayouts; static const QVector kSupportedSampleRates; diff --git a/app/widget/audiomonitor/audiomonitor.cpp b/app/widget/audiomonitor/audiomonitor.cpp index d2285ecc8..c95e5c7b6 100644 --- a/app/widget/audiomonitor/audiomonitor.cpp +++ b/app/widget/audiomonitor/audiomonitor.cpp @@ -20,11 +20,11 @@ #include "audiomonitor.h" -#include #include #include #include "audio/audiomanager.h" +#include "common/decibel.h" #include "common/qtutils.h" namespace olive { @@ -170,7 +170,7 @@ void AudioMonitor::paintGL() db_label = QStringLiteral("%1").arg(i); } - qreal log_val = QAudio::convertVolume(i, QAudio::DecibelVolumeScale, QAudio::LogarithmicVolumeScale); + qreal log_val = Decibel::toLogarithmic(i); QRect db_marking_rect = db_labels_rect; db_marking_rect.adjust(0, db_labels_rect.height() - qRound(log_val * db_labels_rect.height()), 0, 0); @@ -278,7 +278,7 @@ void AudioMonitor::paintGL() } // Convert val to logarithmic scale - vol = QAudio::convertVolume(vol, QAudio::LinearVolumeScale, QAudio::LogarithmicVolumeScale); + vol = Decibel::LinearToLogarithmic(vol); meter_rect.adjust(0, 0, 0, -qRound(meter_rect.height() * vol)); p.drawRect(meter_rect); diff --git a/app/widget/slider/floatslider.cpp b/app/widget/slider/floatslider.cpp index ad460347e..39c00f686 100644 --- a/app/widget/slider/floatslider.cpp +++ b/app/widget/slider/floatslider.cpp @@ -21,9 +21,10 @@ #include "floatslider.h" #include -#include #include +#include "common/decibel.h" + namespace olive { #define super DecimalSliderBase @@ -91,7 +92,7 @@ QString FloatSlider::ValueToString(double val, FloatSlider::DisplayType display, return tr("\xE2\x88\x9E"); } - val = LinearToDecibel(val); + val = Decibel::fromLinear(val); break; case kPercentage: // Multiply value by 100 for user-friendly percentage @@ -124,7 +125,7 @@ QVariant FloatSlider::StringToValue(const QString &s, bool *ok) const if (valid) { // Convert from decibel scale to linear decimal - return DecibelToLinear(decibels); + return Decibel::toLinear(decibels); } break; @@ -159,9 +160,9 @@ QVariant FloatSlider::AdjustDragDistanceInternal(const QVariant &start, const do break; case kDecibel: { - double current_db = LinearToDecibel(start.toDouble()); + double current_db = Decibel::fromLinear(start.toDouble()); current_db += drag; - double adjusted_linear = DecibelToLinear(current_db); + double adjusted_linear = Decibel::toLinear(current_db); return adjusted_linear; } @@ -177,21 +178,4 @@ void FloatSlider::ValueSignalEvent(const QVariant &value) emit ValueChanged(value.toDouble()); } -double FloatSlider::LinearToDecibel(double linear) -{ - return double(20.0) * std::log10(linear); -} - -double FloatSlider::DecibelToLinear(double decibel) -{ - double to_linear = std::pow(double(10.0), decibel / double(20.0)); - - // Minimum threshold that we figure is close enough to 0 that we may as well just return 0 - if (to_linear < 0.000001) { - return 0; - } else { - return to_linear; - } -} - } diff --git a/app/widget/slider/floatslider.h b/app/widget/slider/floatslider.h index 179a7a45e..4000e41bd 100644 --- a/app/widget/slider/floatslider.h +++ b/app/widget/slider/floatslider.h @@ -64,10 +64,6 @@ signals: void ValueChanged(double); private: - static double LinearToDecibel(double linear); - - static double DecibelToLinear(double decibel); - DisplayType display_type_; }; diff --git a/app/widget/viewer/viewer.cpp b/app/widget/viewer/viewer.cpp index 4888a14e5..6fd75f5db 100644 --- a/app/widget/viewer/viewer.cpp +++ b/app/widget/viewer/viewer.cpp @@ -48,7 +48,9 @@ namespace olive { #define super TimeBasedWidget QVector ViewerWidget::instances_; -const int ViewerWidget::kAudioPlaybackInterval = 2; + +// NOTE: Hardcoded interval of size of audio chunk to render and send to the output at a time +const rational ViewerWidget::kAudioPlaybackInterval = rational(1, 8); const int kMaxPreQueueSize = 8; diff --git a/app/widget/viewer/viewer.h b/app/widget/viewer/viewer.h index c8c100d6a..2766cca8d 100644 --- a/app/widget/viewer/viewer.h +++ b/app/widget/viewer/viewer.h @@ -219,7 +219,7 @@ private: ViewerSizer* sizer_; - QAtomicInt playback_speed_; + int playback_speed_; rational last_time_; @@ -261,7 +261,7 @@ private: PackedProcessor packed_processor_; TempoProcessor tempo_processor_; QByteArray prequeued_audio_; - static const int kAudioPlaybackInterval; + static const rational kAudioPlaybackInterval; static QVector instances_;