⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 interlacer.java

📁 用java写的RS算法的交织器
💻 JAVA
字号:
package cmmb.dsp.common;
public class Interlacer {
	private byte[] data;
	private int interlacerLinesNum;
	private int dataLength;

	private final static int INFOR_ROWS_NUM = 207;
	private final static int FEC_ROWS_NUM = 48;
	private final static double FEC_INTERLACE_PARAMETER = 64.0;  

	public Interlacer(byte[] data, int interlacerLinesNum) {
		this.interlacerLinesNum = interlacerLinesNum;
		this.dataLength = data.length;
		this.data = new byte[INFOR_ROWS_NUM * interlacerLinesNum];
		this.data = data;
	}

	public byte[] inforRegionCreater() {
		if (data == null || this.interlacerLinesNum == 0)
			return null;

		byte[][] inforRegion = new byte[this.interlacerLinesNum][INFOR_ROWS_NUM];
		int d, k;
		int colIndex, rowIndex, dataIndex;

		d = this.dataLength % this.interlacerLinesNum;
		k = (int) Math.floor(this.dataLength / this.interlacerLinesNum);
		// 将信息序列data从上到下从左到右填入信息区inforRegion
		// 先填前k-1列
		for (colIndex = 0, dataIndex = 0; colIndex < k; colIndex++) {
			for (rowIndex = 0; rowIndex < this.interlacerLinesNum; rowIndex++) {
				inforRegion[rowIndex][colIndex] = this.data[dataIndex++];
			}
		}
		// 再填第k列
		fillRowK(inforRegion, d, k, dataIndex);
		// 将信息区数据按行的方式从上到下,从左到右读出
		return outputInforRegionData(inforRegion);
	}

	private byte[] outputInforRegionData(byte[][] inforRegion) {
		int colIndex, rowIndex, dataIndex;
		byte[] inforRegionOut = new byte[this.interlacerLinesNum * INFOR_ROWS_NUM];
		for (rowIndex = 0, dataIndex = 0; rowIndex < this.interlacerLinesNum; rowIndex++) {
			for (colIndex = 0; colIndex < INFOR_ROWS_NUM; colIndex++) {
				inforRegionOut[dataIndex++] = inforRegion[rowIndex][colIndex];
			}
		}
		return inforRegionOut;
	}

	private void fillRowK(byte[][] inforRegion, int d, int k, int dataIndex) {
		int g, h, rowIndex;
		if (d != 0) {
			g = (int) Math.floor(this.interlacerLinesNum / d);
			h = (int) Math.floor(this.interlacerLinesNum
					/ (this.interlacerLinesNum - d));

			if (d > this.interlacerLinesNum / 2) {
				for (rowIndex = 0; rowIndex < this.interlacerLinesNum; rowIndex++) {
					if (rowIndex % h == 0
							&& rowIndex < (this.interlacerLinesNum - d) * h) {
						inforRegion[rowIndex][k] = 0;
					} else {
						inforRegion[rowIndex][k] = data[dataIndex++];
					}
				}
			} else if (d > 0) {
				for (rowIndex = 0; rowIndex < this.interlacerLinesNum; rowIndex++) {
					if (rowIndex % g == 0 && rowIndex < d * g) {
						inforRegion[rowIndex][k] = data[dataIndex++];
					} else {
						inforRegion[rowIndex][k] = 0;
					}
				}
			}
		}
	}

	public byte[] fecRegionCreater(byte[][] fecRegion) {
		if (fecRegion == null || this.interlacerLinesNum == 0)
			return null;
		// 第0列不进行操作
		// 第rowIndex列 从上到下循环移位floor(rowIndex*interlacerLinesNum/48)
		circleDisplacement(fecRegion);
		// 将纠错校验数据按照列的方式从上到下、从左到右读出
		return outputFECRegionData(fecRegion);
	}

	private byte[] outputFECRegionData(byte[][] fecRegion) {
		int colIndex, rowIndex, dataIndex;
		byte[] fecRegionOut = new byte[interlacerLinesNum * FEC_ROWS_NUM];
		for (colIndex = 0, dataIndex = 0; colIndex < FEC_ROWS_NUM; colIndex++) {
			for (rowIndex = 0; rowIndex < interlacerLinesNum; rowIndex++) {
				fecRegionOut[dataIndex++] = fecRegion[rowIndex][colIndex];
			}
		}
		return fecRegionOut;
	}

	private void circleDisplacement(byte[][] fecRegion) {
		int colIndex, rowIndex, displacementNum;
		byte[] fecRow = new byte[interlacerLinesNum];
		for (colIndex = 1; colIndex < FEC_ROWS_NUM; colIndex++) {
			displacementNum = ((int) Math.floor(colIndex * interlacerLinesNum
					/ FEC_INTERLACE_PARAMETER))
					% interlacerLinesNum;
			if (displacementNum > 0) {
				for (rowIndex = 0; rowIndex < interlacerLinesNum; rowIndex++) {
					fecRow[rowIndex] = fecRegion[rowIndex][colIndex];
				}
				for (rowIndex = displacementNum; rowIndex < (interlacerLinesNum + displacementNum); rowIndex++) {
					fecRegion[rowIndex % interlacerLinesNum][colIndex] = fecRow[rowIndex
							- displacementNum];
				}
			}
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -