private void ReadSPDIF()
{
if (_ok)
{
byte[] spdif = { 0x72, 0xf8, 0x1f, 0x4e };
if (_rdr.BaseStream.CanSeek)
{
_seekpos = _rdr.BaseStream.Position;
}
// Read the first sample "manually"
// so we can check whether there's a SPDIF or other magic number
// at the beginning of the stream.
int nFirst = (_nc * _bitsPerSample / 8);
byte[] firstBytes = _rdr.ReadBytes(nFirst);
MemoryStream ms = new MemoryStream(firstBytes);
BinaryReader mr = new BinaryReader(ms);
// Save the sample for later use
_first = Next(mr, out _moreThanFirst);
if (firstBytes.Length >= nFirst)
{
// Check whether it's SPDIF-wrapped
_isSPDIF = true;
for (int b = 0; _isSPDIF && b < spdif.Length && b < nFirst; b++)
{
_isSPDIF &= (spdif[b] == firstBytes[b]);
}
}
}
}