forked from jamulussoftware/jamulus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsound.h
129 lines (107 loc) · 4.98 KB
/
sound.h
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/******************************************************************************\
* Copyright (c) 2004-2020
*
* Author(s):
* Volker Fischer
*
******************************************************************************
*
* 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.
*
* This program 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 General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
\******************************************************************************/
#pragma once
#include <QMutex>
#include <QMessageBox>
#include "../src/util.h"
#include "../src/global.h"
#include "../src/soundbase.h"
// copy the ASIO SDK in the llcon/windows directory: "llcon/windows/ASIOSDK2" to
// get it work
#include "asiosys.h"
#include "asio.h"
#include "asiodrivers.h"
/* Definitions ****************************************************************/
// stereo for input and output
#define NUM_IN_OUT_CHANNELS 2
/* Classes ********************************************************************/
class CSound : public CSoundBase
{
Q_OBJECT
public:
CSound ( void ( *fpNewCallback ) ( CVector<int16_t>& psData, void* arg ), void* arg, const QString& strMIDISetup, const bool, const QString& );
virtual ~CSound() { UnloadCurrentDriver(); }
virtual int Init ( const int iNewPrefMonoBufferSize );
virtual void Start();
virtual void Stop();
virtual void OpenDriverSetup() { ASIOControlPanel(); }
// channel selection
virtual int GetNumInputChannels() { return static_cast<int> ( lNumInChanPlusAddChan ); }
virtual QString GetInputChannelName ( const int iDiD ) { return channelInputName[iDiD]; }
virtual void SetLeftInputChannel ( const int iNewChan );
virtual void SetRightInputChannel ( const int iNewChan );
virtual int GetLeftInputChannel() { return vSelectedInputChannels[0]; }
virtual int GetRightInputChannel() { return vSelectedInputChannels[1]; }
virtual int GetNumOutputChannels() { return static_cast<int> ( lNumOutChan ); }
virtual QString GetOutputChannelName ( const int iDiD ) { return channelInfosOutput[iDiD].name; }
virtual void SetLeftOutputChannel ( const int iNewChan );
virtual void SetRightOutputChannel ( const int iNewChan );
virtual int GetLeftOutputChannel() { return vSelectedOutputChannels[0]; }
virtual int GetRightOutputChannel() { return vSelectedOutputChannels[1]; }
virtual float GetInOutLatencyMs() { return fInOutLatencyMs; }
protected:
virtual QString LoadAndInitializeDriver ( QString strDriverName, bool bOpenDriverSetup );
virtual void UnloadCurrentDriver();
int GetActualBufferSize ( const int iDesiredBufferSizeMono );
QString CheckDeviceCapabilities();
bool CheckSampleTypeSupported ( const ASIOSampleType SamType );
bool CheckSampleTypeSupportedForCHMixing ( const ASIOSampleType SamType );
void ResetChannelMapping();
int iASIOBufferSizeMono;
int iASIOBufferSizeStereo;
long lNumInChan;
long lNumInChanPlusAddChan; // includes additional "added" channels
long lNumOutChan;
float fInOutLatencyMs;
CVector<int> vSelectedInputChannels;
CVector<int> vSelectedOutputChannels;
CVector<int16_t> vecsMultChanAudioSndCrd;
QMutex ASIOMutex;
// utility functions
static int16_t Flip16Bits ( const int16_t iIn );
static int32_t Flip32Bits ( const int32_t iIn );
static int64_t Flip64Bits ( const int64_t iIn );
// audio hardware buffer info
struct sHWBufferInfo
{
long lMinSize;
long lMaxSize;
long lPreferredSize;
long lGranularity;
} HWBufferInfo;
// ASIO stuff
ASIODriverInfo driverInfo;
ASIOBufferInfo bufferInfos[2 * MAX_NUM_IN_OUT_CHANNELS]; // for input and output buffers -> "2 *"
ASIOChannelInfo channelInfosInput[MAX_NUM_IN_OUT_CHANNELS];
QString channelInputName[MAX_NUM_IN_OUT_CHANNELS];
ASIOChannelInfo channelInfosOutput[MAX_NUM_IN_OUT_CHANNELS];
bool bASIOPostOutput;
ASIOCallbacks asioCallbacks;
// callbacks
static void bufferSwitch ( long index, ASIOBool processNow );
static ASIOTime* bufferSwitchTimeInfo ( ASIOTime* timeInfo, long index, ASIOBool processNow );
static void sampleRateChanged ( ASIOSampleRate ) {}
static long asioMessages ( long selector, long value, void* message, double* opt );
char* cDriverNames[MAX_NUMBER_SOUND_CARDS];
};