CUETools.Codecs.FLAKE.FlakeWriter.output_residual C# (CSharp) Method

output_residual() private method

private output_residual ( FlacFrame frame, BitWriter bitwriter, FlacSubframeInfo sub ) : void
frame FlacFrame
bitwriter BitWriter
sub FlacSubframeInfo
return void
		unsafe void output_residual(FlacFrame frame, BitWriter bitwriter, FlacSubframeInfo sub)
		{
			// rice-encoded block
			bitwriter.writebits(2, sub.best.rc.coding_method);

			// partition order
			int porder = sub.best.rc.porder;
			int psize = frame.blocksize >> porder;
			//assert(porder >= 0);
			bitwriter.writebits(4, porder);
			int res_cnt = psize - sub.best.order;

			int rice_len = 4 + sub.best.rc.coding_method;
			// residual
			int j = sub.best.order;
			fixed (byte* fixbuf = &frame_buffer[0])
			for (int p = 0; p < (1 << porder); p++)
			{
				int k = sub.best.rc.rparams[p];
				bitwriter.writebits(rice_len, k);
				if (p == 1) res_cnt = psize;
				int cnt = Math.Min(res_cnt, frame.blocksize - j);
				bitwriter.write_rice_block_signed(fixbuf, k, sub.best.residual + j, cnt);
				j += cnt;
			}
		}