Virtu/Library/WaveFormat.cs
Sean Fausett 51d9e8e5f2 Added sound emulation for Silverlight.
--HG--
extra : convert_revision : svn%3Affd33b8c-2492-42e0-bdc5-587b920b7d6d/trunk%4042615
2010-03-08 09:54:04 +00:00

50 lines
1.6 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
{
StringBuilder 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;
}
}