오디오 가져오기
런타임에 오디오를 가져오는 프로세스는 여러 단계로 나눌 수 있습니다:
- Runtime Audio Importer 생성.
- 필요한 대리자들(OnProgress 및 OnResult)에 바인딩.
- 파일이나 버퍼에서 오디오 가져오기.
- OnResult 대리자에서 얻은 가져온 사운드 웨이브를 재생 (여기서 더 많은 정보).
Runtime Audio Importer와 Sound Wave 인스턴스가 조기에 garbage collected되지 않도록 하드 참조를 유지하여 별도의 변수에 할당하는 방식으로 할당하세요. 이는 UPROPERTY(), TStrongObjectPtr, 또는 객체가 파괴되지 않도록 하는 다른 방법을 사용할 수 있습니다.
Blueprints 예제
먼저, Runtime Audio Importer 객체를 생성해야 합니다. 이를 Blueprints에서 별도의 변수로 설정하여 garbage collector가 강한 참조로 처리하도록 보장해야 합니다. 이는 객체의 조기 파괴를 방지합니다.
- Blueprint
- C++
// UPROPERTY() is used here to prevent the object from being prematurely garbage collected
UPROPERTY()
class URuntimeAudioImporterLibrary* Importer;
Importer = URuntimeAudioImporterLibrary::CreateRuntimeAudioImporter();
오디오 데이터 가져오기 진행 상황을 추적하려면 OnProgress
(Blueprints) / OnProgressNative
(C++) 대리자에 바인딩할 수 있습니다. 이렇게 하면 진행 상황을 모니터링하고, 예를 들어 로딩 화면을 구현할 수 있습니다. 이 대리자에 바인딩하려면 바인드 이벤트 노드에서 이벤트 핀을 당기기만 하면 됩니다.
- Blueprint
- C++
// Assuming Importer is a UE reference to a URuntimeAudioImporterLibrary object
// AddWeakLambda is used just as an example. You can use any other method to bind the delegate, such as AddUObject, AddUFunction, etc.
Importer->OnProgressNative.AddWeakLambda(this, [](int32 Percentage)
{
UE_LOG(LogTemp, Log, TEXT("Import progress: %d"), Percentage);
});
오디오 데이터 가져오기 프로세스가 완료되면 알림을 받고, 결과로 얻어진 사운드 웨이브의 참조에 접근하려면, OnResult
(Blueprints) / OnResultNative
(C++) 델리게이트에 바인딩해야 합니다. 또한, 가져온 사운드 웨이브가 가비지 컬렉터가 강한 참조로 처리하도록 하여 원치 않는 조기 가비지 컬렉션을 방지해야 합니다. 이는 Blueprints에서 별도의 변수로 설정함으로써 수행할 수 있습니다.
- Blueprint
- C++
// Assuming Importer is a UE reference to a URuntimeAudioImporterLibrary object
// AddWeakLambda is used just as an example. You can use any other method to bind the delegate, such as AddUObject, AddUFunction, etc.
Importer->OnResultNative.AddWeakLambda(this, [](URuntimeAudioImporterLibrary* Importer, UImportedSoundWave* ImportedSoundWave, ERuntimeImportStatus Status)
{
UE_LOG(LogTemp, Log, TEXT("Import result: %s"), *UEnum::GetValueAsString(Status));
});
관련 함수를 호출하여 오디오 가져오기 프로세스를 시작합니다. 이 함수는 압축 및 비압축 오디오 데이터 형식을 모두 처리할 수 있습니다.
- Blueprint
- C++