rj-action-library/Runtime/Audio/AudioGraph/Generators/WaveTableGenerator.cs

39 lines
814 B
C#
Raw Normal View History

2025-01-03 12:09:23 +00:00
using Godot;
using System.Reflection;
using System.Collections.Generic;
using System.Text;
namespace Rokojori
{
public class WaveTableGenerator:AudioGeneratorMono
{
public readonly AudioStreamInput frequency;
protected WaveTable waveTable;
public WaveTableGenerator( AudioGraph ag, WaveTable waveTable ): base( ag )
{
frequency = new AudioStreamInput( this );
this.waveTable = waveTable;
}
float _phase = 0;
protected override void _Process()
{
for ( int i = 0; i < bufferSize; i++ )
{
float increment = frequency[ i ] / audioGraph.sampleRate;
_phase += increment;
_phase = MathX.Repeat( _phase, 1 );
var value = waveTable.Get( _phase );
output[ i ] = waveTable.Get( _phase );
}
}
}
}