ue-audio-system について
UE 5.8 のオーディオシステムを扱う開発者向けスキルです。再生、ルーティング、MetaSounds、同期、分析に関する検証済み API と実装方法を整理しています。
主な機能
- 01UE 5.8 オーディオ API リファレンス
- 02アセットと再生の制御
- 03減衰、空間化、同時発音数
- 04ミックス、サブミックス、バス
- 05MetaSounds、モジュレーション、分析
活用シーン
- 01ゲーム内アクターの効果音再生
- 02サウンド分類とミックスの設定
- 03アダプティブ音楽と合成効果音の構築
インストール
コマンドをコピーしてターミナルで実行します。
npx skills add https:/ / github.com/ quodsoler/ unreal-engine-skills --skill ue-audio-systemインストール後、Claude Code で/ue-audio-systemを入力して読み込まれたか確認します。
同梱ファイルreferences/audio-component-reference.mdreferences/audio-setup-patterns.md
詳細
UE Audio System
対象エンジン:UE 5.8。以下の API は 5.8 のヘッダーに照らして検証済みです。以前の形式は「非推奨 — 使用しないでください」に記載されています。
サウンドアセット、C++ からの再生、減衰、同時発音数、サウンドクラスとミックス、サブミックス/バスのルーティング、MetaSounds、モジュレーション、Quartz、解析について説明します。エンジン側のコードは Engine/Classes/Sound と Components/AudioComponent.h(モジュール Engine)に、ミキサーは AudioMixer に、パラメーターインターフェイスは AudioExtensions にあります。プラグインモジュール:MetasoundEngine / MetasoundFrontend(MetaSounds)、AudioModulation、AudioSynesthesia(5.8 ではベータ版)、SubtitlesAndClosedCaptions(5.8 ではベータ版)。
// MyGame.Build.cs
PublicDependencyModuleNames.AddRange(new string[] { "Engine", "AudioMixer", "AudioExtensions" });
PrivateDependencyModuleNames.AddRange(new string[] { "MetasoundEngine", "MetasoundFrontend", "AudioModulation" });
コンテキスト
.agents/ue-project-context.md が存在する場合は読み込んでください(モジュール名、規約、有効なプラグイン、GAS/ネットワーク設定)。ファイルがなくても作業を中断しないでください。
リクエストとコードベースから対象領域を特定してください。解釈によってコードが異なる可能性がある場合に限り、質問してください。
| リクエストの内容… | 参照先 |
|---|---|
| 作成するアセットの種類(wave、cue、MetaSound)、ストリーミング | サウンドアセット |
| ゲームプレイコードからサウンドを再生する | サウンドの再生 |
| フェード、一時停止、音量/ピッチ、再生終了コールバック、インスタンスごとのセンド | UAudioComponent の制御 |
| 減衰、3D パンニング、HRTF、オクルージョン、リバーブセンド、フォーカス | 減衰と空間化 |
| 発音数が多すぎる、足音/銃声が重なる、ボイスの奪取 | 同時発音数 |
| カテゴリ別の音量スライダー、ダッキング、コンテキストミックス | サウンドクラスとサウンドミックス |
| ルーティンググループ、マスター音量、オーディオバス、サイドチェーンソース | サブミックス、バス、センド |
| サウンドグループへのリバーブ、EQ、コンプレッション | サブミックスエフェクト |
| プロシージャル/アダプティブオーディオ、ランタイムパラメーター、グラフの構築 | MetaSounds |
| ゲームプレイのカーブ/LFO による連続的なパラメーター制御 | モジュレーション |
| ビート同期のスティンガー、テンポ、音楽的な量子化 | Quartz による音楽同期 |
| オーディオへの反応(FFT、エンベロープ、オフラインのビートマップ) | 解析 |
| 字幕、セリフのテキスト | 字幕 |
| モバイルのボイス予算、専用サーバー、バックグラウンド動作、VR | プラットフォームに関する注意事項 |
| 実装例を含むシステム全体(音楽マネージャー、環境音、武器オーディオ) | オーディオ設定のパターン |
サウンドアセット
USoundBase // abstract base (Sound/SoundBase.h)
├── USoundWave // imported PCM/compressed asset (Sound/SoundWave.h)
│ └── USoundSourceBus // sonifies a UAudioBus (Sound/SoundSourceBus.h)
├── USoundCue // node graph (Sound/SoundCue.h)
└── UMetaSoundSource // procedural graph, derives USoundWaveProcedural
各アセットで設定する主な USoundBase フィールド:SoundClassObject、AttenuationSettings、ConcurrencySet(または bOverrideConcurrency と併用する ConcurrencyOverrides)、Priority(値が高いほどボイスのカリングで残りやすい)、SoundSubmixObject、SoundSubmixSends、BusSends / PreEffectBusSends / PostAttenuationBusSends、VirtualizationMode。
USoundCue のノード:USoundNodeRandom、USoundNodeModulator、USoundNodeMixer、USoundNodeAttenuation、USoundNodeLooping、USoundNodeDelay、USoundNodeDistanceCrossFade、USoundNodeConcatenator、USoundNodeSwitch、USoundNodeWavePlayer。USoundWave::LoadingBehavior(ESoundWaveLoadingBehavior、Sound/SoundWaveLoadingBehavior.h):Inherited、RetainOnLoad、PrimeOnLoad、LoadOnDemand、ForceInline。短い SFX には ForceInline、数分の音声を常駐させない長い音楽には LoadOnDemand を使います。GetLoadingBehavior(bCheckSoundClasses) で読み取り、OverrideLoadingBehavior(ESoundWaveLoadingBehavior::LoadOnDemand) でランタイムにオーバーライドします。
| 基準 | USoundCue | UMetaSoundSource |
|---|---|---|
| ランタイムパラメーター | Wave パラメーターのみ | 型付き入力(float、bool、int32、string、object、trigger) |
| プロシージャル DSP | いいえ | はい(オシレーター、ノイズ、フィルター) |
| C++ からランタイムに構築 | いいえ | はい — UMetaSoundBuilderSubsystem |
| 用途 | ランダム化された事前作成のワンショット | アダプティブミュージック、状態駆動型および合成 SFX |
サウンドの再生
すべての関数は Kismet/GameplayStatics.h にある UGameplayStatics の静的関数です。専用サーバーでは呼び出さないでください。
#include "Kismet/GameplayStatics.h" // + Components/SkeletalMeshComponent.h for GetMesh() below
// PlaySound2D(WorldContext, Sound, Volume=1, Pitch=1, StartTime=0,
// Concurrency=nullptr, OwningActor=nullptr, bIsUISound=true) — UI, music; no handle
UGameplayStatics::PlaySound2D(this, MenuSelectSound, 1.0f, 1.0f, 0.0f, nullptr, nullptr, true);
// PlaySoundAtLocation(WorldContext, Sound, Location, Rotation, Volume=1, Pitch=1, StartTime=0,
// Attenuation=nullptr, Concurrency=nullptr, OwningActor=nullptr, InitialParams=nullptr)
UGameplayStatics::PlaySoundAtLocation(this, GunShotSound, GetActorLocation(), FRotator::ZeroRotator,
1.0f, 1.0f, 0.0f, WeaponAttenuation, FireConcurrency, this);
// SpawnSoundAtLocation(WorldContext, Sound, Location, Rotation=ZeroRotator, Volume=1, Pitch=1,
// StartTime=0, Attenuation=nullptr, Concurrency=nullptr, bAutoDestroy=true)
UAudioComponent* Boom = UGameplayStatics::SpawnSoundAtLocation(this, ExplosionSound, Location,
FRotator::ZeroRotator, 1.0f, 1.0f, 0.0f, ExplosionAttenuation, nullptr, true);
// SpawnSoundAttached(Sound, AttachToComponent, AttachPointName=NAME_None, Location=FVector(ForceInit),
// Rotation=ZeroRotator, LocationType=EAttachLocation::KeepRelativeOffset,
// bStopWhenAttachedToDestroyed=false, Volume=1, Pitch=1, StartTime=0,
// Attenuation=nullptr, Concurrency=nullptr, bAutoDestroy=true)
UAudioComponent* EngineAudio = UGameplayStatics::SpawnSoundAttached(EngineLoopSound, GetMesh(),
TEXT("AudioSocket"), FVector::ZeroVector, FRotator::ZeroRotator,
EAttachLocation::SnapToTarget, /*bStopWhenAttachedToDestroyed=*/true,
1.0f, 1.0f, 0.0f, EngineAttenuation, nullptr, /*bAutoDestroy=*/false);
OwningActor は、オーナー単位の同時実行制御(bLimitToOwner)で基準となるアクターです。サウンドがアクターに属する場合は、必ず渡してください。SpawnSound2D の先頭の引数は PlaySound2D と同じですが、最後の引数は bPersistAcrossLevelTransition, bAutoDestroy です(OwningActor/bIsUISound はありません)。コンポーネントを返します。CreateSound2D は SpawnSound2D と同じ引数を受け取りますが、再生していないコンポーネントを返すため、自分で Play() を呼び出してください。
使い分け:一度だけ再生するサウンドには再生後に破棄される方法を、フェード、停止、パラメーター変更が必要なサウンドには生成したハンドルを、アクターごとに常時再生するループには CreateDefaultSubobject<UAudioComponent> のメンバーを使用します。
UAudioComponent の制御
UAudioComponent(Components/AudioComponent.h)は USceneComponent を継承し、ISoundParameterControllerInterface を実装します。
// Constructor
AudioComponent = CreateDefaultSubobject<UAudioComponent>(TEXT("AudioComponent"));
AudioComponent->SetupAttachment(RootComponent);
AudioComponent->bAutoActivate = false;
AudioComponent->bStopWhenOwnerDestroyed = true;
AudioComponent->bIsUISound = false; // true = keeps playing while the game is paused
// Playback — EAudioFaderCurve: Linear, Logarithmic, SCurve, Sin
AudioComponent->SetSound(EngineLoopSound);
AudioComponent->Play(/*StartTime=*/0.0f);
AudioComponent->FadeIn(0.5f, /*FadeVolumeLevel=*/1.0f, /*StartTime=*/0.0f, EAudioFaderCurve::Linear);
AudioComponent->AdjustVolume(/*Duration=*/0.25f, /*Level=*/0.3f, EAudioFaderCurve::Linear);
AudioComponent->FadeOut(1.0f, /*FadeVolumeLevel=*/0.0f, EAudioFaderCurve::Linear);
AudioComponent->SetVolumeMultiplier(0.5f);
AudioComponent->SetPitchMultiplier(1.2f);
AudioComponent->SetPaused(true);
AudioComponent->Stop();
const bool bPlaying = AudioComponent->IsPlaying();
// EAudioComponentPlayState: Playing, Stopped, Paused, FadingIn, FadingOut
const EAudioComponentPlayState State = AudioComponent->GetPlayState();
アセットを変更せずに、インスタンスごとのルーティングやフィルタリングを行えます。SetSubmixSend(USoundSubmixBase*, float)、SetSourceBusSendPreEffect/PostEffect/PostAttenuation、SetAudioBusSendPostEffect、SetLowPassFilterEnabled/SetLowPassFilterFrequency、対応するハイパスフィルターのペア、SetOutputToBusOnly を使用します。インラインで減衰を設定するには、bOverrideAttenuation = true を設定し、AttenuationOverrides(FSoundAttenuationSettings)に値を入力します。
各デリゲートには 2 つの形式があります(Components/AudioComponent.h:441-481)。Blueprint から参照できる動的な形式では、AddDynamic を使って UFUNCTION をバインドします。...Native の形式では、AddUObject を使い、さらに UAudioComponent* も渡します。対応するペアは OnAudioFinished、OnAudioPlayStateChanged、OnAudioVirtualizationChanged、OnAudioPlaybackPercent、OnAudioSingleEnvelopeValue、OnAudioMultiEnvelopeValue です。EndPlay で RemoveAll(this) を呼び出してバインドを解除します。両方のリストのコードは、references/audio-component-reference.md にあります。
減衰と空間化
USoundAttenuation アセットは、FBaseAttenuationSettings(Engine/Attenuation.h)を継承する FSoundAttenuationSettings(Sound/SoundAttenuation.h)をラップします。
形状(EAttenuationShape::Type):Sphere、Capsule、Box、Cone。カーブ(EAttenuationDistanceModel):Linear、Logarithmic、Inverse、LogReverse、NaturalSound、Custom。NaturalSound は、ゲームプレイのサウンドソースで知覚される音量に最もよく合致します。
FSoundAttenuationSettings Settings;
Settings.DistanceAlgorithm = EAttenuationDistanceModel::NaturalSound; // FBaseAttenuationSettings
Settings.AttenuationShape = EAttenuationShape::Sphere;
Settings.FalloffDistance = 3000.0f;
Settings.bAttenuate = true;
Settings.bSpatialize = true;
// ESoundSpatializationAlgorithm: SPATIALIZATION_Default (panning), SPATIALIZATION_HRTF (plugin)
Settings.SpatializationAlgorithm = SPATIALIZATION_Default;
// Air absorption
Settings.bAttenuateWithLPF = true;
Settings.LPFRadiusMin = 1000.0f;
Settings.LPFRadiusMax = 6000.0f;
Settings.LPFFrequencyAtMin = 20000.0f;
Settings.LPFFrequencyAtMax = 800.0f;
// Occlusion
Settings.bEnableOcclusion = true;
Settings.OcclusionTraceChannel = ECC_Visibility;
Settings.OcclusionLowPassFilterFrequency = 300.0f;
Settings.OcclusionVolumeAttenuation = 0.5f;
Settings.OcclusionInterpolationTime = 0.1f;
// Reverb send — EReverbSendMethod: Linear | CustomCurve | Manual
Settings.bEnableReverbSend = true;
Settings.ReverbSendMethod = EReverbSendMethod::Linear;
Settings.ReverbWetLevelMin = 0.3f;
Settings.ReverbWetLevelMax = 0.95f;
Settings.ReverbDistanceMin = 400.0f;
Settings.ReverbDistanceMax = 4000.0f;
// Distant sounds lose the voice-budget fight first
Settings.bEnablePriorityAttenuation = true;
Settings.PriorityAttenuationMin = 1.0f;
Settings.PriorityAttenuationMax = 0.0f;
リスナーフォーカス(bEnableListenerFocus、FocusAzimuth、NonFocusAzimuth、FocusDistanceScale、NonFocusDistanceScale、NonFocusVolumeAttenuation)を使うと、プレイヤーが見ている対象のサウンドを際立たせることができます。bEnableSendToAudioLink は外部への AudioLink ルーティングを制御します。背景の環境音では無効のままにしてください。
同時実行制御
USoundConcurrency(Sound/SoundConcurrency.h)は FSoundConcurrencySettings をラップします。USoundBase::ConcurrencySet で割り当てるか、bOverrideConcurrency を設定して ConcurrencyOverrides に値を入力します。
FSoundConcurrencySettings& Rules = FireConcurrency->Concurrency; // struct ctor is not ENGINE_API — edit an asset's copy
Rules.MaxCount = 4;
Rules.bLimitToOwner = false;
// EMaxConcurrentResolutionRule::Type — PreventNew, StopOldest, StopFarthestThenPreventNew,
// StopFarthestThenOldest, StopLowestPriority, StopQuietest, StopLowestPriorityThenPreventNew
Rules.ResolutionRule = EMaxConcurrentResolutionRule::StopFarthestThenOldest;
Rules.RetriggerTime = 0.05f; // minimum seconds between plays in this group
Rules.VoiceStealReleaseTime = 0.08f; // fade for evicted voices; 0 clicks
Rules.VolumeScaleMode = EConcurrencyVolumeScaleMode::Distance; // Default | Distance | Priority
Rules.bVolumeScaleCanRelease = true;
Rules.VolumeScaleAttackTime = 0.01f;
Rules.VolumeScaleReleaseTime = 0.5f;
サウンドの種類ごと(足音、衝撃音、弾丸の通過音)に共有する同時実行アセットを 1 つ用意します。MaxCount に達したときにどのサウンドを残すかは、USoundBase::Priority で決まります。
サウンドクラスとサウンドミックス
USoundClass では、各サウンドに FSoundClassProperties 内の独自の Volume/Pitch を持つカテゴリを割り当て、親子階層を設定できます。USoundMix は、TArray<FSoundClassAdjuster> SoundClassEffects(SoundClassObject、VolumeAdjuster、PitchAdjuster、bApplyToChildren)と FadeInTime を保持します。
UGameplayStatics::SetBaseSoundMix(this, DefaultMix); // usually once, or via AudioSettings
UGameplayStatics::PushSoundMixModifier(this, CombatMix); // layers on top
UGameplayStatics::PopSoundMixModifier(this, CombatMix);
UGameplayStatics::ClearSoundMixModifiers(this);
// Duck one class inside an already-pushed mix
UGameplayStatics::SetSoundMixClassOverride(this, CombatMix, MusicClass,
/*Volume=*/0.3f, /*Pitch=*/1.0f, /*FadeInTime=*/0.5f, /*bApplyToChildren=*/true);
UGameplayStatics::ClearSoundMixClassOverride(this, CombatMix, MusicClass, /*FadeOutTime=*/1.0f);
サウンドクラスは、ゲームプレイに応じたダッキングに使用します。プレイヤー向けの音量スライダーには、代わりにサブミックスの出力音量を使用してください。スタックを元に戻す必要がなく、単一の線形ゲインで調整できます。
サブミックス、バス、センド
USoundSubmixBase (Sound/SoundSubmix.h)
├── USoundSubmixWithParentBase
│ ├── USoundSubmix // effect chain, analysis, recording
│ └── USoundfieldSubmix // ambisonics / soundfield
├── UEndpointSubmix
└── USoundfieldEndpointSubmix
MusicSubmix->SetSubmixOutputVolume(this, 0.5f); // linear gain
MusicSubmix->SetSubmixWetLevel(this, 1.0f);
MusicSubmix->SetSubmixDryLevel(this, 0.0f);
MusicSubmix->DynamicConnect(this, MasterSubmix); // re-parent at runtime
MusicSubmix->DynamicDisconnect(this);
音楽/効果音のサブミックスには bMuteWhenBackgrounded = true を設定し、アプリがフォーカスを失ったときに停止するようにします。
センド。 FSoundSubmixSendInfo(Sound/SoundSubmixSend.h)と FSoundSourceBusSendInfo(Sound/SoundSourceBusSend.h)は同じ構造です。制御方式(ESendLevelControlMethod/ESourceBusSendLevelControlMethod — Linear、CustomCurve、Manual)、SendLevel または MinSendLevel/MaxSendLevel + MinSendDistance/MaxSendDistance、CustomSendLevelCurve、そして 5.8 では明示的なフィルターペアが含まれます。
FSoundSubmixSendInfo Send;
Send.SoundSubmix = ReverbSubmix;
Send.SendLevelControlMethod = ESendLevelControlMethod::Manual;
Send.SendLevel = 0.35f;
Send.SendStage = ESubmixSendStage::PostDistanceAttenuation; // or PreDistanceAttenuation
Send.bEnableLPFCutoff = true;
Send.LPFCutoff = 3000.0f; // Hz, 20..20000
Send.bEnableHPFCutoff = false;
Send.HPFCutoff = 20.0f;
オーディオバス。 UAudioBus(Sound/AudioBus.h、EAudioBusChannels の AudioBusChannels)は実行時のパッチポイントです。サウンドをここに送信し、USoundSourceBus で再び音声化し、サブミックスに登録できます。バスを使うと、再生経路を追加せずにサイドチェーンコンプレッサーやアナライザーに信号を送れます。
UAudioMixerBlueprintLibrary::StartAudioBus(this, DuckingBus);
UAudioMixerBlueprintLibrary::RegisterAudioBusToSubmix(this, AnalysisSubmix, DuckingBus);
const bool bActive = UAudioMixerBlueprintLibrary::IsAudioBusActive(this, DuckingBus);
UAudioMixerBlueprintLibrary::UnregisterAudioBusFromSubmix(this, AnalysisSubmix, DuckingBus);
UAudioMixerBlueprintLibrary::StopAudioBus(this, DuckingBus);
サブミックスエフェクト
USoundSubmix::SubmixEffectChain は TArray<TObjectPtr<USoundEffectSubmixPreset>> です。AudioMixer/Classes/SubmixEffects にある同梱プリセットは、USubmixEffectReverbPreset、USubmixEffectSubmixEQPreset、USubmixEffectDynamicsProcessorPreset です。
#include "AudioMixerBlueprintLibrary.h"
#include "SubmixEffects/AudioMixerSubmixEffectReverb.h"
USubmixEffectReverbPreset* Preset = NewObject<USubmixEffectReverbPreset>(this);
FSubmixEffectReverbSettings ReverbSettings;
ReverbSettings.DecayTime = 2.5f;
ReverbSettings.Density = 0.85f;
ReverbSettings.Diffusion = 0.8f;
ReverbSettings.WetLevel = 0.4f;
Preset->SetSettings(ReverbSettings); // thread-safe; assigning Settings directly is editor-time only
const int32 ChainIndex = UAudioMixerBlueprintLibrary::AddSubmixEffect(this, ReverbSubmix, Preset);
UAudioMixerBlueprintLibrary::RemoveSubmixEffect(this, ReverbSubmix, Preset);
UAudioMixerBlueprintLibrary::RemoveSubmixEffectAtIndex(this, ReverbSubmix, ChainIndex);
UAudioMixerBlueprintLibrary::ClearSubmixEffects(this, ReverbSubmix);
SetSubmixEffectChainOverride(WorldContext, Submix, Chain, FadeTimeSec) と ClearSubmixEffectChainOverride(WorldContext, Submix, FadeTimeSec) を使うと、環境に合わせてチェーン全体を切り替えられます。AddMasterSubmixEffect/RemoveMasterSubmixEffect/ClearMasterSubmixEffects はマスターサブミックスに作用します。
ソース側のエフェクトには、USoundEffectSourcePresetChain 内で USoundEffectSourcePreset を使用します(Sound/SoundEffectSource.h)。AAudioVolume は Priority の順に、ボリュームごとに FReverbSettings、FInteriorSettings、サブミックスのセンド/オーバーライド設定を適用します。
MetaSounds
UMetaSoundSource は USoundWaveProcedural → USoundWave → USoundBase を継承するため、上記のすべての関数を通じて再生できます。UAudioComponent が実装する ISoundParameterControllerInterface を通じて、型付き入力を制御します(基底インターフェースは AudioExtensions/Public/AudioParameterControllerInterface.h の IAudioParameterControllerInterface です)。
EngineAudioComp->SetFloatParameter(FName("RPM"), CurrentRPM);
EngineAudioComp->SetBoolParameter(FName("Engaged"), bEngaged);
EngineAudioComp->SetIntParameter(FName("GearIndex"), Gear);
EngineAudioComp->SetStringParameter(FName("SurfaceName"), TEXT("Gravel"));
EngineAudioComp->SetObjectParameter(FName("ImpactWave"), ImpactWave);
EngineAudioComp->SetTriggerParameter(FName("OnGearShift"));
EngineAudioComp->ResetParameters();
// Batch — cheaper than one call per value; SetParameters takes an rvalue array
TArray<FAudioParameter> Batch;
Batch.Emplace(FAudioParameter(FName("RPM"), CurrentRPM));
Batch.Emplace(FAudioParameter(FName("Engaged"), bEngaged));
EngineAudioComp->SetParameters(MoveTemp(Batch));
パラメーター名は MetaSound グラフの入力と完全に一致する必要があります。サウンドが MetaSound ではないコンポーネントにパラメーターを設定しても、エラーにはならず、何も起こりません。
UMetasoundGeneratorHandle::CreateMetaSoundGeneratorHandle(AudioComponent)(MetasoundGeneratorHandle.h)を使うと、実行中のジェネレーターにアクセスできます。IsValid()、GetAudioComponentId()、ApplyParameterPack(UMetasoundParameterPack*)、GetGenerator() のほか、OnGeneratorHandleAttached/OnGeneratorHandleDetached を利用できます。グラフ出力を読み取るには UMetaSoundOutputSubsystem::WatchOutput を使います。
UMetaSoundBuilderSubsystem::Get() → CreateSourceBuilder/CreatePatchBuilder/CreateSourcePresetBuilder を使ってコードからグラフを構築し、続けて AddGraphInputNode、AddNodeByClassName、ConnectNodes、SetNodeInputDefault、Audition を呼び出します。Build(const FMetaSoundBuilderOptions&) は WITH_EDITORONLY_DATA です。実行時には Audition または BuildNewMetaSound(FName)(MetasoundBuilderBase.h:586)を使います。基盤となるドキュメント API は FMetaSoundFrontendDocumentBuilder(MetasoundFrontend/Public/MetasoundFrontendDocumentBuilder.h)です。実例はオーディオ設定のパターンを参照してください。
モジュレーション
AudioModulation プラグインは、音量、ピッチ、フィルターカットオフに連続制御信号をルーティングします。USoundControlBus は値を保持し、USoundModulationGenerator は値を生成し(LFO、エンベロープフォロワー)、USoundControlBusMix はバスのターゲットを設定し、USoundModulationPatch はパラメーター間をマッピングします。バス、ジェネレーター、パッチは USoundModulatorBase を継承します。USoundControlBusMix は通常の UObject です(SoundControlBusMix.h:37)。
// EModulationDestination: Volume, Pitch, Lowpass, Highpass
// EModulationRouting: Disable, Inherit, Override, Union
TSet<USoundModulatorBase*> Modulators;
Modulators.Add(TensionControlBus);
AudioComponent->SetModulationRouting(Modulators, EModulationDestination::Volume, EModulationRouting::Override);
AudioComponent->AddModulationRouting(Modulators, EModulationDestination::Lowpass);
AudioComponent->RemoveModulationRouting(Modulators, EModulationDestination::Lowpass);
const TSet<USoundModulatorBase*> Current = AudioComponent->GetModulators(EModulationDestination::Volume);
アセットでは、モジュレーションは FSoundModulationDestinationSettings(Sound/SoundModulationDestination.h)に格納されます。ここにはベースの Value と TSet<TObjectPtr<USoundModulatorBase>> Modulators が含まれます。ネイティブの Audio::FModulationDestination コードでは、セッターは SetModulators です。
Quartz Music Sync
UQuartzSubsystem は、サンプル精度のミュージカルクロックを実行する UTickableWorldSubsystem です(AudioMixer/Public/Quartz/QuartzSubsystem.h)。
#include "Quartz/QuartzSubsystem.h"
#include "Quartz/AudioMixerClockHandle.h"
UQuartzSubsystem* Quartz = GetWorld()->GetSubsystem<UQuartzSubsystem>();
FQuartzClockSettings ClockSettings; // TimeSignature defaults to 4/4
// Handle-taking calls use UQuartzClockHandle*& — pass a raw local, not a TObjectPtr member
UQuartzClockHandle* ClockHandle = Quartz->CreateNewClock(this, TEXT("MusicClock"), ClockSettings,
/*bOverrideSettingsIfClockExists=*/false, /*bUseAudioEngineClockManager=*/true);
ClockHandle->StartClock(this, ClockHandle);
// EQuartzCommandQuantization: Bar, Beat, ThirtySecondNote and the other note values
FQuartzQuantizationBoundary Boundary;
Boundary.Quantization = EQuartzCommandQuantization::Bar;
Boundary.Multiplier = 1.0f;
Boundary.CountingReferencePoint = EQuarztQuantizationReference::BarRelative;
Boundary.bFireOnClockStart = true;
FOnQuartzCommandEventBP OnQueued;
StingerComponent->PlayQuantized(this, ClockHandle, Boundary, OnQueued,
/*InStartTime=*/0.0f, /*InFadeInDuration=*/0.0f, /*InFadeVolumeLevel=*/1.0f, EAudioFaderCurve::Linear);
ClockHandle->SubscribeToQuantizationEvent(this, EQuartzCommandQuantization::Beat, OnBeat, ClockHandle)(または SubscribeToAllQuantizationEvents)でメトロノームをサブスクライブします。FOnQuartzMetronomeEventBP コールバックは (FName ClockName, EQuartzCommandQuantization, int32 NumBars, int32 Beat, float BeatFraction) を受け取ります。テンポの変更には SetBeatsPerMinute を使用します。この処理自体も量子化されます。
Analysis
USoundSubmix 上でリアルタイムに分析する場合:
MySFXSubmix->StartEnvelopeFollowing(this);
FOnSubmixEnvelopeBP EnvelopeDelegate;
EnvelopeDelegate.BindDynamic(this, &AMyActor::OnSubmixEnvelope);
MySFXSubmix->AddEnvelopeFollowerDelegate(this, EnvelopeDelegate);
MySFXSubmix->StartSpectralAnalysis(this, EFFTSize::Medium, EFFTPeakInterpolationMethod::Linear,
EFFTWindowType::Hann, /*HopSize=*/0.0f, EAudioSpectrumType::MagnitudeSpectrum);
MySFXSubmix->StopSpectralAnalysis(this);
MySFXSubmix->StopEnvelopeFollowing(this);
帯域ベースの FFT コールバックには、FSoundSubmixSpectralAnalysisBandSettings の配列とともに AddSpectralAnalysisDelegate(WorldContext, BandSettings, Delegate, UpdateRate, DecibelNoiseFloor, bDoNormalize, bDoAutoRange, AutoRangeAttackTime, AutoRangeReleaseTime) を使用します。オーディオ設定パターンを参照してください。UAudioMixerBlueprintLibrary::MakeMusicalSpectralAnalysisBandSettings、MakeFullSpectrumSpectralAnalysisBandSettings、MakePresetSpectralAnalysisBandSettings を使うと、これらの配列を作成できます。StartAnalyzingOutput / StopAnalyzingOutput と GetMagnitudeForFrequencies / GetPhaseForFrequencies では、ポーリング API を利用できます。録音には StartRecordingOutput / StopRecordingOutput を使用します(EAudioRecordingExportType::SoundWave または WavFile)。
AudioSynesthesia プラグインを使ってオフラインで分析する場合(5.8 ではベータ版):ULoudnessNRT と UOnsetNRT は、UAudioSynesthesiaNRT → UAudioAnalyzerNRT を継承します。AnalyzeAudio() は WITH_EDITOR の場合にのみ使用できます。クック時にビートマップを生成し、実行時に GetLoudnessAtTime / GetNormalizedChannelOnsetsBetweenTimes で読み取ります。詳細な例はオーディオ設定パターンを参照してください。
Subtitles
SubtitlesAndClosedCaptions プラグイン(5.8 ではベータ版)は、USubtitlesBlueprintFunctionLibrary を使って字幕を制御します。
#include "SubtitlesBlueprintFunctionLibrary.h"
USubtitlesBlueprintFunctionLibrary::QueueSingleSubtitle(
FText::FromString(TEXT("Contact, north ridge.")), /*Duration=*/2.5f, /*StartOffset=*/0.0f,
/*Priority=*/1.0f, ESubtitleType::Subtitle, ESubtitleTiming::InternallyTimed);
USubtitlesBlueprintFunctionLibrary::StopAllSubtitles();
QueueSubtitlesFromAsset / StopSubtitlesInAsset には、サウンドにアタッチされた USubtitleAssetUserData を渡します。エンジン側の FSubtitleManager(Engine/Public/SubtitleManager.h)は、USoundWave::Subtitles キュー用として引き続き利用できます。
Platform Notes
- Windows バックエンド —
Config/Windows/BaseWindowsEngine.iniでAudioMixerModuleName=AudioMixerWasapiを設定します。XAudio2(AudioMixerXAudio2)もプロジェクトごとに選択できます。 - 専用サーバー — オーディオデバイスはありません。すべての再生呼び出しを
GetNetMode() != NM_DedicatedServerでガードします。 - モバイル — ボイス数の予算が厳しくなります。コンカレンシーと
Priorityを活用し、SPATIALIZATION_HRTFは避け、短い SFX にはForceInlineを優先してください。 - バックグラウンド化 — サブミックスの
bMuteWhenBackgroundedを使用するか、FCoreDelegates::ApplicationWillDeactivateDelegateにフックし、GEngine->GetMainAudioDevice()に対してFAudioDevice::SetTransientPrimaryVolume(0.0f)を呼び出します。 - VR — 3D 減衰アセットで
bSpatialize = trueとSPATIALIZATION_HRTFを設定し、空間化プラグインを使用します。 - ピッチ範囲 —
UAudioSettings::GlobalMinPitchScale/GlobalMaxPitchScaleによってクランプされます。
非推奨 — 使用しないでください
| 出力しないこと | 5.8 での使用先 | 出典 |
|---|---|---|
USubmixEffectEQPreset | USubmixEffectSubmixEQPreset | 実在したことがありません。実際のクラスは SubmixEffects/AudioMixerSubmixEffectEQ.h:110 にあります |
FSoundSubmixSendInfo::LPFCutoffFrequency | bEnableLPFCutoff + LPFCutoff | Sound/SoundSubmixSend.h:157 の UE_DEPRECATED(5.8) |
FSoundSubmixSendInfo::HPFCutoffFrequency | bEnableHPFCutoff + HPFCutoff | Sound/SoundSubmixSend.h:161 の UE_DEPRECATED(5.8) |
FSoundSourceBusSendInfo::LPFCutoffFrequency | bEnableLPFCutoff + LPFCutoff | Sound/SoundSourceBusSend.h:86 の UE_DEPRECATED(5.8) |
Audio::FModulationDestination::UpdateModulators | SetModulators | Sound/SoundModulationDestination.h:198 の UE_DEPRECATED(5.8) |
Audio::FModulationDestination::UpdateModulator | SetModulators | Sound/SoundModulationDestination.h:195 の UE_DEPRECATED(5.1) |
USoundWave::CreateSoundWaveProxy | GetSoundWaveProxy() | Sound/SoundWave.h:1204 の UE_DEPRECATED(5.8) |
FSoundWaveProxy::GetZerothChunk およびその他のプロキシアクセサー | GetSoundWaveDataRef() の戻り値を保持する | Sound/SoundWave.h:1813 の UE_DEPRECATED(5.8) |
FSoundWaveProxyReader | FSoundWaveProxyPlayer | Sound/SoundWaveProxyReader.h:19 の UE_DEPRECATED(5.8) |
USubtitlesBlueprintFunctionLibrary::QueueSubtitle | QueueSingleSubtitle | SubtitlesBlueprintFunctionLibrary.h:32 の UE_DEPRECATED(5.8) |
UAudioBusSubsystem::StartAudioBus(Key, Channels, bAutomatic) | InAudioBusName を受け取るオーバーロード | AudioMixer/Public/AudioBusSubsystem.h:83 の UE_DEPRECATED(5.6) |
UAudioMixerBlueprintLibrary::RemoveSubmixEffectPreset | RemoveSubmixEffect | AudioMixerBlueprintLibrary.h:242 の UE_DEPRECATED(4.27) |
UAudioMixerBlueprintLibrary::ReplaceSoundEffectSubmix | ReplaceSubmixEffect | AudioMixerBlueprintLibrary.h:258 の UE_DEPRECATED(4.27) |
FAudioDevice::SetTransientMasterVolume | SetTransientPrimaryVolume | Engine/Public/AudioDevice.h:1892 の UE_DEPRECATED(5.1) |
FAudioComponentParam | FAudioParameter | Components/AudioComponent.h:133 の UE_DEPRECATED(5.0) |
USoundBase::SoundConcurrencySettings_DEPRECATED | ConcurrencySet / ConcurrencyOverrides | Sound/SoundBase.h:183 の _DEPRECATED プロパティ |
よくある間違い
ワンショット再生のたびにコンポーネントを生成する: NewObject<UAudioComponent> を使うと、呼び出しのたびにアタッチされず、登録もされていないコンポーネントが残ります。
// WRONG
UAudioComponent* Comp = NewObject<UAudioComponent>(this);
Comp->SetSound(FireSound);
Comp->Play();
// RIGHT — one-shot
UGameplayStatics::PlaySoundAtLocation(this, FireSound, GetActorLocation());
専用サーバーでオーディオを再生する: オーディオデバイスがないため、呼び出しは無駄な処理となり、ログが大量に出力されます。
if (GetNetMode() != NM_DedicatedServer)
{
UGameplayStatics::PlaySoundAtLocation(this, FireSound, GetActorLocation());
}
ワールド内のサウンドに PlaySound2D を使う: 2D 再生では減衰と空間化が完全に省略されるため、マップの反対側の銃声が最大音量で中央から聞こえます。USoundAttenuation を指定して PlaySoundAtLocation を使用してください。
bAutoDestroy = true のループサウンド: サウンドが終了を報告した最初の時点でハンドルが破棄され、その後の FadeOut の呼び出しはダングリングコンポーネントに対して行われます。ポインターを保持するものには bAutoDestroy = false を渡してください。
PlaySoundAtLocation で OwningActor を設定し忘れる: この場合、bLimitToOwner の同時実行制限はグループ全体の制限にフォールバックします(FConcurrencyHandle::GetMode、SoundConcurrency.cpp:179)。そのため、アクターごとの制限が気付かないうちにグローバルな制限になります。
EndPlay 後もデリゲートをバインドしたままにする: そうしないと、プールに戻されたコンポーネントや自動破棄されたコンポーネントが古いオブジェクトに対して処理を実行します。EndPlay で OnAudioFinished.RemoveAll(this) と Stop() を呼び出してください。
サウンドミックスで音量スライダーを実装する: ミックスのプッシュとポップはスタックで管理されるため、ポップし忘れるとゲームの音量が永続的に下がります。ユーザー設定には USoundSubmix::SetSubmixOutputVolume を使用し、ミックスは一時的なゲームプレイ中の音量抑制に限定してください。
実行時に Preset->Settings を割り当てる: オーディオレンダースレッドは独自のコピーを読み取ります。代わりに、プリセットの SetSettings を呼び出してください。
関連スキル
ue-niagara-effects— オーディオイベントと同期するパーティクルシステムとVFXのタイミングue-animation-system— 足音、フォーリー、台詞をトリガーするアニメーション通知ue-actor-component-architecture— オーディオコンポーネントのライフタイム、アタッチメント、レプリケーションue-gameplay-framework— オーディオマネージャーの配置場所(GameInstance、サブシステム、プレイヤーコントローラー)ue-data-assets-tables— サーフェス/衝撃音用のデータ駆動型サウンドバンクとルックアップテーブルue-sequencer-cinematics— Level Sequence内のオーディオトラック、台詞、音楽ue-cpp-foundations— デリゲートのバインド、UPROPERTY/UFUNCTION、サブシステムへのアクセスパターン