Audio stuff (WIP) - working with mixers!

This commit is contained in:
Texel 2020-08-22 06:35:33 -04:00
parent 177889a1e0
commit 8e47930a3c
16 changed files with 423 additions and 0 deletions

Binary file not shown.

View File

@ -0,0 +1,22 @@
fileFormatVersion: 2
guid: f38804d07e1b7804e8112dd2cfdee185
AudioImporter:
externalObjects: {}
serializedVersion: 6
defaultSettings:
loadType: 0
sampleRateSetting: 0
sampleRateOverride: 44100
compressionFormat: 1
quality: 1
conversionMode: 0
platformSettingOverrides: {}
forceToMono: 0
normalize: 1
preloadAudioData: 1
loadInBackground: 0
ambisonic: 0
3D: 1
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: b136faaf72d7dda4d85f9e47e4f5785f
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,91 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!241 &24100000
AudioMixerController:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: BGMMixer
m_OutputGroup: {fileID: 0}
m_MasterGroup: {fileID: 24300002}
m_Snapshots:
- {fileID: 24500006}
m_StartSnapshot: {fileID: 24500006}
m_SuspendThreshold: -80
m_EnableSuspend: 1
m_UpdateMode: 0
m_ExposedParameters: []
m_AudioMixerGroupViews:
- guids:
- 566c5e0ddf85965418c4e928780bd1c2
name: View
m_CurrentViewIndex: 0
m_TargetSnapshot: {fileID: 24500006}
--- !u!243 &24300002
AudioMixerGroupController:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Master
m_AudioMixer: {fileID: 24100000}
m_GroupID: 566c5e0ddf85965418c4e928780bd1c2
m_Children: []
m_Volume: e237ccf0dc4562d4d917288c333e4914
m_Pitch: c51c08a02aeb2cb4ca6cba414805904c
m_Send: 00000000000000000000000000000000
m_Effects:
- {fileID: 2747661610774394998}
- {fileID: 24400004}
m_UserColorIndex: 0
m_Mute: 0
m_Solo: 0
m_BypassEffects: 0
--- !u!244 &24400004
AudioMixerEffectController:
m_ObjectHideFlags: 3
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name:
m_EffectID: d4017f5208cf4654998c6405c2123e09
m_EffectName: Attenuation
m_MixLevel: 8927544744190b64eac9fd5220e88097
m_Parameters: []
m_SendTarget: {fileID: 0}
m_EnableWetMix: 0
m_Bypass: 0
--- !u!245 &24500006
AudioMixerSnapshotController:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Snapshot
m_AudioMixer: {fileID: 24100000}
m_SnapshotID: 4117f6b7fd784794ba09e4c024f88699
m_FloatValues: {}
m_TransitionOverrides: {}
--- !u!244 &2747661610774394998
AudioMixerEffectController:
m_ObjectHideFlags: 3
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name:
m_EffectID: e469285c525017b489ba03af652b3057
m_EffectName: Pitch Shifter
m_MixLevel: 31e0ac09030b46f4bab48ed4fa32c94e
m_Parameters:
- m_ParameterName: Pitch
m_GUID: 488bd2ac94838f14cadbca3c4455b0de
- m_ParameterName: FFT size
m_GUID: cdf507051bdff514288a92de380a7b9d
- m_ParameterName: Overlap
m_GUID: b6daacd24e06c24488dd0c8d9b8bfd5f
- m_ParameterName: Max channels
m_GUID: 0cefbc19749a7554497b8722a7fbe766
m_SendTarget: {fileID: 0}
m_EnableWetMix: 0
m_Bypass: 0

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: d0e13768ad98ea0468763d11da851a31
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@ -0,0 +1,22 @@
fileFormatVersion: 2
guid: f43397d0b3eb08542bc9c35458308eba
AudioImporter:
externalObjects: {}
serializedVersion: 6
defaultSettings:
loadType: 0
sampleRateSetting: 0
sampleRateOverride: 44100
compressionFormat: 1
quality: 1
conversionMode: 0
platformSettingOverrides: {}
forceToMono: 0
normalize: 1
preloadAudioData: 1
loadInBackground: 0
ambisonic: 0
3D: 1
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1 @@
I made these with bxfr - Texel

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 3ad24be65e3114542a1dcc3b8075919c
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@ -0,0 +1,22 @@
fileFormatVersion: 2
guid: 2cb067bd197684045a82612fcdab33a5
AudioImporter:
externalObjects: {}
serializedVersion: 6
defaultSettings:
loadType: 0
sampleRateSetting: 0
sampleRateOverride: 44100
compressionFormat: 1
quality: 1
conversionMode: 0
platformSettingOverrides: {}
forceToMono: 0
normalize: 1
preloadAudioData: 1
loadInBackground: 0
ambisonic: 0
3D: 1
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,63 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public static class AudioHelper {
static Dictionary<int, AudioClip> ClipByID;
static Dictionary<AudioClip, int> IDByClip;
public enum AudioCategory : byte {
Music = 1,
Fx = 2,
Voice = 3
}
public static float VolumeLevel(AudioCategory category) {
return PlayerPrefs.GetFloat(category.ToString(), 0.375f); // Did you know default volume of 1 is a bad idea
}
public static void SetVolume(AudioCategory category, float level) {
PlayerPrefs.SetFloat(category.ToString(), level);
PlayerPrefs.Save();
}
public static int ByClip(AudioClip clip) {
if (IDByClip == null) Init();
if (IDByClip.TryGetValue(clip, out int idIfPresent)) {
return idIfPresent;
}
Debug.LogWarningFormat("{0} is not resources loaded clip!!", clip.name);
return 0;
}
public static AudioClip ByID(int id) {
if (ClipByID == null) Init();
try {
return ClipByID[id];
} catch {
throw new System.Exception(string.Format("Failure to find SFX with ID {0}", id));
}
}
// Build the audio lookup
static void Init() {
ClipByID = new Dictionary<int, AudioClip>();
IDByClip = new Dictionary<AudioClip,int>();
var allAudio = Resources.LoadAll<AudioClip>("");
for (int i = 0; i < allAudio.Length; ++i) {
var clip = allAudio[i];
ClipByID.Add(i, clip);
IDByClip.Add(clip, i);
}
var oString = "Loaded Sounds: ";
foreach (var key in ClipByID) {
oString += key;
}
Debug.Log(oString);
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1affa7ecbd65bf04cb3ee7fd44d9f370
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,43 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using EntityNetwork;
public class AudioProvider : EntityBase, IAutoRegister
{
public static AudioProvider Instance;
public override void Awake() {
base.Awake();
Instance = this;
bgmSrc = GetComponent<AudioSource>();
}
public float musicSpeed = 1f;
AudioSource bgmSrc;
public void Update() {
// TODO - This is WIP help
//bgmSrc.outputAudioMixerGroup.
}
int lastAudioFrame = 0;
public static void PlaySFX(AudioClip sfx, AudioHelper.AudioCategory category = AudioHelper.AudioCategory.Fx, float volume = 1.0f, bool sendRemote = true) {
if (sfx == null) return;
if (sendRemote)
Instance.RaiseEvent('s', true, AudioHelper.ByClip(sfx), (byte)category, volume);
else
Instance.InternallyPlaySFXEvent(AudioHelper.ByClip(sfx), (byte)category, volume);
}
[NetEvent('s')]
public void InternallyPlaySFXEvent(int sfxID, byte category, float volume) {
// Don't allow multiple audio sources to trigger at once
if (Time.frameCount == lastAudioFrame) return;
lastAudioFrame = Time.frameCount;
var clip = AudioHelper.ByID(sfxID);
AudioSource.PlayClipAtPoint(clip, Camera.main.transform.position, AudioHelper.VolumeLevel((AudioHelper.AudioCategory)category) * volume);
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8ff52355fe571224f9827356ec82bb42
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -838,6 +838,8 @@ GameObject:
- component: {fileID: 1199366272}
- component: {fileID: 1199366271}
- component: {fileID: 1199366270}
- component: {fileID: 1199366274}
- component: {fileID: 1199366273}
m_Layer: 0
m_Name: Main Camera
m_TagString: MainCamera
@ -910,6 +912,118 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!82 &1199366273
AudioSource:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1199366269}
m_Enabled: 1
serializedVersion: 4
OutputAudioMixerGroup: {fileID: 24300002, guid: d0e13768ad98ea0468763d11da851a31,
type: 2}
m_audioClip: {fileID: 8300000, guid: f38804d07e1b7804e8112dd2cfdee185, type: 3}
m_PlayOnAwake: 1
m_Volume: 1
m_Pitch: 1
Loop: 0
Mute: 0
Spatialize: 0
SpatializePostEffects: 0
Priority: 128
DopplerLevel: 1
MinDistance: 1
MaxDistance: 500
Pan2D: 0
rolloffMode: 0
BypassEffects: 0
BypassListenerEffects: 0
BypassReverbZones: 0
rolloffCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 1
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 1
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
panLevelCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
spreadCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
reverbZoneMixCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 1
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
--- !u!114 &1199366274
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1199366269}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 8ff52355fe571224f9827356ec82bb42, type: 3}
m_Name:
m_EditorClassIdentifier:
EntityID: 900
authorityID: -1
musicSpeed: 1
--- !u!1 &1280147033
GameObject:
m_ObjectHideFlags: 0