├── .gitignore ├── Assets ├── Cursor.mat ├── Cursor.mat.meta ├── GranularSynth.js ├── GranularSynth.js.meta ├── Line.mat ├── Line.mat.meta ├── Line.shader ├── Line.shader.meta ├── Main.unity ├── Main.unity.meta ├── PositionView.js ├── PositionView.js.meta ├── Test Clips.meta ├── Test Clips │ ├── Null.aif │ ├── Null.aif.meta │ ├── Piano.aif │ ├── Piano.aif.meta │ ├── Synth Drums.aif │ ├── Synth Drums.aif.meta │ ├── Voice.aif │ └── Voice.aif.meta ├── WaveformView.js └── WaveformView.js.meta ├── LICENSE ├── ProjectSettings ├── AudioManager.asset ├── DynamicsManager.asset ├── EditorBuildSettings.asset ├── EditorSettings.asset ├── InputManager.asset ├── NavMeshLayers.asset ├── NetworkManager.asset ├── ProjectSettings.asset ├── QualitySettings.asset ├── TagManager.asset └── TimeManager.asset └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | [Ll]ibrary/ 2 | [Tt]emp/ 3 | [Oo]bj/ 4 | 5 | # Autogenerated VS/MD solution and project files 6 | *.csproj 7 | *.unityproj 8 | *.sln 9 | *.pidb 10 | *.userprefs 11 | 12 | .DS_Store 13 | -------------------------------------------------------------------------------- /Assets/Cursor.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keijiro/unity-granular-synth/163de70d2bbbbd3b229b89544ae9025ba7dfc235/Assets/Cursor.mat -------------------------------------------------------------------------------- /Assets/Cursor.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b6bf458a13b1f472eb157aab37edd47e 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/GranularSynth.js: -------------------------------------------------------------------------------- 1 | #pragma strict 2 | 3 | var clip : AudioClip; 4 | 5 | var playbackSpeed = 1; 6 | var grainSize = 1000; 7 | var grainStep = 1; 8 | 9 | var guiPlaybackSpeed = 1.0; 10 | var guiGrainSize = 1000.0; 11 | var guiGrainStep = 1.0; 12 | 13 | private var sampleLength : int; 14 | private var samples : float[]; 15 | 16 | private var position = 0; 17 | private var interval = 0; 18 | 19 | function Awake() { 20 | sampleLength = clip.samples; 21 | samples = new float[clip.samples * clip.channels]; 22 | clip.GetData(samples, 0); 23 | } 24 | 25 | function Update() { 26 | var cursor : PositionView = FindObjectOfType(PositionView); 27 | cursor.position = 1.0 / sampleLength * position; 28 | cursor.width = 1.0 / sampleLength * interval * playbackSpeed; 29 | } 30 | 31 | function OnGUI() { 32 | GUILayout.BeginArea(Rect(16, 16, Screen.width - 32, Screen.height - 32)); 33 | GUILayout.FlexibleSpace(); 34 | GUILayout.Label("Playback Speed: " + playbackSpeed); 35 | guiPlaybackSpeed = GUILayout.HorizontalSlider(guiPlaybackSpeed, -4.0, 4.0); 36 | GUILayout.FlexibleSpace(); 37 | GUILayout.Label("Grain Size: " + grainSize); 38 | guiGrainSize = GUILayout.HorizontalSlider(guiGrainSize, 2.0, 10000.0); 39 | GUILayout.FlexibleSpace(); 40 | GUILayout.Label("Grain Step: " + grainStep); 41 | guiGrainStep = GUILayout.HorizontalSlider(guiGrainStep, -3000.0, 3000.0); 42 | GUILayout.FlexibleSpace(); 43 | if (GUILayout.Button("RANDOMIZE!")) { 44 | guiPlaybackSpeed = Random.Range(-2.0, 2.0); 45 | guiGrainSize = Random.Range(200.0, 1000.0); 46 | guiGrainStep = Random.Range(-1500.0, 1500.0); 47 | } 48 | GUILayout.FlexibleSpace(); 49 | GUILayout.EndArea(); 50 | 51 | playbackSpeed = Mathf.RoundToInt(guiPlaybackSpeed); 52 | if (playbackSpeed == 0) playbackSpeed = 1; 53 | grainSize = Mathf.RoundToInt(guiGrainSize); 54 | grainStep = Mathf.RoundToInt(guiGrainStep); 55 | } 56 | 57 | function OnAudioFilterRead(data : float[], channels : int) { 58 | for (var i = 0; i < data.Length; i += 2) { 59 | data[i] = samples[position * 2]; 60 | data[i + 1] = samples[position * 2 + 1]; 61 | 62 | if (--interval <= 0) { 63 | interval = grainSize; 64 | position += grainStep; 65 | } else { 66 | position += playbackSpeed; 67 | } 68 | 69 | while (position >= sampleLength) { 70 | position -= sampleLength; 71 | } 72 | while (position < 0) { 73 | position += sampleLength; 74 | } 75 | } 76 | } -------------------------------------------------------------------------------- /Assets/GranularSynth.js.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 40fa6ae44406c496bb05441090fbbd97 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Assets/Line.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keijiro/unity-granular-synth/163de70d2bbbbd3b229b89544ae9025ba7dfc235/Assets/Line.mat -------------------------------------------------------------------------------- /Assets/Line.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8dfb181907a8745e7b9935a96109d2fa 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Line.shader: -------------------------------------------------------------------------------- 1 | Shader "Custom/Line" { 2 | Properties { 3 | _Color ("Main Color", Color) = (1,1,1,1) 4 | } 5 | SubShader { 6 | Tags {"Queue" = "Transparent" } 7 | Pass { 8 | Blend SrcAlpha OneMinusSrcAlpha 9 | 10 | CGPROGRAM 11 | #pragma vertex vert 12 | #pragma fragment frag 13 | #include "UnityCG.cginc" 14 | 15 | struct v2f { 16 | float4 pos : SV_POSITION; 17 | }; 18 | 19 | float4 _Color; 20 | 21 | v2f vert (appdata_base v) 22 | { 23 | v2f o; 24 | o.pos = mul (UNITY_MATRIX_MVP, v.vertex); 25 | return o; 26 | } 27 | 28 | half4 frag (v2f i) : COLOR 29 | { 30 | return _Color; 31 | } 32 | ENDCG 33 | } 34 | } 35 | FallBack Off 36 | } 37 | -------------------------------------------------------------------------------- /Assets/Line.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 00ee42253d5c84326a86289d566ad126 3 | ShaderImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Main.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keijiro/unity-granular-synth/163de70d2bbbbd3b229b89544ae9025ba7dfc235/Assets/Main.unity -------------------------------------------------------------------------------- /Assets/Main.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 474a1241fbbdc4e2c82352b79dd07369 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/PositionView.js: -------------------------------------------------------------------------------- 1 | #pragma strict 2 | 3 | var position = 0.0; 4 | var width = 1.0; 5 | 6 | function Update () { 7 | transform.localPosition.x = 3.4 * (position + width / 2) - 1.7; 8 | transform.localScale.x = 3.4 * width; 9 | } -------------------------------------------------------------------------------- /Assets/PositionView.js.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c9e71abbf434544d9a83ea7df2601154 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Assets/Test Clips.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9c15365cdcab14135ba1f7f00361cfbb 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Test Clips/Null.aif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keijiro/unity-granular-synth/163de70d2bbbbd3b229b89544ae9025ba7dfc235/Assets/Test Clips/Null.aif -------------------------------------------------------------------------------- /Assets/Test Clips/Null.aif.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 400b9778e41094652aa3fd263e2c53ab 3 | AudioImporter: 4 | serializedVersion: 4 5 | format: -1 6 | quality: .5 7 | stream: 1 8 | 3D: 0 9 | forceToMono: 0 10 | useHardware: 0 11 | loopable: 0 12 | userData: 13 | -------------------------------------------------------------------------------- /Assets/Test Clips/Piano.aif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keijiro/unity-granular-synth/163de70d2bbbbd3b229b89544ae9025ba7dfc235/Assets/Test Clips/Piano.aif -------------------------------------------------------------------------------- /Assets/Test Clips/Piano.aif.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9cb7280d030414fc3ad4e1d14e77477f 3 | AudioImporter: 4 | serializedVersion: 4 5 | format: -1 6 | quality: .5 7 | stream: 1 8 | 3D: 0 9 | forceToMono: 0 10 | useHardware: 0 11 | loopable: 0 12 | userData: 13 | -------------------------------------------------------------------------------- /Assets/Test Clips/Synth Drums.aif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keijiro/unity-granular-synth/163de70d2bbbbd3b229b89544ae9025ba7dfc235/Assets/Test Clips/Synth Drums.aif -------------------------------------------------------------------------------- /Assets/Test Clips/Synth Drums.aif.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0df96533f685245bda377dc30b72770f 3 | AudioImporter: 4 | serializedVersion: 4 5 | format: -1 6 | quality: .5 7 | stream: 1 8 | 3D: 0 9 | forceToMono: 0 10 | useHardware: 0 11 | loopable: 0 12 | userData: 13 | -------------------------------------------------------------------------------- /Assets/Test Clips/Voice.aif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keijiro/unity-granular-synth/163de70d2bbbbd3b229b89544ae9025ba7dfc235/Assets/Test Clips/Voice.aif -------------------------------------------------------------------------------- /Assets/Test Clips/Voice.aif.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d8dd24377b2fb4567a941c693ecfb087 3 | AudioImporter: 4 | serializedVersion: 4 5 | format: -1 6 | quality: .5 7 | stream: 1 8 | 3D: 0 9 | forceToMono: 0 10 | useHardware: 0 11 | loopable: 0 12 | userData: 13 | -------------------------------------------------------------------------------- /Assets/WaveformView.js: -------------------------------------------------------------------------------- 1 | #pragma strict 2 | 3 | var clip : AudioClip; 4 | var resolution = 256; 5 | 6 | private var meshFilter : MeshFilter; 7 | 8 | function Awake () { 9 | meshFilter = GetComponent.(); 10 | meshFilter.mesh = new Mesh(); 11 | } 12 | 13 | function Start () { 14 | var samples = new float[clip.channels * clip.samples]; 15 | clip.GetData(samples, 0); 16 | 17 | var vertices = new Vector3[resolution]; 18 | for (var i = 0; i < resolution; i++) { 19 | var level = samples[samples.Length * i / resolution]; 20 | vertices[i] = Vector3(3.4 / resolution * i - 1.7, level / 2, 0); 21 | } 22 | meshFilter.mesh.vertices = vertices; 23 | 24 | var indices = new int[resolution]; 25 | for (i = 0; i < resolution; i++) { 26 | indices[i] = i; 27 | } 28 | meshFilter.mesh.SetIndices(indices, MeshTopology.LineStrip, 0); 29 | } 30 | -------------------------------------------------------------------------------- /Assets/WaveformView.js.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3196be94e38db4d628ae6c71d6502db7 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Keijiro Takahashi 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keijiro/unity-granular-synth/163de70d2bbbbd3b229b89544ae9025ba7dfc235/ProjectSettings/AudioManager.asset -------------------------------------------------------------------------------- /ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keijiro/unity-granular-synth/163de70d2bbbbd3b229b89544ae9025ba7dfc235/ProjectSettings/DynamicsManager.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keijiro/unity-granular-synth/163de70d2bbbbd3b229b89544ae9025ba7dfc235/ProjectSettings/EditorBuildSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keijiro/unity-granular-synth/163de70d2bbbbd3b229b89544ae9025ba7dfc235/ProjectSettings/EditorSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keijiro/unity-granular-synth/163de70d2bbbbd3b229b89544ae9025ba7dfc235/ProjectSettings/InputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/NavMeshLayers.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keijiro/unity-granular-synth/163de70d2bbbbd3b229b89544ae9025ba7dfc235/ProjectSettings/NavMeshLayers.asset -------------------------------------------------------------------------------- /ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keijiro/unity-granular-synth/163de70d2bbbbd3b229b89544ae9025ba7dfc235/ProjectSettings/NetworkManager.asset -------------------------------------------------------------------------------- /ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keijiro/unity-granular-synth/163de70d2bbbbd3b229b89544ae9025ba7dfc235/ProjectSettings/ProjectSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keijiro/unity-granular-synth/163de70d2bbbbd3b229b89544ae9025ba7dfc235/ProjectSettings/QualitySettings.asset -------------------------------------------------------------------------------- /ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keijiro/unity-granular-synth/163de70d2bbbbd3b229b89544ae9025ba7dfc235/ProjectSettings/TagManager.asset -------------------------------------------------------------------------------- /ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keijiro/unity-granular-synth/163de70d2bbbbd3b229b89544ae9025ba7dfc235/ProjectSettings/TimeManager.asset -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | unity-granular-synth 2 | ==================== 3 | 4 | An implementation of granular synthesizer with Unity. 5 | --------------------------------------------------------------------------------