Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove global oversampling #7228

Merged
merged 1 commit into from
May 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions include/AudioDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ class AudioDevice

virtual void stopProcessing();

void applyQualitySettings();

protected:
// subclasses can re-implement this for being used in conjunction with
// processNextBuffer()
Expand All @@ -110,13 +108,6 @@ class AudioDevice
void clearS16Buffer( int_sample_t * _outbuf,
const fpp_t _frames );

// resample given buffer from samplerate _src_sr to samplerate _dst_sr
fpp_t resample( const surroundSampleFrame * _src,
const fpp_t _frames,
surroundSampleFrame * _dst,
const sample_rate_t _src_sr,
const sample_rate_t _dst_sr );

inline void setSampleRate( const sample_rate_t _new_sr )
{
m_sampleRate = _new_sr;
Expand All @@ -142,9 +133,6 @@ class AudioDevice

QMutex m_devMutex;

SRC_DATA m_srcData;
SRC_STATE * m_srcState;

surroundSampleFrame * m_buffer;

};
Expand Down
2 changes: 1 addition & 1 deletion include/AudioDummy.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class AudioDummy : public QThread, public AudioDevice
delete[] b;
}

const int microseconds = static_cast<int>( audioEngine()->framesPerPeriod() * 1000000.0f / audioEngine()->processingSampleRate() - timer.elapsed() );
const int microseconds = static_cast<int>( audioEngine()->framesPerPeriod() * 1000000.0f / audioEngine()->outputSampleRate() - timer.elapsed() );
if( microseconds > 0 )
{
usleep( microseconds );
Expand Down
55 changes: 2 additions & 53 deletions include/AudioEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,6 @@ class LMMS_EXPORT AudioEngine : public QObject

struct qualitySettings
{
enum class Mode
{
Draft,
HighQuality,
FinalMix
} ;

enum class Interpolation
{
Linear,
Expand All @@ -123,53 +116,11 @@ class LMMS_EXPORT AudioEngine : public QObject
SincBest
} ;

enum class Oversampling
{
None,
X2,
X4,
X8
} ;

Interpolation interpolation;
Oversampling oversampling;

qualitySettings(Mode m)
qualitySettings(Interpolation i) :
interpolation(i)
{
switch (m)
{
case Mode::Draft:
interpolation = Interpolation::Linear;
oversampling = Oversampling::None;
break;
case Mode::HighQuality:
interpolation =
Interpolation::SincFastest;
oversampling = Oversampling::X2;
break;
case Mode::FinalMix:
interpolation = Interpolation::SincBest;
oversampling = Oversampling::X8;
break;
}
}

qualitySettings(Interpolation i, Oversampling o) :
interpolation(i),
oversampling(o)
{
}

int sampleRateMultiplier() const
{
switch( oversampling )
{
case Oversampling::None: return 1;
case Oversampling::X2: return 2;
case Oversampling::X4: return 4;
case Oversampling::X8: return 8;
}
return 1;
}

int libsrcInterpolation() const
Expand Down Expand Up @@ -289,8 +240,6 @@ class LMMS_EXPORT AudioEngine : public QObject
sample_rate_t baseSampleRate() const;
sample_rate_t outputSampleRate() const;
sample_rate_t inputSampleRate() const;
sample_rate_t processingSampleRate() const;


inline float masterGain() const
{
Expand Down
2 changes: 1 addition & 1 deletion include/BandLimitedWave.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class LMMS_EXPORT BandLimitedWave
*/
static inline float freqToLen( float f )
{
return freqToLen( f, Engine::audioEngine()->processingSampleRate() );
return freqToLen( f, Engine::audioEngine()->outputSampleRate() );
}

/*! \brief This method converts frequency to wavelength, but you can use any custom sample rate with it.
Expand Down
8 changes: 4 additions & 4 deletions include/Effect.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class LMMS_EXPORT Effect : public Plugin

inline f_cnt_t timeout() const
{
const float samples = Engine::audioEngine()->processingSampleRate() * m_autoQuitModel.value() / 1000.0f;
const float samples = Engine::audioEngine()->outputSampleRate() * m_autoQuitModel.value() / 1000.0f;
return 1 + ( static_cast<int>( samples ) / Engine::audioEngine()->framesPerPeriod() );
}

Expand Down Expand Up @@ -192,7 +192,7 @@ class LMMS_EXPORT Effect : public Plugin
sample_rate_t _dst_sr )
{
resample( 0, _src_buf,
Engine::audioEngine()->processingSampleRate(),
Engine::audioEngine()->outputSampleRate(),
_dst_buf, _dst_sr,
Engine::audioEngine()->framesPerPeriod() );
}
Expand All @@ -202,9 +202,9 @@ class LMMS_EXPORT Effect : public Plugin
sample_rate_t _src_sr )
{
resample( 1, _src_buf, _src_sr, _dst_buf,
Engine::audioEngine()->processingSampleRate(),
Engine::audioEngine()->outputSampleRate(),
Engine::audioEngine()->framesPerPeriod() * _src_sr /
Engine::audioEngine()->processingSampleRate() );
Engine::audioEngine()->outputSampleRate() );
}
void reinitSRC();

Expand Down
2 changes: 1 addition & 1 deletion include/Oscillator.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ class LMMS_EXPORT Oscillator
control.f1 + 1 :
0;
control.band = waveTableBandFromFreq(
m_freq * m_detuning_div_samplerate * Engine::audioEngine()->processingSampleRate());
m_freq * m_detuning_div_samplerate * Engine::audioEngine()->outputSampleRate());
return control;
}

Expand Down
4 changes: 2 additions & 2 deletions include/Sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ class LMMS_EXPORT Sample
};

Sample() = default;
Sample(const QByteArray& base64, int sampleRate = Engine::audioEngine()->processingSampleRate());
Sample(const sampleFrame* data, size_t numFrames, int sampleRate = Engine::audioEngine()->processingSampleRate());
Sample(const QByteArray& base64, int sampleRate = Engine::audioEngine()->outputSampleRate());
Sample(const sampleFrame* data, size_t numFrames, int sampleRate = Engine::audioEngine()->outputSampleRate());
Sample(const Sample& other);
Sample(Sample&& other);
explicit Sample(const QString& audioFile);
Expand Down
4 changes: 2 additions & 2 deletions include/SampleBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class LMMS_EXPORT SampleBuffer
SampleBuffer(const QString& base64, int sampleRate);
SampleBuffer(std::vector<sampleFrame> data, int sampleRate);
SampleBuffer(
const sampleFrame* data, size_t numFrames, int sampleRate = Engine::audioEngine()->processingSampleRate());
const sampleFrame* data, size_t numFrames, int sampleRate = Engine::audioEngine()->outputSampleRate());

friend void swap(SampleBuffer& first, SampleBuffer& second) noexcept;
auto toBase64() const -> QString;
Expand Down Expand Up @@ -91,7 +91,7 @@ class LMMS_EXPORT SampleBuffer
private:
std::vector<sampleFrame> m_data;
QString m_audioFile;
sample_rate_t m_sampleRate = Engine::audioEngine()->processingSampleRate();
sample_rate_t m_sampleRate = Engine::audioEngine()->outputSampleRate();
};

} // namespace lmms
Expand Down
2 changes: 1 addition & 1 deletion include/SampleLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class LMMS_EXPORT SampleLoader
static QString openWaveformFile(const QString& previousFile = "");
static std::shared_ptr<const SampleBuffer> createBufferFromFile(const QString& filePath);
static std::shared_ptr<const SampleBuffer> createBufferFromBase64(
const QString& base64, int sampleRate = Engine::audioEngine()->processingSampleRate());
const QString& base64, int sampleRate = Engine::audioEngine()->outputSampleRate());
private:
static void displayError(const QString& message);
};
Expand Down
2 changes: 1 addition & 1 deletion plugins/AudioFileProcessor/AudioFileProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ auto AudioFileProcessor::beatLen(NotePlayHandle* note) const -> int
// Otherwise, use the remaining sample duration
const auto baseFreq = instrumentTrack()->baseFreq();
const auto freqFactor = baseFreq / note->frequency()
* Engine::audioEngine()->processingSampleRate()
* Engine::audioEngine()->outputSampleRate()
/ Engine::audioEngine()->baseSampleRate();

const auto startFrame = m_nextPlayStartPoint >= m_sample.endFrame()
Expand Down
2 changes: 1 addition & 1 deletion plugins/BassBooster/BassBooster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ bool BassBoosterEffect::processAudioBuffer( sampleFrame* buf, const fpp_t frames

inline void BassBoosterEffect::changeFrequency()
{
const sample_t fac = Engine::audioEngine()->processingSampleRate() / 44100.0f;
const sample_t fac = Engine::audioEngine()->outputSampleRate() / 44100.0f;

m_bbFX.leftFX().setFrequency( m_bbControls.m_freqModel.value() * fac );
m_bbFX.rightFX().setFrequency( m_bbControls.m_freqModel.value() * fac );
Expand Down
2 changes: 1 addition & 1 deletion plugins/BitInvader/BitInvader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ void BitInvader::playNote( NotePlayHandle * _n,
const_cast<float*>( m_graph.samples() ),
_n,
m_interpolation.value(), factor,
Engine::audioEngine()->processingSampleRate() );
Engine::audioEngine()->outputSampleRate() );
}

const fpp_t frames = _n->framesLeftForCurrentPeriod();
Expand Down
4 changes: 2 additions & 2 deletions plugins/Bitcrush/Bitcrush.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Plugin::Descriptor PLUGIN_EXPORT bitcrush_plugin_descriptor =
BitcrushEffect::BitcrushEffect( Model * parent, const Descriptor::SubPluginFeatures::Key * key ) :
Effect( &bitcrush_plugin_descriptor, parent, key ),
m_controls( this ),
m_sampleRate( Engine::audioEngine()->processingSampleRate() ),
m_sampleRate( Engine::audioEngine()->outputSampleRate() ),
m_filter( m_sampleRate )
{
m_buffer = new sampleFrame[Engine::audioEngine()->framesPerPeriod() * OS_RATE];
Expand All @@ -83,7 +83,7 @@ BitcrushEffect::~BitcrushEffect()

void BitcrushEffect::sampleRateChanged()
{
m_sampleRate = Engine::audioEngine()->processingSampleRate();
m_sampleRate = Engine::audioEngine()->outputSampleRate();
m_filter.setSampleRate( m_sampleRate );
m_filter.setLowpass( m_sampleRate * ( CUTOFF_RATIO * OS_RATIO ) );
m_needsUpdate = true;
Expand Down
2 changes: 1 addition & 1 deletion plugins/CarlaBase/Carla.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ uint32_t CarlaInstrument::handleGetBufferSize() const

double CarlaInstrument::handleGetSampleRate() const
{
return Engine::audioEngine()->processingSampleRate();
return Engine::audioEngine()->outputSampleRate();
}

bool CarlaInstrument::handleIsOffline() const
Expand Down
4 changes: 2 additions & 2 deletions plugins/Compressor/Compressor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ CompressorEffect::CompressorEffect(Model* parent, const Descriptor::SubPluginFea
Effect(&compressor_plugin_descriptor, parent, key),
m_compressorControls(this)
{
m_sampleRate = Engine::audioEngine()->processingSampleRate();
m_sampleRate = Engine::audioEngine()->outputSampleRate();

m_yL[0] = m_yL[1] = COMP_NOISE_FLOOR;

Expand Down Expand Up @@ -560,7 +560,7 @@ inline void CompressorEffect::calcTiltFilter(sample_t inputSample, sample_t &out

void CompressorEffect::changeSampleRate()
{
m_sampleRate = Engine::audioEngine()->processingSampleRate();
m_sampleRate = Engine::audioEngine()->outputSampleRate();

m_coeffPrecalc = COMP_LOG / (m_sampleRate * 0.001f);

Expand Down
4 changes: 2 additions & 2 deletions plugins/CrossoverEQ/CrossoverEQ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Plugin::Descriptor PLUGIN_EXPORT crossovereq_plugin_descriptor =
CrossoverEQEffect::CrossoverEQEffect( Model* parent, const Descriptor::SubPluginFeatures::Key* key ) :
Effect( &crossovereq_plugin_descriptor, parent, key ),
m_controls( this ),
m_sampleRate( Engine::audioEngine()->processingSampleRate() ),
m_sampleRate( Engine::audioEngine()->outputSampleRate() ),
m_lp1( m_sampleRate ),
m_lp2( m_sampleRate ),
m_lp3( m_sampleRate ),
Expand All @@ -78,7 +78,7 @@ CrossoverEQEffect::~CrossoverEQEffect()

void CrossoverEQEffect::sampleRateChanged()
{
m_sampleRate = Engine::audioEngine()->processingSampleRate();
m_sampleRate = Engine::audioEngine()->outputSampleRate();
m_lp1.setSampleRate( m_sampleRate );
m_lp2.setSampleRate( m_sampleRate );
m_lp3.setSampleRate( m_sampleRate );
Expand Down
12 changes: 6 additions & 6 deletions plugins/Delay/DelayEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ DelayEffect::DelayEffect( Model* parent, const Plugin::Descriptor::SubPluginFeat
m_delayControls( this )
{
m_delay = 0;
m_delay = new StereoDelay( 20, Engine::audioEngine()->processingSampleRate() );
m_lfo = new Lfo( Engine::audioEngine()->processingSampleRate() );
m_delay = new StereoDelay( 20, Engine::audioEngine()->outputSampleRate() );
m_lfo = new Lfo( Engine::audioEngine()->outputSampleRate() );
m_outGain = 1.0;
}

Expand Down Expand Up @@ -88,7 +88,7 @@ bool DelayEffect::processAudioBuffer( sampleFrame* buf, const fpp_t frames )
return( false );
}
double outSum = 0.0;
const float sr = Engine::audioEngine()->processingSampleRate();
const float sr = Engine::audioEngine()->outputSampleRate();
const float d = dryLevel();
const float w = wetLevel();
auto dryS = std::array<sample_t, 2>{};
Expand Down Expand Up @@ -123,7 +123,7 @@ bool DelayEffect::processAudioBuffer( sampleFrame* buf, const fpp_t frames )

m_delay->setFeedback( *feedbackPtr );
m_lfo->setFrequency( *lfoTimePtr );
m_currentLength = static_cast<int>(*lengthPtr * Engine::audioEngine()->processingSampleRate());
m_currentLength = static_cast<int>(*lengthPtr * Engine::audioEngine()->outputSampleRate());
m_delay->setLength( m_currentLength + ( *amplitudePtr * ( float )m_lfo->tick() ) );
m_delay->tick( buf[f] );

Expand Down Expand Up @@ -151,8 +151,8 @@ bool DelayEffect::processAudioBuffer( sampleFrame* buf, const fpp_t frames )

void DelayEffect::changeSampleRate()
{
m_lfo->setSampleRate( Engine::audioEngine()->processingSampleRate() );
m_delay->setSampleRate( Engine::audioEngine()->processingSampleRate() );
m_lfo->setSampleRate( Engine::audioEngine()->outputSampleRate() );
m_delay->setSampleRate( Engine::audioEngine()->outputSampleRate() );
}


Expand Down
2 changes: 1 addition & 1 deletion plugins/Dispersion/Dispersion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Plugin::Descriptor PLUGIN_EXPORT dispersion_plugin_descriptor =
DispersionEffect::DispersionEffect(Model* parent, const Descriptor::SubPluginFeatures::Key* key) :
Effect(&dispersion_plugin_descriptor, parent, key),
m_dispersionControls(this),
m_sampleRate(Engine::audioEngine()->processingSampleRate()),
m_sampleRate(Engine::audioEngine()->outputSampleRate()),
m_amountVal(0)
{
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/DualFilter/DualFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ DualFilterEffect::DualFilterEffect( Model* parent, const Descriptor::SubPluginFe
Effect( &dualfilter_plugin_descriptor, parent, key ),
m_dfControls( this )
{
m_filter1 = new BasicFilters<2>( Engine::audioEngine()->processingSampleRate() );
m_filter2 = new BasicFilters<2>( Engine::audioEngine()->processingSampleRate() );
m_filter1 = new BasicFilters<2>( Engine::audioEngine()->outputSampleRate() );
m_filter2 = new BasicFilters<2>( Engine::audioEngine()->outputSampleRate() );

// ensure filters get updated
m_filter1changed = true;
Expand Down
4 changes: 2 additions & 2 deletions plugins/DualFilter/DualFilterControls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ void DualFilterControls::updateFilters()

delete m_effect->m_filter1;
delete m_effect->m_filter2;
m_effect->m_filter1 = new BasicFilters<2>( Engine::audioEngine()->processingSampleRate() );
m_effect->m_filter2 = new BasicFilters<2>( Engine::audioEngine()->processingSampleRate() );
m_effect->m_filter1 = new BasicFilters<2>( Engine::audioEngine()->outputSampleRate() );
m_effect->m_filter2 = new BasicFilters<2>( Engine::audioEngine()->outputSampleRate() );

// flag filters as needing recalculation

Expand Down
Loading
Loading