Skip to content

Commit

Permalink
Merge pull request #16 from lucidcode/wave-forms
Browse files Browse the repository at this point in the history
Add option to configure wave forms
  • Loading branch information
IAmCoder authored Aug 17, 2022
2 parents 8c19248 + 617eb08 commit 97b09fe
Show file tree
Hide file tree
Showing 10 changed files with 258 additions and 105 deletions.
3 changes: 2 additions & 1 deletion Halovision/Halovision.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="SineWaveProvider.cs" />
<Compile Include="WaveProvider.cs" />
<Compile Include="TCMP.cs" />
<Compile Include="VisionForm.cs">
<SubType>Form</SubType>
Expand All @@ -229,6 +229,7 @@
<Compile Include="WaveHeader.cs" />
<Compile Include="WaveNative.cs" />
<Compile Include="WaveOut.cs" />
<Compile Include="WaveType.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Properties\Resources.resx">
Expand Down
44 changes: 36 additions & 8 deletions Halovision/PluginHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ public static bool Auralize
return visionForm.Auralize;
}
}

public static WaveType WaveForm
{
get
{
return visionForm.WaveForm;
}
}
}

namespace EyeMin
Expand Down Expand Up @@ -261,7 +269,10 @@ public override double Value

if (tossValue == 999 - tossHalfLife)
{
PlayGlitch();
if (Device.Auralize)
{
PlayGlitch();
}
}

Device.SetTossValue(tossValue);
Expand Down Expand Up @@ -297,7 +308,9 @@ namespace Vision
public class PluginHandler : lucidcode.LucidScribe.Interface.LucidPluginBase
{
private IWavePlayer player;
private SineWaveProvider sineProvider;
private WaveProvider waveProvider;
private WaveType waveForm;
private WaveOutEvent waveOutEvent;

public override string Name
{
Expand All @@ -309,13 +322,14 @@ public override string Name

public override bool Initialize()
{
sineProvider = new SineWaveProvider();
waveForm = Device.WaveForm;
waveProvider = new WaveProvider(waveForm);

var waveOutEvent = new WaveOutEvent();
waveOutEvent = new WaveOutEvent();
waveOutEvent.NumberOfBuffers = 2;
waveOutEvent.DesiredLatency = 100;
player = waveOutEvent;
player.Init(new SampleToWaveProvider(sineProvider));
player.Init(new SampleToWaveProvider(waveProvider));

return Device.Initialize();
}
Expand All @@ -334,7 +348,8 @@ public override double Value
player.Play();
}
Auralize(vision);
} else
}
else
{
if (player.PlaybackState == PlaybackState.Playing)
{
Expand All @@ -348,8 +363,21 @@ public override double Value

private void Auralize(double frequency)
{
if (frequency > 0) frequency += 128;
sineProvider.Frequency = frequency;
if (waveForm == WaveType.Sin)
{
if (frequency > 0) frequency += 256;
}

if (waveForm != Device.WaveForm)
{
waveForm = Device.WaveForm;
waveProvider = new WaveProvider(waveForm);
player.Stop();
player = waveOutEvent;
player.Init(new SampleToWaveProvider(waveProvider));
player.Play();
}
waveProvider.Frequency = frequency / 2;
}

public override void Dispose()
Expand Down
4 changes: 2 additions & 2 deletions Halovision/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.5.0")]
[assembly: AssemblyFileVersion("1.2.5.0")]
[assembly: AssemblyVersion("1.2.6.0")]
[assembly: AssemblyFileVersion("1.2.6.0")]
75 changes: 0 additions & 75 deletions Halovision/SineWaveProvider.cs

This file was deleted.

41 changes: 41 additions & 0 deletions Halovision/VisionForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public partial class VisionForm : Form
public int DashThreshold = 600;

public bool Auralize = false;
public WaveType WaveForm = WaveType.Square;

private VideoCaptureDevice videoSource;
private Rectangle[] faceRegions;
Expand Down Expand Up @@ -229,6 +230,7 @@ private void LoadSettings()
defaultSettings += "<DotThreshold>200</DotThreshold>";
defaultSettings += "<DashThreshold>600</DashThreshold>";
defaultSettings += "<Classifier>None</Classifier>";
defaultSettings += "<WaveForm>Sqaure</WaveForm>";
defaultSettings += "</Plugin>";
defaultSettings += "</LucidScribeData>";
File.WriteAllText(settingsFilePath, defaultSettings);
Expand Down Expand Up @@ -278,6 +280,15 @@ private void LoadSettings()
cmbClassifier.Text = xmlSettings.DocumentElement.SelectSingleNode("//Classifier").InnerText;
}

if (xmlSettings.DocumentElement.SelectSingleNode("//WaveForm") != null)
{
cmbWaveForm.Text = xmlSettings.DocumentElement.SelectSingleNode("//WaveForm").InnerText;
}
else
{
cmbWaveForm.Text = "Triangle";
}

if (xmlSettings.DocumentElement.SelectSingleNode("//TopMost") != null && xmlSettings.DocumentElement.SelectSingleNode("//TopMost").InnerText == "0")
{
chkTopMost.Checked = false;
Expand Down Expand Up @@ -906,6 +917,7 @@ private void SaveSettings()
}

settings += "<Classifier>" + cmbClassifier.Text + "</Classifier>";
settings += "<WaveForm>" + cmbWaveForm.Text + "</WaveForm>";

if (chkTopMost.Checked)
{
Expand Down Expand Up @@ -1051,5 +1063,34 @@ private void chkCopyFromScreen_CheckedChanged(object sender, EventArgs e)
CopyFromScreen = chkCopyFromScreen.Checked;
SaveSettings();
}

private void cmbWaveForm_SelectedIndexChanged(object sender, EventArgs e)
{
switch (cmbWaveForm.Text)
{
case "Sin":
WaveForm = WaveType.Sin;
break;
case "SawTooth":
WaveForm = WaveType.SawTooth;
break;
case "Sqaure":
WaveForm = WaveType.Square;
break;
case "Triangle":
WaveForm = WaveType.Triangle;
break;
case "Sweep":
WaveForm = WaveType.Sweep;
break;
case "Pink":
WaveForm = WaveType.Pink;
break;
default:
WaveForm = WaveType.Square;
break;
}
SaveSettings();
}
}
}
Loading

0 comments on commit 97b09fe

Please sign in to comment.