Skip to content

Commit

Permalink
A few more tweaks for AU hosting, WIP
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <falktx@falktx.com>
  • Loading branch information
falkTX committed Oct 1, 2024
1 parent 2f7c939 commit e312817
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 27 deletions.
73 changes: 62 additions & 11 deletions source/backend/plugin/CarlaPluginAU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,8 @@ class CarlaPluginAU : public CarlaPlugin,
kAudioUnitProperty_SupportedNumChannels,
kAudioUnitScope_Global,
0, &outDataSize, &outWritable) == noErr
/*
&& outDataSize != 0
&& outDataSize % sizeof(AUChannelInfo) == 0
*/
)
&& outDataSize % sizeof(AUChannelInfo) == 0)
{
const uint32_t numChannels = outDataSize / sizeof(AUChannelInfo);
AUChannelInfo* const channelInfo = new AUChannelInfo[numChannels];
Expand All @@ -279,33 +276,87 @@ class CarlaPluginAU : public CarlaPlugin,
{
AUChannelInfo* highestInfo = &channelInfo[0];

carla_stdout("getProperty returns {%u,%u}... config",
carla_stdout("kAudioUnitProperty_SupportedNumChannels returns {%d,%d}... config",
channelInfo[0].inChannels,
channelInfo[0].outChannels);

for (uint32_t i=1; i<numChannels; ++i)
for (uint32_t i=0; i<numChannels; ++i)
{
if (channelInfo[i].inChannels < 0)
channelInfo[i].inChannels = 2;
if (channelInfo[i].outChannels < 0)
channelInfo[i].outChannels = 2;

if (channelInfo[i].inChannels > highestInfo->inChannels
&& channelInfo[i].outChannels > highestInfo->outChannels)
{
highestInfo = &channelInfo[i];
}
}

audioIns = highestInfo->inChannels;
audioOuts = highestInfo->outChannels;
audioIns = std::min<int16_t>(64, highestInfo->inChannels);
audioOuts = std::min<int16_t>(64, highestInfo->outChannels);
}
else
{
carla_stdout("getProperty failed");
carla_stdout("kAudioUnitProperty_SupportedNumChannels failed");
}

delete[] channelInfo;
}
else
{
carla_stdout("kAudioUnitProperty_SupportedNumChannels returns no configs, assume stereo");
audioIns = audioOuts = 2;
outDataSize = 0;
if (fFunctions.getPropertyInfo(fInterface,
kAudioUnitProperty_ElementCount,
kAudioUnitScope_Input,
0, &outDataSize, &outWritable) == noErr
&& outDataSize == sizeof(UInt32))
{
UInt32 count = 0;
if (fFunctions.getProperty(fInterface,
kAudioUnitProperty_ElementCount,
kAudioUnitScope_Input,
0, &count, &outDataSize) == noErr
&& outDataSize == sizeof(UInt32) && count != 0)
{
AudioStreamBasicDescription desc;
std::memset(&desc, 0, sizeof(desc));
outDataSize = sizeof(AudioStreamBasicDescription);

if (fFunctions.getProperty(fInterface,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Input,
0, &desc, &outDataSize) == noErr)
audioIns = std::min<uint32_t>(64, desc.mChannelsPerFrame);
}
}

outDataSize = 0;
if (fFunctions.getPropertyInfo(fInterface,
kAudioUnitProperty_ElementCount,
kAudioUnitScope_Output,
0, &outDataSize, &outWritable) == noErr
&& outDataSize == sizeof(UInt32))
{
UInt32 count = 0;
if (fFunctions.getProperty(fInterface,
kAudioUnitProperty_ElementCount,
kAudioUnitScope_Output,
0, &count, &outDataSize) == noErr
&& outDataSize == sizeof(UInt32) && count != 0)
{
AudioStreamBasicDescription desc;
std::memset(&desc, 0, sizeof(desc));
outDataSize = sizeof(AudioStreamBasicDescription);

if (fFunctions.getProperty(fInterface,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Output,
0, &desc, &outDataSize) == noErr)
audioOuts = std::min<uint32_t>(64, desc.mChannelsPerFrame);
}
}
}

if (audioIns > 0)
Expand Down
81 changes: 67 additions & 14 deletions source/discovery/carla-discovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2182,21 +2182,84 @@ static bool do_au_check(const char* const filename, const bool doInit)
{
AUChannelInfo* highestInfo = &channelInfo[0];

for (uint32_t i=1; i<numChannels; ++i)
for (uint32_t i=0; i<numChannels; ++i)
{
if (channelInfo[i].inChannels < 0)
channelInfo[i].inChannels = 2;
if (channelInfo[i].outChannels < 0)
channelInfo[i].outChannels = 2;

if (channelInfo[i].inChannels > highestInfo->inChannels
&& channelInfo[i].outChannels > highestInfo->outChannels)
{
highestInfo = &channelInfo[i];
}
}

audioIns = highestInfo->inChannels;
audioOuts = highestInfo->outChannels;
audioIns = std::min<int16_t>(64, highestInfo->inChannels);
audioOuts = std::min<int16_t>(64, highestInfo->outChannels);
}

delete[] channelInfo;
}
else
{
// unsupported for now
interface->Close(interface);
continue;

outDataSize = 0;
if (auGetPropertyInfo(interface,
kAudioUnitProperty_ElementCount,
kAudioUnitScope_Input,
0, &outDataSize, &outWritable) == noErr
&& outDataSize == sizeof(UInt32))
{
UInt32 count = 0;
if (auGetProperty(interface,
kAudioUnitProperty_ElementCount,
kAudioUnitScope_Input,
0, &count, &outDataSize) == noErr
&& outDataSize == sizeof(UInt32) && count != 0)
{
AudioStreamBasicDescription desc;
std::memset(&desc, 0, sizeof(desc));
outDataSize = sizeof(AudioStreamBasicDescription);

if (auGetProperty(interface,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Input,
0, &desc, &outDataSize) == noErr)
audioIns = std::min<uint32_t>(64, desc.mChannelsPerFrame);
}
}

outDataSize = 0;
if (auGetPropertyInfo(interface,
kAudioUnitProperty_ElementCount,
kAudioUnitScope_Output,
0, &outDataSize, &outWritable) == noErr
&& outDataSize == sizeof(UInt32))
{
UInt32 count = 0;
if (auGetProperty(interface,
kAudioUnitProperty_ElementCount,
kAudioUnitScope_Output,
0, &count, &outDataSize) == noErr
&& outDataSize == sizeof(UInt32) && count != 0)
{
AudioStreamBasicDescription desc;
std::memset(&desc, 0, sizeof(desc));
outDataSize = sizeof(AudioStreamBasicDescription);

if (auGetProperty(interface,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Output,
0, &desc, &outDataSize) == noErr)
audioOuts = std::min<uint32_t>(64, desc.mChannelsPerFrame);
}
}
}

// parameter count
outDataSize = 0;
Expand Down Expand Up @@ -2292,17 +2355,7 @@ static bool do_au_check(const char* const filename, const bool doInit)

if (doInit)
{
// test valid scopes
outDataSize = 0;
if (auGetPropertyInfo(interface, kAudioUnitProperty_ElementCount, kAudioUnitScope_Input, 0, &outDataSize, &outWritable) == noErr && outDataSize == sizeof(UInt32))
{
UInt32 count = 0;
if (auGetProperty(interface, kAudioUnitProperty_ElementCount, kAudioUnitScope_Input, 0, &count, &outDataSize) == noErr && outDataSize == sizeof(UInt32) && count != 0)
{
}
}

// TODO
// TODO tests
}

const CFIndex componentNameLen = CFStringGetLength(componentName);
Expand Down
5 changes: 3 additions & 2 deletions source/utils/CarlaStateUtils.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Carla State utils
* Copyright (C) 2012-2023 Filipe Coelho <falktx@falktx.com>
* Copyright (C) 2012-2024 Filipe Coelho <falktx@falktx.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
Expand Down Expand Up @@ -310,7 +310,7 @@ bool CarlaStateSave::fillFromXmlElement(const XmlElement* const xmlElement)
name = xmlSafeStringCharDup(text, false);
else if (tag == "Label" || tag == "URI" || tag == "Identifier" || tag == "Setup")
label = xmlSafeStringCharDup(text, false);
else if (tag == "Binary" || tag == "Filename")
else if (tag == "Binary" || tag == "Bundle" || tag == "Filename")
binary = xmlSafeStringCharDup(text, false);
else if (tag == "UniqueID")
uniqueId = text.getLargeIntValue();
Expand Down Expand Up @@ -594,6 +594,7 @@ void CarlaStateSave::dumpToMemoryStream(MemoryOutputStream& content) const
infoXml << " <Label>" << xmlSafeString(label, true) << "</Label>\n";
break;
case PLUGIN_AU:
infoXml << " <Bundle>" << xmlSafeString(binary, true) << "</Bundle>\n";
infoXml << " <Identifier>" << xmlSafeString(label, true) << "</Identifier>\n";
break;
case PLUGIN_CLAP:
Expand Down

0 comments on commit e312817

Please sign in to comment.