Skip to content

Commit 77734cf

Browse files
committed
A few small tweaks and improved configurability
1 parent 9379e01 commit 77734cf

File tree

5 files changed

+28
-9
lines changed

5 files changed

+28
-9
lines changed

ColorChord.NET/NoteFinder/Gen2NoteFinder.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ public sealed class Gen2NoteFinder : NoteFinderCommon, ITimingSource
2525
[ConfigInt("Octaves", 1, 20, 6)]
2626
public uint OctaveCount { get; private set; }
2727

28+
[ConfigInt("BinsPerOctave", 4, 960, 24)]
29+
private uint BPO = 24;
30+
2831
[ConfigFloat("StartFreq", 0F, 20000F, 55F)]
2932
public float StartFrequency { get; private set; } = 55F;
3033

@@ -77,7 +80,7 @@ public Gen2NoteFinder(string name, Dictionary<string, object> config)
7780

7881
SetupBuffers();
7982
this.SampleRate = 48000; // TODO: Temporary until source is connected ahead of time
80-
this.DFT = new(this.OctaveCount, 24, this.SampleRate, this.StartFrequency, this.LoudnessCorrectionAmount, RunTimingReceivers);
83+
this.DFT = new(this.OctaveCount, this.BPO, this.SampleRate, this.StartFrequency, this.LoudnessCorrectionAmount, RunTimingReceivers);
8184
Reconfigure();
8285
}
8386

@@ -106,7 +109,7 @@ public override void AdjustOutputSpeed(uint period)
106109
public override void SetSampleRate(int sampleRate)
107110
{
108111
this.SampleRate = (uint)sampleRate;
109-
this.DFT = new(this.OctaveCount, 24, this.SampleRate, this.StartFrequency, this.LoudnessCorrectionAmount, RunTimingReceivers);
112+
this.DFT = new(this.OctaveCount, this.BPO, this.SampleRate, this.StartFrequency, this.LoudnessCorrectionAmount, RunTimingReceivers);
110113
Reconfigure();
111114
Log.Debug($"There are {TimingReceivers.Length} timing receivers");
112115
for (int i = 0; i < TimingReceivers.Length; i++)

ColorChord.NET/Outputs/Display/Shaders/Spectrum.frag

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
#version 330 core
22
#extension GL_EXT_gpu_shader4 : enable
33

4-
#define BINS_PER_OCATVE 24
5-
64
in vec2 TexCoord;
75

86
uniform int BinCount;
7+
uniform int BinsPerOctave;
98
uniform sampler2D TextureRawBins;
109
uniform usampler2D TexturePeakBits, TextureWidebandBits;
1110
uniform float ScaleFactor;
@@ -36,7 +35,7 @@ void main()
3635
float ChangeHere = texture(TextureRawBins, vec2((SectionHere + 0.5) / BinCount, 0.75)).r * 10.0;
3736
uint PeakHere = (texture(TexturePeakBits, vec2(((SectionHere / 8) + 0.5) / textureSize(TexturePeakBits, 0).x, 0.5)).r >> (SectionHere % 8)) & 1u;
3837
uint WidebandHere = (texture(TextureWidebandBits, vec2(((SectionHere / 8) + 0.5) / textureSize(TextureWidebandBits, 0).x, 0.5)).r >> (SectionHere % 8)) & 1u;
39-
vec3 Colour = AngleToRGB(mod(float(SectionHere) / BINS_PER_OCATVE, 1.0), 1.0 - (0.8 * WidebandHere), min(1.0, 0.1 + (HeightHere * 3.0)) - (0.9 * WidebandHere));
38+
vec3 Colour = AngleToRGB(mod(float(SectionHere) / BinsPerOctave, 1.0), 1.0 - (0.8 * WidebandHere), min(1.0, 0.1 + (HeightHere * 3.0)) - (0.9 * WidebandHere));
4039
float IsBar = step(abs(TexCoord.y), HeightHere);
4140
//float IsBar = (step(0.0, TexCoord.y) * step(TexCoord.y, HeightHere)) + ((step(0.0, -TexCoord.y) * step(-TexCoord.y, ChangeHere)));
4241
FragColor = vec4((IsBar * Colour) + ((1.0 - IsBar) * vec3(0.1) * PeakHere * Colour), 1.0);

ColorChord.NET/Outputs/Display/Spectrum.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class Spectrum : IDisplayMode, IConfigurableAttr
3030
};
3131

3232
private int VertexBufferHandle, VertexArrayHandle, TextureHandleRawBins, TextureHandlePeakBits, TextureHandleWidebandBits;
33-
private int LocationBinCount, LocationScaleFactor, LocationExponent;
33+
private int LocationBinCount, LocationBPO, LocationScaleFactor, LocationExponent;
3434

3535
private float[] RawDataIn;
3636

@@ -97,6 +97,8 @@ public void Load()
9797

9898
this.LocationBinCount = this.Shader.GetUniformLocation("BinCount");
9999
GL.Uniform1(this.LocationBinCount, this.NoteFinder.AllBinValues.Length);
100+
this.LocationBPO = this.Shader.GetUniformLocation("BinsPerOctave");
101+
GL.Uniform1(this.LocationBPO, this.NoteFinder.BinsPerOctave);
100102
this.LocationScaleFactor = this.Shader.GetUniformLocation("ScaleFactor");
101103
GL.Uniform1(this.LocationScaleFactor, this.ScaleFactor);
102104
this.LocationExponent = this.Shader.GetUniformLocation("Exponent");

ColorChord.NET/Sources/WASAPILoopback.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public void Start()
144144
if (IsErrorAndOut(ErrorCode, "Could not get device timing info.")) { return; }
145145

146146
ErrorCode = this.Client.GetCurrentSharedModeEnginePeriod(out IntPtr MixFormatPtr2, out uint FramesPerBatch); // TODO: Automatically scale this based on the framerate of the outputs
147-
if (IsErrorAndOut(ErrorCode, "Could not get engine periodicity info.")) { return; }
147+
if (IsErrorAndOut(ErrorCode, "Could not get current engine periodicity info.")) { return; }
148148

149149
// Check if we can get PCM data directly (default is usually float)
150150
WaveFormatExtensible RequestedFormat = new()
@@ -170,7 +170,12 @@ public void Start()
170170
Marshal.FreeCoTaskMem(RequestedFormatPtr);
171171
RequestedFormatPtr = IntPtr.Zero;
172172
WaveFormatEx? ResponseFormat = WaveFormatEx.FromPointer(ResponseFormatPtr);
173-
Log.Warn($"WASAPI responded with 0x{IsRequestSupportedRaw:X8} when PCM was requested, falling back to using its format instead.");
173+
174+
#pragma warning disable CS0162 // Unreachable code detected
175+
if (FORCE_DEFAULT_FORMAT) { Log.Warn("Requesting more optimal format from WASAPI was disabled at compile time."); }
176+
else { Log.Warn($"WASAPI responded with 0x{IsRequestSupportedRaw:X8} when PCM was requested, falling back to using its format instead."); }
177+
#pragma warning restore CS0162 // Unreachable code detected
178+
174179
this.FormatIsPCM = (this.MixFormat.IsExtensible() && this.MixFormat.SubFormat == WaveFormatGUIDs.PCM) || (!this.MixFormat.IsExtensible() && this.MixFormat.Format == WaveFormatBasic.PCM);
175180
}
176181
else
@@ -179,6 +184,10 @@ public void Start()
179184
this.FormatIsPCM = true;
180185
}
181186

187+
ErrorCode = this.Client.GetSharedModeEnginePeriod(IsRequestSupported ? RequestedFormatPtr : MixFormatPtr, out uint DefaultPeriodFrames, out uint FundamentalPeriodFrames, out uint MinimumPeriodFrames, out uint MaximumPeriodFrames);
188+
if (IsErrorAndOut(ErrorCode, "Could not get detailed engine periodicity info.")) { return; }
189+
Log.Debug($"WASAPI engine periodicities: default = {DefaultPeriodFrames}, fundamental = {FundamentalPeriodFrames}, min = {MinimumPeriodFrames}, max = {MaximumPeriodFrames} frames.");
190+
182191
Log.Info($"Chosen audio format is {this.MixFormat.Format} {WaveFormatGUIDs.GetNameFromGUID(this.MixFormat.SubFormat)}, {this.MixFormat.ChannelCount} channel, {this.MixFormat.SampleRate}Hz sample rate, {this.MixFormat.BitsPerSample}b per sample.");
183192
Log.Info($"Default transaction period is {DefaultInterval} ticks, minimum is {MinimumInterval} ticks. Current mode is {FramesPerBatch} frames per dispatch.");
184193
this.BytesPerFrame = this.MixFormat.ChannelCount * (this.MixFormat.BitsPerSample / 8);

ColorChord.NET/Visualizers/NoteFinderPassthrough.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ public class NoteFinderPassthrough : IVisualizer, IDiscrete1D
1919
[ConfigFloat("TimePeriod", -1000000, 1000000, 100)]
2020
private float TimePeriod = 100F;
2121

22+
[ConfigFloat("SaturationAmplifier", 0, 1000, 4.5F)]
23+
private float SaturationAmplifier = 4.5F;
24+
25+
[ConfigFloat("SaturationExponent", 0, 100, 2F)]
26+
private float SaturationExponent = 2F;
27+
2228
private List<IOutput> Outputs = new(4);
2329

2430
private uint[] Data;
@@ -40,7 +46,7 @@ public void GetData()
4046
{
4147
ReadOnlySpan<float> RawData = this.NoteFinder.AllBinValues;
4248
if (this.Data.Length != RawData.Length) { this.Data = new uint[RawData.Length]; }
43-
for (int i = 0; i < RawData.Length; i++) { this.Data[i] = VisualizerTools.CCToRGB((float)i / this.NoteFinder.BinsPerOctave, 1F, MathF.Pow(RawData[i] * 4.5F, 2F)); }
49+
for (int i = 0; i < RawData.Length; i++) { this.Data[i] = VisualizerTools.CCToRGB((float)i / this.NoteFinder.BinsPerOctave, 1F, MathF.Pow(RawData[i] * this.SaturationAmplifier, this.SaturationExponent)); }
4450
foreach (IOutput Out in this.Outputs) { Out.Dispatch(); }
4551
}
4652

0 commit comments

Comments
 (0)