public FlakeReader(Stream IO) { if (IO == null) { throw new ArgumentNullException("IO"); } _IO = IO; crc8 = new Crc8(); _framesBuffer = new byte[0x20000]; decode_metadata(); frame = new FlacFrame(PCM.ChannelCount); framereader = new BitReader(); //max_frame_size = 16 + ((Flake.MAX_BLOCKSIZE * PCM.BitsPerSample * PCM.ChannelCount + 1) + 7) >> 3); if (((int)max_frame_size * PCM.BitsPerSample * PCM.ChannelCount * 2 >> 3) > _framesBuffer.Length) { byte[] temp = _framesBuffer; _framesBuffer = new byte[((int)max_frame_size * PCM.BitsPerSample * PCM.ChannelCount * 2 >> 3)]; if (_framesBufferLength > 0) Array.Copy(temp, _framesBufferOffset, _framesBuffer, 0, _framesBufferLength); _framesBufferOffset = 0; } _samplesInBuffer = 0; if (PCM.BitsPerSample != 16 && PCM.BitsPerSample != 24) throw new Exception("invalid flac file"); samplesBuffer = new int[Flake.MAX_BLOCKSIZE * PCM.ChannelCount]; residualBuffer = new int[Flake.MAX_BLOCKSIZE * PCM.ChannelCount]; }
public FlakeReader(string path, Stream IO) { _path = path; _IO = IO != null ? IO : new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 0x10000); crc8 = new Crc8(); crc16 = new Crc16(); _framesBuffer = new byte[0x20000]; decode_metadata(); frame = new FlacFrame(PCM.ChannelCount); framereader = new BitReader(); //max_frame_size = 16 + ((Flake.MAX_BLOCKSIZE * PCM.BitsPerSample * PCM.ChannelCount + 1) + 7) >> 3); if (((int)max_frame_size * PCM.BitsPerSample * PCM.ChannelCount * 2 >> 3) > _framesBuffer.Length) { byte[] temp = _framesBuffer; _framesBuffer = new byte[((int)max_frame_size * PCM.BitsPerSample * PCM.ChannelCount * 2 >> 3)]; if (_framesBufferLength > 0) Array.Copy(temp, _framesBufferOffset, _framesBuffer, 0, _framesBufferLength); _framesBufferOffset = 0; } _samplesInBuffer = 0; if ((PCM.BitsPerSample != 16 && PCM.BitsPerSample != 24) || PCM.ChannelCount != 2 || (PCM.SampleRate != 44100 && PCM.SampleRate != 48000)) throw new Exception("invalid flac file"); samplesBuffer = new int[Flake.MAX_BLOCKSIZE * PCM.ChannelCount]; residualBuffer = new int[Flake.MAX_BLOCKSIZE * PCM.ChannelCount]; }
public void Lte_2() { var crc = Crc8.GetLte(); crc.ComputeHash(Encoding.ASCII.GetBytes("123456789")); Assert.Equal(0xEA, crc.HashAsByte); }
public void Autosar_2() { var crc = Crc8.GetAutosar(); crc.ComputeHash(Encoding.ASCII.GetBytes("123456789")); Assert.Equal(0xDF, crc.HashAsByte); }
public void ICode_7() { var crc = Crc8.GetICode(); crc.ComputeHash(new byte[] { 0x30, 0x00, 0x00, 0x25 }); Assert.Equal(0x00, crc.HashAsByte); }
public void ICode_4() { var crc = Crc8.GetICode(); crc.ComputeHash(new byte[] { 0x30 }); Assert.Equal(0xB4, crc.HashAsByte); }
public void Hitag_2() { var crc = Crc8.GetHitag(); crc.ComputeHash(Encoding.ASCII.GetBytes("123456789")); Assert.Equal(0xB4, crc.HashAsByte); }
public void GsmB_2() { var crc = Crc8.GetGsmB(); crc.ComputeHash(Encoding.ASCII.GetBytes("123456789")); Assert.Equal(0x94, crc.HashAsByte); }
public IEnumerable <ushort> Encode(SmartConfigContext ctx, SmartConfigArguments args) { // Data = total len(1 byte) + apPwd len(1 byte) + SSID CRC(1 byte) + // BSSID CRC(1 byte) + TOTAL XOR(1 byte)+ ipAddress(4 byte) + apPwd + apSsid apPwdLen <= // 105 at the moment var senderIPAddress = args.LocalAddress.GetAddressBytes(); var passwordBytes = args.Password != null?Encoding.ASCII.GetBytes(args.Password) : Constants.EmptyBuffer; var ssid = Encoding.UTF8.GetBytes(args.Ssid); var ssidCrc8 = Crc8.ComputeOnceOnly(ssid); var bssid = args.Bssid?.GetAddressBytes() ?? Constants.EmptyBuffer; var bssidCrc8 = Crc8.ComputeOnceOnly(bssid); var totalLength = (byte)(ExtraHeaderLength + senderIPAddress.Length + passwordBytes.Length + ssid.Length); byte totalXor = ComputeTotalXor(senderIPAddress, passwordBytes, ssid, ssidCrc8, bssidCrc8, totalLength); _framesBuilder.Clear(); this.DoEncode(totalLength, (byte)passwordBytes.Length, ssidCrc8, bssidCrc8, totalXor, senderIPAddress, passwordBytes, ssid, bssid); return(_framesBuilder); }
public FlakeReader(AudioPCMConfig _pcm) { pcm = _pcm; crc8 = new Crc8(); crc16 = new Crc16(); samplesBuffer = new int[Flake.MAX_BLOCKSIZE * PCM.ChannelCount]; residualBuffer = new int[Flake.MAX_BLOCKSIZE * PCM.ChannelCount]; frame = new FlacFrame(PCM.ChannelCount); framereader = new BitReader(); }