public static unsafe ushort Substract(ushort crc1, ushort crc2, long len2) { crc1 = Crc16.Reflect(crc1); crc2 = Crc16.Reflect(crc2); /* degenerate case */ if (len2 == 0) { return(crc1); } if (len2 < 0) throw new ArgumentException("crc.Combine length cannot be negative", "len2"); }
public ushort get_crc16() { if (have_bits_m == 0) { return(crc16_m); } ushort crc = 0; int n = have_bits_m >> 3; for (int i = 0; i < n; i++) { crc = (ushort)((crc << 8) ^ Crc16.table[(crc >> 8) ^ (byte)(cache_m >> (56 - (i << 3)))]); } return(Crc16.Substract(crc16_m, crc, n)); }
static unsafe Crc16() { for (ushort i = 0; i < table.Length; i++) { int crc = i; for (int j = 0; j < GF2_DIM; j++) { if ((crc & (1U << (GF2_DIM - 1))) != 0) { crc = ((crc << 1) ^ polynomial); } else { crc <<= 1; } } table[i] = (ushort)(crc & ((1 << GF2_DIM) - 1)); } combineTable[0, 0] = Crc16.Reflect(polynomial); substractTable[0, GF2_DIM - 1] = reversePolynomial; for (int n = 1; n < GF2_DIM; n++) { combineTable[0, n] = (ushort)(1 << (n - 1)); substractTable[0, n - 1] = (ushort)(1 << n); } fixed(ushort *ct = &combineTable[0, 0], st = &substractTable[0, 0]) { //for (int i = 0; i < GF2_DIM; i++) // st[32 + i] = ct[i]; //invert_binary_matrix(st + 32, st, GF2_DIM); for (int i = 1; i < GF2_DIM; i++) { gf2_matrix_square(ct + i * GF2_DIM, ct + (i - 1) * GF2_DIM); gf2_matrix_square(st + i * GF2_DIM, st + (i - 1) * GF2_DIM); } } }
public static unsafe ushort Combine(ushort crc1, ushort crc2, long len2) { crc1 = Crc16.Reflect(crc1); crc2 = Crc16.Reflect(crc2); /* degenerate case */ if (len2 == 0) { return(crc1); } if (crc1 == 0) { return(crc2); } if (len2 < 0) { throw new ArgumentException("crc.Combine length cannot be negative", "len2"); fixed(ushort *ct = &combineTable[0, 0]) { int n = 3; do { /* apply zeros operator for this bit of len2 */ if ((len2 & 1) != 0) { crc1 = gf2_matrix_times(ct + GF2_DIM * n, crc1); } len2 >>= 1; n = (n + 1) & (GF2_DIM - 1); /* if no more bits set, then done */ } while (len2 != 0); } /* return combined crc */ crc1 ^= crc2; crc1 = Crc16.Reflect(crc1); return(crc1); }
public FlakeWriter(string path, Stream IO, AudioPCMConfig pcm) { _pcm = pcm; //if (_pcm.BitsPerSample != 16) // throw new Exception("Bits per sample must be 16."); if (_pcm.ChannelCount != 2) throw new Exception("ChannelCount must be 2."); channels = pcm.ChannelCount; // flake_validate_params _path = path; _IO = IO; samplesBuffer = new int[Flake.MAX_BLOCKSIZE * (channels == 2 ? 4 : channels)]; residualBuffer = new int[Flake.MAX_BLOCKSIZE * (channels == 2 ? 10 : channels + 1)]; windowBuffer = new float[Flake.MAX_BLOCKSIZE * 2 * lpc.MAX_LPC_WINDOWS]; windowScale = new double[lpc.MAX_LPC_WINDOWS]; eparams.flake_set_defaults(_compressionLevel); eparams.padding_size = 8192; crc8 = new Crc8(); crc16 = new Crc16(); frame = new FlacFrame(channels * 2); }
public FLACCLWriter(string path, Stream IO, AudioPCMConfig pcm) { _pcm = pcm; // FIXME: For now, only 16-bit encoding is supported if (pcm.BitsPerSample != 16 && pcm.BitsPerSample != 24) throw new Exception("Bits per sample must be 16."); //if (pcm.ChannelCount != 2) // throw new Exception("ChannelCount must be 2."); channels = pcm.ChannelCount; sample_rate = pcm.SampleRate; bits_per_sample = (uint) pcm.BitsPerSample; // flake_validate_params _path = path; _IO = IO; eparams.flake_set_defaults(_compressionLevel); eparams.padding_size = 8192; crc8 = new Crc8(); crc16 = new Crc16(); }
public FlakeWriter(string path, Stream IO, AudioPCMConfig pcm) { _pcm = pcm; channels = pcm.ChannelCount; _path = path; _IO = IO; samplesBuffer = new int[Flake.MAX_BLOCKSIZE * (channels == 2 ? 4 : channels)]; residualBuffer = new int[Flake.MAX_BLOCKSIZE * (channels == 2 ? 10 : channels + 1)]; windowBuffer = new float[Flake.MAX_BLOCKSIZE * 2 * lpc.MAX_LPC_WINDOWS]; windowScale = new double[lpc.MAX_LPC_WINDOWS]; eparams.flake_set_defaults(_compressionLevel); eparams.padding_size = 8192; crc8 = new Crc8(); crc16 = new Crc16(); frame = new FlacFrame(channels * 2); }
public ALACWriter(string path, Stream IO, AudioPCMConfig pcm) { _pcm = pcm; if (_pcm.BitsPerSample != 16) throw new Exception("Bits per sample must be 16."); if (_pcm.ChannelCount != 2) throw new Exception("ChannelCount must be 2."); _path = path; _IO = IO; _pathGiven = _IO == null; if (_IO != null && !_IO.CanSeek) throw new NotSupportedException("stream doesn't support seeking"); samplesBuffer = new int[Alac.MAX_BLOCKSIZE * (_pcm.ChannelCount == 2 ? 5 : _pcm.ChannelCount)]; residualBuffer = new int[Alac.MAX_BLOCKSIZE * (_pcm.ChannelCount == 2 ? 6 : _pcm.ChannelCount + 1)]; windowBuffer = new float[Alac.MAX_BLOCKSIZE * 2 * Alac.MAX_LPC_WINDOWS]; eparams.set_defaults(_compressionLevel); eparams.padding_size = 4096; crc8 = new Crc8(); crc16 = new Crc16(); frame = new ALACFrame(_pcm.ChannelCount == 2 ? 5 : _pcm.ChannelCount); chunk_pos = new List<int>(); }
public FlaCudaWriter(string path, Stream IO, AudioPCMConfig pcm) { _pcm = pcm; if (pcm.BitsPerSample != 16) throw new Exception("Bits per sample must be 16."); if (pcm.ChannelCount != 2) throw new Exception("ChannelCount must be 2."); channels = pcm.ChannelCount; sample_rate = pcm.SampleRate; bits_per_sample = (uint) pcm.BitsPerSample; // flake_validate_params _path = path; _IO = IO; windowBuffer = new float[FlaCudaWriter.MAX_BLOCKSIZE * lpc.MAX_LPC_WINDOWS]; eparams.flake_set_defaults(_compressionLevel, !_settings.GPUOnly); eparams.padding_size = 8192; crc8 = new Crc8(); crc16 = new Crc16(); }