From e3c58689b38e5985ee8ea755bf20c61bc77fffdd Mon Sep 17 00:00:00 2001 From: Ulysses Wu Date: Tue, 22 Oct 2024 03:26:13 +0800 Subject: [PATCH] sound_archive: `and` platform `p16` `opus` WIP --- FreeMote.Plugins/Audio/NxAdpcmFormatter.cs | 41 +++++++++------- FreeMote.Plugins/Audio/OpusFormatter.cs | 5 ++ FreeMote.Psb/Plugins/WavFormatter.cs | 55 ++++++++++++++++++---- FreeMote.Psb/Resources/ArchDatas.cs | 20 ++++++-- 4 files changed, 91 insertions(+), 30 deletions(-) diff --git a/FreeMote.Plugins/Audio/NxAdpcmFormatter.cs b/FreeMote.Plugins/Audio/NxAdpcmFormatter.cs index f3dc268..87f46b5 100644 --- a/FreeMote.Plugins/Audio/NxAdpcmFormatter.cs +++ b/FreeMote.Plugins/Audio/NxAdpcmFormatter.cs @@ -84,24 +84,7 @@ public bool TryGetArchData(AudioMetadata md, PsbDictionary channel, out IArchDat Format = PsbAudioFormat.ADPCM }; - if (channel["pan"] is PsbList panList) - { - newData.Pan = panList; - - if (panList.Count == 2) - { - var left = panList[0].GetFloat(); - var right = panList[1].GetFloat(); - if (left == 1.0f && right == 0.0f) - { - newData.ChannelPan = PsbAudioPan.Left; - } - else if (left == 0.0f && right == 1.0f) - { - newData.ChannelPan = PsbAudioPan.Right; - } - } - } + ExtractPan(channel, newData); data = newData; return true; @@ -109,5 +92,27 @@ public bool TryGetArchData(AudioMetadata md, PsbDictionary channel, out IArchDat return false; } + + private static void ExtractPan(PsbDictionary channel, AdpcmArchData newData) + { + if (channel["pan"] is PsbList panList) + { + newData.Pan = panList; + + if (panList.Count == 2) + { + var left = panList[0].GetFloat(); + var right = panList[1].GetFloat(); + if (left == 1.0f && right == 0.0f) + { + newData.ChannelPan = PsbAudioPan.Left; + } + else if (left == 0.0f && right == 1.0f) + { + newData.ChannelPan = PsbAudioPan.Right; + } + } + } + } } } diff --git a/FreeMote.Plugins/Audio/OpusFormatter.cs b/FreeMote.Plugins/Audio/OpusFormatter.cs index 410f29e..a77a020 100644 --- a/FreeMote.Plugins/Audio/OpusFormatter.cs +++ b/FreeMote.Plugins/Audio/OpusFormatter.cs @@ -154,6 +154,11 @@ public bool TryGetArchData(AudioMetadata md, PsbDictionary channel, out IArchDat hasIntro = true; } + if (archDic["data"] is PsbResource res) + { + opus.Data = res; + } + //if (opus.Body != null && opus.Intro == null) //{ // opus.Data = opus.Body.Data; diff --git a/FreeMote.Psb/Plugins/WavFormatter.cs b/FreeMote.Psb/Plugins/WavFormatter.cs index ba54266..1467fe9 100644 --- a/FreeMote.Psb/Plugins/WavFormatter.cs +++ b/FreeMote.Psb/Plugins/WavFormatter.cs @@ -92,19 +92,58 @@ public bool TryGetArchData(AudioMetadata md, PsbDictionary channel, out IArchDat } } - if (channel.Count == 1 && channel["archData"] is PsbDictionary p16Arch && p16Arch["filetype"] is PsbString fileType && fileType == "p16" && p16Arch["data"] is PsbResource p16Data && p16Arch["samprate"] is PsbNumber sampRate) { - var newData = new P16ArchData + if (channel.Count == 1 && channel["archData"] is PsbDictionary p16Arch && p16Arch["filetype"] is PsbString fileType && fileType == "p16" && p16Arch["data"] is PsbResource p16Data && p16Arch["samprate"] is PsbNumber sampRate) { - Data = p16Data, - SampleRate = sampRate.AsInt - }; - data = newData; - return true; + var newData = new P16ArchData + { + Data = p16Data, + SampleRate = sampRate.AsInt + }; + data = newData; + return true; + } + } + + // android 2ch P16 + { + if (channel["archData"] is PsbDictionary p16Arch && p16Arch["ext"] is PsbString ext && ext == ".p16" && p16Arch["data"] is PsbResource p16Data && p16Arch["samprate"] is PsbNumber sampRate) + { + var newData = new P16ArchData + { + Data = p16Data, + SampleRate = sampRate.AsInt + }; + + ExtractPan(channel, newData); + data = newData; + return true; + } } return false; } - + + private static void ExtractPan(PsbDictionary channel, P16ArchData newData) + { + if (channel["pan"] is PsbList panList) + { + newData.Pan = panList; + + if (panList.Count == 2) + { + var left = panList[0].GetFloat(); + var right = panList[1].GetFloat(); + if (left == 1.0f && right == 0.0f) + { + newData.ChannelPan = PsbAudioPan.Left; + } + else if (left == 0.0f && right == 1.0f) + { + newData.ChannelPan = PsbAudioPan.Right; + } + } + } + } } } diff --git a/FreeMote.Psb/Resources/ArchDatas.cs b/FreeMote.Psb/Resources/ArchDatas.cs index 9d98244..8e42e08 100644 --- a/FreeMote.Psb/Resources/ArchDatas.cs +++ b/FreeMote.Psb/Resources/ArchDatas.cs @@ -138,7 +138,7 @@ public class P16ArchData : IArchData public string Extension { get; set; } = ".p16"; public string WaveExtension { get; set; } = ".wav"; public PsbAudioFormat Format => PsbAudioFormat.P16; - public PsbAudioPan ChannelPan => PsbAudioPan.Mono; + public PsbAudioPan ChannelPan { get; set; } = PsbAudioPan.Mono; private PsbResource _data; @@ -148,6 +148,8 @@ public PsbResource Data set => _data = value; } + public PsbList Pan { get; set; } + public IList DataList => new List { _data }; public int SampleRate { get; set; } = 48000; @@ -534,7 +536,17 @@ public class OpusArchData : IArchData public PsbResource Data { get; set; } - public IList DataList => new List { Body?.Data, Intro?.Data }; + public IList DataList { + get + { + if (Data != null) + { + return [Data]; + } + + return [Body.Data, Intro.Data]; + } + } public PsbDictionary PsbArchData { get; set; } @@ -580,7 +592,7 @@ public int ChannelCount //WTF M2? You put ChannelCount in a Channel?? if (Body == null && Intro == null) { - return 0; + return DataList.Count; } return 1; @@ -609,7 +621,7 @@ public PsbAudioPan ChannelPan if (Body == null && Intro == null) { - return PsbAudioPan.IntroBody; + return DataList.Count > 2 ? PsbAudioPan.Multiple : DataList.Count == 2 ? PsbAudioPan.LeftRight : PsbAudioPan.Mono; } return Body == null ? PsbAudioPan.Intro : PsbAudioPan.Body;