/// <summary> /// Fills this subcode buffer with subchannel Q data. calculates the required CRC, as well. /// Returns the crc, calculated or otherwise. /// </summary> public ushort Synthesize_SubchannelQ(ref SubchannelQ sq, bool calculateCRC) { int offset = 12; //Q subchannel begins after P, 12 bytes in SubcodeDeinterleaved[offset + 0] = sq.q_status; SubcodeDeinterleaved[offset + 1] = sq.q_tno; SubcodeDeinterleaved[offset + 2] = sq.q_index; SubcodeDeinterleaved[offset + 3] = sq.min.BCDValue; SubcodeDeinterleaved[offset + 4] = sq.sec.BCDValue; SubcodeDeinterleaved[offset + 5] = sq.frame.BCDValue; SubcodeDeinterleaved[offset + 6] = sq.zero; SubcodeDeinterleaved[offset + 7] = sq.ap_min.BCDValue; SubcodeDeinterleaved[offset + 8] = sq.ap_sec.BCDValue; SubcodeDeinterleaved[offset + 9] = sq.ap_frame.BCDValue; ushort crc16; if (calculateCRC) { crc16 = CRC16_CCITT.Calculate(SubcodeDeinterleaved, offset, 10); } else { crc16 = sq.q_crc; } //CRC is stored inverted and big endian SubcodeDeinterleaved[offset + 10] = (byte)(~(crc16 >> 8)); SubcodeDeinterleaved[offset + 11] = (byte)(~(crc16)); return(crc16); }
/// <summary> /// Calculates the checksum of the provided Q subchannel buffer and emplaces it /// </summary> /// <param name="buffer">12 byte Q subchannel buffer: input and output buffer for operation</param> /// <param name="offset">location within buffer of Q subchannel</param> public static ushort SubQ_SynthChecksum(byte[] buf12, int offset) { ushort crc16 = CRC16_CCITT.Calculate(buf12, offset, 10); //CRC is stored inverted and big endian buf12[offset + 10] = (byte)(~(crc16 >> 8)); buf12[offset + 11] = (byte)(~(crc16)); return(crc16); }
public void Read_SubchannelQ(byte[] buffer, int offset) { buffer[offset + 0] = q_status; buffer[offset + 1] = q_tno.BCDValue; buffer[offset + 2] = q_index.BCDValue; buffer[offset + 3] = q_min.BCDValue; buffer[offset + 4] = q_sec.BCDValue; buffer[offset + 5] = q_frame.BCDValue; buffer[offset + 6] = 0; buffer[offset + 7] = q_amin.BCDValue; buffer[offset + 8] = q_asec.BCDValue; buffer[offset + 9] = q_aframe.BCDValue; ushort crc16 = CRC16_CCITT.Calculate(buffer, 0, 10); //CRC is stored inverted and big endian buffer[offset + 10] = (byte)(~(crc16 >> 8)); buffer[offset + 11] = (byte)(~(crc16)); }
/// <summary> /// Caclulates the checksum of the provided Q subchannel buffer /// </summary> public static ushort SubQ_CalcChecksum(byte[] buf12, int offset) { return(CRC16_CCITT.Calculate(buf12, offset, 10)); }