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

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
140f99c
Remove FIFO thread
sakertooth Dec 17, 2024
a85b145
Add AudioEngine::renderNextBufferChunked and use it in SDL audio device
sakertooth Dec 17, 2024
4a3ca48
Use new chunking function in JACK audio device
sakertooth Dec 17, 2024
e193860
Use new chunking function in OSS audio device
sakertooth Dec 17, 2024
608a7d1
Use new chunking function in PortAudio device
sakertooth Dec 17, 2024
0a956c6
Use new chunking function in PulseAudio device
sakertooth Dec 17, 2024
850a842
Use new chunking function in ALSA device
sakertooth Dec 17, 2024
25802da
Use new chunking function in sndio device
sakertooth Dec 17, 2024
663ca7e
Use new chunking function in soundio device
sakertooth Dec 17, 2024
17a1d34
Remove unused getNextBuffer function
sakertooth Dec 17, 2024
24a2a28
Minor changes
sakertooth Dec 17, 2024
2dbe458
Make renderNextBufferChunked persist buffers across calls to avoid dr…
sakertooth Dec 18, 2024
30db2ef
Make some style changes in AudioSoundIo
sakertooth Dec 18, 2024
0a0122e
Remove redundancy in AudioOss
sakertooth Dec 18, 2024
b2f3579
Check for result from write call again
sakertooth Dec 18, 2024
bf89032
Consider if the audio device has stopped for JACK devices
sakertooth Dec 18, 2024
e4fc133
Consider if the audio device has stopped
sakertooth Dec 18, 2024
ecf9523
Cast bytes to std::size_t
sakertooth Dec 19, 2024
e433ffd
Merge remote-tracking branch 'upstream/master' into revamp-buffers
sakertooth Dec 21, 2024
a03bd17
Avoid copying of rendered buffer in renderNextBufferChunked
sakertooth Dec 24, 2024
885cb32
Remove processNextBuffer function and call writeBuffer directly
sakertooth Dec 25, 2024
3a72faa
Restore functionality to render audio within AudioDummy
sakertooth Dec 27, 2024
c5a16a7
Add stopped variable in AudioDummy
sakertooth Dec 28, 2024
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
1 change: 1 addition & 0 deletions include/AudioAlsa.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class AudioAlsa : public QThread, public AudioDevice
snd_pcm_sw_params_t * m_swParams;

bool m_convertEndian;
std::atomic<bool> m_stopped;

} ;

Expand Down
20 changes: 1 addition & 19 deletions include/AudioDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,10 @@ class AudioDevice
return m_channels;
}

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);

// convert a given audio-buffer to a buffer in signed 16-bit samples
// returns num of bytes in outbuf
int convertToS16(const SampleFrame* _ab,
Expand Down Expand Up @@ -130,12 +117,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
16 changes: 5 additions & 11 deletions include/AudioDummy.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,30 +80,23 @@ class AudioDummy : public QThread, public AudioDevice
private:
void startProcessing() override
{
m_stopped = false;
start();
}

void stopProcessing() override
{
m_stopped = true;
stopProcessingThread( this );
}

void run() override
{
MicroTimer timer;
while( true )
while (!m_stopped)
{
audioEngine()->renderNextBuffer();
timer.reset();
const SampleFrame* b = audioEngine()->nextBuffer();
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 All @@ -112,6 +105,7 @@ class AudioDummy : public QThread, public AudioDevice
}
}

std::atomic<bool> m_stopped;
} ;

} // namespace lmms
Expand Down
48 changes: 6 additions & 42 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 Down Expand Up @@ -160,10 +159,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 @@ -214,6 +210,7 @@ class LMMS_EXPORT AudioEngine : public QObject
return m_framesPerPeriod;
}

fpp_t userFramesPerPeriod() const { return m_userFramesPerPeriod; }

AudioEngineProfiler& profiler()
{
Expand Down Expand Up @@ -278,11 +275,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 +287,8 @@ 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 renderNextBufferChunked(SampleFrame* dst, std::size_t size);

void changeQuality(const struct qualitySettings & qs);

Expand All @@ -322,31 +312,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 +327,6 @@ class LMMS_EXPORT AudioEngine : public QObject
void renderStageEffects();
void renderStageMix();

const SampleFrame* renderNextBuffer();

void swapBuffers();

void clearInternal();
Expand All @@ -369,6 +336,7 @@ class LMMS_EXPORT AudioEngine : public QObject
std::vector<AudioPort *> m_audioPorts;

fpp_t m_framesPerPeriod;
fpp_t m_userFramesPerPeriod;

SampleFrame* m_inputBuffer[2];
f_cnt_t m_inputBufferFrames[2];
Expand Down Expand Up @@ -405,10 +373,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
1 change: 1 addition & 0 deletions include/AudioFileDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class AudioFileDevice : public AudioDevice

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

virtual void writeBuffer(const SampleFrame* buf, const fpp_t frames) = 0;

protected:
int writeData( const void* data, int len );
Expand Down
5 changes: 0 additions & 5 deletions include/AudioJack.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,6 @@ private slots:

std::atomic<MidiJack*> m_midiClient;
std::vector<jack_port_t*> m_outputPorts;
jack_default_audio_sample_t** m_tempOutBufs;
SampleFrame* m_outBuf;

f_cnt_t m_framesDoneInCurBuf;
f_cnt_t m_framesToDoInCurBuf;

#ifdef AUDIO_PORT_SUPPORT
struct StereoPort
Expand Down
1 change: 1 addition & 0 deletions include/AudioOss.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class setupWidget : public gui::AudioDeviceSetupWidget
int m_audioFD;

bool m_convertEndian;
std::atomic<bool> m_stopped;

} ;

Expand Down
5 changes: 0 additions & 5 deletions include/AudioPortAudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,6 @@ class AudioPortAudio : public AudioDevice
PaStreamParameters m_inputParameters;

bool m_wasPAInitError;

SampleFrame* m_outBuf;
std::size_t m_outBufPos;
fpp_t m_outBufSize;

bool m_stopped;

} ;
Expand Down
5 changes: 3 additions & 2 deletions include/AudioPulseAudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,12 @@ class AudioPulseAudio : public QThread, public AudioDevice
void stopProcessing() override;
void run() override;

volatile bool m_quit;

bool m_convertEndian;

bool m_connected;

std::atomic<bool> m_stopped;

QSemaphore m_connectedSemaphore;

} ;
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
2 changes: 0 additions & 2 deletions include/AudioSdl.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ class AudioSdl : public AudioDevice

SDL_AudioSpec m_audioHandle;

SampleFrame* m_outBuf;

size_t m_currentBufferFramePos;
size_t m_currentBufferFramesCount;

Expand Down
1 change: 1 addition & 0 deletions include/AudioSndio.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class AudioSndio : public QThread, public AudioDevice
struct sio_par m_par;

bool m_convertEndian;
std::atomic<bool> m_stopped;
} ;


Expand Down
5 changes: 0 additions & 5 deletions include/AudioSoundIo.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,6 @@ class AudioSoundIo : public AudioDevice
SoundIo *m_soundio;
SoundIoOutStream *m_outstream;

SampleFrame* m_outBuf;
int m_outBufSize;
fpp_t m_outBufFramesTotal;
fpp_t m_outBufFrameIndex;

bool m_stopped;
bool m_outstreamStarted;

Expand Down
Loading
Loading