Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions VideoMode/Design/ui-sounds/action-index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# System menu sound actions

The glass-cube demo uses ten finite IPL effects exposed by published
`DolphinDotNet.GameCube` / SDK `0.1.0-preview.347.1`. The mappings apply to Video,
The glass-cube demo uses ten IPL navigation effects exposed by published
`DolphinDotNet.GameCube` / SDK `0.1.0-preview.361.1`. The mappings apply to Video,
Calendar, Options and Storage. They describe accepted logical actions, rather
than button presses or rendered frames.

Expand Down Expand Up @@ -45,30 +45,39 @@ the independent console SRAM preference and does not imply AESND downmixing.

Off stops active voices and defers the initial firmware read until sound is
enabled. Otherwise preparation runs once on `Task.Run`: read the console IPL,
select its qualified profile and prepare the ten effects. The firmware image
and catalog are disposed before interactive playback; prepared native clips
remain resident. Shutdown cancels pending preparation, awaits it, and disposes
voices before clips. No ROM, PCM, replacement tone or recording is bundled or
written to storage.
select its qualified profile and prepare the same owned `SystemAudioSession`
used by IplResources when `SupportsAudioSession` is true. Navigation dispatches
`PlayCue(SystemMenuSound)` directly; ambience is disabled before each cue,
including when restarting after mute. Six owned cue handles bound overlap.
Off releases the handles and stops the session, clearing its remaining tails.
Older qualified profiles retain the ten finite effects as a fallback.
The firmware image and catalog are disposed before interactive playback;
the owned session or native clips remain resident. The audio-enabled frame loop
awaits a short SDK delay after each frame, matching the IPL explorer's scheduler
yield. Shutdown cancels pending preparation, awaits it, and disposes playback
handles before their session or clips. No ROM, PCM, replacement tone or recording
is bundled or written to storage.

Each effect has a 2 MiB native preparation-scratch budget and the retained bank
is capped at 6 MiB of native audio memory. The [budget audit](budget-audit.md)
The session has a 6 MiB native budget. In the legacy fallback, each effect has a
2 MiB native preparation-scratch budget and the retained bank is capped at
6 MiB of native audio memory. The legacy [budget audit](budget-audit.md)
bounds every SDK-accepted recipe's scratch charge below 2 MiB; the actual sum
of all ten clips on a supported ROM remains unqualified here. The retained-bank
limit is an intentional MEM1 ceiling, with partial clips disposed if exceeded.
These limits are separate from the
2 MiB firmware image and SDK-managed extraction data. Reaching `FirmwareImage` makes the SDK
select an 8 MiB managed heap, replacing this demo's earlier 256 KiB assumption
in audio-enabled builds. Playback performs no firmware reads or effect
preparation in the frame loop; the SDK creates a small channel wrapper per
preparation in the frame loop; the SDK creates a small playback wrapper per
played effect. Audio-disabled instrumentation retains its separate baseline.

Profiles are qualified for early NTSC 1.0, NTSC 1.2 and PAL 1.2. A missing IPL,
unsupported profile or failed preparation leaves navigation working and reports
unavailable audio in the UI Sounds editor. The Cloud environment has no original
IPL configured, so native validation there covers graceful unavailability and
normal interaction; it does not establish audible playback on physical hardware.
Host tests verify routing, repeat/no-op behavior, voice policy and settings
Host tests verify routing, repeat/no-op behavior, both playback backends, voice
policy, session ambience suppression, mute/restart, disposal and settings
migration. Physical listening and supported-ROM playback remain separate checks.

The SDK [firmware resource guide](https://github.com/capz/DolphinDotNet/blob/8f5870f68ec7f5eb1e8103c13af42ce082a3516f/docs/system-firmware-resources.md)
Expand Down
4 changes: 4 additions & 0 deletions VideoMode/Design/ui-sounds/budget-audit.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# IPL UI audio preparation budget audit

This audit applies to the finite-clip fallback. Current VideoMode builds prefer
the owned sequenced session used by IplResources when the profile supports it;
that path does not retain this ten-clip PCM bank.

SDK: published `0.1.0-preview.347.1`, source
`8f5870f68ec7f5eb1e8103c13af42ce082a3516f`.

Expand Down
56 changes: 42 additions & 14 deletions VideoMode/IplUiAudio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

internal enum IplUiAudioState { NotStarted,Loading,Ready,Unavailable,Closed }

// Extract/pre-render the console's qualified finite effects once, off the app
// executor. The rendering loop only publishes completed work and uses resident
// native clips. No firmware bytes or prepared audio are written to storage.
// Prepare the console's qualified audio once, off the app executor. Prefer the
// IPL explorer's sequenced session; older profiles use resident finite clips.
// No firmware bytes or prepared audio are written to storage.
internal sealed class IplUiAudio
{
// The SDK's maximum accepted recipe, decoded sources, PCM and delay lines
Expand All @@ -21,6 +21,8 @@ internal sealed class IplUiAudio
private readonly CancellationTokenSource cancellation=new CancellationTokenSource();
private readonly IplUiAudioPolicy policy=new IplUiAudioPolicy();
private readonly SoundChannel?[] voices=new SoundChannel?[IplUiAudioPolicy.VoiceLimit];
private readonly SystemAudioPlayback?[] cues=new SystemAudioPlayback?[IplUiAudioPolicy.VoiceLimit];
private SystemAudioSession? session;
private Task<Prepared>? loading;
private Task? closing;
private Sound?[]? clips;
Expand All @@ -38,10 +40,12 @@ internal sealed class IplUiAudio
private sealed class Prepared
{
internal readonly Sound?[]? Clips;
internal readonly SystemAudioSession? Session;
internal readonly int Count,Bytes;
internal readonly string Failure;
internal Prepared(Sound?[]? clips,int count,int bytes,string failure)
{Clips=clips;Count=count;Bytes=bytes;Failure=failure;}
internal Prepared(SystemAudioSession session){Session=session;Count=EffectCount;Failure="";}
}
internal void Start()
{
Expand All @@ -57,8 +61,16 @@ private Prepared Prepare()
{
var token=cancellation.Token;int count=0,bytes=0;
using(var image=SystemFirmware.ReadConsole(token))
using(var catalog=image.CreateCatalog(FirmwareCatalogOptions.IncludeMenuAudio,token))
using(var catalog=image.CreateCatalog(FirmwareCatalogOptions.IncludeSystemAudio|FirmwareCatalogOptions.IncludeMenuAudio,token))
{
// Use the same owned, sequenced session as the working IPL
// explorer. Do not render and retain ten separate PCM copies.
if(catalog.SupportsAudioSession)
{
var prepared=SystemResources.CreateAudioSession(catalog,token,BankBudget);
try{token.ThrowIfCancellationRequested();return new Prepared(prepared);}
catch{prepared.Dispose();throw;}
}
for(int i=0;i<EffectCount;i++)
{
token.ThrowIfCancellationRequested();
Expand Down Expand Up @@ -90,16 +102,19 @@ internal void Tick(int level)
Start();
}
if(State==IplUiAudioState.Unavailable){volumeLevel=level;return;}
if(session!=null&&session.State==SystemAudioSessionState.Faulted)
{Unavailable("IPL sequencer faulted.");volumeLevel=level;return;}
if(loading!=null&&loading.IsCompleted)
{
var pending=loading;loading=null;
try
{
var prepared=pending.Result;
clips=prepared.Clips;LoadedCount=prepared.Count;NativeBytes=prepared.Bytes;
if(clips==null)Unavailable(prepared.Failure);
clips=prepared.Clips;session=prepared.Session;LoadedCount=prepared.Count;NativeBytes=prepared.Bytes;
if(clips==null&&session==null)Unavailable(prepared.Failure);
else
{
if(session!=null)NativeBytes=session.GetStatistics().NativeBytes;
State=IplUiAudioState.Ready;Status="System sounds ready.";
SetVolume(volume);DebugOverlay.WriteLine("UI AUDIO READY clips "+LoadedCount+" native bytes "+NativeBytes);
}
Expand All @@ -112,46 +127,59 @@ internal void Tick(int level)
}
private void Unavailable(string detail)
{
for(int i=0;i<voices.Length;i++)ReleaseVoice(i);
session?.Dispose();session=null;DisposeClips(clips);clips=null;
State=IplUiAudioState.Unavailable;Status="System sounds unavailable.";
DebugOverlay.WriteLine("UI AUDIO UNAVAILABLE "+detail);
}
private void ReapVoices()
{
for(int i=0;i<voices.Length;i++)
if(voices[i]!=null&&!voices[i]!.IsPlaying)ReleaseVoice(i);
if(voices[i]!=null&&!voices[i]!.IsPlaying||cues[i]!=null&&!cues[i]!.IsPlaying)ReleaseVoice(i);
}
private void ReleaseVoice(int slot)
{
voices[slot]?.Dispose();voices[slot]=null;policy.Released(slot);
cues[slot]?.Dispose();cues[slot]=null;
}
private void SetVolume(float volume)
{
if(session!=null)session.Volume=volume;
if(clips!=null)for(int i=0;i<clips.Length;i++)if(clips[i]!=null)clips[i]!.Volume=volume;
for(int i=0;i<voices.Length;i++)
{
var voice=voices[i];if(voice==null)continue;
if(volume==0){ReleaseVoice(i);continue;}
var voice=voices[i];if(voice==null)continue;
// The DSP can finish between reaping and this control operation.
try {voice.Volume=volume;}
catch(InvalidOperationException){ReleaseVoice(i);}
}
if(session!=null&&volume==0)session.Stop();
}
internal void Play(IplUiSound sound)
{
int effect=IplUiAudioPolicy.EffectIndex(sound);
if(effect<0)return;
if(stopping||State!=IplUiAudioState.Ready||volumeLevel==0||clips==null||clips[effect]==null)
if(stopping||State!=IplUiAudioState.Ready||volumeLevel==0||session==null&&(clips==null||clips[effect]==null))
{DroppedCount++;return;}
// Inputs received while preparing or muted are discarded, never replayed.
if(!policy.Accept(sound,IplUiAudioPolicy.IsNavigation(sound)?Clock.Timestamp:0))
{ThrottledCount++;return;}
ReapVoices();int slot=policy.NextVoiceSlot();
if(voices[slot]!=null){StolenCount++;ReleaseVoice(slot);}
if(voices[slot]!=null||cues[slot]!=null){StolenCount++;ReleaseVoice(slot);}
try
{
voices[slot]=clips[effect]!.Play();policy.Started(slot);PlayedCount++;
if(session!=null)
{
// SetControl also starts a stopped session. Suppress the idle
// score before queuing a cue, including after mute/unmute.
session.SetControl(SystemAudioControl.AmbienceEnabled,0);
cues[slot]=session.PlayCue((SystemMenuSound)effect);
}
else voices[slot]=clips![effect]!.Play();
policy.Started(slot);PlayedCount++;
}
catch(InvalidOperationException){DroppedCount++;}
catch(InvalidOperationException error){DroppedCount++;DebugOverlay.WriteLine("UI AUDIO PLAY FAILED "+error.Message);}
}
internal Task Close()
{
Expand All @@ -164,10 +192,10 @@ private async Task CloseCore()
var pending=loading;loading=null;
if(pending!=null)
{
try {var prepared=await pending;DisposeClips(prepared.Clips);}
try {var prepared=await pending;DisposeClips(prepared.Clips);prepared.Session?.Dispose();}
catch(Exception error){DebugOverlay.WriteLine("UI AUDIO CLOSE "+error.Message);}
}
DisposeClips(clips);clips=null;cancellation.Dispose();
DisposeClips(clips);clips=null;session?.Dispose();session=null;cancellation.Dispose();
State=IplUiAudioState.Closed;Status="System sounds stopped.";
}
private static void DisposeClips(Sound?[]? sounds)
Expand Down
9 changes: 7 additions & 2 deletions VideoMode/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@
private static async System.Threading.Tasks.Task<int> Main()
{
var audio=new IplUiAudio();int result=0;System.Exception? failure=null;
try{result=RunFrames(audio);}catch(System.Exception error){failure=error;}
try{result=await RunFrames(audio);}catch(System.Exception error){failure=error;}
// Await cancellation outside finally: the GameCube AOT subset does not
// implement ExceptionDispatchInfo used by an awaited finally block.
await audio.Close();
if(failure!=null)throw failure;
return result;
}
private static int RunFrames(IplUiAudio uiAudio)
private static async System.Threading.Tasks.Task<int> RunFrames(IplUiAudio uiAudio)
#else
private static int Main()
#endif
Expand Down Expand Up @@ -156,7 +156,7 @@
#if IPL_VISUAL_REVIEW && !IPL_AA_BENCHMARK
int reviewFrames=0;
#endif
bool storageRefreshHeld=false;

Check warning on line 159 in VideoMode/Program.cs

View workflow job for this annotation

GitHub Actions / native-reporting-build

The variable 'storageRefreshHeld' is assigned but its value is never used

Check warning on line 159 in VideoMode/Program.cs

View workflow job for this annotation

GitHub Actions / native-reporting-build

The variable 'storageRefreshHeld' is assigned but its value is never used

Check warning on line 159 in VideoMode/Program.cs

View workflow job for this annotation

GitHub Actions / native-reporting-build

The variable 'storageRefreshHeld' is assigned but its value is never used

Check warning on line 159 in VideoMode/Program.cs

View workflow job for this annotation

GitHub Actions / native-reporting-build

The variable 'storageRefreshHeld' is assigned but its value is never used

Check warning on line 159 in VideoMode/Program.cs

View workflow job for this annotation

GitHub Actions / native-reporting-build

The variable 'storageRefreshHeld' is assigned but its value is never used
while(true)
{
long frameStart=Clock.Timestamp;
Expand Down Expand Up @@ -272,6 +272,11 @@
#endif
phaseStart=timing?Clock.Timestamp:0;
device.EndFrame();
#if IPL_SYSTEM_AUDIO
// Match the IPL explorer: let the application/service scheduler
// advance preparation and native audio between completed frames.
await System.Threading.Tasks.Task.Delay(1);
#endif
int end=timing?IplFrameProfiler.Since(phaseStart):0;
IplPerformanceOverlay.CompleteFrame(frameStart,prepare,submit,end);
if(IplFrameProfiler.Active)
Expand Down
6 changes: 4 additions & 2 deletions VideoMode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,10 @@ Hardware/TV acceptance and visual comparison inside Dolphin remain separate
from successful compilation; do not treat host visual proofs as emulator captures.

Normal builds enable system menu audio. Preparation reads the console IPL once
in the background and retains the resulting native clips; it does not read
firmware or synthesize effects on each input. Without a supported IPL the demo
in the background and uses the same sequenced audio session as IplResources.
Older qualified profiles fall back to retained finite clips. The audio-enabled
frame loop yields to the SDK scheduler after each frame. Input plays resident
cues without rereading firmware or preparing effects. Without a supported IPL the demo
remains usable and the UI Sounds editor reports audio unavailable. In Dolphin,
an original IPL must already be configured for successful playback. No ROM or
prepared PCM is bundled. `-p:IplSystemAudio=false` excludes this backend;
Expand Down
10 changes: 10 additions & 0 deletions ci/verify_aot.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ def check(name: str, configuration: str, generated_c: Path) -> None:
if api not in c:
raise RuntimeError(f"IplResources: published firmware API is not reachable: {api}")
if name == "VideoMode":
# Audio-disabled measurement builds deliberately omit this backend.
if "IplUiAudio" in c:
for api in ("FirmwareCatalog_get_SupportsAudioSession", "SystemResources_CreateAudioSession",
"SystemAudioSession_PlayCue", "SystemAudioSession_SetControl",
"SystemAudioSession_set_Volume", "SystemAudioPlayback_Dispose"):
if api not in c:
raise RuntimeError(f"VideoMode: IPL session API is not reachable: {api}")
frames = re.search(r"intptr_t dnd_value_VideoMode_Program__RunFrames[^(]*MoveNext[^(]*\([^;]+?\) \{(.*?)\n\}", c, re.S)
if frames is None or "Time_DelayAsync" not in frames.group(1):
raise RuntimeError("VideoMode: audio-enabled frame loop must yield to the SDK scheduler")
def glass_body(method):
match=re.search(r"intptr_t dnd_value_VideoMode_SealedGlassShell_"+method+r"_[^(]+\([^;]+?\) \{(.*?)\n\}",c,re.S)
return match.group(1) if match else None
Expand Down
Loading
Loading