Skip to content

Commit

Permalink
Fix channel counts
Browse files Browse the repository at this point in the history
  • Loading branch information
Nytra committed Jan 5, 2025
1 parent 66881e2 commit 182be57
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 13 deletions.
12 changes: 6 additions & 6 deletions ProjectObsidian/Elements/Audio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,12 @@ public void Process<S>(Span<S> buffer, float lowFreq, float highFreq, float reso

public static class Algorithms
{
public static void SineShapedRingModulation<S>(Span<S> buffer, Span<S> input1, Span<S> input2, float modulationIndex) where S : unmanaged, IAudioSample<S>
public static void SineShapedRingModulation<S>(Span<S> buffer, Span<S> input1, Span<S> input2, float modulationIndex, int channelCount) where S : unmanaged, IAudioSample<S>
{
// Apply sine-shaped ring modulation
for (int i = 0; i < buffer.Length; i++)
{
for (int j = 0; j < buffer[i].ChannelCount; j++)
for (int j = 0; j < channelCount; j++)
{
float carrierValue = input1[i][j];
float modulatorValue = input2[i][j];
Expand Down Expand Up @@ -221,14 +221,14 @@ private static double[] CalculateInstantaneousPhase<S>(Span<S> buffer) where S :
return phase;
}

public static void PhaseModulation<S>(Span<S> buffer, Span<S> input1, Span<S> input2, float modulationIndex) where S : unmanaged, IAudioSample<S>
public static void PhaseModulation<S>(Span<S> buffer, Span<S> input1, Span<S> input2, float modulationIndex, int channelCount) where S : unmanaged, IAudioSample<S>
{
double[] carrierPhase = CalculateInstantaneousPhase(input1);

// Apply phase modulation
for (int i = 0; i < buffer.Length; i++)
{
for (int j = 0; j < buffer[i].ChannelCount; j++)
for (int j = 0; j < channelCount; j++)
{
double modifiedPhase = carrierPhase[i] + (modulationIndex * input2[i][j]);

Expand All @@ -244,12 +244,12 @@ public static void PhaseModulation<S>(Span<S> buffer, Span<S> input1, Span<S> in
}
}

public static void RingModulation<S>(Span<S> buffer, Span<S> input1, Span<S> input2, float modulationIndex) where S : unmanaged, IAudioSample<S>
public static void RingModulation<S>(Span<S> buffer, Span<S> input1, Span<S> input2, float modulationIndex, int channelCount) where S : unmanaged, IAudioSample<S>
{
// Apply ring modulation
for (int i = 0; i < buffer.Length; i++)
{
for (int j = 0; j < buffer[i].ChannelCount; j++)
for (int j = 0; j < channelCount; j++)
{
float carrierValue = input1[i][j];
float modulatorValue = input2[i][j];
Expand Down
3 changes: 2 additions & 1 deletion ProjectObsidian/ProtoFlux/Audio/AudioAdder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using FrooxEngine.ProtoFlux;
using FrooxEngine;
using Elements.Assets;
using Elements.Core;

namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Audio
{
Expand Down Expand Up @@ -50,7 +51,7 @@ public void Read<S>(Span<S> buffer) where S : unmanaged, IAudioSample<S>
{
newBuffer[i] = newBuffer[i].Add(newBuffer2[i]);

for (int j = 0; j < newBuffer[i].ChannelCount; j++)
for (int j = 0; j < ChannelCount; j++)
{
if (newBuffer[i][j] > 1f) newBuffer[i] = newBuffer[i].SetChannel(j, 1f);
else if (newBuffer[i][j] < -1f) newBuffer[i] = newBuffer[i].SetChannel(j, -1f);
Expand Down
2 changes: 1 addition & 1 deletion ProjectObsidian/ProtoFlux/Audio/AudioMultiply.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void Read<S>(Span<S> buffer) where S : unmanaged, IAudioSample<S>
{
newBuffer[i] = newBuffer[i].Multiply(Value);

for (int j = 0; j < newBuffer[i].ChannelCount; j++)
for (int j = 0; j < ChannelCount; j++)
{
if (newBuffer[i][j] > 1f) newBuffer[i] = newBuffer[i].SetChannel(j, 1f);
if (newBuffer[i][j] < -1f) newBuffer[i] = newBuffer[i].SetChannel(j, -1f);
Expand Down
2 changes: 1 addition & 1 deletion ProjectObsidian/ProtoFlux/Audio/AudioSubtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void Read<S>(Span<S> buffer) where S : unmanaged, IAudioSample<S>
{
newBuffer[i] = newBuffer[i].Subtract(newBuffer2[i]);

for (int j = 0; j < newBuffer[i].ChannelCount; j++)
for (int j = 0; j < ChannelCount; j++)
{
if (newBuffer[i][j] > 1f) newBuffer[i] = newBuffer[i].SetChannel(j, 1f);
else if (newBuffer[i][j] < -1f) newBuffer[i] = newBuffer[i].SetChannel(j, -1f);
Expand Down
2 changes: 1 addition & 1 deletion ProjectObsidian/ProtoFlux/Audio/ChannelSplitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class ChannelSplitterProxy : ProtoFluxEngineProxy, IAudioSource

public bool IsActive => Active;

public int ChannelCount => 2;
public int ChannelCount => 1;

public void Read<S>(Span<S> buffer) where S : unmanaged, IAudioSample<S>
{
Expand Down
2 changes: 1 addition & 1 deletion ProjectObsidian/ProtoFlux/Audio/PhaseModulatorNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void Read<S>(Span<S> buffer) where S : unmanaged, IAudioSample<S>
newBuffer2.Fill(default);
}

Algorithms.PhaseModulation(buffer, newBuffer, newBuffer2, ModulationIndex);
Algorithms.PhaseModulation(buffer, newBuffer, newBuffer2, ModulationIndex, ChannelCount);
}
}
[NodeCategory("Obsidian/Audio/Effects")]
Expand Down
2 changes: 1 addition & 1 deletion ProjectObsidian/ProtoFlux/Audio/RingModulatorNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void Read<S>(Span<S> buffer) where S : unmanaged, IAudioSample<S>
newBuffer2.Fill(default);
}

Algorithms.RingModulation(buffer, newBuffer, newBuffer2, ModulationIndex);
Algorithms.RingModulation(buffer, newBuffer, newBuffer2, ModulationIndex, ChannelCount);
}
}
[NodeCategory("Obsidian/Audio/Effects")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void Read<S>(Span<S> buffer) where S : unmanaged, IAudioSample<S>
newBuffer2.Fill(default);
}

Algorithms.SineShapedRingModulation(buffer, newBuffer, newBuffer2, ModulationIndex);
Algorithms.SineShapedRingModulation(buffer, newBuffer, newBuffer2, ModulationIndex, ChannelCount);
}
}
[NodeCategory("Obsidian/Audio/Effects")]
Expand Down

0 comments on commit 182be57

Please sign in to comment.