blob: fa654b5205065231174dec2c09aaac39bc994c47 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
/***************************************************************************
enginesidechain.h
-------------------
copyright : (C) 2008 Albert Santoni
email : gamegod \a\t users.sf.net
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#pragma once
#include <QThread>
#include <QMutex>
#include <QWaitCondition>
#include <QList>
#include "preferences/usersettings.h"
#include "engine/sidechain/sidechainworker.h"
#include "soundio/soundmanagerutil.h"
#include "util/fifo.h"
#include "util/mutex.h"
#include "util/types.h"
class EngineSideChain : public QThread, public AudioDestination {
Q_OBJECT
public:
EngineSideChain(UserSettingsPointer pConfig, CSAMPLE* sidechainMix);
~EngineSideChain() override;
// Not thread-safe, wait-free. Submit buffer of samples to the sidechain for
// processing. Should only be called from a single writer thread (typically
// the engine callback).
void writeSamples(const CSAMPLE* pBuffer, int iFrames);
// Thin wrapper around writeSamples that is used by SoundManager when receiving
// from a sound card input instead of the engine
void receiveBuffer(AudioInput input,
const CSAMPLE* pBuffer,
unsigned int iFrames) override;
// Thread-safe, blocking.
void addSideChainWorker(SideChainWorker* pWorker);
static const int SIDECHAIN_BUFFER_SIZE = 65536;
private:
void run() override;
UserSettingsPointer m_pConfig;
// Indicates that the thread should exit.
volatile bool m_bStopThread;
FIFO<CSAMPLE> m_sampleFifo;
CSAMPLE* m_pWorkBuffer;
CSAMPLE* m_pSidechainMix;
// Provides thread safety around the wait condition below.
QMutex m_waitLock;
// Allows sleeping until we have samples to process.
QWaitCondition m_waitForSamples;
// Sidechain workers registered with EngineSideChain.
MMutex m_workerLock;
QList<SideChainWorker*> m_workers GUARDED_BY(m_workerLock);
};
|