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

📄 mpac.java

📁 优秀的MPEG2-TS流分析软件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:

	//single bitarray to one 2channel bitarray, bitrate_index must hold place for whole frame data
	private boolean[] makeTwoChannel(boolean input[], int transcode, int channel)
	{
		boolean output[] = new boolean[maxBitSize];
		int i=32, o=32;
		int size = getSizeFromIndex(input);
		System.arraycopy(input, 0, output, 0, 32); //copy source frameheader 1:1

		switch(transcode)
		{
			case 1:  //make a simple dual A
				for (int a=0; a < Bal.length; i += Bal[a], o += (Bal[a]<<1), a++) //insert gaps for channel B in BAL
					System.arraycopy(input, i, output, o, Bal[a]);

				System.arraycopy(input, i, output, o, size - i); //append the rest
				o += size - i;
				setChannelMode(output, DUAL); //set to dual
				setBitRateIndex(output, o, channel); //set BR_index 

				break;

			case 2: // make a stereo
			case 3: // make a jointstereo mode 00,  sb 4..31 shared
				int Bal_length = Bal.length;
				int allocation[] = new int[Bal_length];
				int scfsi[] = new int[Bal_length];

				try {
					// copy BAL
					for (int a=0; a < Bal_length; a++)
					{
						for (int b=0; b < Bal[a]; b++)
						{
							if (input[i + b])
							{
								output[o + b] = true;

								if (transcode == 2 || a < 4)
									output[o + Bal[a] + b] = true;

								allocation[a] |= 1<<(Bal[a] - 1 - b);
							}
						}

						i += Bal[a];
						o += (transcode == 2 || a < 4) ? (Bal[a]<<1) : Bal[a]; 
					}

					// copy SCFSI
					for (int a=0; a < Bal_length; a++)
					{
						if (allocation[a] != 0)
						{
							for (int b=0; b < 2; b++)
							{
								if (input[i + b])
								{
									output[o + b] = true;
									output[o + b + 2] = true;
									scfsi[a] |= 1<<(1 - b);
								}
							}

							i += 2; 
							o += 4;
						}
					}

					// copy Scalefactors
					for (int a=0, b=0; a < Bal_length; a++)
					{
						if (allocation[a] != 0)
						{
							switch (scfsi[a])
							{
								case 0:
									b = 18;
									break;

								case 1:
								case 3:
									b = 12;
									break;

								case 2:
									b = 6;
							}

							System.arraycopy(input, i, output, o, b);
							System.arraycopy(input, i, output, o + b, b);
							i += b; 
							o += b<<1; 
						}
					}

					// copy Samples
					for (int x=0; x < 12; x++)
					{
						for (int a=0; a < Bal_length; a++)
						{
							if (allocation[a] != 0)
							{
								int j = Allocation[a][allocation[a]];
								int k = getbits[j];

								if (grouping[j] > 0)
								{
									System.arraycopy(input, i, output, o, k); 
									o += k;

									if (transcode == 2 || a < 4)
									{ 
										System.arraycopy(input, i, output, o, k); 
										o += k; 
									}

									i += k;
								}

								else
								{
									System.arraycopy(input, i, output, o, (3 * k)); 
									o += (3 * k);

									if (transcode == 2 || a < 4)
									{ 
										System.arraycopy(input, i, output, o, (3 * k)); 
										o += (3 * k); 
									}

									i += (3 * k);
								}
							}
						}
					}
				} catch (Exception e) {
					setError(1);
				}

				setChannelMode(output,1 & transcode); //set to stereo/jstereo
				setBitRateIndex(output, o, channel); //set BR_index 
		}

		return output;
	}

	//2channel bitarray to 2 single channel bitarrays
	private boolean[][] splitTwoChannel(boolean input[], int transcode)
	{
		boolean output[][] = new boolean[2][maxBitSize];
		System.arraycopy(input, 0, output[0], 0, 32); //copy source frameheader 1:1 L
		System.arraycopy(input, 0, output[1], 0, 32); //copy source frameheader 1:1 R

		int i=32, o[]= { 32,32 };
		int Bal_length=Bal.length;
		int allocation[][] = new int[2][Bal_length];
		int scfsi[][] = new int[2][Bal_length];

		int bound=32;

		if (Audio.Mode == 1) //source is jointstereo
			bound=(Audio.Mode_extension + 1) * 4; 

		if (bound == 32) 
			bound = Bal_length;

		try {
			//copy BAL
			for (int a=0; a < bound; a++)
			{
				for (int ch=0; ch < 2; ch++)
				{
					for (int b=0; b < Bal[a]; b++)
					{
						if (input[i + b])
						{
							allocation[ch][a] |= 1<<(Bal[a] - 1 - b); 
							output[ch][o[ch] + b] = true; 
						}
					}

					i += Bal[a]; 
					o[ch] += Bal[a]; 
				}
			}

			for (int a=bound; a < Bal_length; a++)
			{
				for (int b=0; b < Bal[a]; b++)
				{
					if (input[i + b])
					{
						for (int ch=0; ch < 2; ch++)
						{
							allocation[ch][a] |= 1<<(Bal[a] - 1 - b);
							output[ch][o[ch] + b] = true;
						}
					}
				}

				i += Bal[a]; 

				for (int ch=0; ch < 2; ch++)
					o[ch] += Bal[a]; 
			}

			//copy SCFSI
			for (int a=0; a < Bal_length; a++)
			{
				for (int ch=0; ch < 2; ch++)
				{
					if (allocation[ch][a] != 0)
					{
						for (int b=0; b < 2; b++)
						{
							if (input[i + b])
							{
								scfsi[ch][a] |= 1<<(1 - b);
								output[ch][o[ch] + b] = true;
							}
						}

						i += 2; 
						o[ch] += 2; 
					}
				}
			}

			//copy Scalefactors
			for (int a=0, b=0; a < Bal_length; a++)
			{
				for (int ch=0; ch < 2; ch++)
				{
					if (allocation[ch][a] != 0)
					{
						switch (scfsi[ch][a])
						{
							case 0:
								b = 18;
								break;

							case 1:
							case 3:
								b = 12;
								break;

							case 2:
								b = 6;
						}

						System.arraycopy(input, i, output[ch], o[ch], b);
						i += b;
						o[ch] += b; 
					}
				}
			}

			//copy Samples
			for (int x=0; x < 12; x++)
			{
				for (int a=0; a < bound; a++)
				{
					for (int ch=0; ch < 2; ch++)
					{
						if (allocation[ch][a] != 0)
						{
							int j = Allocation[a][allocation[ch][a]];
							int k = getbits[j];

							if (grouping[j] > 0)
							{
								System.arraycopy(input, i, output[ch], o[ch], k);
								i += k;
								o[ch] += k; 
							}

							else
							{
								System.arraycopy(input, i, output[ch], o[ch], (3 * k));
								i += (3 * k);
								o[ch] += (3 * k); 
							}
						}
					}
				}

				for (int a=bound; a < Bal_length; a++)
				{
					if (allocation[0][a] != 0)
					{
						int j = Allocation[a][allocation[0][a]];
						int k = getbits[j];

						if (grouping[j] > 0)
						{
							for (int ch=0; ch < 2; ch++)
							{
								System.arraycopy(input, i, output[ch], o[ch], k);
								o[ch] += k; 
							}

							i+=k;
						}

						else
						{
							for (int ch=0; ch < 2; ch++)
							{
								System.arraycopy(input, i, output[ch], o[ch], (3 * k));
								o[ch] += (3 * k); 
							}

							i += (3 * k);
						}
					}
				}
			}
		} catch (Exception e) {
			setError(2);
		}

		for (int ch=0; ch < 2; ch++)
		{
			setChannelMode(output[ch], SINGLE); //set to mono
			setBitRateIndex(output[ch], o[ch], ch + 1); //set BR_index 

			if (getSizeFromIndex(output[ch]) > Sizes[10])
				output[ch] = makeTwoChannel(output[ch], 3, ch + 1);
		}

		return output;
	}

}

/***** options[17]
*  bit 1,0 : if options[10]>=4,  not used anymore, but still set
*   00 = std CBR in complete file
*   01 = VBR same mode = same BR
*   10 = VBR each frame/channel its own 
*   11 = free
*  bit 3,2 : 
*   00 = no restart
*   01 = restart due left ch.
*   10 = restart due right ch.
*   11 = restart due both ch.
*
* bit 7,6,5,4 :  bitrate value of last frame 2channel
* bit 11,10,9,8 :  bitrate value of last frame left
* bit 15,14,13,12 :  bitrate value of last frame right
*
* bit 16 : set to 1 if conversion isn't possible, clear befor the next file
* bit 17 free
* bit63..18 MSB : current audioframes number
******/

⌨️ 快捷键说明

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