2019-10-05 14:49:30 +00:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace cylvester
|
|
|
|
|
{
|
|
|
|
|
public interface ISpectrogram
|
|
|
|
|
{
|
|
|
|
|
Texture2D Texture { get; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class Spectrogram : MonoBehaviour, ISpectrogram
|
|
|
|
|
{
|
|
|
|
|
[SerializeField] private PdBackend pdBackend;
|
|
|
|
|
[SerializeField, Range(1, 16)] private int channel = 1;
|
|
|
|
|
|
2019-10-05 16:09:24 +00:00
|
|
|
|
private IPdArraySelector spectrumArraySelector_;
|
2019-10-05 14:49:30 +00:00
|
|
|
|
private Texture2D texture_;
|
|
|
|
|
private int index_;
|
|
|
|
|
|
|
|
|
|
void Start()
|
|
|
|
|
{
|
2019-10-05 16:09:24 +00:00
|
|
|
|
spectrumArraySelector_ = new PdArraySelector(pdBackend.SpectrumArrayContainer);
|
|
|
|
|
texture_ = new Texture2D(PdConstant.BlockSize, PdConstant.BlockSize, TextureFormat.R8, false);
|
2019-10-05 14:49:30 +00:00
|
|
|
|
|
|
|
|
|
var pixels = texture_.GetPixels();
|
|
|
|
|
for (var i = 0;i < pixels.Length; ++i)
|
|
|
|
|
pixels[i] = Color.black;
|
|
|
|
|
texture_.SetPixels(pixels);
|
|
|
|
|
texture_.Apply();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Update()
|
|
|
|
|
{
|
|
|
|
|
spectrumArraySelector_.Selection = channel - 1;
|
|
|
|
|
var array = spectrumArraySelector_.SelectedArray;
|
2019-10-05 16:09:24 +00:00
|
|
|
|
for (var i = 0; i < PdConstant.BlockSize; i++)
|
2019-10-05 14:49:30 +00:00
|
|
|
|
{
|
|
|
|
|
texture_.SetPixel(i, index_, new Color(array[i], 0f, 0f));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
texture_.Apply();
|
|
|
|
|
|
|
|
|
|
index_++;
|
2019-10-05 16:09:24 +00:00
|
|
|
|
index_ %= PdConstant.BlockSize;
|
2019-10-05 14:49:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Texture2D Texture => texture_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|