Skip to content

Commit

Permalink
Merge pull request #11941 from Holzhaus/channelcount
Browse files Browse the repository at this point in the history
Use `mixxx::audio::ChannelCount` type instead of `int`/`unsigned char`/etc.
  • Loading branch information
Swiftb0y authored Sep 9, 2023
2 parents f4692aa + c3fac62 commit 1fce230
Show file tree
Hide file tree
Showing 24 changed files with 221 additions and 167 deletions.
36 changes: 28 additions & 8 deletions src/engine/enginemaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <QPair>
#include <QtDebug>

#include "audio/types.h"
#include "control/controlaudiotaperpot.h"
#include "control/controlpotmeter.h"
#include "control/controlpushbutton.h"
Expand Down Expand Up @@ -1048,16 +1049,35 @@ void EngineMaster::onInputDisconnected(const AudioInput& input) {
}

void EngineMaster::registerNonEngineChannelSoundIO(SoundManager* pSoundManager) {
pSoundManager->registerInput(AudioInput(AudioPath::RECORD_BROADCAST, 0, 2),
m_pEngineSideChain);

pSoundManager->registerOutput(AudioOutput(AudioOutput::MASTER, 0, 2), this);
pSoundManager->registerOutput(AudioOutput(AudioOutput::HEADPHONES, 0, 2), this);
pSoundManager->registerOutput(AudioOutput(AudioOutput::BOOTH, 0, 2), this);
pSoundManager->registerInput(AudioInput(AudioPath::RECORD_BROADCAST,
0,
mixxx::audio::ChannelCount::stereo()),
m_pEngineSideChain);

pSoundManager->registerOutput(AudioOutput(AudioOutput::MASTER,
0,
mixxx::audio::ChannelCount::stereo()),
this);
pSoundManager->registerOutput(AudioOutput(AudioOutput::HEADPHONES,
0,
mixxx::audio::ChannelCount::stereo()),
this);
pSoundManager->registerOutput(AudioOutput(AudioOutput::BOOTH,
0,
mixxx::audio::ChannelCount::stereo()),
this);
for (int o = EngineChannel::LEFT; o <= EngineChannel::RIGHT; o++) {
pSoundManager->registerOutput(AudioOutput(AudioOutput::BUS, 0, 2, o), this);
pSoundManager->registerOutput(
AudioOutput(AudioOutput::BUS,
0,
mixxx::audio::ChannelCount::stereo(),
o),
this);
}
pSoundManager->registerOutput(AudioOutput(AudioOutput::RECORD_BROADCAST, 0, 2), this);
pSoundManager->registerOutput(AudioOutput(AudioOutput::RECORD_BROADCAST,
0,
mixxx::audio::ChannelCount::stereo()),
this);
}

bool EngineMaster::sidechainMixRequired() const {
Expand Down
5 changes: 2 additions & 3 deletions src/engine/filters/enginefilterpan.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

#include <string.h>

#include "engine/engine.h"
#include "engine/engineobject.h"
#include "util/assert.h"

static constexpr int numChannels = 2;

template<unsigned int SIZE>
class EngineFilterPan : public EngineObjectConstIn {
public:
Expand Down Expand Up @@ -123,7 +122,7 @@ class EngineFilterPan : public EngineObjectConstIn {
int m_leftDelayFrames;
int m_oldLeftDelayFrames;
int m_delayFrame;
CSAMPLE m_buf[SIZE * numChannels];
CSAMPLE m_buf[SIZE * mixxx::kEngineChannelCount];
bool m_doRamping;
bool m_doStart;
};
5 changes: 2 additions & 3 deletions src/engine/filters/enginefilterpansingle.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@

#include <string.h>

#include "engine/engine.h"
#include "engine/engineobject.h"
#include "util/assert.h"

static constexpr int numChannels = 2;

template<unsigned int SIZE>
class EngineFilterPanSingle {
public:
Expand Down Expand Up @@ -78,6 +77,6 @@ class EngineFilterPanSingle {

protected:
int m_delayFrame;
CSAMPLE m_buf[SIZE * numChannels];
CSAMPLE m_buf[SIZE * mixxx::kEngineChannelCount];
bool m_doStart;
};
8 changes: 4 additions & 4 deletions src/engine/sidechain/enginenetworkstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ class EngineNetworkStream {
qint64 getInputStreamTimeUs();
qint64 getInputStreamTimeFrames();

int getNumOutputChannels() {
mixxx::audio::ChannelCount getNumOutputChannels() {
return m_numOutputChannels;
}

int getNumInputChannels() {
mixxx::audio::ChannelCount getNumInputChannels() {
return m_numInputChannels;
}

Expand All @@ -46,8 +46,8 @@ class EngineNetworkStream {
void debugOutputSlots();

FIFO<CSAMPLE>* m_pInputFifo;
int m_numOutputChannels;
int m_numInputChannels;
mixxx::audio::ChannelCount m_numOutputChannels;
mixxx::audio::ChannelCount m_numInputChannels;
mixxx::audio::SampleRate m_sampleRate;
qint64 m_inputStreamStartTimeUs;
qint64 m_inputStreamFramesWritten;
Expand Down
7 changes: 3 additions & 4 deletions src/engine/sidechain/enginesidechain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,10 @@ void EngineSideChain::receiveBuffer(const AudioInput& input,
void EngineSideChain::writeSamples(const CSAMPLE* pBuffer, int iFrames) {
Trace sidechain("EngineSideChain::writeSamples");
// TODO: remove assumption of stereo buffer
constexpr int kChannels = 2;
const int iSamples = iFrames * kChannels;
int samples_written = m_sampleFifo.write(pBuffer, iSamples);
const int numSamples = iFrames * mixxx::kEngineChannelCount;
const int numSamplesWritten = m_sampleFifo.write(pBuffer, numSamples);

if (samples_written != iSamples) {
if (numSamplesWritten != numSamples) {
Counter("EngineSideChain::writeSamples buffer overrun").increment();
}

Expand Down
7 changes: 3 additions & 4 deletions src/engine/sidechain/networkoutputstreamworker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ const mixxx::Logger kLogger("NetworkStreamWorker");
} // namespace

NetworkOutputStreamWorker::NetworkOutputStreamWorker()
: m_numOutputChannels(0),
m_workerState(NETWORKSTREAMWORKER_STATE_NEW),
: m_workerState(NETWORKSTREAMWORKER_STATE_NEW),
m_functionCode(0),
m_runCount(0),
m_streamStartTimeUs(-1),
Expand All @@ -31,7 +30,7 @@ QSharedPointer<FIFO<CSAMPLE>> NetworkOutputStreamWorker::getOutputFifo() {
}

void NetworkOutputStreamWorker::startStream(
mixxx::audio::SampleRate sampleRate, int numOutputChannels) {
mixxx::audio::SampleRate sampleRate, mixxx::audio::ChannelCount numOutputChannels) {
m_sampleRate = sampleRate;
m_numOutputChannels = numOutputChannels;

Expand All @@ -41,7 +40,7 @@ void NetworkOutputStreamWorker::startStream(

void NetworkOutputStreamWorker::stopStream() {
m_sampleRate = mixxx::audio::SampleRate();
m_numOutputChannels = 0;
m_numOutputChannels = mixxx::audio::ChannelCount();

m_streamStartTimeUs = -1;
}
Expand Down
5 changes: 3 additions & 2 deletions src/engine/sidechain/networkoutputstreamworker.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ class NetworkOutputStreamWorker {
virtual void setOutputFifo(QSharedPointer<FIFO<CSAMPLE>> pOutputFifo);
virtual QSharedPointer<FIFO<CSAMPLE>> getOutputFifo();

void startStream(mixxx::audio::SampleRate sampleRate, int numOutputChannels);
void startStream(mixxx::audio::SampleRate sampleRate,
mixxx::audio::ChannelCount numOutputChannels);
void stopStream();

virtual bool threadWaiting();
Expand Down Expand Up @@ -85,7 +86,7 @@ class NetworkOutputStreamWorker {

private:
mixxx::audio::SampleRate m_sampleRate;
int m_numOutputChannels;
mixxx::audio::ChannelCount m_numOutputChannels;

int m_workerState;
int m_functionCode;
Expand Down
6 changes: 5 additions & 1 deletion src/mixer/auxiliary.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "mixer/auxiliary.h"

#include "audio/types.h"
#include "control/controlproxy.h"
#include "engine/channels/engineaux.h"
#include "engine/enginemaster.h"
Expand All @@ -17,7 +18,10 @@ Auxiliary::Auxiliary(PlayerManager* pParent,
ChannelHandleAndGroup channelGroup = pEngine->registerChannelGroup(group);
EngineAux* pAuxiliary = new EngineAux(channelGroup, pEffectsManager);
pEngine->addChannel(pAuxiliary);
AudioInput auxInput = AudioInput(AudioPath::AUXILIARY, 0, 2, index);
AudioInput auxInput = AudioInput(AudioPath::AUXILIARY,
0,
mixxx::audio::ChannelCount::stereo(),
index);
pSoundManager->registerInput(auxInput, pAuxiliary);

m_pInputConfigured = make_parented<ControlProxy>(group, "input_configured", this);
Expand Down
6 changes: 5 additions & 1 deletion src/mixer/microphone.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "mixer/microphone.h"

#include "audio/types.h"
#include "control/controlproxy.h"
#include "engine/channels/enginemicrophone.h"
#include "engine/enginemaster.h"
Expand All @@ -18,7 +19,10 @@ Microphone::Microphone(PlayerManager* pParent,
EngineMicrophone* pMicrophone =
new EngineMicrophone(channelGroup, pEffectsManager);
pEngine->addChannel(pMicrophone);
AudioInput micInput = AudioInput(AudioPath::MICROPHONE, 0, 2, index);
AudioInput micInput = AudioInput(AudioPath::MICROPHONE,
0,
mixxx::audio::ChannelCount::stereo(),
index);
pSoundManager->registerInput(micInput, pMicrophone);

m_pInputConfigured = make_parented<ControlProxy>(group, "input_configured", this);
Expand Down
14 changes: 11 additions & 3 deletions src/mixer/playermanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <QRegularExpression>

#include "audio/types.h"
#include "control/controlobject.h"
#include "effects/effectsmanager.h"
#include "engine/channels/enginedeck.h"
Expand Down Expand Up @@ -428,12 +429,19 @@ void PlayerManager::addDeckInner() {

// Register the deck output with SoundManager.
m_pSoundManager->registerOutput(
AudioOutput(AudioOutput::DECK, 0, 2, deckIndex), m_pEngine);
AudioOutput(AudioOutput::DECK,
0,
mixxx::audio::ChannelCount::stereo(),
deckIndex),
m_pEngine);

// Register vinyl input signal with deck for passthrough support.
EngineDeck* pEngineDeck = pDeck->getEngineDeck();
m_pSoundManager->registerInput(
AudioInput(AudioInput::VINYLCONTROL, 0, 2, deckIndex), pEngineDeck);
m_pSoundManager->registerInput(AudioInput(AudioInput::VINYLCONTROL,
0,
mixxx::audio::ChannelCount::stereo(),
deckIndex),
pEngineDeck);

// Setup equalizer and QuickEffect chain for this deck.
m_pEffectsManager->addDeck(handleGroup);
Expand Down
13 changes: 6 additions & 7 deletions src/preferences/dialog/dlgprefsounditem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void DlgPrefSoundItem::refreshDevices(const QList<SoundDevicePointer>& devices)
void DlgPrefSoundItem::deviceChanged(int index) {
channelComboBox->clear();
SoundDeviceId selection = deviceComboBox->itemData(index).value<SoundDeviceId>();
unsigned int numChannels = 0;
mixxx::audio::ChannelCount numChannels;
if (selection == SoundDeviceId()) {
goto emitAndReturn;
} else {
Expand All @@ -93,12 +93,12 @@ void DlgPrefSoundItem::deviceChanged(int index) {
}
}
}
if (numChannels == 0) {
if (!numChannels.isValid()) {
goto emitAndReturn;
} else {
unsigned char minChannelsForType =
mixxx::audio::ChannelCount minChannelsForType =
AudioPath::minChannelsForType(m_type);
unsigned char maxChannelsForType =
mixxx::audio::ChannelCount maxChannelsForType =
AudioPath::maxChannelsForType(m_type);

// Count down from the max so that stereo channels are first.
Expand Down Expand Up @@ -185,8 +185,7 @@ void DlgPrefSoundItem::writePath(SoundManagerConfig* config) const {
QPoint channelData = channelComboBox->itemData(
channelComboBox->currentIndex()).toPoint();
int channelBase = channelData.x();
int channelCount = channelData.y();

const auto channelCount = mixxx::audio::ChannelCount(channelData.y());

if (m_isInput) {
config->addInput(
Expand Down Expand Up @@ -282,7 +281,7 @@ void DlgPrefSoundItem::setChannel(unsigned int channelBase,
* Checks that a given device can act as a source/input for our type.
*/
int DlgPrefSoundItem::hasSufficientChannels(const SoundDevice& device) const {
unsigned char needed(AudioPath::minChannelsForType(m_type));
const auto needed = AudioPath::minChannelsForType(m_type);

if (m_isInput) {
return device.getNumInputChannels() >= needed;
Expand Down
12 changes: 6 additions & 6 deletions src/soundio/sounddevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ SoundDevice::SoundDevice(UserSettingsPointer config, SoundManager* sm)
: m_pConfig(config),
m_pSoundManager(sm),
m_strDisplayName("Unknown Soundcard"),
m_iNumOutputChannels(2),
m_iNumInputChannels(2),
m_numOutputChannels(mixxx::audio::ChannelCount::stereo()),
m_numInputChannels(mixxx::audio::ChannelCount::stereo()),
m_sampleRate(SoundManagerConfig::kMixxxDefaultSampleRate),
m_hostAPI("Unknown API"),
m_configFramesPerBuffer(0) {
}

int SoundDevice::getNumInputChannels() const {
return m_iNumInputChannels;
mixxx::audio::ChannelCount SoundDevice::getNumInputChannels() const {
return m_numInputChannels;
}

int SoundDevice::getNumOutputChannels() const {
return m_iNumOutputChannels;
mixxx::audio::ChannelCount SoundDevice::getNumOutputChannels() const {
return m_numOutputChannels;
}

void SoundDevice::setSampleRate(mixxx::audio::SampleRate sampleRate) {
Expand Down
8 changes: 4 additions & 4 deletions src/soundio/sounddevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class SoundDevice {
virtual void writeProcess(SINT framesPerBuffer) = 0;
virtual QString getError() const = 0;
virtual mixxx::audio::SampleRate getDefaultSampleRate() const = 0;
int getNumOutputChannels() const;
int getNumInputChannels() const;
mixxx::audio::ChannelCount getNumOutputChannels() const;
mixxx::audio::ChannelCount getNumInputChannels() const;
SoundDeviceStatus addOutput(const AudioOutputBuffer& out);
SoundDeviceStatus addInput(const AudioInputBuffer& in);
const QList<AudioInputBuffer>& inputs() const {
Expand Down Expand Up @@ -78,9 +78,9 @@ class SoundDevice {
// The name of the soundcard, as displayed to the user
QString m_strDisplayName;
// The number of output channels that the soundcard has
int m_iNumOutputChannels;
mixxx::audio::ChannelCount m_numOutputChannels;
// The number of input channels that the soundcard has
int m_iNumInputChannels;
mixxx::audio::ChannelCount m_numInputChannels;
// The current samplerate for the sound device.
mixxx::audio::SampleRate m_sampleRate;
// The name of the audio API used by this device.
Expand Down
Loading

0 comments on commit 1fce230

Please sign in to comment.