Skip to content

Commit

Permalink
Merge pull request #10 from lucidcode/illuminate
Browse files Browse the repository at this point in the history
Add RAW vision channel and improve sound quality
  • Loading branch information
IAmCoder committed Aug 13, 2022
2 parents 360cb4a + 5985974 commit e2e1bdb
Show file tree
Hide file tree
Showing 12 changed files with 919 additions and 30 deletions.
Binary file not shown.
168 changes: 168 additions & 0 deletions Halovision/FifoStream.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
using System;
using System.IO;
using System.Linq;
using System.Collections;

namespace lucidcode.LucidScribe.Plugin.Halovision
{
public class FifoStream : Stream
{
private const int BlockSize = 65536;
private const int MaxBlocksInCache = (3 * 1024 * 1024) / BlockSize;

private int m_Size;
private int m_RPos;
private int m_WPos;
private Stack m_UsedBlocks = new Stack();
private ArrayList m_Blocks = new ArrayList();

private byte[] AllocBlock()
{
byte[] Result = null;
Result = m_UsedBlocks.Count > 0 ? (byte[])m_UsedBlocks.Pop() : new byte[BlockSize];
return Result;
}
private void FreeBlock(byte[] block)
{
if (m_UsedBlocks.Count < MaxBlocksInCache)
m_UsedBlocks.Push(block);
}
private byte[] GetWBlock()
{
byte[] Result = null;
if (m_WPos < BlockSize && m_Blocks.Count > 0)
Result = (byte[])m_Blocks[m_Blocks.Count - 1];
else
{
Result = AllocBlock();
m_Blocks.Add(Result);
m_WPos = 0;
}
return Result;
}

// Stream members
public override bool CanRead
{
get { return true; }
}
public override bool CanSeek
{
get { return false; }
}
public override bool CanWrite
{
get { return true; }
}
public override long Length
{
get
{
lock (this)
return m_Size;
}
}
public override long Position
{
get { throw new InvalidOperationException(); }
set { throw new InvalidOperationException(); }
}
public override void Close()
{
Flush();
}
public override void Flush()
{
lock (this)
{
foreach (byte[] block in m_Blocks)
FreeBlock(block);
m_Blocks.Clear();
m_RPos = 0;
m_WPos = 0;
m_Size = 0;
}
}
public override void SetLength(long len)
{
throw new InvalidOperationException();
}
public override long Seek(long pos, SeekOrigin o)
{
throw new InvalidOperationException();
}
public override int Read(byte[] buf, int ofs, int count)
{
lock (this)
{
int Result = Peek(buf, ofs, count);
Advance(Result);
return Result;
}
}
public override void Write(byte[] buf, int ofs, int count)
{
lock (this)
{
int Left = count;
while (Left > 0)
{
int ToWrite = Math.Min(BlockSize - m_WPos, Left);
Array.Copy(buf, ofs + count - Left, GetWBlock(), m_WPos, ToWrite);
m_WPos += ToWrite;
Left -= ToWrite;
}
m_Size += count;
}
}

// extra stuff
public int Advance(int count)
{
lock (this)
{
int SizeLeft = count;
while (SizeLeft > 0 && m_Size > 0)
{
if (m_RPos == BlockSize)
{
m_RPos = 0;
FreeBlock((byte[])m_Blocks[0]);
m_Blocks.RemoveAt(0);
}
int ToFeed = m_Blocks.Count == 1 ? Math.Min(m_WPos - m_RPos, SizeLeft) : Math.Min(BlockSize - m_RPos, SizeLeft);
m_RPos += ToFeed;
SizeLeft -= ToFeed;
m_Size -= ToFeed;
}
return count - SizeLeft;
}
}
public int Peek(byte[] buf, int ofs, int count)
{
lock (this)
{
int SizeLeft = count;
int TempBlockPos = m_RPos;
int TempSize = m_Size;

int CurrentBlock = 0;
while (SizeLeft > 0 && TempSize > 0)
{
if (TempBlockPos == BlockSize)
{
TempBlockPos = 0;
CurrentBlock++;
}
int Upper = CurrentBlock < m_Blocks.Count - 1 ? BlockSize : m_WPos;
int ToFeed = Math.Min(Upper - TempBlockPos, SizeLeft);
Array.Copy((byte[])m_Blocks[CurrentBlock], TempBlockPos, buf, ofs + count - SizeLeft, ToFeed);
SizeLeft -= ToFeed;
TempBlockPos += ToFeed;
TempSize -= ToFeed;
}
return count - SizeLeft;
}
}
}
}
2 changes: 0 additions & 2 deletions Halovision/FormatChunk.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace lucidcode.LucidScribe.Plugin.Halovision
{
Expand Down
37 changes: 37 additions & 0 deletions Halovision/Halovision.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@
<HintPath>Dependencies\lucidcode.LucidScribe.Interface.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="lucidcode.LucidScribe.Interface.Illuminated">
<HintPath>Dependencies\lucidcode.LucidScribe.Interface.Illuminated.dll</HintPath>
</Reference>
<Reference Include="lucidcode.LucidScribe.TCMP">
<HintPath>Dependencies\lucidcode.LucidScribe.TCMP.dll</HintPath>
</Reference>
Expand All @@ -134,6 +137,30 @@
<HintPath>..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualBasic" />
<Reference Include="Microsoft.Win32.Registry, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Win32.Registry.4.7.0\lib\net461\Microsoft.Win32.Registry.dll</HintPath>
</Reference>
<Reference Include="NAudio, Version=2.1.0.0, Culture=neutral, PublicKeyToken=e279aa5131008a41, processorArchitecture=MSIL">
<HintPath>..\packages\NAudio.2.1.0\lib\net472\NAudio.dll</HintPath>
</Reference>
<Reference Include="NAudio.Asio, Version=2.1.0.0, Culture=neutral, PublicKeyToken=e279aa5131008a41, processorArchitecture=MSIL">
<HintPath>..\packages\NAudio.Asio.2.1.0\lib\netstandard2.0\NAudio.Asio.dll</HintPath>
</Reference>
<Reference Include="NAudio.Core, Version=2.1.0.0, Culture=neutral, PublicKeyToken=e279aa5131008a41, processorArchitecture=MSIL">
<HintPath>..\packages\NAudio.Core.2.1.0\lib\netstandard2.0\NAudio.Core.dll</HintPath>
</Reference>
<Reference Include="NAudio.Midi, Version=2.1.0.0, Culture=neutral, PublicKeyToken=e279aa5131008a41, processorArchitecture=MSIL">
<HintPath>..\packages\NAudio.Midi.2.1.0\lib\netstandard2.0\NAudio.Midi.dll</HintPath>
</Reference>
<Reference Include="NAudio.Wasapi, Version=2.1.0.0, Culture=neutral, PublicKeyToken=e279aa5131008a41, processorArchitecture=MSIL">
<HintPath>..\packages\NAudio.Wasapi.2.1.0\lib\netstandard2.0\NAudio.Wasapi.dll</HintPath>
</Reference>
<Reference Include="NAudio.WinForms, Version=2.1.0.0, Culture=neutral, PublicKeyToken=e279aa5131008a41, processorArchitecture=MSIL">
<HintPath>..\packages\NAudio.WinForms.2.1.0\lib\net472\NAudio.WinForms.dll</HintPath>
</Reference>
<Reference Include="NAudio.WinMM, Version=2.1.0.0, Culture=neutral, PublicKeyToken=e279aa5131008a41, processorArchitecture=MSIL">
<HintPath>..\packages\NAudio.WinMM.2.1.0\lib\netstandard2.0\NAudio.WinMM.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
Expand Down Expand Up @@ -166,6 +193,12 @@
<Private>True</Private>
</Reference>
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Security.AccessControl, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Security.AccessControl.4.7.0\lib\net461\System.Security.AccessControl.dll</HintPath>
</Reference>
<Reference Include="System.Security.Principal.Windows, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Security.Principal.Windows.4.7.0\lib\net461\System.Security.Principal.Windows.dll</HintPath>
</Reference>
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll</HintPath>
</Reference>
Expand All @@ -178,13 +211,15 @@
</ItemGroup>
<ItemGroup>
<Compile Include="DataChunk.cs" />
<Compile Include="FifoStream.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="SignalGenerator.cs" />
<Compile Include="SineGenerator.cs" />
<Compile Include="TCMP.cs" />
<Compile Include="VisionForm.cs">
Expand All @@ -196,6 +231,8 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="VLC.cs" />
<Compile Include="WaveHeader.cs" />
<Compile Include="WaveNative.cs" />
<Compile Include="WaveOut.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Properties\Resources.resx">
Expand Down
Loading

0 comments on commit e2e1bdb

Please sign in to comment.