jamulus/mac/sound.h

126 lines
5.2 KiB
C++
Executable file

/******************************************************************************\
* 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.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
\******************************************************************************/
#pragma once
#include <CoreAudio/CoreAudio.h>
#include <AudioToolbox/AudioToolbox.h>
#include <CoreMIDI/CoreMIDI.h>
#include <QMutex>
#include "soundbase.h"
#include "global.h"
/* Classes ********************************************************************/
class CSound : public CSoundBase
{
public:
CSound ( void (*fpNewProcessCallback) ( CVector<short>& psData, void* arg ),
void* arg,
const int iCtrlMIDIChannel,
const bool bNoAutoJackConnect,
const QString& strJackClientName );
virtual int Init ( const int iNewPrefMonoBufferSize );
virtual void Start();
virtual void Stop();
// channel selection
virtual int GetNumInputChannels() { return iNumInChan; }
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; }
// these variables should be protected but cannot since we want
// to access them from the callback function
CVector<short> vecsTmpAudioSndCrdStereo;
int iCoreAudioBufferSizeMono;
int iCoreAudioBufferSizeStereo;
AudioDeviceID CurrentAudioInputDeviceID;
AudioDeviceID CurrentAudioOutputDeviceID;
int iNumInChan;
int iNumOutChan;
int iSelInputLeftChannel;
int iSelInputRightChannel;
int iSelOutputLeftChannel;
int iSelOutputRightChannel;
protected:
virtual QString LoadAndInitializeDriver ( int iIdx, bool );
QString CheckDeviceCapabilities ( const int iDriverIdx );
int CountChannels ( AudioDeviceID devID,
const int iNumChanPerFrame,
bool isInput );
UInt32 SetBufferSize ( AudioDeviceID& audioDeviceID,
const bool bIsInput,
UInt32 iPrefBufferSize );
void GetAudioDeviceInfos ( const AudioDeviceID DeviceID,
QString& strDeviceName,
bool& bIsInput,
bool& bIsOutput );
bool ConvertCFStringToQString ( const CFStringRef stringRef, QString& sOut );
// callbacks
static OSStatus deviceNotification ( AudioDeviceID,
UInt32,
const AudioObjectPropertyAddress* inAddresses,
void* inRefCon );
static OSStatus callbackIO ( AudioDeviceID inDevice,
const AudioTimeStamp*,
const AudioBufferList* inInputData,
const AudioTimeStamp*,
AudioBufferList* outOutputData,
const AudioTimeStamp*,
void* inRefCon );
static void callbackMIDI ( const MIDIPacketList* pktlist,
void* refCon,
void* );
AudioDeviceID audioInputDevice[MAX_NUMBER_SOUND_CARDS];
AudioDeviceID audioOutputDevice[MAX_NUMBER_SOUND_CARDS];
AudioDeviceIOProcID audioInputProcID;
AudioDeviceIOProcID audioOutputProcID;
MIDIPortRef midiInPortRef;
QString sChannelNamesInput[MAX_NUM_IN_OUT_CHANNELS];
QString sChannelNamesOutput[MAX_NUM_IN_OUT_CHANNELS];
QMutex Mutex;
};