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

Fix PortAudio backend #7444

Open
wants to merge 48 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
359ca7b
Suggest the default low latency
sakertooth Aug 11, 2024
44da003
Remove verbose comments
sakertooth Aug 11, 2024
8af8bcb
Completely remove old PortAudio < v19 code
sakertooth Aug 11, 2024
f14188a
Remove redundant header guard
sakertooth Aug 11, 2024
5a6c2ff
Rename and move setup widget into gui namespace
sakertooth Aug 11, 2024
f9c5c4a
Fix naming of callback functions
sakertooth Aug 11, 2024
5badd59
Merge AudioPortAudioSetupWidget and AudioPortAudioSetupUtil
sakertooth Aug 11, 2024
7433c15
Fix naming in constructor
sakertooth Aug 11, 2024
7eb6089
Fix naming for parameters of callback functions
sakertooth Aug 11, 2024
a342db7
Move closing brace up
sakertooth Aug 11, 2024
71a4ab2
Clean up constructor
sakertooth Aug 11, 2024
12b9de4
Replace printf calls on error with std::cerr
sakertooth Aug 11, 2024
261642d
Use unique_ptr for m_outBuf
sakertooth Aug 11, 2024
9952bf8
Do not use multiple techniques to start and stop the stream
sakertooth Aug 12, 2024
849667d
Merge remote-tracking branch 'upstream/master' into cleanup-portaudio…
sakertooth Aug 12, 2024
a762042
Move back to using paComplete
sakertooth Aug 12, 2024
bb21cf4
Fix naming style
sakertooth Aug 12, 2024
b7963c7
Replace memset with std::fill_n
sakertooth Aug 12, 2024
4ff2725
Remove redundant frames variable
sakertooth Aug 12, 2024
333c081
Simplify nested for loop
sakertooth Aug 12, 2024
6c7c25c
Fix unsigned comparison
sakertooth Aug 12, 2024
0647ddc
Use Qt's combo boxes
sakertooth Aug 12, 2024
88aaace
Include memory header
sakertooth Aug 12, 2024
c43246b
Remove LcdSpinBox forward declaration
sakertooth Aug 12, 2024
937d054
Stop searching for devices when the correct device is found
sakertooth Jan 15, 2025
ce342b9
Fix formatting
sakertooth Jan 15, 2025
4d07a4f
Set suggestedLatency to the correct values
sakertooth Jan 15, 2025
db4aea6
Stop clamping channel count to 2
sakertooth Jan 16, 2025
b64b231
Use default number of channels when no amount is specified in the config
sakertooth Jan 18, 2025
5cafcaa
Simplify construction logic
sakertooth Jan 27, 2025
b383855
Use QString::number instead of trying to construct string from number
sakertooth Jan 27, 2025
eed45c5
Stop calculating latency twice
sakertooth Jan 27, 2025
b92c176
Add whitespace
sakertooth Jan 27, 2025
2d8af61
Remove input device
sakertooth Jan 27, 2025
30a1603
Apply adjustments
sakertooth Jan 30, 2025
afc32a4
Update devices when backend changes
sakertooth Jan 30, 2025
a18ea26
Add PortAudio initialization RAII guard
sakertooth Jan 30, 2025
269ba38
Improve backend, device, and channel finding and selection logic
sakertooth Jan 31, 2025
2781c7e
Early return when no backend or device is selected, update both devic…
sakertooth Jan 31, 2025
39d7b3c
Set sample rate and channel count lazily
sakertooth Jan 31, 2025
d7b950a
Support downmixing to mono
sakertooth Jan 31, 2025
58ad256
Remove anonymous namespace
sakertooth Jan 31, 2025
8f74a06
Merge remote-tracking branch 'upstream' into cleanup-portaudio-backend
sakertooth Jan 31, 2025
34efa35
Merge remote-tracking branch 'upstream' into cleanup-portaudio-backend
sakertooth Jan 31, 2025
ce08aa5
Fix audio processing to work with any number of channels
sakertooth Jan 31, 2025
8b35ba0
Fix audio glitches when playing wiith buffer sizes other than 256
sakertooth Feb 4, 2025
47fb7ba
Set sample rate and channel count even on failure to open device
sakertooth Feb 4, 2025
f357c9c
Make adjustment
sakertooth Feb 4, 2025
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
115 changes: 26 additions & 89 deletions include/AudioPortAudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,137 +25,74 @@
#ifndef LMMS_AUDIO_PORTAUDIO_H
#define LMMS_AUDIO_PORTAUDIO_H

#include <QObject>

#include "lmmsconfig.h"
#include "ComboBoxModel.h"

#ifdef LMMS_HAVE_PORTAUDIO

# include <portaudio.h>

# include "AudioDevice.h"
# include "AudioDeviceSetupWidget.h"

# if defined paNeverDropInput || defined paNonInterleaved
# define PORTAUDIO_V19
# else
# define PORTAUDIO_V18
# endif
#include <QObject>
#include <memory>
#include <portaudio.h>

#endif
#include "AudioDevice.h"
#include "AudioDeviceSetupWidget.h"

class QComboBox;

namespace lmms
{

class AudioPortAudioSetupUtil : public QObject
namespace gui {

class AudioPortAudioSetupWidget : public gui::AudioDeviceSetupWidget
{
Q_OBJECT
public slots:
public:
AudioPortAudioSetupWidget(QWidget* _parent);

void updateBackends();
void updateDevices();
void updateChannels();

public:
ComboBoxModel m_backendModel;
ComboBoxModel m_deviceModel;
};


#ifdef LMMS_HAVE_PORTAUDIO


namespace gui
{
class ComboBox;
class LcdSpinBox;
}
void saveSettings() override;
void show() override;

private:
QComboBox* m_backendComboBox;
QComboBox* m_deviceComboBox;
};
} // namespace gui

class AudioPortAudio : public AudioDevice
{
public:
AudioPortAudio( bool & _success_ful, AudioEngine* audioEngine );
AudioPortAudio(bool& successful, AudioEngine* engine);
~AudioPortAudio() override;

inline static QString name()
{
return QT_TRANSLATE_NOOP( "AudioDeviceSetupWidget", "PortAudio" );
}

int process_callback(const float* _inputBuffer, float* _outputBuffer, f_cnt_t _framesPerBuffer);

class setupWidget : public gui::AudioDeviceSetupWidget
{
public:
setupWidget( QWidget * _parent );
~setupWidget() override;

void saveSettings() override;
void show() override;

private:
gui::ComboBox * m_backend;
gui::ComboBox * m_device;
AudioPortAudioSetupUtil m_setupUtil;

} ;

private:
void startProcessing() override;
void stopProcessing() override;

#ifdef PORTAUDIO_V19
static int _process_callback( const void *_inputBuffer, void * _outputBuffer,
unsigned long _framesPerBuffer,
const PaStreamCallbackTimeInfo * _timeInfo,
PaStreamCallbackFlags _statusFlags,
void *arg );

#else

#define paContinue 0
#define paComplete 1
#define Pa_GetDeviceCount Pa_CountDevices
#define Pa_GetDefaultInputDevice Pa_GetDefaultInputDeviceID
#define Pa_GetDefaultOutputDevice Pa_GetDefaultOutputDeviceID
#define Pa_IsStreamActive Pa_StreamActive

static int _process_callback( void * _inputBuffer, void * _outputBuffer,
unsigned long _framesPerBuffer, PaTimestamp _outTime, void * _arg );


using PaTime = double;
using PaDeviceIndex = PaDeviceID;

using PaStreamParameters = struct
{
PaDeviceIndex device;
int channelCount;
PaSampleFormat sampleFormat;
PaTime suggestedLatency;
void *hostApiSpecificStreamInfo;

} PaStreamParameters;
#endif // PORTAUDIO_V19
int processCallback(const float* inputBuffer, float* outputBuffer, f_cnt_t framesPerBuffer);
static int processCallback(const void* inputBuffer, void* outputBuffer, unsigned long framesPerBuffer,
const PaStreamCallbackTimeInfo* timeInfo, PaStreamCallbackFlags statusFlags, void* arg);

PaStream * m_paStream;
PaStreamParameters m_outputParameters;
PaStreamParameters m_inputParameters;

bool m_wasPAInitError;

SampleFrame* m_outBuf;
std::unique_ptr<SampleFrame[]> m_outBuf;
std::size_t m_outBufPos;
fpp_t m_outBufSize;
};

bool m_stopped;

} ;
} // namespace lmms

#endif // LMMS_HAVE_PORTAUDIO

} // namespace lmms

#endif // LMMS_AUDIO_PORTAUDIO_H
Loading
Loading