integrated the essential changes from emlynmac from https://github.com/corrados/jamulus/pull/44
This commit is contained in:
parent
854d5a128f
commit
d0c0a4722a
3 changed files with 60 additions and 14 deletions
|
@ -254,6 +254,37 @@ void CSound::GetAudioDeviceInfos ( const AudioDeviceID DeviceID,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CSound::CountChannels ( AudioDeviceID devID,
|
||||||
|
bool isInput )
|
||||||
|
{
|
||||||
|
OSStatus err;
|
||||||
|
UInt32 propSize;
|
||||||
|
int result = 0;
|
||||||
|
|
||||||
|
AudioObjectPropertyScope theScope = isInput ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
|
||||||
|
|
||||||
|
AudioObjectPropertyAddress theAddress = { kAudioDevicePropertyStreamConfiguration,
|
||||||
|
theScope,
|
||||||
|
0 };
|
||||||
|
|
||||||
|
AudioObjectGetPropertyDataSize ( devID, &theAddress, 0, NULL, &propSize );
|
||||||
|
|
||||||
|
AudioBufferList *buflist = (AudioBufferList*) malloc ( propSize );
|
||||||
|
|
||||||
|
err = AudioObjectGetPropertyData ( devID, &theAddress, 0, NULL, &propSize, buflist );
|
||||||
|
|
||||||
|
if ( !err )
|
||||||
|
{
|
||||||
|
for ( UInt32 i = 0; i < buflist->mNumberBuffers; ++i )
|
||||||
|
{
|
||||||
|
result += buflist->mBuffers[i].mNumberChannels;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free ( buflist );
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
QString CSound::LoadAndInitializeDriver ( int iDriverIdx )
|
QString CSound::LoadAndInitializeDriver ( int iDriverIdx )
|
||||||
{
|
{
|
||||||
// check device capabilities if it fullfills our requirements
|
// check device capabilities if it fullfills our requirements
|
||||||
|
@ -415,9 +446,6 @@ QString CSound::CheckDeviceCapabilities ( const int iDriverIdx )
|
||||||
"not compatible with this software." );
|
"not compatible with this software." );
|
||||||
}
|
}
|
||||||
|
|
||||||
// store the input number of channels for this stream
|
|
||||||
iNumInChan = CurDevStreamFormat.mChannelsPerFrame;
|
|
||||||
|
|
||||||
// check the output
|
// check the output
|
||||||
AudioObjectGetPropertyData ( outputStreamID,
|
AudioObjectGetPropertyData ( outputStreamID,
|
||||||
&stPropertyAddress,
|
&stPropertyAddress,
|
||||||
|
@ -436,8 +464,9 @@ QString CSound::CheckDeviceCapabilities ( const int iDriverIdx )
|
||||||
"not compatible with this software." );
|
"not compatible with this software." );
|
||||||
}
|
}
|
||||||
|
|
||||||
// store the output number of channels for this stream
|
// store the input and out number of channels for this device
|
||||||
iNumOutChan = CurDevStreamFormat.mChannelsPerFrame;
|
iNumInChan = CountChannels ( audioInputDevice[iDriverIdx], true );
|
||||||
|
iNumOutChan = CountChannels ( audioInputDevice[iDriverIdx], false );
|
||||||
|
|
||||||
// clip the number of input/output channels to our allowed maximum
|
// clip the number of input/output channels to our allowed maximum
|
||||||
if ( iNumInChan > MAX_NUM_IN_OUT_CHANNELS )
|
if ( iNumInChan > MAX_NUM_IN_OUT_CHANNELS )
|
||||||
|
@ -473,7 +502,7 @@ QString CSound::CheckDeviceCapabilities ( const int iDriverIdx )
|
||||||
// add the "[n]:" at the beginning as is in the Audio-Midi-Setup
|
// add the "[n]:" at the beginning as is in the Audio-Midi-Setup
|
||||||
if ( !bConvOK || ( iPropertySize == 0 ) )
|
if ( !bConvOK || ( iPropertySize == 0 ) )
|
||||||
{
|
{
|
||||||
// use a defalut name in case there was an error or the name is empty
|
// use a default name in case there was an error or the name is empty
|
||||||
sChannelNamesInput[iCurInCH] =
|
sChannelNamesInput[iCurInCH] =
|
||||||
QString ( "%1: Channel %1" ).arg ( iCurInCH + 1 );
|
QString ( "%1: Channel %1" ).arg ( iCurInCH + 1 );
|
||||||
}
|
}
|
||||||
|
@ -783,10 +812,28 @@ OSStatus CSound::callbackIO ( AudioDeviceID inDevice,
|
||||||
|
|
||||||
if ( inDevice == pSound->CurrentAudioInputDeviceID )
|
if ( inDevice == pSound->CurrentAudioInputDeviceID )
|
||||||
{
|
{
|
||||||
// check size (float32 has four bytes)
|
// we should have a matching number of buffers to channels
|
||||||
if ( inInputData->mBuffers[0].mDataByteSize ==
|
if ( inInputData->mNumberBuffers == (UInt32) iNumInChan &&
|
||||||
static_cast<UInt32> ( iCoreAudioBufferSizeMono * iNumInChan * 4 ) )
|
inInputData->mBuffers[0].mDataByteSize == static_cast<UInt32> ( iCoreAudioBufferSizeMono * 4 ) )
|
||||||
{
|
{
|
||||||
|
// One buffer per channel mode
|
||||||
|
AudioBuffer left = inInputData->mBuffers[iSelInputLeftChannel];
|
||||||
|
Float32* pLeftData = static_cast<Float32*> ( left.mData );
|
||||||
|
AudioBuffer right = inInputData->mBuffers[iSelInputRightChannel];
|
||||||
|
Float32* pRightData = static_cast<Float32*> ( right.mData );
|
||||||
|
|
||||||
|
// copy input data
|
||||||
|
for ( int i = 0; i < iCoreAudioBufferSizeMono; i++ )
|
||||||
|
{
|
||||||
|
// left
|
||||||
|
pSound->vecsTmpAudioSndCrdStereo[2 * i] = (short) ( pLeftData[i] * _MAXSHORT );
|
||||||
|
|
||||||
|
// right
|
||||||
|
pSound->vecsTmpAudioSndCrdStereo[2 * i + 1] = (short) ( pRightData[i] * _MAXSHORT );
|
||||||
|
}
|
||||||
|
} else if ( inInputData->mBuffers[0].mDataByteSize == static_cast<UInt32> ( iCoreAudioBufferSizeMono * iNumInChan * 4 ) )
|
||||||
|
{
|
||||||
|
// One buffer with all the channels in
|
||||||
// get a pointer to the input data of the correct type
|
// get a pointer to the input data of the correct type
|
||||||
Float32* pInData = static_cast<Float32*> ( inInputData->mBuffers[0].mData );
|
Float32* pInData = static_cast<Float32*> ( inInputData->mBuffers[0].mData );
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <CoreAudio/CoreAudio.h>
|
#include <CoreAudio/CoreAudio.h>
|
||||||
|
#include <AudioToolbox/AudioToolbox.h>
|
||||||
#include <CoreMIDI/CoreMIDI.h>
|
#include <CoreMIDI/CoreMIDI.h>
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include "soundbase.h"
|
#include "soundbase.h"
|
||||||
|
@ -76,7 +77,9 @@ public:
|
||||||
protected:
|
protected:
|
||||||
virtual QString LoadAndInitializeDriver ( int iIdx );
|
virtual QString LoadAndInitializeDriver ( int iIdx );
|
||||||
|
|
||||||
QString CheckDeviceCapabilities ( const int iDriverIdx );
|
QString CheckDeviceCapabilities ( const int iDriverIdx );
|
||||||
|
OSStatus CountChannels ( AudioDeviceID devID,
|
||||||
|
bool isInput );
|
||||||
|
|
||||||
UInt32 SetBufferSize ( AudioDeviceID& audioDeviceID,
|
UInt32 SetBufferSize ( AudioDeviceID& audioDeviceID,
|
||||||
const bool bIsInput,
|
const bool bIsInput,
|
||||||
|
|
|
@ -60,8 +60,4 @@ protected:
|
||||||
CSvgHistoryGraph SvgHistoryGraph;
|
CSvgHistoryGraph SvgHistoryGraph;
|
||||||
bool bDoLogging;
|
bool bDoLogging;
|
||||||
QFile File;
|
QFile File;
|
||||||
|
|
||||||
private:
|
|
||||||
int iHistNumItems;
|
|
||||||
int iHistMaxDays;
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue