Skip to content

Commit

Permalink
sound_archive: and platform p16 opus WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
UlyssesWu committed Oct 21, 2024
1 parent 905ebc6 commit e3c5868
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 30 deletions.
41 changes: 23 additions & 18 deletions FreeMote.Plugins/Audio/NxAdpcmFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,30 +84,35 @@ 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;
}

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;
}
}
}
}
}
}
5 changes: 5 additions & 0 deletions FreeMote.Plugins/Audio/OpusFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
55 changes: 47 additions & 8 deletions FreeMote.Psb/Plugins/WavFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
}
}
}
20 changes: 16 additions & 4 deletions FreeMote.Psb/Resources/ArchDatas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -148,6 +148,8 @@ public PsbResource Data
set => _data = value;
}

public PsbList Pan { get; set; }

public IList<PsbResource> DataList => new List<PsbResource> { _data };

public int SampleRate { get; set; } = 48000;
Expand Down Expand Up @@ -534,7 +536,17 @@ public class OpusArchData : IArchData

public PsbResource Data { get; set; }

public IList<PsbResource> DataList => new List<PsbResource> { Body?.Data, Intro?.Data };
public IList<PsbResource> DataList {
get
{
if (Data != null)
{
return [Data];
}

return [Body.Data, Intro.Data];
}
}


public PsbDictionary PsbArchData { get; set; }
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit e3c5868

Please sign in to comment.