Created
April 9, 2017 01:34
-
-
Save elliotwoods/748a0ff99c1cbb910a25c97ec4de02df to your computer and use it in GitHub Desktop.
DynamicBuffer (VAudio)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#region usings | |
using System; | |
using System.ComponentModel.Composition; | |
using VVVV.PluginInterfaces.V1; | |
using VVVV.PluginInterfaces.V2; | |
using VVVV.Utils.VColor; | |
using VVVV.Utils.VMath; | |
using VVVV.Core.Logging; | |
using VVVV.Audio; | |
using NAudio; | |
#endregion usings | |
namespace VVVV.Nodes | |
{ | |
#region PluginInfo | |
[PluginInfo(Name = "DynamicBuffer", Category = "VAudio", Version = "Value", Help = "Basic template with one value in/out", Tags = "c#")] | |
#endregion PluginInfo | |
public class ValueVAudioDynamicBufferNode : GenericAudioSourceNode<DynamicBufferSignal> | |
{ | |
#region fields & pins | |
[Input("Input", DefaultValue = 0.0)] | |
public IDiffSpread<ISpread<double>> FInput; | |
[Import()] | |
public ILogger FLogger; | |
#endregion fields & pins | |
protected override void SetParameters(int SliceIndex, DynamicBufferSignal instance) | |
{ | |
float[] buffer = new float[FInput[SliceIndex].SliceCount]; | |
for(int i=0; i<FInput[SliceIndex].SliceCount; i++) { | |
buffer[i] = (float) FInput[SliceIndex][i]; | |
instance.SetBuffer(buffer); | |
} | |
} | |
protected override DynamicBufferSignal GetInstance(int i) { | |
return new DynamicBufferSignal(); | |
} | |
protected override int GetSpreadMax(int previousSpreadMax) { | |
return FInput.SliceCount; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#region usings | |
using System; | |
using System.ComponentModel.Composition; | |
using VVVV.PluginInterfaces.V1; | |
using VVVV.PluginInterfaces.V2; | |
using VVVV.Utils.VColor; | |
using VVVV.Utils.VMath; | |
using VVVV.Core.Logging; | |
using VVVV.Audio; | |
#endregion usings | |
namespace VVVV.Nodes { | |
public class DynamicBufferSignal : AudioSignal { | |
int FOffset = 0; | |
float[] FBuffer; | |
Object FBufferLock = new Object(); | |
protected override void FillBuffer(float[] buffer, int offset, int count) { | |
//if we're not ready then just provide zeros | |
if (this.FBuffer == null) { | |
for(int i=0; i<count; i++) { | |
buffer[offset + i] = 0.0f; | |
} | |
} | |
lock(FBufferLock) { | |
for(int i=0; i<count; i++) { | |
buffer[offset + i] = FBuffer[FOffset]; | |
FOffset++; | |
FOffset %= FBuffer.Length; | |
} | |
} | |
} | |
public void SetBuffer(float[] buffer) { | |
lock(FBufferLock) { | |
FBuffer = buffer; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment