2014-01-05 17:52:38 +01:00
|
|
|
/******************************************************************************\
|
2020-01-01 15:41:43 +01:00
|
|
|
* Copyright (c) 2004-2020
|
2014-01-05 17:52:38 +01:00
|
|
|
*
|
|
|
|
* 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.,
|
|
|
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
\******************************************************************************/
|
|
|
|
|
2019-07-09 08:52:38 +02:00
|
|
|
#pragma once
|
2014-01-05 17:52:38 +01:00
|
|
|
|
2015-11-17 18:42:28 +01:00
|
|
|
#include <CoreAudio/CoreAudio.h>
|
2020-04-10 20:29:14 +02:00
|
|
|
#include <AudioToolbox/AudioToolbox.h>
|
2019-01-12 13:45:08 +01:00
|
|
|
#include <CoreMIDI/CoreMIDI.h>
|
2014-01-05 17:52:38 +01:00
|
|
|
#include <QMutex>
|
|
|
|
#include "soundbase.h"
|
|
|
|
#include "global.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* Classes ********************************************************************/
|
|
|
|
class CSound : public CSoundBase
|
|
|
|
{
|
|
|
|
public:
|
2020-04-30 22:03:01 +02:00
|
|
|
CSound ( void (*fpNewProcessCallback) ( CVector<short>& psData, void* arg ),
|
|
|
|
void* arg,
|
|
|
|
const int iCtrlMIDIChannel,
|
2020-04-30 22:18:11 +02:00
|
|
|
const bool ,
|
|
|
|
const QString& );
|
2014-01-05 17:52:38 +01:00
|
|
|
|
|
|
|
virtual int Init ( const int iNewPrefMonoBufferSize );
|
|
|
|
virtual void Start();
|
|
|
|
virtual void Stop();
|
|
|
|
|
2015-11-19 20:36:47 +01:00
|
|
|
// channel selection
|
2020-05-01 15:57:14 +02:00
|
|
|
virtual int GetNumInputChannels() { return iNumInChanPlusAddChan; }
|
2015-11-19 20:36:47 +01:00
|
|
|
virtual QString GetInputChannelName ( const int iDiD ) { return sChannelNamesInput[iDiD]; }
|
|
|
|
virtual void SetLeftInputChannel ( const int iNewChan );
|
|
|
|
virtual void SetRightInputChannel ( const int iNewChan );
|
|
|
|
virtual int GetLeftInputChannel() { return iSelInputLeftChannel; }
|
|
|
|
virtual int GetRightInputChannel() { return iSelInputRightChannel; }
|
|
|
|
|
|
|
|
virtual int GetNumOutputChannels() { return iNumOutChan; }
|
|
|
|
virtual QString GetOutputChannelName ( const int iDiD ) { return sChannelNamesOutput[iDiD]; }
|
|
|
|
virtual void SetLeftOutputChannel ( const int iNewChan );
|
|
|
|
virtual void SetRightOutputChannel ( const int iNewChan );
|
|
|
|
virtual int GetLeftOutputChannel() { return iSelOutputLeftChannel; }
|
|
|
|
virtual int GetRightOutputChannel() { return iSelOutputRightChannel; }
|
|
|
|
|
2014-01-05 17:52:38 +01:00
|
|
|
// these variables should be protected but cannot since we want
|
|
|
|
// to access them from the callback function
|
|
|
|
CVector<short> vecsTmpAudioSndCrdStereo;
|
|
|
|
int iCoreAudioBufferSizeMono;
|
|
|
|
int iCoreAudioBufferSizeStereo;
|
2015-11-15 20:21:24 +01:00
|
|
|
AudioDeviceID CurrentAudioInputDeviceID;
|
2015-11-19 20:36:47 +01:00
|
|
|
AudioDeviceID CurrentAudioOutputDeviceID;
|
|
|
|
int iNumInChan;
|
2020-05-01 15:57:14 +02:00
|
|
|
int iNumInChanPlusAddChan; // includes additional "added" channels
|
2015-11-19 20:36:47 +01:00
|
|
|
int iNumOutChan;
|
|
|
|
int iSelInputLeftChannel;
|
|
|
|
int iSelInputRightChannel;
|
|
|
|
int iSelOutputLeftChannel;
|
|
|
|
int iSelOutputRightChannel;
|
2020-05-02 17:15:18 +02:00
|
|
|
int iSelInBufferLeft;
|
|
|
|
int iSelInBufferRight;
|
|
|
|
int iSelInInterlChLeft;
|
|
|
|
int iSelInInterlChRight;
|
|
|
|
int iSelAddInBufferLeft;
|
|
|
|
int iSelAddInBufferRight;
|
|
|
|
int iSelAddInInterlChLeft;
|
|
|
|
int iSelAddInInterlChRight;
|
|
|
|
int iSelOutBufferLeft;
|
|
|
|
int iSelOutBufferRight;
|
|
|
|
int iSelOutInterlChLeft;
|
|
|
|
int iSelOutInterlChRight;
|
|
|
|
CVector<int> vecNumInBufChan;
|
|
|
|
CVector<int> vecNumOutBufChan;
|
2014-01-05 17:52:38 +01:00
|
|
|
|
|
|
|
protected:
|
2020-04-20 19:57:21 +02:00
|
|
|
virtual QString LoadAndInitializeDriver ( int iIdx, bool );
|
2014-01-05 17:52:38 +01:00
|
|
|
|
2020-05-02 17:15:18 +02:00
|
|
|
QString CheckDeviceCapabilities ( const int iDriverIdx );
|
|
|
|
void UpdateChSelection();
|
|
|
|
|
2020-04-15 16:11:01 +02:00
|
|
|
int CountChannels ( AudioDeviceID devID,
|
|
|
|
bool isInput );
|
2014-01-05 17:52:38 +01:00
|
|
|
|
|
|
|
UInt32 SetBufferSize ( AudioDeviceID& audioDeviceID,
|
|
|
|
const bool bIsInput,
|
|
|
|
UInt32 iPrefBufferSize );
|
|
|
|
|
|
|
|
void GetAudioDeviceInfos ( const AudioDeviceID DeviceID,
|
|
|
|
QString& strDeviceName,
|
|
|
|
bool& bIsInput,
|
|
|
|
bool& bIsOutput );
|
|
|
|
|
2015-11-19 20:36:47 +01:00
|
|
|
bool ConvertCFStringToQString ( const CFStringRef stringRef, QString& sOut );
|
|
|
|
|
2014-01-05 17:52:38 +01:00
|
|
|
// callbacks
|
|
|
|
static OSStatus deviceNotification ( AudioDeviceID,
|
|
|
|
UInt32,
|
2015-11-13 23:27:25 +01:00
|
|
|
const AudioObjectPropertyAddress* inAddresses,
|
|
|
|
void* inRefCon );
|
2014-01-05 17:52:38 +01:00
|
|
|
|
2015-11-15 20:21:24 +01:00
|
|
|
static OSStatus callbackIO ( AudioDeviceID inDevice,
|
|
|
|
const AudioTimeStamp*,
|
|
|
|
const AudioBufferList* inInputData,
|
|
|
|
const AudioTimeStamp*,
|
|
|
|
AudioBufferList* outOutputData,
|
|
|
|
const AudioTimeStamp*,
|
|
|
|
void* inRefCon );
|
2014-01-05 17:52:38 +01:00
|
|
|
|
2019-01-12 15:32:41 +01:00
|
|
|
static void callbackMIDI ( const MIDIPacketList* pktlist,
|
|
|
|
void* refCon,
|
|
|
|
void* );
|
|
|
|
|
2015-11-17 18:42:28 +01:00
|
|
|
AudioDeviceID audioInputDevice[MAX_NUMBER_SOUND_CARDS];
|
|
|
|
AudioDeviceID audioOutputDevice[MAX_NUMBER_SOUND_CARDS];
|
|
|
|
AudioDeviceIOProcID audioInputProcID;
|
|
|
|
AudioDeviceIOProcID audioOutputProcID;
|
2014-01-05 17:52:38 +01:00
|
|
|
|
2019-01-12 15:32:41 +01:00
|
|
|
MIDIPortRef midiInPortRef;
|
|
|
|
|
2015-11-19 20:36:47 +01:00
|
|
|
QString sChannelNamesInput[MAX_NUM_IN_OUT_CHANNELS];
|
|
|
|
QString sChannelNamesOutput[MAX_NUM_IN_OUT_CHANNELS];
|
|
|
|
|
2015-11-17 18:42:28 +01:00
|
|
|
QMutex Mutex;
|
2014-01-05 17:52:38 +01:00
|
|
|
};
|