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 the FIFO thread #7568

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
15 changes: 1 addition & 14 deletions include/AudioDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,10 @@ class AudioDevice

void processNextBuffer();

virtual void startProcessing()
{
m_inProcess = true;
}

virtual void startProcessing();
virtual void stopProcessing();

protected:
// subclasses can re-implement this for being used in conjunction with
// processNextBuffer()
virtual void writeBuffer(const SampleFrame* /* _buf*/, const fpp_t /*_frames*/) {}

// called by according driver for fetching new sound-data
fpp_t getNextBuffer(SampleFrame* _ab);

Expand Down Expand Up @@ -130,12 +122,7 @@ class AudioDevice
sample_rate_t m_sampleRate;
ch_cnt_t m_channels;
AudioEngine* m_audioEngine;
bool m_inProcess;

QMutex m_devMutex;

SampleFrame* m_buffer;

};

} // namespace lmms
Expand Down
6 changes: 1 addition & 5 deletions include/AudioDummy.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,11 @@ class AudioDummy : public QThread, public AudioDevice
while( true )
{
timer.reset();
const SampleFrame* b = audioEngine()->nextBuffer();
const SampleFrame* b = audioEngine()->renderNextBuffer();
if( !b )
{
break;
}
if( audioEngine()->hasFifoWriter() )
{
delete[] b;
}

const int microseconds = static_cast<int>( audioEngine()->framesPerPeriod() * 1000000.0f / audioEngine()->outputSampleRate() - timer.elapsed() );
if( microseconds > 0 )
Expand Down
54 changes: 7 additions & 47 deletions include/AudioEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
#include "lmms_basics.h"
#include "SampleFrame.h"
#include "LocklessList.h"
#include "FifoBuffer.h"
#include "AudioEngineProfiler.h"
#include "PlayHandle.h"

Expand All @@ -50,11 +49,6 @@ class MidiClient;
class AudioPort;
class AudioEngineWorkerThread;


constexpr fpp_t MINIMUM_BUFFER_SIZE = 32;
constexpr fpp_t DEFAULT_BUFFER_SIZE = 256;
constexpr fpp_t MAXIMUM_BUFFER_SIZE = 4096;

constexpr int BYTES_PER_SAMPLE = sizeof(sample_t);
constexpr int BYTES_PER_INT_SAMPLE = sizeof(int_sample_t);
constexpr int BYTES_PER_FRAME = sizeof(SampleFrame);
Expand All @@ -65,6 +59,10 @@ class LMMS_EXPORT AudioEngine : public QObject
{
Q_OBJECT
public:
constexpr static auto MinimumBufferSize = 32;
constexpr static auto DefaultBufferSize = 256;
constexpr static auto MaximumBufferSize = 1024;

/**
* @brief RAII helper for requestChangesInModel.
* Used by AudioEngine::requestChangesGuard.
Expand Down Expand Up @@ -160,10 +158,7 @@ class LMMS_EXPORT AudioEngine : public QObject

//! Set new audio device. Old device will be deleted,
//! unless it's stored using storeAudioDevice
void setAudioDevice( AudioDevice * _dev,
const struct qualitySettings & _qs,
bool _needs_fifo,
bool startNow );
void setAudioDevice(AudioDevice* _dev, const struct qualitySettings& _qs, bool startNow);
void storeAudioDevice();
void restoreAudioDevice();
inline AudioDevice * audioDev()
Expand Down Expand Up @@ -278,11 +273,6 @@ class LMMS_EXPORT AudioEngine : public QObject

bool criticalXRuns() const;

inline bool hasFifoWriter() const
{
return m_fifoWriter != nullptr;
}

void pushInputFrames( SampleFrame* _ab, const f_cnt_t _frames );

inline const SampleFrame* inputBuffer()
Expand All @@ -295,10 +285,7 @@ class LMMS_EXPORT AudioEngine : public QObject
return m_inputBufferFrames[ m_inputBufferRead ];
}

inline const SampleFrame* nextBuffer()
{
return hasFifoWriter() ? m_fifo->read() : renderNextBuffer();
}
const SampleFrame* renderNextBuffer();

void changeQuality(const struct qualitySettings & qs);

Expand All @@ -322,31 +309,10 @@ class LMMS_EXPORT AudioEngine : public QObject


private:
using Fifo = FifoBuffer<SampleFrame*>;

class fifoWriter : public QThread
{
public:
fifoWriter( AudioEngine * audioEngine, Fifo * fifo );

void finish();


private:
AudioEngine * m_audioEngine;
Fifo * m_fifo;
volatile bool m_writing;

void run() override;

void write(SampleFrame* buffer);
} ;


AudioEngine( bool renderOnly );
~AudioEngine() override;

void startProcessing(bool needsFifo = true);
void startProcessing();
void stopProcessing();


Expand All @@ -358,8 +324,6 @@ class LMMS_EXPORT AudioEngine : public QObject
void renderStageEffects();
void renderStageMix();

const SampleFrame* renderNextBuffer();

void swapBuffers();

void clearInternal();
Expand Down Expand Up @@ -405,10 +369,6 @@ class LMMS_EXPORT AudioEngine : public QObject
MidiClient * m_midiClient;
QString m_midiClientName;

// FIFO stuff
Fifo * m_fifo;
fifoWriter * m_fifoWriter;

AudioEngineProfiler m_profiler;

bool m_clearSignal;
Expand Down
4 changes: 4 additions & 0 deletions include/AudioFileDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#define LMMS_AUDIO_FILE_DEVICE_H

#include <QFile>
#include <memory>

#include "AudioDevice.h"
#include "OutputSettings.h"
Expand All @@ -49,6 +50,8 @@ class AudioFileDevice : public AudioDevice

OutputSettings const & getOutputSettings() const { return m_outputSettings; }

void processNextBuffer();
virtual void writeBuffer(const SampleFrame* buffer, const f_cnt_t frames) = 0;

protected:
int writeData( const void* data, int len );
Expand All @@ -66,6 +69,7 @@ class AudioFileDevice : public AudioDevice
private:
QFile m_outputFile;
OutputSettings m_outputSettings;
std::unique_ptr<SampleFrame[]> m_buffer;
} ;

using AudioFileDeviceInstantiaton
Expand Down
2 changes: 1 addition & 1 deletion include/AudioSampleRecorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class AudioSampleRecorder : public AudioDevice
std::shared_ptr<const SampleBuffer> createSampleBuffer();

private:
void writeBuffer(const SampleFrame* _ab, const fpp_t _frames) override;
void writeBuffer(const SampleFrame* _ab, const fpp_t _frames);

using BufferList = QList<QPair<SampleFrame*, fpp_t>>;
BufferList m_buffers;
Expand Down
13 changes: 4 additions & 9 deletions plugins/StereoEnhancer/StereoEnhancer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ StereoEnhancerEffect::StereoEnhancerEffect(
const Descriptor::SubPluginFeatures::Key * _key ) :
Effect( &stereoenhancer_plugin_descriptor, _parent, _key ),
m_seFX( DspEffectLibrary::StereoEnhancer( 0.0f ) ),
m_delayBuffer( new SampleFrame[DEFAULT_BUFFER_SIZE] ),
m_delayBuffer(Engine::audioEngine()->framesPerPeriod()),
m_currFrame( 0 ),
m_bbControls( this )
{
Expand All @@ -71,11 +71,6 @@ StereoEnhancerEffect::StereoEnhancerEffect(

StereoEnhancerEffect::~StereoEnhancerEffect()
{
if( m_delayBuffer )
{
delete [] m_delayBuffer;
}

m_currFrame = 0;
}

Expand Down Expand Up @@ -103,7 +98,7 @@ Effect::ProcessStatus StereoEnhancerEffect::processImpl(SampleFrame* buf, const
if( frameIndex < 0 )
{
// e.g. difference = -10, frameIndex = DBS - 10
frameIndex += DEFAULT_BUFFER_SIZE;
frameIndex += m_delayBuffer.size();
}

//sample_t s[2] = { buf[f][0], buf[f][1] }; //Vanilla
Expand All @@ -116,7 +111,7 @@ Effect::ProcessStatus StereoEnhancerEffect::processImpl(SampleFrame* buf, const

// Update currFrame
m_currFrame += 1;
m_currFrame %= DEFAULT_BUFFER_SIZE;
m_currFrame %= m_delayBuffer.size();
}

if( !isRunning() )
Expand All @@ -132,7 +127,7 @@ Effect::ProcessStatus StereoEnhancerEffect::processImpl(SampleFrame* buf, const

void StereoEnhancerEffect::clearMyBuffer()
{
for (auto i = std::size_t{0}; i < DEFAULT_BUFFER_SIZE; i++)
for (auto i = std::size_t{0}; i < m_delayBuffer.size(); i++)
{
m_delayBuffer[i][0] = 0.0f;
m_delayBuffer[i][1] = 0.0f;
Expand Down
2 changes: 1 addition & 1 deletion plugins/StereoEnhancer/StereoEnhancer.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class StereoEnhancerEffect : public Effect
private:
DspEffectLibrary::StereoEnhancer m_seFX;

SampleFrame* m_delayBuffer;
std::vector<SampleFrame> m_delayBuffer;
int m_currFrame;

StereoEnhancerControls m_bbControls;
Expand Down
2 changes: 1 addition & 1 deletion plugins/VstEffect/VstEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ VstEffect::VstEffect( Model * _parent,
Effect::ProcessStatus VstEffect::processImpl(SampleFrame* buf, const fpp_t frames)
{
assert(m_plugin != nullptr);
static thread_local auto tempBuf = std::array<SampleFrame, MAXIMUM_BUFFER_SIZE>();
static thread_local auto tempBuf = std::array<SampleFrame, AudioEngine::MaximumBufferSize>();

std::memcpy(tempBuf.data(), buf, sizeof(SampleFrame) * frames);
if (m_pluginMutex.tryLock(Engine::getSong()->isExporting() ? -1 : 0))
Expand Down
Loading
Loading