From cb599bf5ca4274e706fd1303cb51993d1d203ab4 Mon Sep 17 00:00:00 2001 From: Chikashi Miyama Date: Sat, 5 Oct 2019 18:09:24 +0200 Subject: [PATCH] refer #62 --- UnityProject/Assembly-CSharp.csproj | 5 +- .../UnitTest_SpectrumGeneratorPlayMode.cs | 14 ++-- .../Scenes/Examples/Texture/Texture.unity | 80 ++++++++----------- .../Scenes/Examples/Texture/TextureMapper.cs | 14 +++- ...mArrayContainer.cs => PdArrayContainer.cs} | 8 +- ...ainer.cs.meta => PdArrayContainer.cs.meta} | 0 ...rumArraySelector.cs => PdArraySelector.cs} | 8 +- ...lector.cs.meta => PdArraySelector.cs.meta} | 0 .../Assets/Scripts/PdConnection/PdBackend.cs | 20 +++-- .../Assets/Scripts/PdConnection/PdConstant.cs | 2 +- .../Scripts/PdConnection/PdSpectrumBind.cs | 4 +- .../Scripts/PdConnection/Spectrogram.cs | 10 +-- .../PdConnection/SpectrumGeneratorPlayMode.cs | 4 +- .../Assets/Scripts/PdConnection/Waveform.cs | 51 ++++++++++++ ...veformTexture.cs.meta => Waveform.cs.meta} | 0 .../Scripts/PdConnection/WaveformTexture.cs | 25 ------ .../StreamingAssets/pd/patch/analyzer.pd | 2 +- 17 files changed, 137 insertions(+), 110 deletions(-) rename UnityProject/Assets/Scripts/PdConnection/{SpectrumArrayContainer.cs => PdArrayContainer.cs} (77%) rename UnityProject/Assets/Scripts/PdConnection/{SpectrumArrayContainer.cs.meta => PdArrayContainer.cs.meta} (100%) rename UnityProject/Assets/Scripts/PdConnection/{SpectrumArraySelector.cs => PdArraySelector.cs} (60%) rename UnityProject/Assets/Scripts/PdConnection/{SpectrumArraySelector.cs.meta => PdArraySelector.cs.meta} (100%) create mode 100644 UnityProject/Assets/Scripts/PdConnection/Waveform.cs rename UnityProject/Assets/Scripts/PdConnection/{WaveformTexture.cs.meta => Waveform.cs.meta} (100%) delete mode 100644 UnityProject/Assets/Scripts/PdConnection/WaveformTexture.cs diff --git a/UnityProject/Assembly-CSharp.csproj b/UnityProject/Assembly-CSharp.csproj index a4d77d9..76f75fd 100644 --- a/UnityProject/Assembly-CSharp.csproj +++ b/UnityProject/Assembly-CSharp.csproj @@ -66,8 +66,8 @@ - - + + @@ -76,7 +76,6 @@ - diff --git a/UnityProject/Assets/Editor/UnitTest/UnitTest_SpectrumGeneratorPlayMode.cs b/UnityProject/Assets/Editor/UnitTest/UnitTest_SpectrumGeneratorPlayMode.cs index f5174fe..2f5681f 100644 --- a/UnityProject/Assets/Editor/UnitTest/UnitTest_SpectrumGeneratorPlayMode.cs +++ b/UnityProject/Assets/Editor/UnitTest/UnitTest_SpectrumGeneratorPlayMode.cs @@ -7,7 +7,7 @@ namespace cylvester [TestFixture] public class UnitTest_SpectrumGeneratorPlayMode { - private ISpectrumArraySelector spectrumArraySelector_; + private IPdArraySelector pdArraySelector_; private Rect selectionRect_; private Rect noSelectionRect_; private float[] dummyData_; @@ -17,8 +17,8 @@ namespace cylvester public void SetUp() { dummyData_ = new float[100]; - spectrumArraySelector_ = Substitute.For(); - spectrumArraySelector_.SelectedArray.Returns(dummyData_); + pdArraySelector_ = Substitute.For(); + pdArraySelector_.SelectedArray.Returns(dummyData_); selectionRect_ = new Rect {x = 9, y = 9, width = 3, height = 3}; noSelectionRect_ = new Rect {width = 0, height = 0}; } @@ -26,7 +26,7 @@ namespace cylvester [Test] public void Construction() { - var spectrumGenerator = new SpectrumGeneratorPlayMode(100, 101, spectrumArraySelector_); + var spectrumGenerator = new SpectrumGeneratorPlayMode(100, 101, pdArraySelector_); Assert.AreEqual(100, spectrumGenerator.Spectrum.width); Assert.AreEqual(101, spectrumGenerator.Spectrum.height); @@ -38,7 +38,7 @@ namespace cylvester for (var i = 0; i < dummyData_.Length; ++i) dummyData_[i] = 100f; // loud sound - var spectrumGenerator = new SpectrumGeneratorPlayMode(100, 100, spectrumArraySelector_); + var spectrumGenerator = new SpectrumGeneratorPlayMode(100, 100, pdArraySelector_); var validPixel = spectrumGenerator.Update(selectionRect_); Assert.AreEqual(1, validPixel); @@ -50,7 +50,7 @@ namespace cylvester for (var i = 0; i < dummyData_.Length; ++i) dummyData_[i] = 0.001f; // soft sound - var spectrumGenerator = new SpectrumGeneratorPlayMode(100, 100, spectrumArraySelector_); + var spectrumGenerator = new SpectrumGeneratorPlayMode(100, 100, pdArraySelector_); var validPixel = spectrumGenerator.Update(selectionRect_); Assert.AreEqual(0, validPixel); @@ -62,7 +62,7 @@ namespace cylvester for (var i = 0; i < dummyData_.Length; ++i) dummyData_[i] = 100f; // loud sound - var spectrumGenerator = new SpectrumGeneratorPlayMode(100, 100, spectrumArraySelector_); + var spectrumGenerator = new SpectrumGeneratorPlayMode(100, 100, pdArraySelector_); var validPixel = spectrumGenerator.Update(noSelectionRect_); Assert.AreEqual(0, validPixel); diff --git a/UnityProject/Assets/Scenes/Examples/Texture/Texture.unity b/UnityProject/Assets/Scenes/Examples/Texture/Texture.unity index dcf25fb..82caec6 100644 --- a/UnityProject/Assets/Scenes/Examples/Texture/Texture.unity +++ b/UnityProject/Assets/Scenes/Examples/Texture/Texture.unity @@ -131,7 +131,6 @@ GameObject: - component: {fileID: 90124700} - component: {fileID: 90124699} - component: {fileID: 90124698} - - component: {fileID: 90124697} m_Layer: 0 m_Name: Spectrogram m_TagString: Untagged @@ -139,19 +138,6 @@ GameObject: m_NavMeshLayer: 0 m_StaticEditorFlags: 0 m_IsActive: 1 ---- !u!114 &90124697 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 90124696} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 126d8ce7fcb65564f97a02ec1f5d7fde, type: 3} - m_Name: - m_EditorClassIdentifier: - spectrogram: {fileID: 130019220} --- !u!23 &90124698 MeshRenderer: m_ObjectHideFlags: 0 @@ -223,6 +209,7 @@ GameObject: - component: {fileID: 130019219} - component: {fileID: 130019218} - component: {fileID: 130019220} + - component: {fileID: 130019221} m_Layer: 0 m_Name: PdBackend m_TagString: Untagged @@ -274,6 +261,20 @@ MonoBehaviour: m_EditorClassIdentifier: pdBackend: {fileID: 130019218} channel: 1 +--- !u!114 &130019221 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 130019217} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 773d4bc755fe4e4a9ddf830af14ff758, type: 3} + m_Name: + m_EditorClassIdentifier: + pdBackend: {fileID: 130019218} + channel: 1 --- !u!1 &404245778 GameObject: m_ObjectHideFlags: 0 @@ -283,6 +284,7 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 404245779} + - component: {fileID: 404245780} m_Layer: 0 m_Name: Planes m_TagString: Untagged @@ -307,6 +309,22 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 3 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &404245780 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 404245778} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 126d8ce7fcb65564f97a02ec1f5d7fde, type: 3} + m_Name: + m_EditorClassIdentifier: + waveform: {fileID: 130019221} + spectrogram: {fileID: 130019220} + waveformPanel: {fileID: 2147024058} + spectrogramPanel: {fileID: 90124696} --- !u!1 &555401020 GameObject: m_ObjectHideFlags: 0 @@ -318,7 +336,6 @@ GameObject: - component: {fileID: 555401024} - component: {fileID: 555401023} - component: {fileID: 555401022} - - component: {fileID: 555401021} m_Layer: 0 m_Name: Spectrum m_TagString: Untagged @@ -326,20 +343,6 @@ GameObject: m_NavMeshLayer: 0 m_StaticEditorFlags: 0 m_IsActive: 1 ---- !u!64 &555401021 -MeshCollider: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 555401020} - m_Material: {fileID: 0} - m_IsTrigger: 0 - m_Enabled: 1 - serializedVersion: 3 - m_Convex: 0 - m_CookingOptions: 14 - m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0} --- !u!23 &555401022 MeshRenderer: m_ObjectHideFlags: 0 @@ -357,7 +360,7 @@ MeshRenderer: m_RenderingLayerMask: 1 m_RendererPriority: 0 m_Materials: - - {fileID: 2100000, guid: 73c176f402d2c2f4d929aa5da7585d17, type: 2} + - {fileID: 2100000, guid: 416cd1054fe561246b9c57b0f3b4ad15, type: 2} m_StaticBatchInfo: firstSubMesh: 0 subMeshCount: 0 @@ -788,7 +791,6 @@ GameObject: - component: {fileID: 2147024062} - component: {fileID: 2147024061} - component: {fileID: 2147024060} - - component: {fileID: 2147024059} m_Layer: 0 m_Name: Waveform m_TagString: Untagged @@ -796,20 +798,6 @@ GameObject: m_NavMeshLayer: 0 m_StaticEditorFlags: 0 m_IsActive: 1 ---- !u!64 &2147024059 -MeshCollider: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 2147024058} - m_Material: {fileID: 0} - m_IsTrigger: 0 - m_Enabled: 1 - serializedVersion: 3 - m_Convex: 0 - m_CookingOptions: 14 - m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0} --- !u!23 &2147024060 MeshRenderer: m_ObjectHideFlags: 0 @@ -827,7 +815,7 @@ MeshRenderer: m_RenderingLayerMask: 1 m_RendererPriority: 0 m_Materials: - - {fileID: 2100000, guid: f044463ea66a19c47aef13261142b54e, type: 2} + - {fileID: 2100000, guid: 416cd1054fe561246b9c57b0f3b4ad15, type: 2} m_StaticBatchInfo: firstSubMesh: 0 subMeshCount: 0 diff --git a/UnityProject/Assets/Scenes/Examples/Texture/TextureMapper.cs b/UnityProject/Assets/Scenes/Examples/Texture/TextureMapper.cs index 84bf6d8..472c4e6 100644 --- a/UnityProject/Assets/Scenes/Examples/Texture/TextureMapper.cs +++ b/UnityProject/Assets/Scenes/Examples/Texture/TextureMapper.cs @@ -6,18 +6,26 @@ namespace cylvester { public class TextureMapper : MonoBehaviour { + [SerializeField] private Waveform waveform; [SerializeField] private Spectrogram spectrogram; - private Renderer renderer_; + + [SerializeField] private GameObject waveformPanel; + [SerializeField] private GameObject spectrogramPanel; + + private Renderer waveFormRenderer_; + private Renderer spectroGramRenderer_; private static readonly int baseColorMap_ = Shader.PropertyToID("_BaseColorMap"); void Start() { - renderer_ = GetComponent(); + waveFormRenderer_ = waveformPanel.GetComponent(); + spectroGramRenderer_ = spectrogramPanel.GetComponent(); } void Update() { - renderer_.material.SetTexture(baseColorMap_, spectrogram.Texture); + waveFormRenderer_.material.SetTexture(baseColorMap_, waveform.Texture); + spectroGramRenderer_.material.SetTexture(baseColorMap_, spectrogram.Texture); } } } \ No newline at end of file diff --git a/UnityProject/Assets/Scripts/PdConnection/SpectrumArrayContainer.cs b/UnityProject/Assets/Scripts/PdConnection/PdArrayContainer.cs similarity index 77% rename from UnityProject/Assets/Scripts/PdConnection/SpectrumArrayContainer.cs rename to UnityProject/Assets/Scripts/PdConnection/PdArrayContainer.cs index 48eabd5..673fc83 100644 --- a/UnityProject/Assets/Scripts/PdConnection/SpectrumArrayContainer.cs +++ b/UnityProject/Assets/Scripts/PdConnection/PdArrayContainer.cs @@ -1,6 +1,6 @@ namespace cylvester { - public interface ISpectrumArrayContainer + public interface IPdArrayContainer { IPdArray this[int index] { get; } } @@ -10,19 +10,19 @@ namespace cylvester void Update(); } - public class SpectrumArrayContainer : ISpectrumArrayContainer, IUpdater + public class PdArrayContainer : IPdArrayContainer, IUpdater { private readonly IPdArray[] arrays_; private readonly IUpdater[] updaters_; - public SpectrumArrayContainer() + public PdArrayContainer(string prefix) { arrays_ = new IPdArray[PdConstant.NumMaxInputChannels]; updaters_ = new IUpdater[PdConstant.NumMaxInputChannels]; for (var i = 0; i < PdConstant.NumMaxInputChannels; ++i) { - arrays_[i] = new PdArray("fft_" + i, PdConstant.FftSize); + arrays_[i] = new PdArray(prefix + i, PdConstant.BlockSize); updaters_[i] = (IUpdater) arrays_[i]; } } diff --git a/UnityProject/Assets/Scripts/PdConnection/SpectrumArrayContainer.cs.meta b/UnityProject/Assets/Scripts/PdConnection/PdArrayContainer.cs.meta similarity index 100% rename from UnityProject/Assets/Scripts/PdConnection/SpectrumArrayContainer.cs.meta rename to UnityProject/Assets/Scripts/PdConnection/PdArrayContainer.cs.meta diff --git a/UnityProject/Assets/Scripts/PdConnection/SpectrumArraySelector.cs b/UnityProject/Assets/Scripts/PdConnection/PdArraySelector.cs similarity index 60% rename from UnityProject/Assets/Scripts/PdConnection/SpectrumArraySelector.cs rename to UnityProject/Assets/Scripts/PdConnection/PdArraySelector.cs index becccb8..4b0dc55 100644 --- a/UnityProject/Assets/Scripts/PdConnection/SpectrumArraySelector.cs +++ b/UnityProject/Assets/Scripts/PdConnection/PdArraySelector.cs @@ -1,17 +1,17 @@ namespace cylvester { - public interface ISpectrumArraySelector + public interface IPdArraySelector { int Selection { set; } float[] SelectedArray { get; } } - public class SpectrumArraySelector : ISpectrumArraySelector + public class PdArraySelector : IPdArraySelector { private int selection_; - private readonly ISpectrumArrayContainer arrayContainer_; + private readonly IPdArrayContainer arrayContainer_; - public SpectrumArraySelector(ISpectrumArrayContainer arrayContainer) + public PdArraySelector(IPdArrayContainer arrayContainer) { arrayContainer_ = arrayContainer; } diff --git a/UnityProject/Assets/Scripts/PdConnection/SpectrumArraySelector.cs.meta b/UnityProject/Assets/Scripts/PdConnection/PdArraySelector.cs.meta similarity index 100% rename from UnityProject/Assets/Scripts/PdConnection/SpectrumArraySelector.cs.meta rename to UnityProject/Assets/Scripts/PdConnection/PdArraySelector.cs.meta diff --git a/UnityProject/Assets/Scripts/PdConnection/PdBackend.cs b/UnityProject/Assets/Scripts/PdConnection/PdBackend.cs index a8de9d9..f90ee0c 100644 --- a/UnityProject/Assets/Scripts/PdConnection/PdBackend.cs +++ b/UnityProject/Assets/Scripts/PdConnection/PdBackend.cs @@ -1,13 +1,12 @@ using System; using UnityEngine; -using UnityEngine.Events; - namespace cylvester { public interface IPdBackend { - ISpectrumArrayContainer SpectrumArrayContainer{ get; } + IPdArrayContainer SpectrumArrayContainer{ get; } + IPdArrayContainer WaveformArrayContainer{ get; } } public class PdBackend : MonoBehaviour, IPdBackend @@ -15,7 +14,6 @@ namespace cylvester [SerializeField] UnityControlEvent onControlMessageReceived = null; public int samplePlayback; - private IUpdater spectrumArrayUpdater_; private IChangeObserver samplePlaybackObserver_; @@ -23,15 +21,22 @@ namespace cylvester private IPdReceiver pdReceiver_; private IMidiParser midiParser_; private IDspController dspController_; - public ISpectrumArrayContainer SpectrumArrayContainer { get; private set; } - + + public IPdArrayContainer SpectrumArrayContainer { get; private set; } + private IUpdater spectrumArrayUpdater_; + public IPdArrayContainer WaveformArrayContainer { get; private set; } + private IUpdater waveformArrayUpdater_; + private Action onSamplePlaybackChanged_; private Action onControlMessageReceived_; private void Awake() { - SpectrumArrayContainer = new SpectrumArrayContainer(); + SpectrumArrayContainer = new PdArrayContainer("fft_"); + WaveformArrayContainer = new PdArrayContainer("wave_"); + spectrumArrayUpdater_ = (IUpdater) SpectrumArrayContainer; + waveformArrayUpdater_ = (IUpdater) WaveformArrayContainer; pdSender_ = new PdSender(PdConstant.ip, PdConstant.sendPort); pdReceiver_ = new PdReceiver(PdConstant.receivedPort); @@ -69,6 +74,7 @@ namespace cylvester { pdReceiver_.Update(); spectrumArrayUpdater_.Update(); + waveformArrayUpdater_.Update(); samplePlaybackObserver_.Value = samplePlayback; } } diff --git a/UnityProject/Assets/Scripts/PdConnection/PdConstant.cs b/UnityProject/Assets/Scripts/PdConnection/PdConstant.cs index 054e78e..89af0d5 100644 --- a/UnityProject/Assets/Scripts/PdConnection/PdConstant.cs +++ b/UnityProject/Assets/Scripts/PdConnection/PdConstant.cs @@ -12,6 +12,6 @@ namespace cylvester public static readonly string ip = "127.0.0.1"; public static readonly int sendPort = 54345; public static readonly int receivedPort = 56765; - public static readonly int FftSize = 512; + public static readonly int BlockSize = 512; } } \ No newline at end of file diff --git a/UnityProject/Assets/Scripts/PdConnection/PdSpectrumBind.cs b/UnityProject/Assets/Scripts/PdConnection/PdSpectrumBind.cs index 1851a34..a546e9f 100644 --- a/UnityProject/Assets/Scripts/PdConnection/PdSpectrumBind.cs +++ b/UnityProject/Assets/Scripts/PdConnection/PdSpectrumBind.cs @@ -15,7 +15,7 @@ namespace cylvester [SerializeField] private int channel = 0; private ISpectrumGenerator spectrumGenerator_; - private ISpectrumArraySelector arraySelector_; + private IPdArraySelector arraySelector_; public int TextureWidth { get; } = 512; public int TextureHeight { get; } = 256; @@ -24,7 +24,7 @@ namespace cylvester private void Start() { - arraySelector_ = new SpectrumArraySelector(pdBackend.SpectrumArrayContainer); + arraySelector_ = new PdArraySelector(pdBackend.SpectrumArrayContainer); spectrumGenerator_ = new SpectrumGeneratorPlayMode(TextureWidth, TextureHeight, arraySelector_); } diff --git a/UnityProject/Assets/Scripts/PdConnection/Spectrogram.cs b/UnityProject/Assets/Scripts/PdConnection/Spectrogram.cs index df5b272..30c75f9 100644 --- a/UnityProject/Assets/Scripts/PdConnection/Spectrogram.cs +++ b/UnityProject/Assets/Scripts/PdConnection/Spectrogram.cs @@ -14,14 +14,14 @@ namespace cylvester [SerializeField] private PdBackend pdBackend; [SerializeField, Range(1, 16)] private int channel = 1; - private SpectrumArraySelector spectrumArraySelector_; + private IPdArraySelector spectrumArraySelector_; private Texture2D texture_; private int index_; void Start() { - spectrumArraySelector_ = new SpectrumArraySelector(pdBackend.SpectrumArrayContainer); - texture_ = new Texture2D(PdConstant.FftSize, PdConstant.FftSize, TextureFormat.R8, false); + spectrumArraySelector_ = new PdArraySelector(pdBackend.SpectrumArrayContainer); + texture_ = new Texture2D(PdConstant.BlockSize, PdConstant.BlockSize, TextureFormat.R8, false); var pixels = texture_.GetPixels(); for (var i = 0;i < pixels.Length; ++i) @@ -34,7 +34,7 @@ namespace cylvester { spectrumArraySelector_.Selection = channel - 1; var array = spectrumArraySelector_.SelectedArray; - for (var i = 0; i < PdConstant.FftSize; i++) + for (var i = 0; i < PdConstant.BlockSize; i++) { texture_.SetPixel(i, index_, new Color(array[i], 0f, 0f)); } @@ -42,7 +42,7 @@ namespace cylvester texture_.Apply(); index_++; - index_ %= PdConstant.FftSize; + index_ %= PdConstant.BlockSize; } public Texture2D Texture => texture_; diff --git a/UnityProject/Assets/Scripts/PdConnection/SpectrumGeneratorPlayMode.cs b/UnityProject/Assets/Scripts/PdConnection/SpectrumGeneratorPlayMode.cs index 92bcf74..b766700 100644 --- a/UnityProject/Assets/Scripts/PdConnection/SpectrumGeneratorPlayMode.cs +++ b/UnityProject/Assets/Scripts/PdConnection/SpectrumGeneratorPlayMode.cs @@ -4,9 +4,9 @@ namespace cylvester { public class SpectrumGeneratorPlayMode : SpectrumGenerator, ISpectrumGenerator { - private ISpectrumArraySelector arraySelector_; + private IPdArraySelector arraySelector_; - public SpectrumGeneratorPlayMode(int textureWidth, int textureHeight, ISpectrumArraySelector arraySelector) + public SpectrumGeneratorPlayMode(int textureWidth, int textureHeight, IPdArraySelector arraySelector) :base(textureWidth, textureHeight) { arraySelector_ = arraySelector; diff --git a/UnityProject/Assets/Scripts/PdConnection/Waveform.cs b/UnityProject/Assets/Scripts/PdConnection/Waveform.cs new file mode 100644 index 0000000..9726a6c --- /dev/null +++ b/UnityProject/Assets/Scripts/PdConnection/Waveform.cs @@ -0,0 +1,51 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace cylvester +{ + public interface IWaveform + { + Texture2D Texture { get; } + } + + public class Waveform : MonoBehaviour, ISpectrogram + { + [SerializeField] private PdBackend pdBackend; + [SerializeField, Range(1, 16)] private int channel = 1; + + private IPdArraySelector waveformArraySelector_; + private Texture2D texture_; + private int[] cache_; + + void Start() + { + cache_ = new int[PdConstant.BlockSize]; + waveformArraySelector_ = new PdArraySelector(pdBackend.WaveformArrayContainer); + texture_ = new Texture2D(PdConstant.BlockSize, PdConstant.BlockSize, TextureFormat.R8, false); + + var pixels = texture_.GetPixels(); + for (var i = 0;i < pixels.Length; ++i) + pixels[i] = Color.black; + texture_.SetPixels(pixels); + texture_.Apply(); + } + + void Update() + { + waveformArraySelector_.Selection = channel - 1; + var array = waveformArraySelector_.SelectedArray; + for (var i = 0; i < PdConstant.BlockSize; i++) + { + var y = (int)(256f * Mathf.Clamp(array[i], -1f, 1f)) + 256; + texture_.SetPixel(i , cache_[i], Color.black); + texture_.SetPixel(i , y, Color.white); + cache_[i] = y; + } + + texture_.Apply(); + } + + public Texture2D Texture => texture_; + } +} \ No newline at end of file diff --git a/UnityProject/Assets/Scripts/PdConnection/WaveformTexture.cs.meta b/UnityProject/Assets/Scripts/PdConnection/Waveform.cs.meta similarity index 100% rename from UnityProject/Assets/Scripts/PdConnection/WaveformTexture.cs.meta rename to UnityProject/Assets/Scripts/PdConnection/Waveform.cs.meta diff --git a/UnityProject/Assets/Scripts/PdConnection/WaveformTexture.cs b/UnityProject/Assets/Scripts/PdConnection/WaveformTexture.cs deleted file mode 100644 index b4edd82..0000000 --- a/UnityProject/Assets/Scripts/PdConnection/WaveformTexture.cs +++ /dev/null @@ -1,25 +0,0 @@ -using UnityEngine; - -namespace cylvester -{ - public class WaveformTexture : MonoBehaviour - { - [SerializeField] PdBackend PdBackend = null; - [SerializeField, Range(1, 16)] private int channel = 1; - - - private Texture2D texture2D_; - - private void Start() - { - texture2D_ = new Texture2D(PdConstant.FftSize, PdConstant.FftSize, TextureFormat.R16, false); - } - - private void Update() - { - - - texture2D_.Apply(); - } - } -} \ No newline at end of file diff --git a/UnityProject/Assets/StreamingAssets/pd/patch/analyzer.pd b/UnityProject/Assets/StreamingAssets/pd/patch/analyzer.pd index 3f7c371..ebea439 100644 --- a/UnityProject/Assets/StreamingAssets/pd/patch/analyzer.pd +++ b/UnityProject/Assets/StreamingAssets/pd/patch/analyzer.pd @@ -1,4 +1,4 @@ -#N canvas 800 326 670 468 10; +#N canvas 412 304 670 468 10; #X obj 217 251 adc~ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16; #X obj 49 386 dac~, f 6; #N canvas 215 619 730 390 analyzers_______________________________