Merged changed from Croakfang's branch. (#72)
* merge (#71) * Bug fix, improved UI layout and live vocals * Bug Fixes, New Live Compatibility --------- Co-authored-by: CroakFang <1605296300@qq.com> * recovered shader functions * Fixed texture loading for costume 0015 --------- Co-authored-by: CroakFang <1605296300@qq.com>
This commit is contained in:
@@ -9,6 +9,8 @@ public class UmaViewerAudio
|
||||
{
|
||||
|
||||
static UmaViewerMain Main => UmaViewerMain.Instance;
|
||||
public static int LastAudioPartIndex = -1;
|
||||
|
||||
public struct UmaSoundInfo
|
||||
{
|
||||
public UmaDatabaseEntry awb;
|
||||
@@ -20,7 +22,42 @@ public class UmaViewerAudio
|
||||
public bool enable;
|
||||
public float volume;
|
||||
public float pan;
|
||||
public int cur_active_source = - 1;
|
||||
public AudioSource activeSource;
|
||||
public List<AudioSource> sourceList;
|
||||
|
||||
public void SwitchActiveSource(int index, bool forceUpdate = false)
|
||||
{
|
||||
if (cur_active_source == index && !forceUpdate) return;
|
||||
cur_active_source = index;
|
||||
for(int i = 0; i < sourceList.Count; i++)
|
||||
{
|
||||
if (i + 1 == index)
|
||||
{
|
||||
activeSource = sourceList[i];
|
||||
sourceList[i].volume = volume;
|
||||
sourceList[i].panStereo = pan;
|
||||
}
|
||||
else
|
||||
{
|
||||
sourceList[i].volume = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetVolume(float volume)
|
||||
{
|
||||
if (volume == this.volume || !activeSource) return;
|
||||
this.volume = volume;
|
||||
activeSource.volume = volume;
|
||||
}
|
||||
|
||||
public void SetPanStereo(float pan)
|
||||
{
|
||||
if (pan == this.pan || !activeSource) return;
|
||||
this.pan = pan;
|
||||
activeSource.panStereo = pan;
|
||||
}
|
||||
}
|
||||
|
||||
static public UmaSoundInfo getSoundPath(string name)
|
||||
@@ -96,21 +133,11 @@ public class UmaViewerAudio
|
||||
right3 = 6,
|
||||
}
|
||||
|
||||
public static void ApplyMainVolume(CuteAudioSource sourceList)
|
||||
{
|
||||
foreach (var source in sourceList.sourceList)
|
||||
{
|
||||
source.volume = (sourceList.enable ? sourceList.volume : 0);
|
||||
source.panStereo = sourceList.pan;
|
||||
}
|
||||
}
|
||||
|
||||
static public void AlterUpdate(float _liveCurrentTime, PartEntry partInfo, List<CuteAudioSource> liveVocal)
|
||||
static public void AlterUpdate(float _liveCurrentTime, PartEntry partInfo, List<CuteAudioSource> liveVocal, bool forceUpdate = false)
|
||||
{
|
||||
|
||||
var timeLineData = partInfo.PartSettings["time"];
|
||||
|
||||
//need to improve
|
||||
var targetIndex = 0;
|
||||
for (int i = timeLineData.Count - 1; i >= 0; i--)
|
||||
{
|
||||
@@ -121,32 +148,96 @@ public class UmaViewerAudio
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < liveVocal.Count; i++)
|
||||
{
|
||||
string partName = liveVocal[i].tag;
|
||||
if (LastAudioPartIndex == targetIndex) return;
|
||||
LastAudioPartIndex = targetIndex;
|
||||
|
||||
if (partInfo.PartSettings.ContainsKey(partName)){
|
||||
liveVocal[i].enable = partInfo.PartSettings[partName][targetIndex] > 0;
|
||||
|
||||
if (partInfo.PartSettings.ContainsKey(partName + "_vol"))
|
||||
{
|
||||
var volume = partInfo.PartSettings[partName + "_vol"][targetIndex];
|
||||
liveVocal[i].volume = (volume == 999 ? 1 : volume);
|
||||
}
|
||||
|
||||
float volume_rate = 1;
|
||||
if (partInfo.PartSettings.ContainsKey("volume_rate"))
|
||||
{
|
||||
volume_rate = partInfo.PartSettings["volume_rate"][targetIndex];
|
||||
}
|
||||
|
||||
if (volume_rate == 999) //chorus
|
||||
{
|
||||
var activeVocal = new List<CuteAudioSource>();
|
||||
for (int i = 0; i < liveVocal.Count; i++)
|
||||
{
|
||||
var vocal = liveVocal[i];
|
||||
var partName = vocal.tag;
|
||||
var active_index = (int)partInfo.PartSettings[partName][targetIndex];
|
||||
vocal.SwitchActiveSource(active_index, forceUpdate);
|
||||
|
||||
if (partInfo.PartSettings.ContainsKey(partName + "_pan"))
|
||||
{
|
||||
var pan = partInfo.PartSettings[partName + "_pan"][targetIndex];
|
||||
liveVocal[i].pan = (pan == 999 ? 0 : pan);
|
||||
var part = partInfo.PartSettings[partName + "_pan"];
|
||||
var pan = part[targetIndex];
|
||||
vocal.SetPanStereo(pan == 999 ? 0 : pan);
|
||||
}
|
||||
|
||||
if (active_index > 0)
|
||||
{
|
||||
activeVocal.Add(vocal);
|
||||
}
|
||||
}
|
||||
|
||||
switch(activeVocal.Count)
|
||||
{
|
||||
case 1:
|
||||
activeVocal[0].SetVolume(0.9954f);
|
||||
break;
|
||||
case 2:
|
||||
activeVocal[0].SetVolume(0.7031f);
|
||||
activeVocal[1].SetVolume(0.7031f);
|
||||
break;
|
||||
case 3:
|
||||
activeVocal[0].SetVolume(0.7056f);
|
||||
activeVocal[1].SetVolume(0.56f);
|
||||
activeVocal[1].SetVolume(0.56f);
|
||||
break;
|
||||
default:
|
||||
var per_vol = CalculateApproximateDBValues(0.9954f, activeVocal.Count);
|
||||
activeVocal.ForEach(v => v.SetVolume(per_vol));
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < liveVocal.Count; i++)
|
||||
{
|
||||
var vocal = liveVocal[i];
|
||||
var partName = vocal.tag;
|
||||
var active_index = (int)partInfo.PartSettings[partName][targetIndex];
|
||||
vocal.SwitchActiveSource(active_index, forceUpdate);
|
||||
|
||||
if (partInfo.PartSettings.ContainsKey(partName))
|
||||
{
|
||||
|
||||
if (partInfo.PartSettings.ContainsKey(partName + "_vol"))
|
||||
{
|
||||
var part = partInfo.PartSettings[partName + "_vol"];
|
||||
var volume = part[targetIndex];
|
||||
vocal.SetVolume(volume == 999 ? 0 : volume);
|
||||
}
|
||||
|
||||
if (partInfo.PartSettings.ContainsKey(partName + "_pan"))
|
||||
{
|
||||
var part = partInfo.PartSettings[partName + "_pan"];
|
||||
var pan = part[targetIndex];
|
||||
vocal.SetPanStereo(pan == 999 ? 0 : pan);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
foreach(var cute in liveVocal)
|
||||
{
|
||||
ApplyMainVolume(cute);
|
||||
}
|
||||
static public float CalculateApproximateDBValues(float total_volume, int num_sounds)
|
||||
{
|
||||
var total_db = 15f;
|
||||
var P0 = total_volume * (Math.Pow(10, total_db / 10));
|
||||
var P_per_sound = P0 / num_sounds;
|
||||
var per_volume = 10 * Math.Log10(P_per_sound / total_volume);
|
||||
return (float)(per_volume / total_db);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user