mirror of
https://github.com/digital-jellyfish/Virtu.git
synced 2024-11-23 19:30:59 +00:00
365e5723c1
--HG-- extra : convert_revision : svn%3Affd33b8c-2492-42e0-bdc5-587b920b7d6d/trunk%4050811
50 lines
1.7 KiB
C#
50 lines
1.7 KiB
C#
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
|
|
namespace Jellyfish.Library
|
|
{
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
public sealed class WaveFormat
|
|
{
|
|
public WaveFormat(int sampleRate, int sampleChannels, int sampleBits)
|
|
{
|
|
_formatTag = WaveFormatPcm;
|
|
_samplesPerSec = sampleRate;
|
|
_channels = (short)sampleChannels;
|
|
_bitsPerSample = (short)sampleBits;
|
|
_blockAlign = (short)(sampleChannels * sampleBits / 8);
|
|
_averageBytesPerSec = sampleRate * _blockAlign;
|
|
}
|
|
|
|
public string ToHexString() // little endian
|
|
{
|
|
var builder = new StringBuilder();
|
|
|
|
builder.AppendHex(_formatTag);
|
|
builder.AppendHex(_channels);
|
|
builder.AppendHex(_samplesPerSec);
|
|
builder.AppendHex(_averageBytesPerSec);
|
|
builder.AppendHex(_blockAlign);
|
|
builder.AppendHex(_bitsPerSample);
|
|
builder.AppendHex(_size);
|
|
|
|
return builder.ToString();
|
|
}
|
|
|
|
public int SamplesPerSec { get { return _samplesPerSec; } } // no auto props
|
|
public int Channels { get { return _channels; } }
|
|
public int BitsPerSample { get { return _bitsPerSample; } }
|
|
public int AverageBytesPerSec { get { return _averageBytesPerSec; } }
|
|
|
|
private const int WaveFormatPcm = 1;
|
|
|
|
private short _formatTag;
|
|
private short _channels;
|
|
private int _samplesPerSec;
|
|
private int _averageBytesPerSec;
|
|
private short _blockAlign;
|
|
private short _bitsPerSample;
|
|
private short _size;
|
|
}
|
|
}
|