Skip to content

Commit

Permalink
add output context
Browse files Browse the repository at this point in the history
  • Loading branch information
CrSjimo committed Jul 21, 2024
1 parent 5a43560 commit 28e8364
Show file tree
Hide file tree
Showing 9 changed files with 702 additions and 0 deletions.
66 changes: 66 additions & 0 deletions src/device/AbstractOutputContext.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/******************************************************************************
* Copyright (c) 2024 CrSjimo *
* *
* This file is part of TALCS. *
* *
* TALCS is free software: you can redistribute it and/or modify it under the *
* terms of the GNU Lesser General Public License as published by the Free *
* Software Foundation, either version 3 of the License, or (at your option) *
* any later version. *
* *
* TALCS is distributed in the hope that it will be useful, but WITHOUT ANY *
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for *
* more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with TALCS. If not, see <https://www.gnu.org/licenses/>. *
******************************************************************************/

#include "AbstractOutputContext.h"
#include "AbstractOutputContext_p.h"

#include <TalcsCore/MixerAudioSource.h>
#include <TalcsDevice/AudioSourcePlayback.h>

namespace talcs {

AbstractOutputContext::AbstractOutputContext(QObject *parent) : QObject(parent), d_ptr(new AbstractOutputContextPrivate) {
Q_D(AbstractOutputContext);
d->q_ptr = this;

d->preMixer = std::make_unique<MixerAudioSource>();
d->controlMixer = std::make_unique<MixerAudioSource>();
d->playback = std::make_unique<AudioSourcePlayback>(d->controlMixer.get(), false, false);

d->controlMixer->addSource(d->preMixer.get());
}

AbstractOutputContext::~AbstractOutputContext() = default;

AudioDevice *AbstractOutputContext::device() const {
Q_D(const AbstractOutputContext);
return d->device;
}

AudioSourcePlayback *AbstractOutputContext::playback() const {
Q_D(const AbstractOutputContext);
return d->playback.get();
}

MixerAudioSource *AbstractOutputContext::controlMixer() const {
Q_D(const AbstractOutputContext);
return d->controlMixer.get();
}

MixerAudioSource *AbstractOutputContext::preMixer() const {
Q_D(const AbstractOutputContext);
return d->preMixer.get();
}

void AbstractOutputContext::setDevice(AudioDevice *device) {
Q_D(AbstractOutputContext);
d->device = device;
emit deviceChanged();
}
}
64 changes: 64 additions & 0 deletions src/device/AbstractOutputContext.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/******************************************************************************
* Copyright (c) 2024 CrSjimo *
* *
* This file is part of TALCS. *
* *
* TALCS is free software: you can redistribute it and/or modify it under the *
* terms of the GNU Lesser General Public License as published by the Free *
* Software Foundation, either version 3 of the License, or (at your option) *
* any later version. *
* *
* TALCS is distributed in the hope that it will be useful, but WITHOUT ANY *
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for *
* more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with TALCS. If not, see <https://www.gnu.org/licenses/>. *
******************************************************************************/

#ifndef TALCS_ABSTRACTOUTPUTCONTEXT_H
#define TALCS_ABSTRACTOUTPUTCONTEXT_H

#include <QObject>

#include <TalcsDevice/TalcsDeviceGlobal.h>

namespace talcs {

class AudioDevice;
class AudioSourcePlayback;

class MixerAudioSource;

class AbstractOutputContextPrivate;

class TALCSDEVICE_EXPORT AbstractOutputContext : public QObject {
Q_OBJECT
Q_DECLARE_PRIVATE(AbstractOutputContext)
public:
~AbstractOutputContext() override;

AudioDevice *device() const;
AudioSourcePlayback *playback() const;
MixerAudioSource *controlMixer() const;
MixerAudioSource *preMixer() const;

signals:
void bufferSizeChanged(qint64 bufferSize);
void sampleRateChanged(double sampleRate);
void deviceChanged();

protected:
explicit AbstractOutputContext(QObject *parent = nullptr);

void setDevice(AudioDevice *device);

private:
QScopedPointer<AbstractOutputContextPrivate> d_ptr;

};

} // talcs

#endif //TALCS_ABSTRACTOUTPUTCONTEXT_H
40 changes: 40 additions & 0 deletions src/device/AbstractOutputContext_p.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/******************************************************************************
* Copyright (c) 2024 CrSjimo *
* *
* This file is part of TALCS. *
* *
* TALCS is free software: you can redistribute it and/or modify it under the *
* terms of the GNU Lesser General Public License as published by the Free *
* Software Foundation, either version 3 of the License, or (at your option) *
* any later version. *
* *
* TALCS is distributed in the hope that it will be useful, but WITHOUT ANY *
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for *
* more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with TALCS. If not, see <https://www.gnu.org/licenses/>. *
******************************************************************************/

#ifndef TALCS_ABSTRACTOUTPUTCONTEXT_P_H
#define TALCS_ABSTRACTOUTPUTCONTEXT_P_H

#include <memory>

#include <TalcsDevice/AbstractOutputContext.h>

namespace talcs {
class AbstractOutputContextPrivate {
Q_DECLARE_PUBLIC(AbstractOutputContext)
public:
AbstractOutputContext *q_ptr;

std::unique_ptr<MixerAudioSource> preMixer;
std::unique_ptr<MixerAudioSource> controlMixer;
std::unique_ptr<AudioSourcePlayback> playback;
AudioDevice *device = nullptr;
};
}

#endif //TALCS_ABSTRACTOUTPUTCONTEXT_P_H
Loading

0 comments on commit 28e8364

Please sign in to comment.