-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from lucidcode/auralize
Add option to listen to graph
- Loading branch information
Showing
11 changed files
with
302 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.