Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 912640f

Browse files
music syncing enabled'
1 parent c4c5e32 commit 912640f

13 files changed

+596
-37
lines changed

‎UnityScripting/Assembly-CSharp.csproj

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
4-
<LangVersion>4</LangVersion>
4+
<LangVersion>6</LangVersion>
55
</PropertyGroup>
66
<PropertyGroup>
77
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -13,7 +13,7 @@
1313
<OutputType>Library</OutputType>
1414
<AppDesignerFolder>Properties</AppDesignerFolder>
1515
<AssemblyName>Assembly-CSharp</AssemblyName>
16-
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
16+
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
1717
<FileAlignment>512</FileAlignment>
1818
<BaseDirectory>Assets</BaseDirectory>
1919
</PropertyGroup>
@@ -22,7 +22,7 @@
2222
<DebugType>full</DebugType>
2323
<Optimize>false</Optimize>
2424
<OutputPath>Temp\bin\Debug\</OutputPath>
25-
<DefineConstants>DEBUG;TRACE;UNITY_5_3_OR_NEWER;UNITY_5_4_OR_NEWER;UNITY_5_5_OR_NEWER;UNITY_5_6_OR_NEWER;UNITY_2017_1_OR_NEWER;UNITY_2017_2_OR_NEWER;UNITY_2017_3_OR_NEWER;UNITY_2017_3_1;UNITY_2017_3;UNITY_2017;PLATFORM_ARCH_64;UNITY_64;ENABLE_AUDIO;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_DUCK_TYPING;ENABLE_GENERICS;ENABLE_PVR_GI;ENABLE_MICROPHONE;ENABLE_MULTIPLE_DISPLAYS;ENABLE_PHYSICS;ENABLE_SPRITERENDERER_FLIPPING;ENABLE_SPRITES;ENABLE_GRID;ENABLE_TILEMAP;ENABLE_TERRAIN;ENABLE_RAKNET;ENABLE_DIRECTOR;ENABLE_UNET;ENABLE_LZMA;ENABLE_UNITYEVENTS;ENABLE_WEBCAM;ENABLE_WWW;ENABLE_CLOUD_SERVICES_COLLAB;ENABLE_CLOUD_SERVICES_COLLAB_SOFTLOCKS;ENABLE_CLOUD_SERVICES_ADS;ENABLE_CLOUD_HUB;ENABLE_CLOUD_PROJECT_ID;ENABLE_CLOUD_SERVICES_USE_WEBREQUEST;ENABLE_CLOUD_SERVICES_UNET;ENABLE_CLOUD_SERVICES_BUILD;ENABLE_CLOUD_LICENSE;ENABLE_EDITOR_HUB;ENABLE_EDITOR_HUB_LICENSE;ENABLE_WEBSOCKET_CLIENT;ENABLE_DIRECTOR_AUDIO;ENABLE_DIRECTOR_TEXTURE;ENABLE_TIMELINE;ENABLE_EDITOR_METRICS;ENABLE_EDITOR_METRICS_CACHING;ENABLE_NATIVE_ARRAY;ENABLE_SPRITE_MASKING;INCLUDE_DYNAMIC_GI;INCLUDE_GI;ENABLE_MONO_BDWGC;PLATFORM_SUPPORTS_MONO;RENDER_SOFTWARE_CURSOR;INCLUDE_PUBNUB;ENABLE_PLAYMODE_TESTS_RUNNER;ENABLE_VIDEO;ENABLE_RMGUI;ENABLE_PACKMAN;ENABLE_CUSTOM_RENDER_TEXTURE;ENABLE_STYLE_SHEETS;ENABLE_LOCALIZATION;PLATFORM_STANDALONE_WIN;PLATFORM_STANDALONE;UNITY_STANDALONE_WIN;UNITY_STANDALONE;ENABLE_SUBSTANCE;ENABLE_RUNTIME_GI;ENABLE_MOVIES;ENABLE_NETWORK;ENABLE_CRUNCH_TEXTURE_COMPRESSION;ENABLE_UNITYWEBREQUEST;ENABLE_CLOUD_SERVICES;ENABLE_CLOUD_SERVICES_ANALYTICS;ENABLE_CLOUD_SERVICES_PURCHASING;ENABLE_CLOUD_SERVICES_CRASH_REPORTING;ENABLE_EVENT_QUEUE;ENABLE_CLUSTERINPUT;ENABLE_VR;ENABLE_AR;ENABLE_WEBSOCKET_HOST;ENABLE_MONO;NET_2_0_SUBSET;ENABLE_PROFILER;UNITY_ASSERTIONS;UNITY_EDITOR;UNITY_EDITOR_64;UNITY_EDITOR_WIN;ENABLE_NATIVE_ARRAY_CHECKS;UNITY_TEAM_LICENSE</DefineConstants>
25+
<DefineConstants>DEBUG;TRACE;UNITY_5_3_OR_NEWER;UNITY_5_4_OR_NEWER;UNITY_5_5_OR_NEWER;UNITY_5_6_OR_NEWER;UNITY_2017_1_OR_NEWER;UNITY_2017_2_OR_NEWER;UNITY_2017_3_OR_NEWER;UNITY_2017_3_1;UNITY_2017_3;UNITY_2017;PLATFORM_ARCH_64;UNITY_64;ENABLE_AUDIO;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_DUCK_TYPING;ENABLE_GENERICS;ENABLE_PVR_GI;ENABLE_MICROPHONE;ENABLE_MULTIPLE_DISPLAYS;ENABLE_PHYSICS;ENABLE_SPRITERENDERER_FLIPPING;ENABLE_SPRITES;ENABLE_GRID;ENABLE_TILEMAP;ENABLE_TERRAIN;ENABLE_RAKNET;ENABLE_DIRECTOR;ENABLE_UNET;ENABLE_LZMA;ENABLE_UNITYEVENTS;ENABLE_WEBCAM;ENABLE_WWW;ENABLE_CLOUD_SERVICES_COLLAB;ENABLE_CLOUD_SERVICES_COLLAB_SOFTLOCKS;ENABLE_CLOUD_SERVICES_ADS;ENABLE_CLOUD_HUB;ENABLE_CLOUD_PROJECT_ID;ENABLE_CLOUD_SERVICES_USE_WEBREQUEST;ENABLE_CLOUD_SERVICES_UNET;ENABLE_CLOUD_SERVICES_BUILD;ENABLE_CLOUD_LICENSE;ENABLE_EDITOR_HUB;ENABLE_EDITOR_HUB_LICENSE;ENABLE_WEBSOCKET_CLIENT;ENABLE_DIRECTOR_AUDIO;ENABLE_DIRECTOR_TEXTURE;ENABLE_TIMELINE;ENABLE_EDITOR_METRICS;ENABLE_EDITOR_METRICS_CACHING;ENABLE_NATIVE_ARRAY;ENABLE_SPRITE_MASKING;INCLUDE_DYNAMIC_GI;INCLUDE_GI;ENABLE_MONO_BDWGC;PLATFORM_SUPPORTS_MONO;RENDER_SOFTWARE_CURSOR;INCLUDE_PUBNUB;ENABLE_PLAYMODE_TESTS_RUNNER;ENABLE_VIDEO;ENABLE_RMGUI;ENABLE_PACKMAN;ENABLE_CUSTOM_RENDER_TEXTURE;ENABLE_STYLE_SHEETS;ENABLE_LOCALIZATION;PLATFORM_STANDALONE_WIN;PLATFORM_STANDALONE;UNITY_STANDALONE_WIN;UNITY_STANDALONE;ENABLE_SUBSTANCE;ENABLE_RUNTIME_GI;ENABLE_MOVIES;ENABLE_NETWORK;ENABLE_CRUNCH_TEXTURE_COMPRESSION;ENABLE_UNITYWEBREQUEST;ENABLE_CLOUD_SERVICES;ENABLE_CLOUD_SERVICES_ANALYTICS;ENABLE_CLOUD_SERVICES_PURCHASING;ENABLE_CLOUD_SERVICES_CRASH_REPORTING;ENABLE_EVENT_QUEUE;ENABLE_CLUSTERINPUT;ENABLE_VR;ENABLE_AR;ENABLE_WEBSOCKET_HOST;ENABLE_MONO;NET_4_6;ENABLE_PROFILER;UNITY_ASSERTIONS;UNITY_EDITOR;UNITY_EDITOR_64;UNITY_EDITOR_WIN;ENABLE_NATIVE_ARRAY_CHECKS;UNITY_TEAM_LICENSE</DefineConstants>
2626
<ErrorReport>prompt</ErrorReport>
2727
<WarningLevel>4</WarningLevel>
2828
<NoWarn>0169</NoWarn>
@@ -44,14 +44,16 @@
4444
<Reference Include="System.Runtime.Serialization" />
4545
<Reference Include="System.Xml.Linq" />
4646
<Reference Include="UnityEngine">
47-
<HintPath>C:/Program Files/Unity2017.3/Editor/Data/Managed\UnityEngine.dll</HintPath>
47+
<HintPath>C:\Program Files\Unity2017.3\Editor\Data\Managed\UnityEngine.dll</HintPath>
4848
</Reference>
4949
<Reference Include="UnityEditor">
5050
<HintPath>C:/Program Files/Unity2017.3/Editor/Data/Managed/UnityEditor.dll</HintPath>
5151
</Reference>
5252
</ItemGroup>
5353
<ItemGroup>
54+
<Compile Include="Assets\MusicSyncVisualizer\AudioSpectrum.cs" />
5455
<Compile Include="Assets\MusicSyncVisualizer\AudioSyncer.cs" />
56+
<Compile Include="Assets\MusicSyncVisualizer\AudioSyncScale.cs" />
5557
<Reference Include="Vuforia.UnityExtensions.Editor">
5658
<HintPath>C:/Program Files/Unity2017.3/Editor/Data/PlaybackEngines/VuforiaSupport/Managed/Editor/Vuforia.UnityExtensions.Editor.dll</HintPath>
5759
</Reference>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
5+
public class AudioSpectrum : MonoBehaviour {
6+
7+
private void Update()
8+
{
9+
AudioListener.GetSpectrumData(m_audioSpectrum, 0, fftWindow);
10+
11+
if (m_audioSpectrum != null && m_audioSpectrum.Length > 0)
12+
spectrumValue = m_audioSpectrum[0] * 100;
13+
}
14+
15+
private void Start()
16+
{
17+
m_audioSpectrum = new float[64];
18+
}
19+
20+
private void Awake()
21+
{
22+
if (instance != null)
23+
{
24+
Destroy(gameObject);
25+
}
26+
else
27+
{
28+
instance = this;
29+
DontDestroyOnLoad(gameObject);
30+
}
31+
}
32+
33+
public float spectrumValue { get; private set; }
34+
35+
public FFTWindow fftWindow;
36+
37+
private float[] m_audioSpectrum;
38+
39+
public static AudioSpectrum instance;
40+
41+
}

‎UnityScripting/Assets/MusicSyncVisualizer/AudioSpectrum.cs.meta

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
5+
public class AudioSyncScale : AudioSyncer {
6+
7+
private IEnumerator MoveToScale(Vector3 _target)
8+
{
9+
Vector3 _curr = transform.localScale;
10+
Vector3 _initial = _curr;
11+
float _timer = 0;
12+
13+
while (_curr != _target)
14+
{
15+
_curr = Vector3.Lerp(_initial, _target, _timer / timeToBeat);
16+
_timer += Time.deltaTime;
17+
18+
transform.localScale = _curr;
19+
20+
yield return null;
21+
}
22+
}
23+
24+
public override void OnUpdate()
25+
{
26+
base.OnUpdate();
27+
transform.localScale = Vector3.Lerp(transform.localScale, restScale, restSmoothTime * Time.deltaTime);
28+
}
29+
30+
public override void OnBeat()
31+
{
32+
base.OnBeat();
33+
34+
StopCoroutine("MoveToScale");
35+
StartCoroutine("MoveToScale", beatScale);
36+
}
37+
38+
public Vector3 beatScale;
39+
public Vector3 restScale;
40+
public float timeToBeat;
41+
public float restSmoothTime;
42+
}

‎UnityScripting/Assets/MusicSyncVisualizer/AudioSyncScale.cs.meta

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎UnityScripting/Assets/MusicSyncVisualizer/AudioSyncer.cs

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,43 @@
44

55
public class AudioSyncer : MonoBehaviour {
66

7-
private void Update()
8-
{
9-
audio.GetSpectrumData(m_audioSpectrum, 0, fftWindow);
10-
11-
m_audioValue = 0;
12-
13-
for (int i = 1; i < m_audioSpectrum.Length - 1; i++)
7+
public virtual void OnBeat()
8+
{
9+
Debug.Log("beat");
10+
m_timer = 0;
11+
}
12+
13+
public virtual void OnUpdate()
14+
{
15+
m_previousAudioValue = m_audioValue;
16+
m_audioValue = AudioSpectrum.instance.spectrumValue;
17+
18+
if (m_previousAudioValue > bias &&
19+
m_audioValue <= bias)
1420
{
15-
/*Debug.DrawLine(new Vector3(i - 1, m_audioSpectrum[i] + 10, 0), new Vector3(i, m_audioSpectrum[i + 1] + 10, 0), Color.red);
16-
Debug.DrawLine(new Vector3(i - 1, Mathf.Log(m_audioSpectrum[i - 1]) + 10, 2), new Vector3(i, Mathf.Log(m_audioSpectrum[i]) + 10, 2), Color.cyan);
17-
Debug.DrawLine(new Vector3(Mathf.Log(i - 1), m_audioSpectrum[i - 1] - 10, 1), new Vector3(Mathf.Log(i), m_audioSpectrum[i] - 10, 1), Color.green);
18-
Debug.DrawLine(new Vector3(Mathf.Log(i - 1), Mathf.Log(m_audioSpectrum[i - 1]), 3), new Vector3(Mathf.Log(i), Mathf.Log(m_audioSpectrum[i]), 3), Color.blue);*/
21+
if (m_timer > timeStep)
22+
OnBeat();
23+
}
1924

20-
m_audioValue -= Mathf.Log(m_audioSpectrum[i - 1]) / 50;
25+
if (m_previousAudioValue <= bias &&
26+
m_audioValue > bias)
27+
{
28+
if (m_timer > timeStep)
29+
OnBeat();
2130
}
2231

23-
Debug.DrawLine(Vector3.zero, new Vector3(0, 15 - m_audioValue, 0), Color.white);
24-
Debug.DrawLine(Vector3.zero, new Vector3(0, minimumThreshold, 0), Color.green);
25-
Debug.DrawLine(new Vector3(0, maxThreshold, 0), new Vector3 (0, 15 - m_audioValue, 0), Color.red);
26-
Debug.Log(m_audioValue);
27-
}
32+
m_timer += Time.deltaTime;
33+
}
2834

29-
private void Start()
30-
{
31-
m_audioSpectrum=newfloat[64];
32-
}
35+
private void Update()
36+
{
37+
OnUpdate();
38+
}
3339

34-
public AudioSource audio;
35-
public FFTWindow fftWindow;
36-
public float minimumThreshold;
37-
public float maxThreshold;
40+
public float bias;
41+
public float timeStep;
3842

39-
private float[]m_audioSpectrum;
43+
private floatm_previousAudioValue;
4044
private float m_audioValue;
45+
private float m_timer;
4146
}

‎UnityScripting/Assets/MusicSyncVisualizer/AudioSyncer.cs.meta

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
8.25 MB
Binary file not shown.

‎UnityScripting/Assets/MusicSyncVisualizer/ES_Dazed Summer - Jack Elphick.mp3.meta

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
4.88 MB
Binary file not shown.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /