I've been trying for a while to try and have multiple listeners in a scene record the audio they pick up individually.
How I've been trying to do this is by making each listener output to a different audio device and record it. I've been trying to use the AK::SoundEngine::AddOutput() func to do this, but every time I use it it says audio device share set doesn't exists, even if I send in what I think is the System audio device. This is my first time using wwise so I could definitely be messing up something here.
I have a Audio Device called "System [System]", and a Audio Bus called "Master Audio Bus" (and a couple other ones, but I'm trying to make this work with the default first, unless I'm way-off with my approach)
TTuple <AkUInt32, FString> AAudioManager::SearchAudioDeviceIdByName(FString deviceName)
{
TTuple <AkUInt32, FString> result;
AkUInt32 deviceId = AK_INVALID_DEVICE_ID;
if (deviceName.Len() == 0) {
// getting default device
AK::GetWindowsDevice(-1, deviceId, NULL, AkDeviceState_Active);
auto deviceNameWstr = AK::GetWindowsDeviceName(-1, deviceId, AkDeviceState_Active);
result.Key = deviceId;
result.Value = FString(deviceNameWstr);
}
else {
AkUInt32 immDeviceCount = AK::GetWindowsDeviceCount(AkDeviceState_Active);
for (AkUInt32 i = 0; i < immDeviceCount; ++i) {
AK::GetWindowsDevice(i, deviceId, NULL, AkDeviceState_Active);
auto deviceNameWstr = AK::GetWindowsDeviceName(i, deviceId, AkDeviceState_Active);
if (FString(deviceNameWstr).Contains(deviceName)) {
result.Key = deviceId;
result.Value = FString(deviceNameWstr);
break;
}
}
}
return result;
}
AkOutputDeviceID AAudioManager::AddCustomOutput(FString AudioDevice, FString WwiseDevice, AkGameObjectID in_pComponent)
{
TTuple <AkUInt32, FString> Device;
AkOutputDeviceID deviceId = AK_INVALID_DEVICE_ID;
FString WwiseDeviceName = "System";
AKRESULT res = AK_Fail;
if (AudioDevice.Len() == 0 && WwiseDevice.Len() == 0) {
return deviceId;
}
if (WwiseDevice.Len() > 0) {
WwiseDeviceName = WwiseDevice;
}
Device = SearchAudioDeviceIdByName(*AudioDevice);
if (Device.Key)
{
AkOutputSettings outputSettings(*WwiseDeviceName, Device.Key);
auto gameObjID = in_pComponent;
res = AK::SoundEngine::AddOutput(outputSettings, &deviceId, &gameObjID, 1);
}
else
{
UE_LOG(LogAkAudio, Error, TEXT("Failed to find audio device %s"), *AudioDevice, *WwiseDeviceName, res);
}
FString componentName = FString("Listener");
if (res != AK_Success)
{
UE_LOG(LogAkAudio, Error, TEXT("Error attaching of AkComponent \"%s\" to \"%s\" <-> \"%s\". Error \"%d"), *componentName, *AudioDevice, *WwiseDeviceName, res);
}
else
{
UE_LOG(LogAkAudio, Warning, TEXT("AkComponent \"%s\" attached to \"%s\" <-> \"%s\" "), *componentName, *Device.Value, *WwiseDeviceName);
}
return deviceId;
}
AKRESULT AAudioManager::RemoveCustomOutput(AkOutputDeviceID deviceId)
{
return AK::SoundEngine::RemoveOutput(deviceId);
}
// Called when the game starts or when spawned
void AAudioManager::BeginPlay()
{
Super::BeginPlay();
//FAkAudioDevice* AudioDevice = FAkAudioDevice::Get()
if (listeners.Num() <= 0)
{
UE_LOG(LogTemp, Error, TEXT("No Listeners Assigned to AudioManager!"));
return;
}
TArray<AkGameObjectID> listenerIDs;
for (int i = 0; i < listeners.Num(); i++)
{
listenerIDs.Add(listeners[i]);
AkOutputDeviceID id = 0;
//assign output for listener
//AkOutputSettings outputSettings1("Mic", listenerIDs.Last() /*Player ID (first player)*/);
//AK::SoundEngine::AddOutput(outputSettings1, NULL, &listenerIDs.Last(), 1);
AddCustomOutput("System", "Master Audio Bus", listenerIDs.Last());
AK::SoundEngine::RegisterGameObj(listeners[i], "My Default Listener");
//AK::SoundEngine::Query::SetBusEffect()
}
AK::SoundEngine::SetDefaultListeners(&(listenerIDs[0]), listenerIDs.Num());
}
Thank you.