public unsafe FlacSubFrameLPC(FlacBitReader reader, FlacFrameHeader header, FlacSubFrameData data, int bps, int order) : base(header) { //warmup _warmup = new int[FlacConstant.MaxLpcOrder]; for (int i = 0; i < order; i++) { _warmup[i] = data.ResidualBuffer[i] = reader.ReadBitsSigned(bps); } //header int u32 = (int)reader.ReadBits(FlacConstant.SubframeLpcQlpCoeffPrecisionLen); if (u32 == (1 << FlacConstant.SubframeLpcQlpCoeffPrecisionLen) - 1) { Debug.WriteLine("Invalid FlacLPC qlp coeff precision."); return; //return false; } _qlpCoeffPrecision = u32 + 1; int level = reader.ReadBitsSigned(FlacConstant.SubframeLpcQlpShiftLen); if (level < 0) throw new Exception("negative shift"); _lpcShiftNeeded = level; _qlpCoeffs = new int[FlacConstant.MaxLpcOrder]; //qlp coeffs for (int i = 0; i < order; i++) { _qlpCoeffs[i] = reader.ReadBitsSigned(_qlpCoeffPrecision); } Residual = new FlacResidual(reader, header, data, order); for (int i = 0; i < order; i++) { data.DestBuffer[i] = data.ResidualBuffer[i]; } int i1 = order; int result = 0; while ((i1 >>= 1) != 0) { result++; } if (bps + _qlpCoeffPrecision + result <= 32) { if (bps <= 16 && _qlpCoeffPrecision <= 16) RestoreLPCSignal(data.ResidualBuffer + order, data.DestBuffer + order, header.BlockSize - order, order); //Restore(data.residualBuffer + order, data.destBuffer, Header.BlockSize - order, order, order); else RestoreLPCSignal(data.ResidualBuffer + order, data.DestBuffer + order, header.BlockSize - order, order); } else { RestoreLPCSignalWide(data.ResidualBuffer + order, data.DestBuffer + order, header.BlockSize - order, order);//RestoreWide(data.residualBuffer + order, data.destBuffer, Header.BlockSize - order, order, order); } }
public unsafe FlacSubFrameFixed(FlacBitReader reader, FlacFrameHeader header, FlacSubFrameData data, int bps, int order) : base(header) { for (int i = 0; i < order; i++) { data.ResidualBuffer[i] = data.DestBuffer[i] = reader.ReadBitsSigned(bps); } Residual = new FlacResidual(reader, header, data, order); //necessary for decoding RestoreSignal(data, header.BlockSize - order, order); }
public unsafe bool ProcessResidual(FlacBitReader reader, FlacFrameHeader header, FlacSubFrameData data, int order) { data.Content.UpdateSize(PartitionOrder); int porder = PartitionOrder; FlacEntropyCoding codingMethod = CodingMethod; int psize = header.BlockSize >> porder; int resCnt = psize - order; int ricelength = 4 + (int)codingMethod; //4bit = RICE I | 5bit = RICE II //residual int j = order; int *r = data.ResidualBuffer + j; int partitioncount = 1 << porder; for (int p = 0; p < partitioncount; p++) { if (p == 1) { resCnt = psize; } int n = Math.Min(resCnt, header.BlockSize - j); int k = Content.Parameters[p] = (int)reader.ReadBits(ricelength); if (k == (1 << ricelength) - 1) { k = (int)reader.ReadBits(5); for (int i = n; i > 0; i--) { *(r) = reader.ReadBitsSigned((int)k); } } else { ReadFlacRiceBlock(reader, n, (int)k, r); r += n; } j += n; } return(true); }
public unsafe bool ProcessResidual(FlacBitReader reader, FlacFrameHeader header, FlacSubFrameData data, int order) { data.Content.UpdateSize(PartitionOrder); int porder = PartitionOrder; FlacEntropyCoding codingMethod = CodingMethod; int psize = header.BlockSize >> porder; int resCnt = psize - order; int ricelength = 4 + (int)codingMethod; //4bit = RICE I | 5bit = RICE II //residual int j = order; int* r = data.ResidualBuffer + j; int partitioncount = 1 << porder; for (int p = 0; p < partitioncount; p++) { if (p == 1) resCnt = psize; int n = Math.Min(resCnt, header.BlockSize - j); int k = Content.Parameters[p] = (int)reader.ReadBits(ricelength); if (k == (1 << ricelength) - 1) { k = (int)reader.ReadBits(5); for (int i = n; i > 0; i--) { *(r) = reader.ReadBitsSigned((int)k); } } else { ReadFlacRiceBlock(reader, n, (int)k, r); r += n; } j += n; } return true; }
public unsafe FlacSubFrameLPC(FlacBitReader reader, FlacFrameHeader header, FlacSubFrameData data, int bps, int order) : base(header) { //warmup _warmup = new int[FlacConstant.MaxLpcOrder]; for (int i = 0; i < order; i++) { _warmup[i] = data.ResidualBuffer[i] = reader.ReadBitsSigned(bps); } //header int u32 = (int)reader.ReadBits(FlacConstant.SubframeLpcQlpCoeffPrecisionLen); if (u32 == (1 << FlacConstant.SubframeLpcQlpCoeffPrecisionLen) - 1) { Debug.WriteLine("Invalid FlacLPC qlp coeff precision."); return; //return false; } _qlpCoeffPrecision = u32 + 1; int level = reader.ReadBitsSigned(FlacConstant.SubframeLpcQlpShiftLen); if (level < 0) { throw new Exception("negative shift"); } _lpcShiftNeeded = level; _qlpCoeffs = new int[FlacConstant.MaxLpcOrder]; //qlp coeffs for (int i = 0; i < order; i++) { _qlpCoeffs[i] = reader.ReadBitsSigned(_qlpCoeffPrecision); } Residual = new FlacResidual(reader, header, data, order); for (int i = 0; i < order; i++) { data.DestBuffer[i] = data.ResidualBuffer[i]; } int i1 = order; int result = 0; while ((i1 >>= 1) != 0) { result++; } if (bps + _qlpCoeffPrecision + result <= 32) { if (bps <= 16 && _qlpCoeffPrecision <= 16) { RestoreLPCSignal(data.ResidualBuffer + order, data.DestBuffer + order, header.BlockSize - order, order); //Restore(data.residualBuffer + order, data.destBuffer, Header.BlockSize - order, order, order); } else { RestoreLPCSignal(data.ResidualBuffer + order, data.DestBuffer + order, header.BlockSize - order, order); } } else { RestoreLPCSignalWide(data.ResidualBuffer + order, data.DestBuffer + order, header.BlockSize - order, order);//RestoreWide(data.residualBuffer + order, data.destBuffer, Header.BlockSize - order, order, order); } }