Lip sync should now be able to handle stereo audio where one track is silent, but Unity's microphone input is forced to mono audio anyways. It still improves things with canned audio.
This commit is contained in:
parent
e9f0c35f0b
commit
b09639b71d
1 changed files with 26 additions and 2 deletions
|
|
@ -806,8 +806,32 @@ public class OpenSeeVRMDriver : MonoBehaviour {
|
|||
return;
|
||||
|
||||
audioVolume = 0f;
|
||||
foreach (float v in buffer)
|
||||
audioVolume += Mathf.Abs(v);
|
||||
float leftVolume = 0f;
|
||||
float rightVolume = 0f;
|
||||
bool channel = false;
|
||||
foreach (float v in buffer) {
|
||||
float sample = Mathf.Abs(v);
|
||||
audioVolume += sample;
|
||||
if (channels > 1) {
|
||||
if (channel)
|
||||
rightVolume += sample;
|
||||
channel = !channel;
|
||||
}
|
||||
}
|
||||
if (channels > 1) {
|
||||
leftVolume = audioVolume - rightVolume;
|
||||
if (rightVolume < leftVolume / 3f) {
|
||||
audioVolume = 2f * leftVolume;
|
||||
for (int i = 0; i + 1 < buffer.Length; i += 2) {
|
||||
buffer[i + 1] = buffer[i];
|
||||
}
|
||||
} else if (leftVolume < rightVolume / 3f) {
|
||||
audioVolume = 2f * rightVolume;
|
||||
for (int i = 0; i + 1 < buffer.Length; i += 2) {
|
||||
buffer[i] = buffer[i + 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
audioVolume /= buffer.Length;
|
||||
|
||||
int totalLen = partialPos + buffer.Length;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue