Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions Halovision/DataChunk.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace lucidcode.LucidScribe.Plugin.Halovision
{
internal class DataChunk
{
private const string CHUNK_ID = "data";

public string ChunkId { get; private set; }
public UInt32 ChunkSize { get; set; }
public short[] WaveData { get; private set; }

public DataChunk()
{
ChunkId = CHUNK_ID;
ChunkSize = 0;
}

public UInt32 Length()
{
return (UInt32)GetBytes().Length;
}

public byte[] GetBytes()
{
List<Byte> chunkBytes = new List<Byte>();

chunkBytes.AddRange(Encoding.ASCII.GetBytes(ChunkId));
chunkBytes.AddRange(BitConverter.GetBytes(ChunkSize));
byte[] bufferBytes = new byte[WaveData.Length * 2];
Buffer.BlockCopy(WaveData, 0, bufferBytes, 0,
bufferBytes.Length);
chunkBytes.AddRange(bufferBytes.ToList());

return chunkBytes.ToArray();
}

public void AddSampleData(short[] leftBuffer,
short[] rightBuffer)
{
WaveData = new short[leftBuffer.Length +
rightBuffer.Length];
int bufferOffset = 0;
for (int index = 0; index < WaveData.Length; index += 2)
{
WaveData[index] = leftBuffer[bufferOffset];
WaveData[index + 1] = rightBuffer[bufferOffset];
bufferOffset++;
}
ChunkSize = (UInt32)WaveData.Length * 2;
}
}
}
79 changes: 79 additions & 0 deletions Halovision/FormatChunk.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace lucidcode.LucidScribe.Plugin.Halovision
{
internal class FormatChunk
{
private ushort _bitsPerSample;
private ushort _channels;
private uint _frequency;
private const string CHUNK_ID = "fmt ";

public string ChunkId { get; private set; }
public UInt32 ChunkSize { get; private set; }
public UInt16 FormatTag { get; private set; }

public UInt16 Channels
{
get { return _channels; }
set { _channels = value; RecalcBlockSizes(); }
}

public UInt32 Frequency
{
get { return _frequency; }
set { _frequency = value; RecalcBlockSizes(); }
}

public UInt32 AverageBytesPerSec { get; private set; }
public UInt16 BlockAlign { get; private set; }

public UInt16 BitsPerSample
{
get { return _bitsPerSample; }
set { _bitsPerSample = value; RecalcBlockSizes(); }
}

public FormatChunk()
{
ChunkId = CHUNK_ID;
ChunkSize = 16;
FormatTag = 1; // MS PCM (Uncompressed wave file)
Channels = 2; // Default to stereo
Frequency = 44100; // Default to 44100hz
BitsPerSample = 16; // Default to 16bits
RecalcBlockSizes();
}

private void RecalcBlockSizes()
{
BlockAlign = (UInt16)(_channels * (_bitsPerSample / 8));
AverageBytesPerSec = _frequency * BlockAlign;
}

public byte[] GetBytes()
{
List<Byte> chunkBytes = new List<byte>();

chunkBytes.AddRange(Encoding.ASCII.GetBytes(ChunkId));
chunkBytes.AddRange(BitConverter.GetBytes(ChunkSize));
chunkBytes.AddRange(BitConverter.GetBytes(FormatTag));
chunkBytes.AddRange(BitConverter.GetBytes(Channels));
chunkBytes.AddRange(BitConverter.GetBytes(Frequency));
chunkBytes.AddRange(BitConverter.GetBytes(AverageBytesPerSec));
chunkBytes.AddRange(BitConverter.GetBytes(BlockAlign));
chunkBytes.AddRange(BitConverter.GetBytes(BitsPerSample));

return chunkBytes.ToArray();
}

public UInt32 Length()
{
return (UInt32)GetBytes().Length;
}
}
}
4 changes: 4 additions & 0 deletions Halovision/Halovision.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,15 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="DataChunk.cs" />
<Compile Include="FormatChunk.cs" />
<Compile Include="PluginHandler.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="SineGenerator.cs" />
<Compile Include="TCMP.cs" />
<Compile Include="VisionForm.cs">
<SubType>Form</SubType>
Expand All @@ -192,6 +195,7 @@
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="VLC.cs" />
<Compile Include="WaveHeader.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Properties\Resources.resx">
Expand Down
44 changes: 40 additions & 4 deletions Halovision/PluginHandler.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Media;
using System.Threading;
using System.Windows.Forms;

Expand Down Expand Up @@ -126,6 +128,14 @@ public static bool TCMP
return visionForm.TCMP;
}
}

public static bool Auralize
{
get
{
return visionForm.Auralize;
}
}
}

namespace EyeMin
Expand Down Expand Up @@ -251,6 +261,8 @@ namespace Vision
{
public class PluginHandler : lucidcode.LucidScribe.Interface.LucidPluginBase
{
SoundPlayer sound = new SoundPlayer();

public override string Name
{
get
Expand All @@ -268,13 +280,37 @@ public override double Value
{
get
{
double tempValue = Device.GetVision();
if (tempValue > 999) { tempValue = 999; }
if (tempValue < 0) { tempValue = 0; }
return tempValue;
double vision = Device.GetVision();
if (vision > 999) { vision = 999; }
if (vision < 0) { vision = 0; }

if (Device.Auralize && vision > 0) {
Auralize(vision);
}

return vision;
}
}

private void Auralize(double frequency)
{
var header = new WaveHeader();
var format = new FormatChunk();
var austioChunk = new DataChunk();
var sineData = new SineGenerator(frequency);

austioChunk.AddSampleData(sineData.Data, sineData.Data);
header.FileLength += format.Length() + austioChunk.Length();

var soundBytes = new List<byte>();
soundBytes.AddRange(header.GetBytes());
soundBytes.AddRange(format.GetBytes());
soundBytes.AddRange(austioChunk.GetBytes());

sound.Stream = new MemoryStream(soundBytes.ToArray());
sound.Play();
}

public override void Dispose()
{
Device.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.1.5.0")]
[assembly: AssemblyFileVersion("1.1.5.0")]
[assembly: AssemblyVersion("1.1.6.0")]
[assembly: AssemblyFileVersion("1.1.6.0")]
37 changes: 37 additions & 0 deletions Halovision/SineGenerator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;

namespace lucidcode.LucidScribe.Plugin.Halovision
{
internal class SineGenerator
{
private readonly double _frequency;
private short[] _dataBuffer;

public short[] Data { get { return _dataBuffer; } }

public SineGenerator(double frequency)
{
_frequency = frequency;
GenerateData();
}

private void GenerateData()
{
UInt32 sampleRate = 44100;

uint bufferSize = sampleRate / 10;
_dataBuffer = new short[bufferSize];

int amplitude = 32760;

double timePeriod = (Math.PI * 2 * _frequency) /
(sampleRate);

for (uint index = 0; index < bufferSize - 1; index++)
{
_dataBuffer[index] = Convert.ToInt16(amplitude *
Math.Sin(timePeriod * index));
}
}
}
}
23 changes: 23 additions & 0 deletions Halovision/VisionForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public partial class VisionForm : Form
public int DotThreshold = 200;
public int DashThreshold = 600;

public bool Auralize = false;

private VideoCaptureDevice videoSource;
private Rectangle[] faceRegions;
private CascadeClassifier cascadeClassifier;
Expand Down Expand Up @@ -223,6 +225,7 @@ private void LoadSettings()
defaultSettings += "<CopyFromScreen>0</CopyFromScreen>";
defaultSettings += "<RecordVideo>0</RecordVideo>";
defaultSettings += "<TCMP>0</TCMP>";
defaultSettings += "<Auralize>0</Auralize>";
defaultSettings += "<DotThreshold>200</DotThreshold>";
defaultSettings += "<DashThreshold>600</DashThreshold>";
defaultSettings += "<Classifier>None</Classifier>";
Expand Down Expand Up @@ -353,6 +356,11 @@ private void LoadSettings()
{
dashThresholdInput.Value = DashThreshold;
}

if (xmlSettings.DocumentElement.SelectSingleNode("//Auralize") != null && xmlSettings.DocumentElement.SelectSingleNode("//Auralize").InnerText == "1")
{
chkAuralize.Checked = true;
}
}

private void cmbDevices_SelectedIndexChanged(object sender, EventArgs e)
Expand Down Expand Up @@ -917,6 +925,15 @@ private void SaveSettings()
settings += "<TCMP>0</TCMP>";
}

if (chkAuralize.Checked)
{
settings += "<Auralize>1</Auralize>";
}
else
{
settings += "<Auralize>0</Auralize>";
}

settings += "<DotThreshold>" + dotThresholdInput.Value + "</DotThreshold>";
settings += "<DashThreshold>" + dashThresholdInput.Value + "</DashThreshold>";

Expand Down Expand Up @@ -952,6 +969,12 @@ private void chkTCMP_CheckedChanged(object sender, EventArgs e)
SaveSettings();
}

private void chkAuralize_CheckedChanged(object sender, EventArgs e)
{
Auralize = chkAuralize.Checked;
SaveSettings();
}

private void txtDeviceURL_TextChanged(object sender, EventArgs e)
{
SaveSettings();
Expand Down
Loading