Skip to content

Commit

Permalink
Wasm.Audio
Browse files Browse the repository at this point in the history
  • Loading branch information
nkast committed May 22, 2022
1 parent bd6f0f0 commit 4c2a5ea
Show file tree
Hide file tree
Showing 18 changed files with 1,076 additions and 0 deletions.
50 changes: 50 additions & 0 deletions Wasm.Audio/Audio/AudioBuffer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System;
using nkast.Wasm.Dom;

namespace nkast.Wasm.Audio
{
public class AudioBuffer : JSObject
{
BaseAudioContext _context;

internal AudioBuffer(int uid, BaseAudioContext context) : base(uid)
{
_context = context;
}

public int SampleRate
{
get { return InvokeRet<int>("nkAudioBuffer.GetSampleRate"); }
}

public int Length
{
get { return InvokeRet<int>("nkAudioBuffer.GetLength"); }
}

public int NumberOfChannels
{
get { return InvokeRet<int>("nkAudioBuffer.GetNumberOfChannels"); }
}

public void CopyToChannel(float[] source, int channelNumber)
{
Invoke("nkAudioBuffer.CopyToChannel", channelNumber, source);
}

protected override void Dispose(bool disposing)
{
if (IsDisposed)
return;

if (disposing)
{

}

_context = null;

base.Dispose(disposing);
}
}
}
38 changes: 38 additions & 0 deletions Wasm.Audio/Audio/AudioBufferSourceNode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using nkast.Wasm.Dom;

namespace nkast.Wasm.Audio
{
public class AudioBufferSourceNode : AudioScheduledSourceNode
{

internal AudioBufferSourceNode(int uid, BaseAudioContext context) : base(uid, context)
{
}

public AudioBuffer Buffer
{
get { throw new NotImplementedException(); }
set { Invoke("nkAudioBufferSourceNode.SetBuffer", value.Uid); }
}

public bool Loop
{
get { return InvokeRet<bool>("nkAudioBufferSourceNode.GetLoop"); }
set { Invoke("nkAudioBufferSourceNode.SetLoop", value ? 1 : 0); }
}

protected override void Dispose(bool disposing)
{
if (IsDisposed)
return;

if (disposing)
{

}

base.Dispose(disposing);
}
}
}
47 changes: 47 additions & 0 deletions Wasm.Audio/Audio/AudioContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using Microsoft.JSInterop.WebAssembly;
using nkast.Wasm.Dom;

namespace nkast.Wasm.Audio
{
public class AudioContext : BaseAudioContext
{
public AudioContext() : base(Register())
{
}


private static int Register()
{
WebAssemblyJSRuntime runtime = new WasmJSRuntime();
int uid = runtime.InvokeUnmarshalled<int>("nkAudioContext.Create");
return uid;
}

public void Close()
{
Invoke("nkAudioContext.Close");
}

protected override void Dispose(bool disposing)
{
if (IsDisposed)
return;

if (disposing)
{

}

Close();

base.Dispose(disposing);
}

internal sealed class WasmJSRuntime : WebAssemblyJSRuntime
{
}

}
}
30 changes: 30 additions & 0 deletions Wasm.Audio/Audio/AudioDestinationNode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using nkast.Wasm.Dom;

namespace nkast.Wasm.Audio
{
public class AudioDestinationNode : AudioNode
{
internal AudioDestinationNode(int uid, BaseAudioContext context) : base(uid, context)
{
}

public int MaxChannelCount
{
get { return InvokeRet<int>("nkAudioDestinationNode.GetMaxChannelCount"); }
}

protected override void Dispose(bool disposing)
{
if (IsDisposed)
return;

if (disposing)
{

}

base.Dispose(disposing);
}
}
}
84 changes: 84 additions & 0 deletions Wasm.Audio/Audio/AudioListener.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using System;
using nkast.Wasm.Dom;

namespace nkast.Wasm.Audio
{
public class AudioListener : JSObject
{
BaseAudioContext _context;

internal AudioListener(int uid, BaseAudioContext context) : base(uid)
{
_context = context;
}

public float PositionX
{
get { throw new NotImplementedException(); }
set { Invoke("nkAudioListener.SetPositionX", value); }
}

public float PositionY
{
get { throw new NotImplementedException(); }
set { Invoke("nkAudioListener.SetPositionY", value); }
}

public float PositionZ
{
get { throw new NotImplementedException(); }
set { Invoke("nkAudioListener.SetPositionZ", value); }
}

public float ForwardX
{
get { throw new NotImplementedException(); }
set { Invoke("nkAudioListener.SetForwardX", value); }
}

public float ForwardY
{
get { throw new NotImplementedException(); }
set { Invoke("nkAudioListener.SetForwardY", value); }
}

public float ForwardZ
{
get { throw new NotImplementedException(); }
set { Invoke("nkAudioListener.SetForwardZ", value); }
}

public float UpX
{
get { throw new NotImplementedException(); }
set { Invoke("nkAudioListener.SetUpX", value); }
}

public float UpY
{
get { throw new NotImplementedException(); }
set { Invoke("nkAudioListener.SetUpY", value); }
}

public float UpZ
{
get { throw new NotImplementedException(); }
set { Invoke("nkAudioListener.SetUpZ", value); }
}

protected override void Dispose(bool disposing)
{
if (IsDisposed)
return;

if (disposing)
{

}

_context = null;

base.Dispose(disposing);
}
}
}
42 changes: 42 additions & 0 deletions Wasm.Audio/Audio/AudioNode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using nkast.Wasm.Dom;

namespace nkast.Wasm.Audio
{
public class AudioNode : JSObject
{
BaseAudioContext _context;

protected BaseAudioContext Context { get { return _context; } }

internal AudioNode(int uid, BaseAudioContext context) : base(uid)
{
_context = context;
}

public void Connect(AudioNode destination)
{
Invoke("nkAudioNode.Connect", destination.Uid);
}

public void Disconnect(AudioNode destination)
{
Invoke("nkAudioNode.Disconnect", destination.Uid);
}

protected override void Dispose(bool disposing)
{
if (IsDisposed)
return;

if (disposing)
{

}

_context = null;

base.Dispose(disposing);
}
}
}
67 changes: 67 additions & 0 deletions Wasm.Audio/Audio/AudioParam.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System;
using nkast.Wasm.Dom;

namespace nkast.Wasm.Audio
{
public class AudioParam : JSObject
{
BaseAudioContext _context;

internal AudioParam(int uid, BaseAudioContext context) : base(uid)
{
_context = context;
}

public float Value
{
get { throw new NotImplementedException(); }
set { Invoke("nkAudioParam.SetValue", value); }
}

public void SetValueAtTime(float value, float startTime)
{
Invoke("nkAudioParam.SetValueAtTime", value, startTime);
}

public void LinearRampToValueAtTime(float value, float endTime)
{
Invoke("nkAudioParam.LinearRampToValueAtTime", value, endTime);
}

public void ExponentialRampToValueAtTime(float value, float endTime)
{
Invoke("nkAudioParam.ExponentialRampToValueAtTime", value, endTime);
}

public void SetTargetAtTime(float target, float startTime, float timeConstant)
{
Invoke("nkAudioParam.SetTargetAtTime", target, startTime, timeConstant);
}

public void SetValueCurveAtTime(float[] values, float startTime, float duration)
{
Invoke("nkAudioParam.SetValueCurveAtTime", startTime, duration, values);
}

public void CancelScheduledValues(float startTime)
{
Invoke("nkAudioParam.CancelScheduledValues", startTime);
}


protected override void Dispose(bool disposing)
{
if (IsDisposed)
return;

if (disposing)
{

}

_context = null;

base.Dispose(disposing);
}
}
}
Loading

0 comments on commit 4c2a5ea

Please sign in to comment.