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
6 changes: 3 additions & 3 deletions .github/workflows/samples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ jobs:
shell: bash
run: |
mkdir -p "$RUNNER_TEMP/ipl-resources-dol"
cp IplResources/bin/Release/net8.0/IplResources.dol "$RUNNER_TEMP/ipl-resources-dol/IplResources-early-ipl.dol"
sha256sum "$RUNNER_TEMP/ipl-resources-dol/IplResources-early-ipl.dol"
cp IplResources/bin/Release/net8.0/IplResources.dol "$RUNNER_TEMP/ipl-resources-dol/IplResources.dol"
sha256sum "$RUNNER_TEMP/ipl-resources-dol/IplResources.dol"
- name: Build IPL hardware diagnostic from the published SDK
if: matrix.group == 'ipl'
run: python3 tools/ipl-diagnostics/build.py --output "${{ runner.temp }}/ipl-diagnostics"
Expand All @@ -146,6 +146,6 @@ jobs:
if: matrix.group == 'ipl'
with:
name: ipl-resources-dol
path: ${{ runner.temp }}/ipl-resources-dol/IplResources-early-ipl.dol
path: ${{ runner.temp }}/ipl-resources-dol/IplResources.dol
if-no-files-found: error
retention-days: 14
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<!-- Keep this in sync with global.json (MSBuild SDK version). -->
<DndPackageVersion>0.1.0-preview.349.1</DndPackageVersion>
<DndPackageVersion>0.1.0-preview.361.1</DndPackageVersion>
<!-- Shared native sample controls: Z toggles statistics; Start leaves result screens. -->
<DndSampleControls Condition="'$(DndSampleControls)' == ''">true</DndSampleControls>
</PropertyGroup>
Expand Down
Binary file added IplResources/Design/approved-complete-audio.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
103 changes: 103 additions & 0 deletions IplResources/IplAudioResources.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
using System;
using System.Threading;
using Dolphin.Audio;
using Dolphin.Diagnostics;
using Dolphin.System;

internal sealed class IplAudioResources : IDisposable
{
internal FirmwareCatalog? Catalog;
internal SystemAudioSession? Session;
internal SystemAudioCueInfo[] Cues=new SystemAudioCueInfo[0];
internal string AudioFailure="";
internal readonly Sound?[] Sounds=new Sound?[13];
internal readonly string[] Status=new string[13],Details=new string[13];
internal readonly string[] Sources=new string[13];
internal FirmwareAudioSampleInfo[] Samples=new FirmwareAudioSampleInfo[0];
internal string[] SampleNames=new string[0],SampleDetails=new string[0],SampleStatus=new string[0];
internal string Revision="CONSOLE IPL";
internal static IplAudioResources Prepare(CancellationToken cancellation)
{
var result=new IplAudioResources();
try
{
// Reads the configured console/emulator ROM through EXI. No file
// probes, embedded Nintendo assets, synthetic sound or WAV fallback.
using var image=SystemFirmware.ReadConsole(cancellation);
result.Catalog=image.CreateCatalog(FirmwareCatalogOptions.IncludeSystemAudio,cancellation);
if(result.Catalog.SupportsAudioSession)
{
try {result.Session=SystemResources.CreateAudioSession(result.Catalog,cancellation);result.Cues=result.Catalog.GetAudioCues();}
catch(OperationCanceledException){throw;}
catch(Exception error){result.AudioFailure=error.Message;DebugOverlay.WriteLine("IPL SESSION FAILED "+error.Message);}
}
if(result.Session!=null)
{
result.Samples=new FirmwareAudioSampleInfo[result.Session.SampleCount];
// PlaySample accepts descriptors owned by this prepared session.
for(int i=0;i<result.Samples.Length;i++)result.Samples[i]=result.Session.GetSample(i);
}
else result.Samples=result.Catalog.GetAudioSamples();
result.SampleNames=new string[result.Samples.Length];result.SampleDetails=new string[result.Samples.Length];result.SampleStatus=new string[result.Samples.Length];
for(int i=0;i<result.Samples.Length;i++)
{
var info=result.Samples[i];
result.SampleNames[i]=info.WaveId<0?"Sample "+(i+1):"Wave "+info.WaveId;
result.SampleDetails[i]="Mono "+(info.Codec<2?"ADPCM":info.Codec==2?"PCM8":"PCM16")+" / "+(info.SampleRate/1000)+" kHz";result.SampleStatus[i]="READY";
}
if(image.Revision.Contains("Revision 1.2"))result.Revision=image.Revision.Contains("PAL")?"PAL 1.2":"NTSC 1.2";
else result.Revision="EARLY IPL";
if(result.Session!=null)
{
DebugOverlay.WriteLine("IPL SESSION READY "+result.Session.ProfileId+" SOURCES "+result.Samples.Length);
return result;
}
for(int i=0;i<result.Sounds.Length;i++)
{
cancellation.ThrowIfCancellationRequested();
if(result.AudioFailure.Length!=0){result.Status[i]="AUDIO UNAVAILABLE";result.Details[i]=result.AudioFailure;continue;}
try
{
if(i<3)
{
var variant=(SystemStartupSoundVariant)i;
if(result.Catalog.TryGetStartupSoundInfo(variant,out var info)&&info!=null)
{
result.Sounds[i]=SystemResources.CreateStartupVariantSound(result.Catalog,variant,cancellation);
result.Sources[i]="Wave IDs "+info.LeftSourceWaveId+" / "+info.RightSourceWaveId;
}
else if(i==0)
{
result.Sounds[i]=SystemResources.CreateStartupSound(result.Catalog,cancellation);
result.Sources[i]="Stereo startup archive";
}
else {result.Status[i]="UNAVAILABLE";result.Details[i]="Startup unsupported";continue;}
}
else
{
var identity=IplSelection.Effects[i-3];
if(!result.Catalog.TryGetMenuSoundInfo(identity,out var info)||info==null)
{result.Status[i]="UNAVAILABLE";result.Details[i]="Menu profile unsupported";continue;}
// New metadata exposes original instrument IDs, distinct
// from the raw WSYS enumeration order.
string ids=info.SourceWaveCount==1?"Wave ID ":"Wave IDs ";
for(int source=0;source<info.SourceWaveCount;source++)
ids+=(source==0?"":" / ")+info.GetSourceWaveId(source);
result.Sources[i]=ids;
DebugOverlay.WriteLine(IplSelection.Names[i]+" "+info.ProfileId+" "+ids);
result.Sounds[i]=SystemResources.CreateMenuSound(result.Catalog,identity,cancellation);
}
var sound=result.Sounds[i]!;result.Status[i]="READY";
result.Details[i]=(sound.Channels==2?"Stereo":"Mono")+" / "+(sound.SampleRate/1000)+" kHz";
}
catch(NotSupportedException){result.Status[i]="UNAVAILABLE";result.Details[i]=i<3?"Startup unsupported":"Menu profile unsupported";}
}
DebugOverlay.WriteLine("IPL AUDIO PREPARED "+result.Catalog.MenuAudioRetainedBytes);
return result;
}
catch {result.Dispose();throw;}
}
public void Dispose()
{Session?.Dispose();Session=null;Catalog?.Dispose();Catalog=null;foreach(var sound in Sounds)sound?.Dispose();}
}

199 changes: 199 additions & 0 deletions IplResources/IplPlayback.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Dolphin.Audio;
using Dolphin.Diagnostics;
using Dolphin.System;
using Dolphin.Timing;

// Owns the currently auditioned cue/source. Repeating sections belong to the
// SDK; this UI never supplies loop flags, loop endpoints or a repeat scheduler.
internal sealed class IplPlayback
{
private readonly IplAudioResources resources;
private readonly CancellationToken cancellation;
private SystemAudioSession? Session=>resources.Session;
private SystemAudioPlayback? playback;
private SoundChannel? voice;
private SystemAudioSample? sample;
private Task<SystemAudioSample>? pending;
private int sampleIndex=-1,pendingIndex=-1;
private bool autoplay,startup;
private int motion=-1;
private long motionStart,warmStart,nextStats;
internal int PlayingCategory {get;private set;}=-1;
internal int PlayingIndex {get;private set;}=-1;
internal bool AmbienceEnabled {get;private set;}
internal bool Warming=>AmbienceEnabled&&!startup&&Clock.Timestamp-warmStart<5000000;
internal bool Pending=>pending!=null;
internal string Error {get;private set;}="";
internal SystemAudioStatistics? Statistics {get;private set;}
internal IplPlayback(IplAudioResources resources,CancellationToken cancellation)
{this.resources=resources;this.cancellation=cancellation;}
private void ClearAudition()
{
playback?.Dispose();playback=null;voice?.Dispose();voice=null;autoplay=false;
PlayingCategory=-1;PlayingIndex=-1;
if(motion>=0&&Session!=null&&Session.State==SystemAudioSessionState.Playing)
{
Session.SetControl(SystemAudioControl.CubeMotion,0);
Session.SetControl(SystemAudioControl.SubmenuMotion,0);
}
motion=-1;
}
internal void Stop()
{
ClearAudition();Session?.Stop();startup=false;AmbienceEnabled=false;Error="";
DebugOverlay.WriteLine("IPL STOP");
}
private void StartIdle()
{
if(startup){Session!.Stop();startup=false;}
bool stopped=Session!.State==SystemAudioSessionState.Stopped;
Session.Start();Session.SetControl(SystemAudioControl.AmbienceEnabled,AmbienceEnabled?1:0);
if(stopped)warmStart=Clock.Timestamp;
}
internal void Play(int category,int index)
{
if(pending!=null)return;
Error="";ClearAudition();
try
{
if(Session!=null)
{
if(category==0)
{
Session.PlayStartup((SystemStartupSoundVariant)index);
startup=true;AmbienceEnabled=true;
}
else if(category==3)
{
AmbienceEnabled=true;StartIdle();
if(index==1||index==2){motion=index-1;motionStart=Clock.Timestamp;}
else if(index>=3)Session.OutputMode=index==3?SystemAudioOutputMode.Stereo:SystemAudioOutputMode.Mono;
}
else
{
StartIdle();
playback=category==4?Session.PlaySample(resources.Samples[index]):
Session.PlayCue((SystemAudioCue)(category==1?index:index+12));
}
PlayingCategory=category;PlayingIndex=index;
}
else if(category==4)
{
if(sample!=null&&sampleIndex==index)
{voice=sample.Play();PlayingCategory=4;PlayingIndex=index;}
else
{
sample?.Dispose();sample=null;sampleIndex=-1;pendingIndex=index;autoplay=true;
pending=SystemResources.CreateAudioSampleAsync(resources.Catalog!,resources.Samples[index],cancellation);
}
}
else if(category<2)
{
int sound=category==0?index:index+3;
if(resources.Sounds[sound]!=null)
{voice=resources.Sounds[sound]!.Play();PlayingCategory=category;PlayingIndex=index;}
}
DebugOverlay.WriteLine("IPL PLAY "+category+"/"+index);
}
catch(Exception error){Error=error.Message;DebugOverlay.WriteLine("IPL PLAY FAILED "+error.Message);}
}
internal void ToggleAmbience()
{
if(Session==null)return;
try
{
Error="";AmbienceEnabled=!AmbienceEnabled;
if(!startup)
{
bool stopped=Session.State==SystemAudioSessionState.Stopped;
Session.SetControl(SystemAudioControl.AmbienceEnabled,AmbienceEnabled?1:0);
if(stopped||AmbienceEnabled)warmStart=Clock.Timestamp;
}
DebugOverlay.WriteLine(AmbienceEnabled?"IPL AMBIENCE ON":"IPL AMBIENCE OFF");
}
catch(Exception error){Error=error.Message;DebugOverlay.WriteLine("IPL CONTROL FAILED "+error.Message);}
}
internal void Update(bool exiting)
{
if(pending!=null&&pending.IsCompleted)
{
try
{
var prepared=pending.GetAwaiter().GetResult();
if(exiting)prepared.Dispose();
else
{
sample=prepared;sampleIndex=pendingIndex;
if(autoplay){voice=sample.Play();PlayingCategory=4;PlayingIndex=sampleIndex;}
}
}
catch(OperationCanceledException){}
catch(Exception error){Error=error.Message;resources.SampleStatus[pendingIndex]="UNAVAILABLE";}
pending=null;pendingIndex=-1;autoplay=false;
}
if(exiting)return;
if(voice!=null&&!voice.IsPlaying||playback!=null&&!playback.IsPlaying)
{
DebugOverlay.WriteLine("IPL ENDED "+PlayingCategory+"/"+PlayingIndex);
voice?.Dispose();voice=null;playback?.Dispose();playback=null;PlayingCategory=-1;PlayingIndex=-1;
}
if(Session==null)return;
long now=Clock.Timestamp;
if(Session.State==SystemAudioSessionState.Faulted){Error="Audio fault - restart demo";motion=-1;startup=false;}
else
{
if(startup&&!Session.IsStartupPlaying)
{
startup=false;warmStart=now;PlayingCategory=-1;PlayingIndex=-1;
Session.SetControl(SystemAudioControl.AmbienceEnabled,AmbienceEnabled?1:0);
DebugOverlay.WriteLine("IPL STARTUP HANDOVER");
}
if(motion>=0)
{
// Animate the verified original motion control, not audio loops.
float phase=(float)((now-motionStart)%4000000)/2000000;
Session.SetControl(motion==0?SystemAudioControl.CubeMotion:SystemAudioControl.SubmenuMotion,phase<=1?phase:2-phase);
}
}
if(now>=nextStats){Statistics=Session.GetStatistics();nextStats=now+250000;}
}
internal string Status(int category,int index)
{
if(Error.Length!=0)return "PLAYBACK FAILED";
if(Session!=null)
{
if(Session.State==SystemAudioSessionState.Faulted)return "AUDIO FAULT";
if(category==3&&AmbienceEnabled)return Warming?"STARTING AMBIENCE":"PLAYING";
return PlayingCategory==category&&PlayingIndex==index?"PLAYING":"READY";
}
if(category==4)return pendingIndex==index?"PREPARING":PlayingCategory==4&&PlayingIndex==index?"PLAYING":resources.SampleStatus[index];
return PlayingCategory==category&&PlayingIndex==index?"PLAYING":resources.Status[category==0?index:index+3];
}
internal string Details(int category,int index)
{
if(Error.Length!=0)return Error;
if(category==4)return resources.SampleDetails[index];
if(Session==null)return resources.Details[category==0?index:index+3];
if(category==0)return "Original stereo startup score";
if(category==3)return Session.OutputMode==SystemAudioOutputMode.Mono?"Original ambience / mono":"Original ambience / stereo";
return "Original sequenced cue";
}
internal string Repeat(int category,int index)
{
if(category==4)return resources.Samples[index].HasLoop?"LOOPS AUTOMATICALLY":"PLAYS ONCE";
if(Session==null)return resources.Sources[category==0?index:index+3]??"";
if(category==0)return "THEN IDLE AMBIENCE";
if(category==3)return AmbienceEnabled?"CONTINUOUS / Y TO MUTE":"Y TO ENABLE AMBIENCE";
var cue=(SystemAudioCue)(category==1?index:index+12);
foreach(var info in resources.Cues)if(info.Cue==cue)return info.RepeatsUntilStopped?"REPEATS UNTIL STOPPED":"PLAYS ONCE";
return "UNAVAILABLE";
}
internal async Task CloseAsync()
{
if(pending!=null){try{(await pending).Dispose();}catch(Exception){}pending=null;}
Stop();sample?.Dispose();sample=null;
}
}
32 changes: 29 additions & 3 deletions IplResources/IplSelection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,38 @@
// Pure navigation shared with host tests; resource creation stays in Program.
internal sealed class IplSelection
{
internal static readonly string[] Names={"Startup","Turn side","Turn center","Enter menu","Back","Cancel edit","Confirm edit","Change value","Change field","Change row","Open editor"};
internal static readonly string[] Categories={"STARTUP","MENU","CARDS","AMBIENCE","SAMPLES"};
internal const int VisibleRows=6;
internal static readonly string[] Names={"Normal","One controller Z","Four controller Z","Turn side","Turn center","Enter menu","Back","Cancel edit","Confirm edit","Change value","Change field","Change row","Open editor"};
internal static readonly string[] CardNames={"Erase / move done","Copy / format done","Transfer from A","Transfer from B","Copy transfer done","Move to B done","Move to A done"};
internal static readonly string[] AmbienceNames={"Idle ambience","Cube motion","Submenu motion","Stereo output","Mono output"};
internal static string GetName(int category,int index)
{
if(category==0)return Names[index];
if(category==1)return index<10?Names[index+3]:index==10?"Press Start":"Error";
if(category==2)return CardNames[index];
if(category==3)return AmbienceNames[index];
throw new System.ArgumentOutOfRangeException(nameof(category));
}
internal static readonly SystemMenuSound[] Effects={SystemMenuSound.TurnSide,SystemMenuSound.TurnCenter,SystemMenuSound.Select,SystemMenuSound.Back,SystemMenuSound.OptionCancel,SystemMenuSound.OptionConfirm,SystemMenuSound.OptionMove1,SystemMenuSound.OptionMove2,SystemMenuSound.OptionMove3,SystemMenuSound.OptionSelect};
internal static readonly SystemTexture[] Textures={SystemTexture.LogoTop,SystemTexture.LogoLeft,SystemTexture.LogoRight,SystemTexture.Environment,SystemTexture.Tiles,SystemTexture.Wordmark};
internal static readonly string[] TextureNames={"Logo top","Logo left","Logo right","Environment","Tiles","Wordmark"};
internal int Selected {get;private set;}
private readonly int[] selected=new int[5];
private readonly int[] counts={3,10,0,0,0};
internal int Category {get;private set;}
internal int Selected=>selected[Category];
internal int Count=>counts[Category];
internal int FirstVisible=>Selected/VisibleRows*VisibleRows;
internal int Texture {get;private set;}
internal void Move(int direction)=>Selected=(Selected+direction+Names.Length)%Names.Length;
internal void SetCompleteAudio(bool supported)
{
counts[1]=supported?12:10;counts[2]=supported?CardNames.Length:0;counts[3]=supported?AmbienceNames.Length:0;
for(int i=1;i<=3;i++)if(selected[i]>=counts[i])selected[i]=0;
}
internal void SetSampleCount(int count)
{counts[4]=count;if(selected[4]>=count)selected[4]=0;}
internal void Move(int direction)
{int count=Count;if(count>0)selected[Category]=(Selected+direction+count)%count;}
internal void NextCategory(int direction)=>Category=(Category+direction+Categories.Length)%Categories.Length;
internal void NextTexture()=>Texture=(Texture+1)%Textures.Length;
}
Loading
Loading