2019-09-28 18:17:39 +00:00
|
|
|
|
using System;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace cylvester
|
|
|
|
|
{
|
2019-10-01 13:08:35 +00:00
|
|
|
|
public class PdBackend : MonoBehaviour
|
2019-09-28 18:17:39 +00:00
|
|
|
|
{
|
2019-10-02 16:17:08 +00:00
|
|
|
|
public int samplePlayback;
|
2019-10-04 13:35:23 +00:00
|
|
|
|
public ISpectrumArrayContainer spectrumArrayContainer;
|
2019-10-01 13:08:35 +00:00
|
|
|
|
|
|
|
|
|
private IChangeObserver<int> samplePlaybackObserver_;
|
|
|
|
|
private Action onSamplePlaybackChanged_;
|
|
|
|
|
private IPdSocket pdSocket_;
|
2019-10-05 04:15:15 +00:00
|
|
|
|
private IDspController dspController_;
|
2019-10-02 16:17:08 +00:00
|
|
|
|
|
|
|
|
|
private void Awake()
|
2019-09-28 18:17:39 +00:00
|
|
|
|
{
|
2019-10-04 13:35:23 +00:00
|
|
|
|
spectrumArrayContainer = new SpectrumArrayContainer();
|
2019-10-01 13:08:35 +00:00
|
|
|
|
pdSocket_ = new PdSocket(PdConstant.ip, PdConstant.port);
|
2019-10-05 04:15:15 +00:00
|
|
|
|
dspController_ = new DspController(pdSocket_);
|
|
|
|
|
|
2019-10-01 13:08:35 +00:00
|
|
|
|
samplePlaybackObserver_ = new ChangeObserver<int>(samplePlayback);
|
|
|
|
|
|
|
|
|
|
onSamplePlaybackChanged_ = () =>
|
|
|
|
|
{
|
2019-10-05 04:15:15 +00:00
|
|
|
|
pdSocket_.Send(new[]{(byte)PdMessage.SampleSound, (byte)samplePlayback});
|
2019-10-01 13:08:35 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
samplePlaybackObserver_.ValueChanged += onSamplePlaybackChanged_;
|
2019-10-05 04:15:15 +00:00
|
|
|
|
dspController_.State = true;
|
2019-09-28 18:17:39 +00:00
|
|
|
|
|
2019-10-05 04:15:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-29 19:53:47 +00:00
|
|
|
|
private void OnDestroy()
|
2019-09-28 18:17:39 +00:00
|
|
|
|
{
|
2019-10-05 04:15:15 +00:00
|
|
|
|
dspController_.State = false;
|
2019-10-01 13:08:35 +00:00
|
|
|
|
pdSocket_?.Dispose();
|
|
|
|
|
samplePlaybackObserver_.ValueChanged -= onSamplePlaybackChanged_;
|
2019-09-28 18:17:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-29 19:53:47 +00:00
|
|
|
|
public void Update()
|
2019-09-28 18:17:39 +00:00
|
|
|
|
{
|
2019-10-04 13:35:23 +00:00
|
|
|
|
spectrumArrayContainer.Update();
|
2019-10-01 13:08:35 +00:00
|
|
|
|
samplePlaybackObserver_.Value = samplePlayback;
|
2019-09-28 18:17:39 +00:00
|
|
|
|
}
|
2019-10-05 04:15:15 +00:00
|
|
|
|
|
|
|
|
|
|
2019-09-28 18:17:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|