fractal audio

This commit is contained in:
Cat Flynn 2021-01-07 02:00:17 +00:00
parent e1efc7954a
commit 2654d6bfbb
12 changed files with 273 additions and 36 deletions

8
Assets/Data.meta Normal file
View File

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

View File

@ -32,7 +32,7 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
Path: Assets/FMOD/Desktop/Master.bank Path: Assets/FMOD/Desktop/Master.bank
Name: Master Name: Master
lastModified: 637455188020000000 lastModified: 637454808856759986
LoadResult: 0 LoadResult: 0
FileSizes: [] FileSizes: []
Exists: 1 Exists: 1
@ -81,7 +81,7 @@ MonoBehaviour:
- {fileID: -5408626126966111271} - {fileID: -5408626126966111271}
StringsBanks: StringsBanks:
- {fileID: 6606792957875447575} - {fileID: 6606792957875447575}
stringsBankWriteTime: 637455188020000000 stringsBankWriteTime: 637454808856769971
cacheVersion: 4 cacheVersion: 4
--- !u!114 &6606792957875447575 --- !u!114 &6606792957875447575
MonoBehaviour: MonoBehaviour:
@ -97,7 +97,7 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
Path: Assets/FMOD/Desktop/Master.strings.bank Path: Assets/FMOD/Desktop/Master.strings.bank
Name: Master.strings Name: Master.strings
lastModified: 637455188020000000 lastModified: 637454808856769971
LoadResult: 0 LoadResult: 0
FileSizes: FileSizes:
- Name: - Name:

View File

@ -10,8 +10,8 @@ GameObject:
m_Component: m_Component:
- component: {fileID: 3397488660173986649} - component: {fileID: 3397488660173986649}
- component: {fileID: 3397488660173986648} - component: {fileID: 3397488660173986648}
- component: {fileID: 3397488660173986651}
- component: {fileID: 3397488660173986646} - component: {fileID: 3397488660173986646}
- component: {fileID: 1450132965988037794}
m_Layer: 0 m_Layer: 0
m_Name: Main Camera m_Name: Main Camera
m_TagString: MainCamera m_TagString: MainCamera
@ -76,14 +76,6 @@ Camera:
m_OcclusionCulling: 1 m_OcclusionCulling: 1
m_StereoConvergence: 10 m_StereoConvergence: 10
m_StereoSeparation: 0.022 m_StereoSeparation: 0.022
--- !u!81 &3397488660173986651
AudioListener:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3397488660173986650}
m_Enabled: 1
--- !u!114 &3397488660173986646 --- !u!114 &3397488660173986646
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -116,6 +108,19 @@ MonoBehaviour:
m_RequiresDepthTexture: 0 m_RequiresDepthTexture: 0
m_RequiresColorTexture: 0 m_RequiresColorTexture: 0
m_Version: 2 m_Version: 2
--- !u!114 &1450132965988037794
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3397488660173986650}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 86c6556701af9e04380698b89f691b6e, type: 3}
m_Name:
m_EditorClassIdentifier:
ListenerNumber: -1
--- !u!1 &3397488660425852636 --- !u!1 &3397488660425852636
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -371,7 +376,7 @@ Transform:
m_GameObject: {fileID: 3397488660842926092} m_GameObject: {fileID: 3397488660842926092}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 105.96986, y: -8.773619, z: 846.83606} m_LocalPosition: {x: 105.96986, y: -8.773619, z: 846.83606}
m_LocalScale: {x: 1109.1631, y: 1039.2305, z: 1} m_LocalScale: {x: 1053.1565, y: 1039.2305, z: 1}
m_Children: [] m_Children: []
m_Father: {fileID: 3397488661916228001} m_Father: {fileID: 3397488661916228001}
m_RootOrder: 1 m_RootOrder: 1
@ -461,6 +466,7 @@ GameObject:
serializedVersion: 6 serializedVersion: 6
m_Component: m_Component:
- component: {fileID: 3397488660859550701} - component: {fileID: 3397488660859550701}
- component: {fileID: 2477419886909461543}
m_Layer: 0 m_Layer: 0
m_Name: Rendering m_Name: Rendering
m_TagString: Untagged m_TagString: Untagged
@ -484,6 +490,22 @@ Transform:
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 0 m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &2477419886909461543
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3397488660859550700}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 3832fa92b7c91804697fe9f4f858b5d4, type: 3}
m_Name:
m_EditorClassIdentifier:
_fractal: {fileID: 3397488660425852632}
_tunnel: {fileID: 3397488660842926088}
_channel: 0
_sample: 0
--- !u!1 &3397488661354499722 --- !u!1 &3397488661354499722
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -123,6 +123,60 @@ NavMeshSettings:
debug: debug:
m_Flags: 0 m_Flags: 0
m_NavMeshData: {fileID: 0} m_NavMeshData: {fileID: 0}
--- !u!1 &84273093
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 84273095}
- component: {fileID: 84273094}
m_Layer: 0
m_Name: App
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &84273094
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 84273093}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 9a6610d2e704f1648819acc8d7460285, type: 3}
m_Name:
m_EditorClassIdentifier:
CollisionTag:
Event: event:/Music
PlayEvent: 1
StopEvent: 2
AllowFadeout: 1
TriggerOnce: 0
Preload: 0
Params: []
OverrideAttenuation: 0
OverrideMinDistance: 0
OverrideMaxDistance: 0
--- !u!4 &84273095
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 84273093}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 8
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &186457103 --- !u!1 &186457103
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -445,7 +499,7 @@ PrefabInstance:
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 3397488660842926093, guid: 1f82f952c53fc7449a0091cf29ba3def, type: 3} - target: {fileID: 3397488660842926093, guid: 1f82f952c53fc7449a0091cf29ba3def, type: 3}
propertyPath: m_LocalScale.x propertyPath: m_LocalScale.x
value: 1847.5209 value: 2268.2031
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 3397488660859550700, guid: 1f82f952c53fc7449a0091cf29ba3def, type: 3} - target: {fileID: 3397488660859550700, guid: 1f82f952c53fc7449a0091cf29ba3def, type: 3}
propertyPath: m_Name propertyPath: m_Name
@ -816,6 +870,7 @@ GameObject:
m_Component: m_Component:
- component: {fileID: 1250063708} - component: {fileID: 1250063708}
- component: {fileID: 1250063707} - component: {fileID: 1250063707}
- component: {fileID: 1250063710}
m_Layer: 0 m_Layer: 0
m_Name: Audio m_Name: Audio
m_TagString: Untagged m_TagString: Untagged
@ -836,7 +891,7 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
bpm: 180 bpm: 180
OnBeat: _onBeat:
m_PersistentCalls: m_PersistentCalls:
m_Calls: m_Calls:
- m_Target: {fileID: 186457106} - m_Target: {fileID: 186457106}
@ -877,6 +932,24 @@ Transform:
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 7 m_RootOrder: 7
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1250063710
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1250063706}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: b9468c5f457ace64f8d4df6d642b107f, type: 3}
m_Name:
m_EditorClassIdentifier:
LoadEvent: 1
UnloadEvent: 2
Banks:
- Master
CollisionTag:
PreloadSamples: 1
--- !u!1 &1395215960 --- !u!1 &1395215960
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -2,8 +2,9 @@ using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.Serialization;
public class AudioBeatManager : MonoBehaviour public class AudioBeatManager : MonoBehaviour, IAudioBeatManager
{ {
[SerializeField] private float bpm; [SerializeField] private float bpm;
public float TimeBetweenBeats => _bps * Time.deltaTime; public float TimeBetweenBeats => _bps * Time.deltaTime;
@ -11,8 +12,11 @@ public class AudioBeatManager : MonoBehaviour
private float _bps; private float _bps;
private int _currentBeat = 0; private int _currentBeat = 0;
private float _timer; private float _timer;
public IntEvent OnBeat; [SerializeField] [FormerlySerializedAs("OnBeat")]
private IntEvent _onBeat;
public IntEvent OnBeat => _onBeat;
public event Action<int> OnBeatEvent; public event Action<int> OnBeatEvent;
private void Awake() private void Awake()
{ {
@ -32,4 +36,10 @@ public class AudioBeatManager : MonoBehaviour
OnBeatEvent?.Invoke(_currentBeat); OnBeatEvent?.Invoke(_currentBeat);
} }
} }
}
public interface IAudioBeatManager
{
public IntEvent OnBeat { get; }
public event Action<int> OnBeatEvent;
} }

View File

@ -0,0 +1,40 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using FMODUnity;
using NUnit.Framework;
using TMPro;
using UnityEngine;
using UnityEngine.Rendering.Universal;
public class AudioVisualizer : MonoBehaviour
{
[SerializeField] private Renderer _fractal;
[SerializeField] private Renderer _tunnel;
[SerializeField] private AudioVisualizerSettings _settings;
// https://qa.fmod.com/t/getting-spectrum-of-master-channel-in-unity/12579/2
// private FMOD.Studio.EventInstance _event;
private FMOD.DSP _fft;
private float _initialPower;
private void Start()
{
// _event = RuntimeManager.CreateInstance("event:/Music");
RuntimeManager.CoreSystem.createDSPByType(FMOD.DSP_TYPE.FFT, out _fft);
RuntimeManager.CoreSystem.getMasterChannelGroup(out var channelGroup);
channelGroup.addDSP(FMOD.CHANNELCONTROL_DSP_INDEX.HEAD, _fft);
_settings.Initialise(_fractal.material, _tunnel.material);
}
private void LateUpdate()
{
_settings.Update(_fft, _fractal, _tunnel);
}
}

View File

@ -0,0 +1,67 @@
using System;
using System.Runtime.InteropServices;
using FMOD;
using UnityEngine;
[CreateAssetMenu(menuName = "Audio Visualizer Settings")]
public class AudioVisualizerSettings : ScriptableObject
{
[Serializable]
private struct ShaderPropertyAnimation
{
public string name;
public float multiplier;
[UnityEngine.Range(0, 5)]
public int channel;
[UnityEngine.Range(0, 2048)]
public int sample;
public float Initial { get; set; }
}
[SerializeField] private ShaderPropertyAnimation[] _fractalAnimations;
[SerializeField] private ShaderPropertyAnimation[] _tunnelAnimations;
public void Initialise(Material fractal, Material tunnel)
{
for (int i = 0; i < _fractalAnimations.Length; i++)
{
var anim = _fractalAnimations[i];
anim.Initial = fractal.GetFloat(anim.name);
_fractalAnimations[i] = anim;
}
for (int i = 0; i < _tunnelAnimations.Length; i++)
{
var anim = _tunnelAnimations[i];
anim.Initial = tunnel.GetFloat(anim.name);
_tunnelAnimations[i] = anim;
}
}
public void Update(DSP fft, Renderer fractal, Renderer tunnel)
{
fft.getParameterData((int) FMOD.DSP_FFT.SPECTRUMDATA, out var unmanagedData, out var length);
var fftData = (FMOD.DSP_PARAMETER_FFT) Marshal.PtrToStructure(unmanagedData, typeof(FMOD.DSP_PARAMETER_FFT));
var spectrum = fftData.spectrum;
var l = spectrum.Length;
if (l == 0) return;
for (int i = 0; i < _fractalAnimations.Length; i++)
{
var anim = _fractalAnimations[i];
var a = spectrum[anim.channel][anim.sample];
fractal.material.SetFloat(anim.name, anim.Initial + anim.multiplier * a);
}
for (int i = 0; i < _tunnelAnimations.Length; i++)
{
var anim = _tunnelAnimations[i];
var a = spectrum[anim.channel][anim.sample];
tunnel.material.SetFloat(anim.name, anim.Initial + anim.multiplier * a);
}
}
}

View File

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

View File

@ -1,18 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FractalController : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}

View File

@ -0,0 +1,16 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a918b83cb0f52b445bf4975f41eaf321, type: 3}
m_Name: Audio Visualiser Settings
m_EditorClassIdentifier:
_fractalAnimations: []
_tunnelAnimations: []

View File

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