AkAcousticTexture.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*******************************************************************************
  2. The content of this file includes portions of the proprietary AUDIOKINETIC Wwise
  3. Technology released in source code form as part of the game integration package.
  4. The content of this file may not be used without valid licenses to the
  5. AUDIOKINETIC Wwise Technology.
  6. Note that the use of the game engine is subject to the Unreal(R) Engine End User
  7. License Agreement at https://www.unrealengine.com/en-US/eula/unreal
  8. License Usage
  9. Licensees holding valid licenses to the AUDIOKINETIC Wwise Technology may use
  10. this file in accordance with the end user license agreement provided with the
  11. software or, alternatively, in accordance with the terms contained
  12. in a written agreement between you and Audiokinetic Inc.
  13. Copyright (c) 2023 Audiokinetic Inc.
  14. *******************************************************************************/
  15. #include "AkAcousticTexture.h"
  16. #include "Wwise/Stats/AkAudio.h"
  17. #if WITH_EDITORONLY_DATA
  18. #include "Wwise/WwiseProjectDatabase.h"
  19. #include "Wwise/WwiseResourceCooker.h"
  20. #include "AkAudioDevice.h"
  21. #endif
  22. void UAkAcousticTexture::Serialize(FArchive& Ar)
  23. {
  24. Super::Serialize(Ar);
  25. if (HasAnyFlags(RF_ClassDefaultObject))
  26. {
  27. return;
  28. }
  29. #if !UE_SERVER
  30. #if WITH_EDITORONLY_DATA
  31. if (Ar.IsCooking() && Ar.IsSaving() && !Ar.CookingTarget()->IsServerOnly())
  32. {
  33. FWwiseAcousticTextureCookedData CookedDataToArchive;
  34. if (auto* ResourceCooker = FWwiseResourceCooker::GetForArchive(Ar))
  35. {
  36. ResourceCooker->PrepareCookedData(CookedDataToArchive, GetValidatedInfo(AcousticTextureInfo));
  37. }
  38. CookedDataToArchive.Serialize(Ar);
  39. }
  40. #else
  41. AcousticTextureCookedData.Serialize(Ar);
  42. #endif
  43. #endif
  44. }
  45. #if WITH_EDITORONLY_DATA
  46. bool UAkAcousticTexture::ObjectIsInSoundBanks()
  47. {
  48. auto* ResourceCooker = FWwiseResourceCooker::GetDefault();
  49. if (UNLIKELY(!ResourceCooker))
  50. {
  51. UE_LOG(LogAkAudio, Error, TEXT("UAkAcousticTexture::GetWwiseRef: ResourceCooker not initialized"));
  52. return false;
  53. }
  54. auto ProjectDatabase = ResourceCooker->GetProjectDatabase();
  55. if (UNLIKELY(!ProjectDatabase))
  56. {
  57. UE_LOG(LogAkAudio, Error, TEXT("UAkAcousticTexture::GetWwiseRef: ProjectDatabase not initialized"));
  58. return false;
  59. }
  60. FWwiseObjectInfo* AudioTypeInfo = &AcousticTextureInfo;
  61. const FWwiseRefAcousticTexture AcousticTextureRef = FWwiseDataStructureScopeLock(*ProjectDatabase).GetAcousticTexture(
  62. GetValidatedInfo(AcousticTextureInfo));
  63. return AcousticTextureRef.IsValid();
  64. }
  65. void UAkAcousticTexture::FillInfo()
  66. {
  67. auto* ResourceCooker = FWwiseResourceCooker::GetDefault();
  68. if (UNLIKELY(!ResourceCooker))
  69. {
  70. UE_LOG(LogAkAudio, Error, TEXT("UAkAcousticTexture::FillInfo: ResourceCooker not initialized"));
  71. return;
  72. }
  73. auto ProjectDatabase = ResourceCooker->GetProjectDatabase();
  74. if (UNLIKELY(!ProjectDatabase))
  75. {
  76. UE_LOG(LogAkAudio, Error, TEXT("UAkAcousticTexture::FillInfo: ProjectDatabase not initialized"));
  77. return;
  78. }
  79. FWwiseObjectInfo* AudioTypeInfo = &AcousticTextureInfo;
  80. const FWwiseRefAcousticTexture AcousticTextureRef = FWwiseDataStructureScopeLock(*ProjectDatabase).GetAcousticTexture(
  81. GetValidatedInfo(AcousticTextureInfo));
  82. if (AcousticTextureRef.AcousticTextureName().ToString().IsEmpty() || !AcousticTextureRef.AcousticTextureGuid().IsValid() || AcousticTextureRef.AcousticTextureId() == AK_INVALID_UNIQUE_ID)
  83. {
  84. UE_LOG(LogAkAudio, Warning, TEXT("UAkAcousticTexture::FillInfo: Valid object not found in Project Database"));
  85. return;
  86. }
  87. AudioTypeInfo->WwiseName = AcousticTextureRef.AcousticTextureName();
  88. AudioTypeInfo->WwiseGuid = AcousticTextureRef.AcousticTextureGuid();
  89. AudioTypeInfo->WwiseShortId = AcousticTextureRef.AcousticTextureId();
  90. }
  91. void UAkAcousticTexture::GetAcousticTextureCookedData()
  92. {
  93. SCOPED_AKAUDIO_EVENT_2(TEXT("GetAcousticTextureCookedData"));
  94. if (!IWwiseProjectDatabaseModule::ShouldInitializeProjectDatabase())
  95. {
  96. return;
  97. }
  98. auto* ProjectDatabase = FWwiseProjectDatabase::Get();
  99. if (!ProjectDatabase || !ProjectDatabase->IsProjectDatabaseParsed())
  100. {
  101. UE_LOG(LogAkAudio, VeryVerbose, TEXT("UAkAcousticTexture::GetAcousticTextureCookedData: Not loading '%s' because project database is not parsed."), *GetName())
  102. return;
  103. }
  104. auto* ResourceCooker = FWwiseResourceCooker::GetDefault();
  105. if (UNLIKELY(!ResourceCooker))
  106. {
  107. return;
  108. }
  109. ResourceCooker->PrepareCookedData(AcousticTextureCookedData, GetValidatedInfo(AcousticTextureInfo));
  110. }
  111. #endif