-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from voxell-tech/develop
v1.2.1
- Loading branch information
Showing
24 changed files
with
10,533 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,7 +101,6 @@ crashlytics-build.properties | |
AudioClips/ | ||
*.mp3 | ||
*.wav | ||
*.audio | ||
|
||
# license | ||
LICENSE.meta | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
## [1.2.1] | ||
|
||
### Changes | ||
|
||
Add in VX.Audio (remove *.audio from `.gitignore`). | ||
|
||
## [1.2.0] | ||
|
||
### Changes | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
This program is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU General Public License | ||
as published by the Free Software Foundation; either version 2 | ||
of the License, or (at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program; if not, write to the Free Software Foundation, | ||
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
The Original Code is Copyright (C) 2020 Voxell Technologies. | ||
All rights reserved. | ||
*/ | ||
|
||
using UnityEngine; | ||
using UnityEngine.VFX; | ||
|
||
namespace Voxell.Audio | ||
{ | ||
[RequireComponent(typeof(VisualEffect))] | ||
[RequireComponent(typeof(AudioSource))] | ||
public sealed partial class AudioCore : MonoBehaviour | ||
{ | ||
private const float EPSILON = 0.001f; | ||
|
||
void Start() | ||
{ | ||
InitAgentInteraction(); | ||
InitAudioVisualizer(); | ||
} | ||
|
||
void Update() => UpdateAgentInteraction(); | ||
void FixedUpdate() => UpdateAudioVisualizer(); | ||
|
||
internal static class ShaderPropertyId | ||
{ | ||
public static readonly int sampleCount = Shader.PropertyToID("sampleCount"); | ||
public static readonly int transform = Shader.PropertyToID("transform"); | ||
public static readonly int oldTransform = Shader.PropertyToID("oldTransform"); | ||
public static readonly int framRate = Shader.PropertyToID("framRate"); | ||
} | ||
|
||
internal static class ShaderBufferId | ||
{ | ||
public static readonly int cb_samplePoints = Shader.PropertyToID("cb_samplePoints"); | ||
public static readonly int cb_position = Shader.PropertyToID("cb_position"); | ||
public static readonly int cb_oldPosition = Shader.PropertyToID("cb_oldPosition"); | ||
public static readonly int cb_normal = Shader.PropertyToID("cb_normal;"); | ||
public static readonly int tex_positionMap = Shader.PropertyToID("tex_positionMap"); | ||
public static readonly int tex_velocityMap = Shader.PropertyToID("tex_velocityMap"); | ||
public static readonly int tex_normalMap = Shader.PropertyToID("tex_normalMap"); | ||
} | ||
|
||
internal static class VFXPropertyId | ||
{ | ||
public static readonly int mesh_sampleMesh = Shader.PropertyToID("SampleMesh"); | ||
public static readonly int float_forceMultiplier = Shader.PropertyToID("ForceMultiplier"); | ||
public static readonly int int_triangleCount = Shader.PropertyToID("TriangleCount"); | ||
public static readonly int float_idleNoiseSpeed = Shader.PropertyToID("IdleNoiseSpeed"); | ||
public static readonly int float_noiseIntensity = Shader.PropertyToID("NoiseIntensity"); | ||
public static readonly int float3_noiseScale = Shader.PropertyToID("NoiseScale"); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
This program is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU General Public License | ||
as published by the Free Software Foundation; either version 2 | ||
of the License, or (at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program; if not, write to the Free Software Foundation, | ||
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
The Original Code is Copyright (C) 2020 Voxell Technologies. | ||
All rights reserved. | ||
*/ | ||
|
||
using UnityEngine; | ||
|
||
namespace Voxell.Audio | ||
{ | ||
public partial class AudioCore | ||
{ | ||
[Header("Audio Visualizer Interaction")] | ||
[Tooltip("Velocity of audio visualizer when there is no interaction")] | ||
public Vector2 idleVelocity = new Vector2(1.0f, -1.0f); | ||
|
||
[Tooltip("Minimum turbulence for VFX graph when there is no interaction or extra force")] | ||
public float idleNoiseIntensity = 0.1f; | ||
public float maxNoiseIntensity = 0.3f; | ||
|
||
[Tooltip("Sensitivity of the audio visualizer on mouse drag")] | ||
public float rotationMultiplier = 500; | ||
|
||
[Range(0.8f, 0.99f), Tooltip("A number that multiplies the velocity of the audio visualizer on each update")] | ||
public float velocityDamping = 0.9f; | ||
|
||
[Tooltip("Multiplier of noise intensity before sending it to the VFX graph")] | ||
public float intensityCoefficient = 0.1f; | ||
|
||
private Vector2 _rotationVelocity; | ||
|
||
private void InitAgentInteraction() => _rotationVelocity = Vector2.zero; | ||
|
||
private void UpdateAgentInteraction() | ||
{ | ||
// if (Input.GetMouseButton(0)) OnMouseDrag(); | ||
|
||
if (Vector3.Dot(transform.up, Vector3.up) >= 0) | ||
transform.Rotate(Camera.main.transform.up, -Vector3.Dot(_rotationVelocity, Camera.main.transform.right), Space.World); | ||
else | ||
transform.Rotate(Camera.main.transform.up, -Vector3.Dot(_rotationVelocity, Camera.main.transform.right), Space.World); | ||
|
||
transform.Rotate(Camera.main.transform.right, Vector3.Dot(_rotationVelocity, Camera.main.transform.up), Space.World); | ||
_rotationVelocity *= velocityDamping; | ||
_rotationVelocity += idleVelocity*Time.deltaTime; | ||
|
||
if (_rotationVelocity.magnitude <= EPSILON) _rotationVelocity = Vector2.zero; | ||
|
||
float intensity = Mathf.Clamp(_rotationVelocity.magnitude * intensityCoefficient, idleNoiseIntensity, maxNoiseIntensity); | ||
audioVFX.SetFloat(VFXPropertyId.float_noiseIntensity, intensity); | ||
} | ||
|
||
/// <summary> | ||
/// Calcualte mouse drag force and apply rotational force accordingly | ||
/// </summary> | ||
private void OnMouseDrag() | ||
{ | ||
float rotationX = Input.GetAxis("Mouse X")*rotationMultiplier*Mathf.Deg2Rad; | ||
float rotationY = Input.GetAxis("Mouse Y")*rotationMultiplier*Mathf.Deg2Rad; | ||
|
||
_rotationVelocity = new Vector2(rotationX, rotationY); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
This program is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU General Public License | ||
as published by the Free Software Foundation; either version 2 | ||
of the License, or (at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program; if not, write to the Free Software Foundation, | ||
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
The Original Code is Copyright (C) 2020 Voxell Technologies. | ||
All rights reserved. | ||
*/ | ||
|
||
using UnityEngine; | ||
|
||
namespace Voxell.Audio | ||
{ | ||
public class AudioProcessor | ||
{ | ||
public AudioSource source; | ||
public AudioProfile profile; | ||
|
||
public float[] samples; | ||
public int freqSize; | ||
public int bandAverage; | ||
public int[] bandDistribution; | ||
|
||
public AudioProcessor(ref AudioSource source, ref AudioProfile profile) | ||
{ | ||
Debug.Assert(profile.frequencyRange > profile.bandSize, "Number of triangles should not exceed frequency range."); | ||
this.source = source; | ||
this.profile = profile; | ||
|
||
samples = new float[profile.sampleSize]; | ||
|
||
float freqInterval = AudioSettings.outputSampleRate/profile.sampleSize; | ||
float currFreq = 0.0f; | ||
freqSize = 0; | ||
|
||
for (int s=0; s < profile.sampleSize; s++) | ||
{ | ||
currFreq += freqInterval; | ||
if (currFreq < profile.frequencyRange) freqSize ++; | ||
else break; | ||
} | ||
|
||
bandAverage = Mathf.Max(1, freqSize/profile.bandSize); | ||
|
||
bandDistribution = new int[profile.bandSize+1]; | ||
bandDistribution[0] = 0; | ||
for (int b=0; b < profile.bandSize; b++) | ||
bandDistribution[b+1] = bandAverage + b*bandAverage; | ||
} | ||
|
||
public void SampleSpectrum() => source.GetSpectrumData(samples, profile.channel, profile.window); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
This program is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU General Public License | ||
as published by the Free Software Foundation; either version 2 | ||
of the License, or (at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program; if not, write to the Free Software Foundation, | ||
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
The Original Code is Copyright (C) 2020 Voxell Technologies. | ||
All rights reserved. | ||
*/ | ||
|
||
using UnityEngine; | ||
|
||
namespace Voxell.Audio | ||
{ | ||
[System.Serializable] | ||
public class AudioProfile | ||
{ | ||
public int channel; | ||
public FFTWindow window; | ||
public int sampleSize; | ||
public float power; | ||
public float scale; | ||
public int smoothingIterations; | ||
[Range(5000, 20000)] public int frequencyRange; | ||
[HideInInspector] public int bandSize; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.