コード例 #1
0
ファイル: AiffFileReader.cs プロジェクト: zouhunter/SAEA
		public static void ReadAiffHeader(Stream stream, out WaveFormat format, out long dataChunkPosition, out int dataChunkLength, List<AiffFileReader.AiffChunk> chunks)
		{
			dataChunkPosition = -1L;
			format = null;
			BinaryReader binaryReader = new BinaryReader(stream);
			if (AiffFileReader.ReadChunkName(binaryReader) != "FORM")
			{
				throw new FormatException("Not an AIFF file - no FORM header.");
			}
			AiffFileReader.ConvertInt(binaryReader.ReadBytes(4));
			string a = AiffFileReader.ReadChunkName(binaryReader);
			if (a != "AIFC" && a != "AIFF")
			{
				throw new FormatException("Not an AIFF file - no AIFF/AIFC header.");
			}
			dataChunkLength = 0;
			while (binaryReader.BaseStream.Position < binaryReader.BaseStream.Length)
			{
				AiffFileReader.AiffChunk aiffChunk = AiffFileReader.ReadChunkHeader(binaryReader);
				if (aiffChunk.ChunkName == "\0\0\0\0" || binaryReader.BaseStream.Position + (long)((ulong)aiffChunk.ChunkLength) > binaryReader.BaseStream.Length)
				{
					break;
				}
				if (aiffChunk.ChunkName == "COMM")
				{
					short channels = AiffFileReader.ConvertShort(binaryReader.ReadBytes(2));
					AiffFileReader.ConvertInt(binaryReader.ReadBytes(4));
					short bits = AiffFileReader.ConvertShort(binaryReader.ReadBytes(2));
					double num = IEEE.ConvertFromIeeeExtended(binaryReader.ReadBytes(10));
					format = new WaveFormat((int)num, (int)bits, (int)channels);
					if (aiffChunk.ChunkLength > 18u && a == "AIFC")
					{
						if (new string(binaryReader.ReadChars(4)).ToLower() != "none")
						{
							throw new FormatException("Compressed AIFC is not supported.");
						}
						binaryReader.ReadBytes((int)(aiffChunk.ChunkLength - 22u));
					}
					else
					{
						binaryReader.ReadBytes((int)(aiffChunk.ChunkLength - 18u));
					}
				}
				else if (aiffChunk.ChunkName == "SSND")
				{
					uint num2 = AiffFileReader.ConvertInt(binaryReader.ReadBytes(4));
					AiffFileReader.ConvertInt(binaryReader.ReadBytes(4));
					dataChunkPosition = (long)((ulong)(aiffChunk.ChunkStart + 16u + num2));
					dataChunkLength = (int)(aiffChunk.ChunkLength - 8u);
					binaryReader.BaseStream.Position += (long)((ulong)(aiffChunk.ChunkLength - 8u));
				}
				else
				{
					if (chunks != null)
					{
						chunks.Add(aiffChunk);
					}
					binaryReader.BaseStream.Position += (long)((ulong)aiffChunk.ChunkLength);
				}
			}
			if (format == null)
			{
				throw new FormatException("Invalid AIFF file - No COMM chunk found.");
			}
			if (dataChunkPosition == -1L)
			{
				throw new FormatException("Invalid AIFF file - No SSND chunk found.");
			}
		}
コード例 #2
0
ファイル: AiffFileReader.cs プロジェクト: zouhunter/SAEA
		private static AiffFileReader.AiffChunk ReadChunkHeader(BinaryReader br)
		{
			return new AiffFileReader.AiffChunk((uint)br.BaseStream.Position, AiffFileReader.ReadChunkName(br), AiffFileReader.ConvertInt(br.ReadBytes(4)));
		}