Replace naudio.dll with code
This commit is contained in:
+213
@@ -0,0 +1,213 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) CRI Middleware Co., Ltd.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#if UNITY_2019_3_OR_NEWER && CRIWARE_TIMELINE_1_OR_NEWER
|
||||
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEditor.Timeline;
|
||||
using UnityEngine.Events;
|
||||
using System;
|
||||
|
||||
namespace CriWare {
|
||||
|
||||
namespace CriTimeline.Atom {
|
||||
|
||||
public partial class CriAtomClipWaveformPreviewer {
|
||||
|
||||
private class CriAtomClipWaveformCanvas : IDisposable {
|
||||
private const string SHADER = "CRIWARE/CriAtomClipWaveformRender";
|
||||
private const int DEFAULT_TEXTURE_WIDTH = 4096;
|
||||
private static readonly Color backgroundColor = Color.clear;
|
||||
private static readonly Color waveColorForAll = new Color(1.0f, 0.635f, 0.0f, 1.0f); /* yellow */
|
||||
private static readonly Color waveColorForMono = new Color(0.332f, 0.661f, 0.991f, 1f); /* blue */
|
||||
|
||||
private Texture2D texture;
|
||||
private Material material;
|
||||
private int scanPosition = 0;
|
||||
private ClipBackgroundRegion lastRegion;
|
||||
private int lastWidth = 0;
|
||||
private bool lastLoop = false;
|
||||
private bool isDirty = true;
|
||||
private bool isDisposed = false;
|
||||
|
||||
public UnityAction updated = null;
|
||||
|
||||
public bool IsDirty {
|
||||
get { return isDirty; }
|
||||
set {
|
||||
if (isDirty = value) {
|
||||
scanPosition = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public CriAtomClipWaveformCanvas() {
|
||||
this.texture = null;
|
||||
this.material = new Material(Shader.Find(SHADER));
|
||||
}
|
||||
|
||||
~CriAtomClipWaveformCanvas() {
|
||||
dispose();
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
dispose();
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
public void UpdateTexture(ref CriAtomClipWaveformInfo info, bool loop, ClipBackgroundRegion? region = null, bool renderOnce = false) {
|
||||
const int BATCH_NUM_PIXEL = 50;
|
||||
|
||||
int scanWidth = region.HasValue ? (int)region.Value.position.width : DEFAULT_TEXTURE_WIDTH;
|
||||
|
||||
if (texture == null) {
|
||||
texture = new Texture2D(scanWidth, info.waveformInfo.numChannels, TextureFormat.RG16, false);
|
||||
texture.wrapMode = TextureWrapMode.Clamp;
|
||||
texture.filterMode = FilterMode.Bilinear;
|
||||
} else if (renderOnce == false) {
|
||||
if (region.HasValue && lastWidth != scanWidth) {
|
||||
#if UNITY_2021_2_OR_NEWER
|
||||
texture.Reinitialize(scanWidth, texture.height);
|
||||
#else
|
||||
texture.Resize(scanWidth, texture.height);
|
||||
#endif
|
||||
this.IsDirty = true;
|
||||
lastWidth = scanWidth;
|
||||
}
|
||||
if (region.HasValue && region.Value != lastRegion) {
|
||||
this.IsDirty = true;
|
||||
lastRegion = region.Value;
|
||||
}
|
||||
if (loop != lastLoop) {
|
||||
this.IsDirty = true;
|
||||
lastLoop = loop;
|
||||
}
|
||||
}
|
||||
|
||||
if (isDirty) {
|
||||
if (this.scanPosition >= scanWidth) {
|
||||
this.IsDirty = false;
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
long startSmpIdx = region.HasValue
|
||||
? (long)((region.Value.startTime / info.waveDurationSecond) * info.waveformInfo.numSamples)
|
||||
: 0;
|
||||
long endSmpIdx = region.HasValue
|
||||
? (long)((region.Value.endTime / info.waveDurationSecond) * info.waveformInfo.numSamples)
|
||||
: (info.waveformInfo.numSamples - 1);
|
||||
long smpLength = endSmpIdx - startSmpIdx + 1;
|
||||
|
||||
float samplePerPixel = smpLength / (float)scanWidth;
|
||||
if (samplePerPixel <= 0) {
|
||||
samplePerPixel = float.Epsilon;
|
||||
}
|
||||
|
||||
for (int y = 0; y < texture.height; ++y) {
|
||||
for (int x = scanPosition; x < scanPosition + BATCH_NUM_PIXEL; ++x) {
|
||||
Int16 maxValue, minValue;
|
||||
long startPnt = (long)(startSmpIdx + x * samplePerPixel);
|
||||
if (loop) {
|
||||
startPnt %= info.waveformInfo.numSamples;
|
||||
}
|
||||
long range = (long)Mathf.Ceil(samplePerPixel);
|
||||
if (startPnt + range > info.waveformInfo.numSamples) {
|
||||
range = (long)Mathf.Floor(info.waveformInfo.numSamples - startPnt);
|
||||
}
|
||||
GetMinMaxPcmArray(info.lpcmBufferByInterleave,
|
||||
startPnt,
|
||||
range,
|
||||
y,
|
||||
info.waveformInfo.numChannels,
|
||||
out minValue, out maxValue);
|
||||
texture.SetPixel(x, y, new Color(
|
||||
maxValue / (float)Int16.MaxValue,
|
||||
minValue / (float)Int16.MinValue,
|
||||
0));
|
||||
}
|
||||
}
|
||||
|
||||
texture.Apply();
|
||||
|
||||
scanPosition += BATCH_NUM_PIXEL;
|
||||
|
||||
if (this.updated != null) {
|
||||
this.updated();
|
||||
}
|
||||
}
|
||||
|
||||
private static void GetMinMaxPcmArray(Int16[] array, long index, long length, int channel, int numChannels, out Int16 min, out Int16 max) {
|
||||
Int16 maxValue = 0;
|
||||
Int16 minValue = 0;
|
||||
for (long i = 0; i < length; i++) {
|
||||
var currentIndex = (index + i) * numChannels + channel;
|
||||
var amplitude = array[currentIndex];
|
||||
if (maxValue < amplitude) {
|
||||
maxValue = amplitude;
|
||||
}
|
||||
if (minValue > amplitude) {
|
||||
minValue = amplitude;
|
||||
}
|
||||
}
|
||||
max = maxValue;
|
||||
min = minValue;
|
||||
}
|
||||
|
||||
public void Draw(Rect rect) {
|
||||
if (this.texture == null || this.material == null) { return; }
|
||||
Graphics.DrawTexture(rect, this.texture, this.material);
|
||||
}
|
||||
|
||||
public void SetMatParams(
|
||||
RenderChannelMode channelMode,
|
||||
int numChannels,
|
||||
bool isLooping,
|
||||
bool isMuted,
|
||||
float scale,
|
||||
float offset)
|
||||
{
|
||||
this.material.SetTexture("_MainTex", this.texture);
|
||||
this.material.SetColor("_BacCol", backgroundColor);
|
||||
this.material.SetColor("_ForCol", channelMode == RenderChannelMode.All ? waveColorForAll : waveColorForMono);
|
||||
this.material.SetFloat("_Channel", channelMode == RenderChannelMode.All ? numChannels : 1);
|
||||
|
||||
this.material.SetFloat("_Scale", scale);
|
||||
this.material.SetFloat("_Offset", offset);
|
||||
|
||||
this.material.SetInt("_IsLoop", isLooping ? 1 : 0);
|
||||
this.material.SetInt("_IsMute", isMuted ? 1 : 0);
|
||||
this.material.SetInt("_ForceMono", channelMode == RenderChannelMode.Mono ? 1 : 0);
|
||||
}
|
||||
|
||||
private void dispose() {
|
||||
if (this.isDisposed) { return; }
|
||||
|
||||
if (Application.isPlaying) {
|
||||
UnityEngine.Object.Destroy(this.texture);
|
||||
UnityEngine.Object.Destroy(this.material);
|
||||
} else {
|
||||
UnityEngine.Object.DestroyImmediate(this.texture);
|
||||
UnityEngine.Object.DestroyImmediate(this.material);
|
||||
}
|
||||
this.texture = null;
|
||||
this.material = null;
|
||||
|
||||
this.isDisposed = true;
|
||||
}
|
||||
|
||||
} //class CriAtomClipWaveformCanvas
|
||||
|
||||
} //partial class CriAtomClipWaveformPreviewer
|
||||
|
||||
} //namespace CriTimeline.Atom
|
||||
|
||||
} //namespace CriWare
|
||||
|
||||
#endif
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f0f13bdc836d8464aabbebf21dab6560
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
Shader "CRIWARE/CriAtomClipWaveformRender" {
|
||||
Properties{
|
||||
_MainTex("Main Texture", 2D) = "white" { }
|
||||
}
|
||||
|
||||
SubShader{
|
||||
Pass {
|
||||
Tags { "RenderType" = "Opaque" }
|
||||
Cull Off
|
||||
ZWrite Off
|
||||
ZTest Always
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
uniform sampler2D _MainTex;
|
||||
uniform float4 _MainTex_ST;
|
||||
uniform fixed4 _BacCol;
|
||||
uniform fixed4 _ForCol;
|
||||
uniform float _Offset;
|
||||
uniform float _Scale;
|
||||
uniform int _IsLoop;
|
||||
uniform int _IsMute;
|
||||
uniform float _Channel;
|
||||
uniform int _ForceMono;
|
||||
|
||||
struct appdata {
|
||||
float4 vertex : POSITION;
|
||||
float4 texcoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct v2f {
|
||||
float4 pos : SV_POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
inline float zero_amplitude(v2f v, float volume) {
|
||||
return floor(volume * 100.0) == 0.0 ? abs(ddy(v.uv.y)) : volume;
|
||||
}
|
||||
|
||||
v2f vert(appdata v) {
|
||||
v2f o;
|
||||
o.pos = UnityObjectToClipPos(v.vertex);
|
||||
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
|
||||
o.uv.x *= _Scale;
|
||||
o.uv.x += _Offset;
|
||||
return o;
|
||||
}
|
||||
|
||||
fixed4 frag(v2f v) : SV_Target {
|
||||
float channel_height = (1.0 / (_Channel));
|
||||
int ch = floor(v.uv.y / (1.0 / _Channel)) + 1;
|
||||
|
||||
/* uv.y reads the values in reverse order of texture creation. */
|
||||
/* but _ForceMono is true, read the first channel at the end. */
|
||||
float2 ch_vec2 = {frac(v.uv.x), _Channel > 1 ? (ch - 1) * (1.0 / (_Channel - 1)) : 0.0 };
|
||||
ch_vec2.y = _ForceMono < 1 ? 1.0 - ch_vec2.y : ch_vec2.y;
|
||||
|
||||
float volume_max = tex2D(_MainTex, ch_vec2).r * channel_height / 2.0;
|
||||
volume_max = zero_amplitude(v, volume_max);
|
||||
volume_max = v.uv.x > 1 && _IsLoop < 1 ? abs(ddy(v.uv.y)) : volume_max;
|
||||
volume_max = _IsMute >= 1 ? abs(ddy(v.uv.y)) : volume_max;
|
||||
|
||||
float volume_min = tex2D(_MainTex, ch_vec2).g * channel_height / 2.0;
|
||||
volume_min = zero_amplitude(v, volume_min);
|
||||
volume_min = v.uv.x > 1 && _IsLoop < 1 ? abs(ddy(v.uv.y)) : volume_min;
|
||||
volume_min = _IsMute >= 1 ? abs(ddy(v.uv.y)) : volume_min;
|
||||
|
||||
float uvY = v.uv.y - ((channel_height / 2.0) * ch * 2.0) + channel_height / 2.0;
|
||||
fixed4 col = lerp(
|
||||
_BacCol,
|
||||
_ForCol,
|
||||
-volume_min <= uvY && uvY <= volume_max
|
||||
);
|
||||
clip(col.a - 0.5);
|
||||
return col;
|
||||
}
|
||||
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f420a9b00c3898a4eb0ed6f645a04081
|
||||
timeCreated: 1606370626
|
||||
licenseType: Pro
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,302 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2019 CRI Middleware Co., Ltd.
|
||||
*
|
||||
****************************************************************************/
|
||||
//#define CRI_TIMELINE_ATOM_VERBOSE_DEBUG
|
||||
|
||||
#if UNITY_2018_1_OR_NEWER && CRIWARE_TIMELINE_1_OR_NEWER
|
||||
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEditor.Timeline;
|
||||
using UnityEngine.Timeline;
|
||||
using System.Runtime.InteropServices;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CriWare {
|
||||
|
||||
namespace CriTimeline.Atom {
|
||||
|
||||
[CustomPropertyDrawer(typeof(CriAtomBehaviour))]
|
||||
public class CriAtomTimelineDrawer : PropertyDrawer {
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
|
||||
SerializedProperty volumeProp = property.FindPropertyRelative("volume");
|
||||
SerializedProperty pitchProp = property.FindPropertyRelative("pitch");
|
||||
SerializedProperty aisacProp = property.FindPropertyRelative("AISACValue");
|
||||
|
||||
EditorGUILayout.PropertyField(volumeProp);
|
||||
EditorGUILayout.PropertyField(pitchProp);
|
||||
EditorGUILayout.PropertyField(aisacProp);
|
||||
}
|
||||
}
|
||||
|
||||
[CustomEditor(typeof(CriAtomClipBase)), CanEditMultipleObjects]
|
||||
public class CriAtomClipEditor : UnityEditor.Editor { }
|
||||
|
||||
[CustomEditor(typeof(CriAtomTrack))]
|
||||
public class CriAtomTrackEditor : UnityEditor.Editor {
|
||||
private CriAtomTrack m_object;
|
||||
|
||||
public void OnEnable() {
|
||||
if (target != null) {
|
||||
m_object = target as CriAtomTrack;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI() {
|
||||
if (m_object == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
serializedObject.Update();
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
|
||||
EditorGUILayout.LabelField("Track Settings", EditorStyles.boldLabel);
|
||||
DrawLine(Color.black);
|
||||
m_object.m_AisacControls
|
||||
= EditorGUILayout.TextField("Aisac Control", m_object.m_AisacControls);
|
||||
m_object.m_StopOnWrapping
|
||||
= EditorGUILayout.Toggle("Stop On Wrapping", m_object.m_StopOnWrapping);
|
||||
m_object.m_StopAtGraphEnd
|
||||
= EditorGUILayout.Toggle("Stop At Graph End", m_object.m_StopAtGraphEnd);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
EditorGUILayout.LabelField("Unity Editor", EditorStyles.boldLabel);
|
||||
DrawLine(Color.black);
|
||||
|
||||
m_object.m_IsRenderMono
|
||||
= EditorGUILayout.Toggle("Show Mono Waveform", m_object.m_IsRenderMono);
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
if (EditorGUI.EndChangeCheck()) {
|
||||
EditorUtility.SetDirty(m_object);
|
||||
}
|
||||
}
|
||||
|
||||
private static void DrawLine(Color color, int thickness = 1, int padding = 10) {
|
||||
Rect rect = EditorGUILayout.GetControlRect(GUILayout.Height(padding + thickness));
|
||||
rect.height = thickness;
|
||||
rect.y += padding / 2;
|
||||
rect.x -= 2;
|
||||
rect.width += 6;
|
||||
EditorGUI.DrawRect(rect, color);
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
|
||||
[CustomTimelineEditor(typeof(CriAtomClipBase))]
|
||||
public class CriAtomClipWaveformEditor : UnityEditor.Timeline.ClipEditor {
|
||||
private Dictionary<CriAtomClipBase, CriAtomClipWaveformPreviewer> atomClipPreviewDirectory
|
||||
= new Dictionary<CriAtomClipBase, CriAtomClipWaveformPreviewer>();
|
||||
|
||||
public override void OnCreate(TimelineClip clip, TrackAsset track, TimelineClip clonedFrom) {
|
||||
base.OnCreate(clip, track, clonedFrom);
|
||||
#if CRI_TIMELINE_ATOM_VERBOSE_DEBUG
|
||||
Debug.Log("[CRIWARE][Timeline] OnCreate");
|
||||
#endif
|
||||
|
||||
atomClipPreviewDirectory.Clear();
|
||||
|
||||
CriAtomClipBase atomClip = clip.asset as CriAtomClipBase;
|
||||
atomClipPreviewDirectory.Add(atomClip, new CriAtomClipWaveformPreviewer(atomClip));
|
||||
}
|
||||
|
||||
public override void OnClipChanged(TimelineClip clip) {
|
||||
base.OnClipChanged(clip);
|
||||
#if CRI_TIMELINE_ATOM_VERBOSE_DEBUG
|
||||
Debug.Log("[CRIWARE][Timeline] OnClipChanged");
|
||||
#endif
|
||||
|
||||
CriAtomClipBase atomClip = clip.asset as CriAtomClipBase;
|
||||
if (atomClipPreviewDirectory.ContainsKey(atomClip)) {
|
||||
return;
|
||||
}
|
||||
atomClipPreviewDirectory.Add(atomClip, new CriAtomClipWaveformPreviewer(atomClip));
|
||||
}
|
||||
|
||||
public override void DrawBackground(TimelineClip clip, ClipBackgroundRegion region) {
|
||||
base.DrawBackground(clip, region);
|
||||
#if CRI_TIMELINE_ATOM_VERBOSE_DEBUG
|
||||
Debug.Log("[CRIWARE][Timeline] DrawBackground");
|
||||
|
||||
Debug.Log("region.startTime : " + region.startTime.ToString() + "region.endTime : " + region.endTime.ToString());
|
||||
#endif
|
||||
|
||||
CriAtomClipBase atomClip = clip.asset as CriAtomClipBase;
|
||||
CriAtomClipWaveformPreviewer atomClipPreviewer;
|
||||
if (!atomClipPreviewDirectory.TryGetValue(atomClip, out atomClipPreviewer)) {
|
||||
#if CRI_TIMELINE_ATOM_VERBOSE_DEBUG
|
||||
Debug.LogError("[CRIWARE][Timeline] not contains key : " + clip.displayName);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
if (!atomClipPreviewer.HasDecodeTask()) {
|
||||
atomClipPreviewDirectory.Remove(atomClip);
|
||||
atomClipPreviewDirectory.Add(atomClip, new CriAtomClipWaveformPreviewer(atomClip));
|
||||
}
|
||||
|
||||
if (!atomClipPreviewer.HasPreviewData()) {
|
||||
/* While decoding or decode error. Skip renderring. */
|
||||
return;
|
||||
}
|
||||
|
||||
atomClipPreviewer.IsLooping = atomClip.loopWithinClip;
|
||||
atomClipPreviewer.IsMuted = atomClip.muted;
|
||||
CriAtomTrack atomTrack = clip.parentTrack as CriAtomTrack;
|
||||
if (atomTrack.m_IsRenderMono) {
|
||||
atomClipPreviewer.ChannelMode = CriAtomClipWaveformPreviewer.RenderChannelMode.Mono;
|
||||
} else {
|
||||
atomClipPreviewer.ChannelMode = CriAtomClipWaveformPreviewer.RenderChannelMode.All;
|
||||
}
|
||||
|
||||
if (Event.current.type == EventType.Repaint) {
|
||||
atomClipPreviewer.RenderMaterial(region);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public partial class CriAtomClipWaveformPreviewer {
|
||||
/* Number of drawing channels */
|
||||
public enum RenderChannelMode {
|
||||
Mono = 0, /* Mono(Left Channel) */
|
||||
All /* All Channels */
|
||||
}
|
||||
|
||||
public bool IsLooping = false;
|
||||
public bool IsMuted = true;
|
||||
public RenderChannelMode ChannelMode = RenderChannelMode.Mono;
|
||||
|
||||
private struct CriAtomClipWaveformInfo {
|
||||
public CriAtomEx.WaveformInfo waveformInfo;
|
||||
public double waveDurationSecond;
|
||||
public Int16[] lpcmBufferByInterleave;
|
||||
}
|
||||
|
||||
private Task decodeTask = null;
|
||||
private CriAtomClipWaveformInfo atomClipWaveformInfo;
|
||||
private CriAtomClipWaveformCanvas simpleCanvas;
|
||||
private CriAtomClipWaveformCanvas regionalCanvas;
|
||||
|
||||
public CriAtomClipWaveformPreviewer(CriAtomClipBase criAtomClip) {
|
||||
if (!CriAtomTimelinePreviewer.IsInitialized || string.IsNullOrEmpty(criAtomClip.AcbPath)) {
|
||||
return;
|
||||
}
|
||||
var acb = CriAtomTimelinePreviewer.Instance.GetAcb(criAtomClip.AcbPath, criAtomClip.AwbPath);
|
||||
if (acb == null) {
|
||||
Debug.LogError("[CRIWARE][Timeline] faild to load acb object.");
|
||||
return;
|
||||
}
|
||||
|
||||
decodeTask = Task.Run(() =>
|
||||
{
|
||||
this.atomClipWaveformInfo = new CriAtomClipWaveformInfo();
|
||||
if (!acb.GetWaveFormInfo(criAtomClip.CueName, out this.atomClipWaveformInfo.waveformInfo)) {
|
||||
/* without waveform */
|
||||
return;
|
||||
}
|
||||
this.atomClipWaveformInfo.lpcmBufferByInterleave = new Int16[this.atomClipWaveformInfo.waveformInfo.numSamples * this.atomClipWaveformInfo.waveformInfo.numChannels];
|
||||
if (!LoadWaveform(acb.nativeHandle, criAtomClip.CueName, ref this.atomClipWaveformInfo.lpcmBufferByInterleave)) {
|
||||
this.atomClipWaveformInfo.lpcmBufferByInterleave = null;
|
||||
return;
|
||||
}
|
||||
this.atomClipWaveformInfo.waveDurationSecond = this.atomClipWaveformInfo.waveformInfo.numSamples / (double)this.atomClipWaveformInfo.waveformInfo.samplingRate;
|
||||
});
|
||||
|
||||
simpleCanvas = new CriAtomClipWaveformCanvas();
|
||||
simpleCanvas.updated += () => {
|
||||
TimelineEditor.Refresh(RefreshReason.WindowNeedsRedraw);
|
||||
};
|
||||
regionalCanvas = new CriAtomClipWaveformCanvas();
|
||||
regionalCanvas.updated += () => {
|
||||
TimelineEditor.Refresh(RefreshReason.WindowNeedsRedraw);
|
||||
};
|
||||
}
|
||||
|
||||
~CriAtomClipWaveformPreviewer() {
|
||||
if (decodeTask != null) {
|
||||
if (!decodeTask.IsCompleted) {
|
||||
decodeTask.Wait();
|
||||
}
|
||||
decodeTask.Dispose();
|
||||
decodeTask = null;
|
||||
}
|
||||
simpleCanvas.Dispose();
|
||||
simpleCanvas = null;
|
||||
regionalCanvas.Dispose();
|
||||
regionalCanvas = null;
|
||||
}
|
||||
|
||||
public bool HasDecodeTask() {
|
||||
return decodeTask == null ? false : true;
|
||||
}
|
||||
|
||||
public bool HasPreviewData() {
|
||||
if (decodeTask == null || decodeTask.IsFaulted || decodeTask.IsCanceled || !decodeTask.IsCompleted) {
|
||||
return false;
|
||||
}
|
||||
/* decodeTask.IsCompleted == true and buffer == null is decode error. */
|
||||
return this.atomClipWaveformInfo.lpcmBufferByInterleave != null;
|
||||
}
|
||||
|
||||
public void RenderMaterial(ClipBackgroundRegion region) {
|
||||
if (region.position.height <= 0 | region.position.width <= 0) {
|
||||
/* region.position is invalid. */
|
||||
return;
|
||||
}
|
||||
|
||||
simpleCanvas.UpdateTexture(ref this.atomClipWaveformInfo, this.IsLooping, renderOnce:true);
|
||||
regionalCanvas.UpdateTexture(ref this.atomClipWaveformInfo, this.IsLooping, region);
|
||||
|
||||
simpleCanvas.SetMatParams(
|
||||
channelMode: ChannelMode,
|
||||
numChannels: this.atomClipWaveformInfo.waveformInfo.numChannels,
|
||||
isLooping: this.IsLooping,
|
||||
isMuted: this.IsMuted,
|
||||
scale: (float)((region.endTime - region.startTime) / this.atomClipWaveformInfo.waveDurationSecond),
|
||||
offset: (float)(region.startTime / this.atomClipWaveformInfo.waveDurationSecond));
|
||||
|
||||
regionalCanvas.SetMatParams(
|
||||
channelMode: ChannelMode,
|
||||
numChannels: this.atomClipWaveformInfo.waveformInfo.numChannels,
|
||||
isLooping: this.IsLooping,
|
||||
isMuted: this.IsMuted,
|
||||
scale: 1f,
|
||||
offset: 0);
|
||||
|
||||
if (regionalCanvas.IsDirty) {
|
||||
simpleCanvas.Draw(region.position);
|
||||
} else {
|
||||
regionalCanvas.Draw(region.position);
|
||||
}
|
||||
}
|
||||
|
||||
private static bool LoadWaveform(IntPtr acbHn, string cueName, ref System.Int16[] decodeLpcmBuffer) {
|
||||
var gcHandle = GCHandle.Alloc(decodeLpcmBuffer, GCHandleType.Pinned);
|
||||
var result = CRIWAREF2B79675(acbHn, cueName, gcHandle.AddrOfPinnedObject(), decodeLpcmBuffer.LongLength);
|
||||
gcHandle.Free();
|
||||
return result;
|
||||
}
|
||||
|
||||
#region DLL Import
|
||||
#if !CRIWARE_ENABLE_HEADLESS_MODE
|
||||
[DllImport(CriWare.Common.pluginName, CallingConvention = CriWare.Common.pluginCallingConvention)]
|
||||
private static extern bool CRIWAREF2B79675(IntPtr acbHn, string cue_name, IntPtr decode_lpcm_buffer, System.Int64 decodeLpcmBufferLength);
|
||||
#else
|
||||
private static bool CRIWAREF2B79675(IntPtr acbHn, string cue_name, IntPtr decode_lpcm_buffer, System.Int64 decodeLpcmBufferLength) {return false;}
|
||||
#endif
|
||||
#endregion
|
||||
}
|
||||
|
||||
#endif //UNITY_2019_3_OR_NEWER
|
||||
|
||||
}
|
||||
|
||||
} //namespace CriWare
|
||||
|
||||
#endif //UNITY_2018_1_OR_NEWER
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 64709c1c359e022439e2bde0e6afa2d4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user