backport macOS AudioDevice cleanup into 5_1-new (#1735)
* Replaced Deprecated AudioDevice Functions * Fixed an oversight. I still didn’t see any issues.
This commit is contained in:
@@ -58,10 +58,15 @@ static void SetSampleRate( AudioUnit au, Float64 desiredRate )
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AudioObjectPropertyAddress RateAddr = {
|
||||||
|
kAudioDevicePropertyNominalSampleRate,
|
||||||
|
kAudioDevicePropertyScopeOutput,
|
||||||
|
kAudioObjectPropertyElementWildcard
|
||||||
|
};
|
||||||
|
|
||||||
Float64 rate = 0.0;
|
Float64 rate = 0.0;
|
||||||
size = sizeof( Float64 );
|
size = sizeof( Float64 );
|
||||||
if( (error = AudioDeviceGetProperty(OutputDevice, 0, false, kAudioDevicePropertyNominalSampleRate,
|
if( (error = AudioObjectGetPropertyData(OutputDevice, &RateAddr, 0, NULL, &size, &rate)) )
|
||||||
&size, &rate)) )
|
|
||||||
{
|
{
|
||||||
LOG->Warn( WERROR("Couldn't get the device's sample rate", error) );
|
LOG->Warn( WERROR("Couldn't get the device's sample rate", error) );
|
||||||
return;
|
return;
|
||||||
@@ -69,8 +74,13 @@ static void SetSampleRate( AudioUnit au, Float64 desiredRate )
|
|||||||
if( rate == desiredRate )
|
if( rate == desiredRate )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if( (error = AudioDeviceGetPropertyInfo(OutputDevice, 0, false, kAudioDevicePropertyAvailableNominalSampleRates,
|
AudioObjectPropertyAddress AvailableRatesAddr = {
|
||||||
&size, NULL)) )
|
kAudioDevicePropertyAvailableNominalSampleRates,
|
||||||
|
kAudioDevicePropertyScopeOutput,
|
||||||
|
kAudioObjectPropertyElementWildcard
|
||||||
|
};
|
||||||
|
|
||||||
|
if( (error = AudioObjectGetPropertyData(OutputDevice, &AvailableRatesAddr, 0, NULL, &size, NULL)) )
|
||||||
{
|
{
|
||||||
LOG->Warn( WERROR("Couldn't get available nominal sample rates info", error) );
|
LOG->Warn( WERROR("Couldn't get available nominal sample rates info", error) );
|
||||||
return;
|
return;
|
||||||
@@ -79,8 +89,7 @@ static void SetSampleRate( AudioUnit au, Float64 desiredRate )
|
|||||||
const int num = size/sizeof(AudioValueRange);
|
const int num = size/sizeof(AudioValueRange);
|
||||||
AudioValueRange *ranges = new AudioValueRange[num];
|
AudioValueRange *ranges = new AudioValueRange[num];
|
||||||
|
|
||||||
if( (error = AudioDeviceGetProperty(OutputDevice, 0, false, kAudioDevicePropertyAvailableNominalSampleRates,
|
if( (error = AudioObjectGetPropertyData(OutputDevice, &AvailableRatesAddr, 0, NULL, &size, ranges)) )
|
||||||
&size, ranges)) )
|
|
||||||
{
|
{
|
||||||
LOG->Warn( WERROR("Couldn't get available nominal sample rates", error) );
|
LOG->Warn( WERROR("Couldn't get available nominal sample rates", error) );
|
||||||
delete[] ranges;
|
delete[] ranges;
|
||||||
@@ -104,8 +113,7 @@ static void SetSampleRate( AudioUnit au, Float64 desiredRate )
|
|||||||
if( bestRate == 0.0 )
|
if( bestRate == 0.0 )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if( (error = AudioDeviceSetProperty(OutputDevice, NULL, 0, false, kAudioDevicePropertyNominalSampleRate,
|
if( (error = AudioObjectSetPropertyData(OutputDevice, &RateAddr, 0, NULL, sizeof(Float64), &bestRate)) )
|
||||||
sizeof(Float64), &bestRate)) )
|
|
||||||
{
|
{
|
||||||
LOG->Warn( WERROR("Couldn't set the device's sample rate", error) );
|
LOG->Warn( WERROR("Couldn't set the device's sample rate", error) );
|
||||||
}
|
}
|
||||||
@@ -240,15 +248,27 @@ float RageSoundDriver_AU::GetPlayLatency() const
|
|||||||
return 0.0f;
|
return 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AudioObjectPropertyAddress RateAddr = {
|
||||||
|
kAudioDevicePropertyNominalSampleRate,
|
||||||
|
kAudioDevicePropertyScopeOutput,
|
||||||
|
kAudioObjectPropertyElementWildcard
|
||||||
|
};
|
||||||
|
|
||||||
size = sizeof( Float64 );
|
size = sizeof( Float64 );
|
||||||
if( (error = AudioDeviceGetProperty(OutputDevice, 0, false, kAudioDevicePropertyNominalSampleRate, &size, &sampleRate)) )
|
if( (error = AudioObjectGetPropertyData(OutputDevice, &RateAddr, 0, NULL, &size, &sampleRate)) )
|
||||||
{
|
{
|
||||||
LOG->Warn( WERROR("Couldn't get the device sample rate", error) );
|
LOG->Warn( WERROR("Couldn't get the device sample rate", error) );
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AudioObjectPropertyAddress BufferAddr = {
|
||||||
|
kAudioDevicePropertyBufferFrameSize,
|
||||||
|
kAudioDevicePropertyScopeOutput,
|
||||||
|
kAudioObjectPropertyElementWildcard
|
||||||
|
};
|
||||||
|
|
||||||
size = sizeof( UInt32 );
|
size = sizeof( UInt32 );
|
||||||
if( (error = AudioDeviceGetProperty(OutputDevice, 0, false, kAudioDevicePropertyBufferFrameSize, &size, &bufferSize)) )
|
if( (error = AudioObjectGetPropertyData(OutputDevice, &BufferAddr, 0, NULL, &size, &bufferSize)) )
|
||||||
{
|
{
|
||||||
LOG->Warn( WERROR("Couldn't determine buffer size", error) );
|
LOG->Warn( WERROR("Couldn't determine buffer size", error) );
|
||||||
bufferSize = 0;
|
bufferSize = 0;
|
||||||
@@ -256,16 +276,28 @@ float RageSoundDriver_AU::GetPlayLatency() const
|
|||||||
|
|
||||||
UInt32 frames;
|
UInt32 frames;
|
||||||
|
|
||||||
|
AudioObjectPropertyAddress LatencyAddr = {
|
||||||
|
kAudioDevicePropertyLatency,
|
||||||
|
kAudioDevicePropertyScopeOutput,
|
||||||
|
kAudioObjectPropertyElementWildcard
|
||||||
|
};
|
||||||
|
|
||||||
size = sizeof( UInt32 );
|
size = sizeof( UInt32 );
|
||||||
if( (error = AudioDeviceGetProperty(OutputDevice, 0, false, kAudioDevicePropertyLatency, &size, &frames)) )
|
if( (error = AudioObjectGetPropertyData(OutputDevice, &LatencyAddr, 0, NULL, &size, &frames)) )
|
||||||
{
|
{
|
||||||
LOG->Warn( WERROR( "Couldn't get device latency", error) );
|
LOG->Warn( WERROR( "Couldn't get device latency", error) );
|
||||||
frames = 0;
|
frames = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AudioObjectPropertyAddress SafetyAddr = {
|
||||||
|
kAudioDevicePropertySafetyOffset,
|
||||||
|
kAudioDevicePropertyScopeOutput,
|
||||||
|
kAudioObjectPropertyElementWildcard
|
||||||
|
};
|
||||||
|
|
||||||
bufferSize += frames;
|
bufferSize += frames;
|
||||||
size = sizeof( UInt32 );
|
size = sizeof( UInt32 );
|
||||||
if( (error = AudioDeviceGetProperty(OutputDevice, 0, false, kAudioDevicePropertySafetyOffset, &size, &frames)) )
|
if( (error = AudioObjectGetPropertyData(OutputDevice, &SafetyAddr, 0, NULL, &size, &frames)) )
|
||||||
{
|
{
|
||||||
LOG->Warn( WERROR("Couldn't get device safety offset", error) );
|
LOG->Warn( WERROR("Couldn't get device safety offset", error) );
|
||||||
frames = 0;
|
frames = 0;
|
||||||
@@ -274,7 +306,13 @@ float RageSoundDriver_AU::GetPlayLatency() const
|
|||||||
size = sizeof( UInt32 );
|
size = sizeof( UInt32 );
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if( (error = AudioDeviceGetPropertyInfo(OutputDevice, 0, false, kAudioDevicePropertyStreams, &size, NULL)) )
|
AudioObjectPropertyAddress StreamsAddr = {
|
||||||
|
kAudioDevicePropertyStreams,
|
||||||
|
kAudioDevicePropertyScopeOutput,
|
||||||
|
kAudioObjectPropertyElementWildcard
|
||||||
|
};
|
||||||
|
|
||||||
|
if( (error = AudioObjectGetPropertyData(OutputDevice, &StreamsAddr, 0, NULL, &size, NULL)) )
|
||||||
{
|
{
|
||||||
LOG->Warn( WERROR("Device has no streams", error) );
|
LOG->Warn( WERROR("Device has no streams", error) );
|
||||||
break;
|
break;
|
||||||
@@ -287,13 +325,20 @@ float RageSoundDriver_AU::GetPlayLatency() const
|
|||||||
}
|
}
|
||||||
AudioStreamID *streams = new AudioStreamID[num];
|
AudioStreamID *streams = new AudioStreamID[num];
|
||||||
|
|
||||||
if( (error = AudioDeviceGetProperty(OutputDevice, 0, false, kAudioDevicePropertyStreams, &size, streams)) )
|
if( (error = AudioObjectGetPropertyData(OutputDevice, &StreamsAddr, 0, NULL, &size, streams)) )
|
||||||
{
|
{
|
||||||
LOG->Warn( WERROR("Cannot get device's streams", error) );
|
LOG->Warn( WERROR("Cannot get device's streams", error) );
|
||||||
delete[] streams;
|
delete[] streams;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if( (error = AudioStreamGetProperty(streams[0], 0, kAudioDevicePropertyLatency, &size, &frames)) )
|
|
||||||
|
AudioObjectPropertyAddress LatencyAddr = {
|
||||||
|
kAudioDevicePropertyLatency,
|
||||||
|
kAudioDevicePropertyScopeOutput,
|
||||||
|
kAudioObjectPropertyElementWildcard
|
||||||
|
};
|
||||||
|
|
||||||
|
if( (error = AudioObjectGetPropertyData(streams[0], &LatencyAddr, 0, NULL, &size, &frames)) )
|
||||||
{
|
{
|
||||||
LOG->Warn( WERROR("Stream does not report latency", error) );
|
LOG->Warn( WERROR("Stream does not report latency", error) );
|
||||||
frames = 0;
|
frames = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user