refer #62
This commit is contained in:
parent
02c73bd350
commit
cb599bf5ca
17 changed files with 137 additions and 110 deletions
|
@ -66,8 +66,8 @@
|
|||
<Compile Include="Assets\Scripts\PdConnection\DspController.cs" />
|
||||
<Compile Include="Assets\Scripts\PdConnection\MidiParser.cs" />
|
||||
<Compile Include="Assets\Scripts\PdConnection\PdReceiver.cs" />
|
||||
<Compile Include="Assets\Scripts\PdConnection\SpectrumArrayContainer.cs" />
|
||||
<Compile Include="Assets\Scripts\PdConnection\SpectrumArraySelector.cs" />
|
||||
<Compile Include="Assets\Scripts\PdConnection\PdArrayContainer.cs" />
|
||||
<Compile Include="Assets\Scripts\PdConnection\PdArraySelector.cs" />
|
||||
<Compile Include="Assets\Scripts\PdConnection\ISpectrumGenerator.cs" />
|
||||
<Compile Include="Assets\Scripts\PdConnection\PdArray.cs" />
|
||||
<Compile Include="Assets\Scripts\PdConnection\PdBackend.cs" />
|
||||
|
@ -76,7 +76,6 @@
|
|||
<Compile Include="Assets\Scripts\PdConnection\PdSender.cs" />
|
||||
<Compile Include="Assets\Scripts\PdConnection\PdSpectrumBind.cs" />
|
||||
<Compile Include="Assets\Scripts\PdConnection\SpectrumGeneratorPlayMode.cs" />
|
||||
<Compile Include="Assets\Scripts\PdConnection\WaveformTexture.cs" />
|
||||
<Compile Include="Assets\Scripts\TemplateLibrary\ChangeObserver.cs" />
|
||||
<Compile Include="Assets\Scripts\Versioning\VersionToggleBehaviour.cs" />
|
||||
<Compile Include="Assets\Scripts\VideoInput\ComponentFactory.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<ISpectrumArraySelector>();
|
||||
spectrumArraySelector_.SelectedArray.Returns(dummyData_);
|
||||
pdArraySelector_ = Substitute.For<IPdArraySelector>();
|
||||
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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<Renderer>();
|
||||
waveFormRenderer_ = waveformPanel.GetComponent<Renderer>();
|
||||
spectroGramRenderer_ = spectrogramPanel.GetComponent<Renderer>();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
renderer_.material.SetTexture(baseColorMap_, spectrogram.Texture);
|
||||
waveFormRenderer_.material.SetTexture(baseColorMap_, waveform.Texture);
|
||||
spectroGramRenderer_.material.SetTexture(baseColorMap_, spectrogram.Texture);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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];
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -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<int> 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<ControlMessage> 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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_);
|
||||
}
|
||||
|
||||
|
|
|
@ -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_;
|
||||
|
|
|
@ -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;
|
||||
|
|
51
UnityProject/Assets/Scripts/PdConnection/Waveform.cs
Normal file
51
UnityProject/Assets/Scripts/PdConnection/Waveform.cs
Normal file
|
@ -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_;
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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_______________________________
|
||||
|
|
Loading…
Reference in a new issue