2015-08-26 22:42:40 +02:00
|
|
|
|
// (c) Giora Tamir (giora@gtamir.com), 2005
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace Nikse.SubtitleEdit.Core.ContainerFormats
|
|
|
|
|
{
|
|
|
|
|
public class RiffDecodeHeader
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
#region private members
|
|
|
|
|
|
2017-08-20 10:31:30 +02:00
|
|
|
|
private readonly RiffParser _parser;
|
2015-08-26 22:42:40 +02:00
|
|
|
|
|
2017-08-20 10:31:30 +02:00
|
|
|
|
private double _frameRate;
|
|
|
|
|
private int _maxBitRate;
|
|
|
|
|
private int _totalFrames;
|
|
|
|
|
private int _numStreams;
|
|
|
|
|
private int _width;
|
|
|
|
|
private int _height;
|
2015-08-26 22:42:40 +02:00
|
|
|
|
|
2017-08-20 10:31:30 +02:00
|
|
|
|
private string _isft;
|
2015-08-26 22:42:40 +02:00
|
|
|
|
|
2017-08-20 10:31:30 +02:00
|
|
|
|
private double _vidDataRate;
|
|
|
|
|
private string _vidHandler;
|
|
|
|
|
private double _audDataRate;
|
|
|
|
|
private string _audHandler;
|
2015-08-26 22:42:40 +02:00
|
|
|
|
|
2017-08-20 10:31:30 +02:00
|
|
|
|
private int _numChannels;
|
|
|
|
|
private int _samplesPerSec;
|
|
|
|
|
private int _bitsPerSec;
|
|
|
|
|
private int _bitsPerSample;
|
2015-08-26 22:42:40 +02:00
|
|
|
|
|
|
|
|
|
#endregion private members
|
|
|
|
|
|
|
|
|
|
#region public members
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Access the internal parser object
|
|
|
|
|
/// </summary>
|
|
|
|
|
public RiffParser Parser
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2017-08-20 10:31:30 +02:00
|
|
|
|
return _parser;
|
2015-08-26 22:42:40 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public double FrameRate
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
double rate = 0.0;
|
2017-08-20 10:31:30 +02:00
|
|
|
|
if (_frameRate > 0.0)
|
2019-01-19 14:40:37 +01:00
|
|
|
|
{
|
2017-08-20 10:31:30 +02:00
|
|
|
|
rate = 1000000.0 / _frameRate;
|
2019-01-19 14:40:37 +01:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-26 22:42:40 +02:00
|
|
|
|
return rate;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string MaxBitRate
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2017-08-20 10:31:30 +02:00
|
|
|
|
return String.Format("{0:N} Kb/Sec", _maxBitRate / 128);
|
2015-08-26 22:42:40 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int TotalFrames
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2017-08-20 10:31:30 +02:00
|
|
|
|
return _totalFrames;
|
2015-08-26 22:42:40 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public double TotalMilliseconds
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
double totalTime = 0.0;
|
2017-08-20 10:31:30 +02:00
|
|
|
|
if (_frameRate > 0.0)
|
2015-08-26 22:42:40 +02:00
|
|
|
|
{
|
2017-08-20 10:31:30 +02:00
|
|
|
|
totalTime = _totalFrames * _frameRate / TimeCode.BaseUnit;
|
2015-08-26 22:42:40 +02:00
|
|
|
|
}
|
|
|
|
|
return totalTime;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string NumStreams
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2017-08-20 10:31:30 +02:00
|
|
|
|
return String.Format("Streams in file: {0:G}", _numStreams);
|
2015-08-26 22:42:40 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string FrameSize
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2017-08-20 10:31:30 +02:00
|
|
|
|
return String.Format("{0:G} x {1:G} pixels per frame", _width, _height);
|
2015-08-26 22:42:40 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int Width
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2017-08-20 10:31:30 +02:00
|
|
|
|
return _width;
|
2015-08-26 22:42:40 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int Height
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2017-08-20 10:31:30 +02:00
|
|
|
|
return _height;
|
2015-08-26 22:42:40 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string VideoDataRate
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2017-08-20 10:31:30 +02:00
|
|
|
|
return String.Format("Video rate {0:N2} frames/Sec", _vidDataRate);
|
2015-08-26 22:42:40 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string AudioDataRate
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2017-08-20 10:31:30 +02:00
|
|
|
|
return String.Format("Audio rate {0:N2} Kb/Sec", _audDataRate / TimeCode.BaseUnit);
|
2015-08-26 22:42:40 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string VideoHandler
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2017-08-20 10:31:30 +02:00
|
|
|
|
return _vidHandler;
|
2015-08-26 22:42:40 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string AudioHandler
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2017-08-20 10:31:30 +02:00
|
|
|
|
return String.Format("Audio handler 4CC code: {0}", _audHandler);
|
2015-08-26 22:42:40 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string ISFT
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2017-08-20 10:31:30 +02:00
|
|
|
|
return _isft;
|
2015-08-26 22:42:40 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string NumChannels
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2017-08-20 10:31:30 +02:00
|
|
|
|
return String.Format("Audio channels: {0}", _numChannels);
|
2015-08-26 22:42:40 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string SamplesPerSec
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2017-08-20 10:31:30 +02:00
|
|
|
|
return String.Format("Audio rate: {0:N0} Samples/Sec", _samplesPerSec);
|
2015-08-26 22:42:40 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string BitsPerSec
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2017-08-20 10:31:30 +02:00
|
|
|
|
return String.Format("Audio rate: {0:N0} Bytes/Sec", _bitsPerSec);
|
2015-08-26 22:42:40 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string BitsPerSample
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2017-08-20 10:31:30 +02:00
|
|
|
|
return String.Format("Audio data: {0:N0} bits/Sample", _bitsPerSample);
|
2015-08-26 22:42:40 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion public members
|
|
|
|
|
|
|
|
|
|
#region Constructor
|
|
|
|
|
|
|
|
|
|
public RiffDecodeHeader(RiffParser rp)
|
|
|
|
|
{
|
2017-08-20 10:31:30 +02:00
|
|
|
|
_parser = rp;
|
2015-08-26 22:42:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Clear()
|
|
|
|
|
{
|
2017-08-20 10:31:30 +02:00
|
|
|
|
_frameRate = 0;
|
|
|
|
|
_height = 0;
|
|
|
|
|
_maxBitRate = 0;
|
|
|
|
|
_numStreams = 0;
|
|
|
|
|
_totalFrames = 0;
|
|
|
|
|
_width = 0;
|
|
|
|
|
|
|
|
|
|
_isft = String.Empty;
|
|
|
|
|
|
|
|
|
|
_vidDataRate = 0;
|
|
|
|
|
_audDataRate = 0;
|
|
|
|
|
_vidHandler = String.Empty;
|
|
|
|
|
_audHandler = String.Empty;
|
|
|
|
|
|
|
|
|
|
_numChannels = 0;
|
|
|
|
|
_samplesPerSec = 0;
|
|
|
|
|
_bitsPerSample = 0;
|
|
|
|
|
_bitsPerSec = 0;
|
2015-08-26 22:42:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion Constructor
|
|
|
|
|
|
|
|
|
|
#region Default element processing
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Default list element handler - skip the entire list
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="rp"></param>
|
2017-08-20 10:31:30 +02:00
|
|
|
|
/// <param name="fourCc"></param>
|
2015-08-26 22:42:40 +02:00
|
|
|
|
/// <param name="length"></param>
|
2017-08-20 10:31:30 +02:00
|
|
|
|
private void ProcessList(RiffParser rp, int fourCc, int length)
|
2015-08-26 22:42:40 +02:00
|
|
|
|
{
|
|
|
|
|
rp.SkipData(length);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion Default element processing
|
|
|
|
|
|
|
|
|
|
#region Decode AVI
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Handle chunk elements found in the AVI file. Ignores unknown chunks and
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="rp"></param>
|
2017-08-20 10:31:30 +02:00
|
|
|
|
/// <param name="fourCc"></param>
|
2015-08-26 22:42:40 +02:00
|
|
|
|
/// <param name="unpaddedLength"></param>
|
|
|
|
|
/// <param name="paddedLength"></param>
|
2017-08-20 10:31:30 +02:00
|
|
|
|
private void ProcessAviChunk(RiffParser rp, int fourCc, int unpaddedLength, int paddedLength)
|
2015-08-26 22:42:40 +02:00
|
|
|
|
{
|
2017-08-20 10:31:30 +02:00
|
|
|
|
if (AviRiffData.ckidMainAVIHeader == fourCc)
|
2015-08-26 22:42:40 +02:00
|
|
|
|
{
|
|
|
|
|
// Main AVI header
|
2017-08-20 10:31:30 +02:00
|
|
|
|
DecodeAviHeader(rp, paddedLength);
|
2015-08-26 22:42:40 +02:00
|
|
|
|
}
|
2017-08-20 10:31:30 +02:00
|
|
|
|
else if (AviRiffData.ckidAVIStreamHeader == fourCc)
|
2015-08-26 22:42:40 +02:00
|
|
|
|
{
|
|
|
|
|
// Stream header
|
2017-08-20 10:31:30 +02:00
|
|
|
|
DecodeAviStream(rp, paddedLength);
|
2015-08-26 22:42:40 +02:00
|
|
|
|
}
|
2017-08-20 10:31:30 +02:00
|
|
|
|
else if (AviRiffData.ckidAVIISFT == fourCc)
|
2015-08-26 22:42:40 +02:00
|
|
|
|
{
|
|
|
|
|
Byte[] ba = new byte[paddedLength];
|
|
|
|
|
rp.ReadData(ba, 0, paddedLength);
|
|
|
|
|
StringBuilder sb = new StringBuilder(unpaddedLength);
|
|
|
|
|
for (int i = 0; i < unpaddedLength; ++i)
|
|
|
|
|
{
|
2019-01-19 14:40:37 +01:00
|
|
|
|
if (0 != ba[i])
|
|
|
|
|
{
|
|
|
|
|
sb.Append((char)ba[i]);
|
|
|
|
|
}
|
2015-08-26 22:42:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-20 10:31:30 +02:00
|
|
|
|
_isft = sb.ToString();
|
2015-08-26 22:42:40 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Unknon chunk - skip
|
|
|
|
|
rp.SkipData(paddedLength);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Handle List elements found in the AVI file. Ignores unknown lists and recursively looks
|
|
|
|
|
/// at the content of known lists.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="rp"></param>
|
2017-08-20 10:31:30 +02:00
|
|
|
|
/// <param name="fourCc"></param>
|
2015-08-26 22:42:40 +02:00
|
|
|
|
/// <param name="length"></param>
|
2017-08-20 10:31:30 +02:00
|
|
|
|
private void ProcessAviList(RiffParser rp, int fourCc, int length)
|
2015-08-26 22:42:40 +02:00
|
|
|
|
{
|
2017-08-20 10:31:30 +02:00
|
|
|
|
RiffParser.ProcessChunkElement pac = ProcessAviChunk;
|
|
|
|
|
RiffParser.ProcessListElement pal = ProcessAviList;
|
2015-08-26 22:42:40 +02:00
|
|
|
|
|
|
|
|
|
// Is this the header?
|
2017-08-20 10:31:30 +02:00
|
|
|
|
if ((AviRiffData.ckidAVIHeaderList == fourCc)
|
|
|
|
|
|| (AviRiffData.ckidAVIStreamList == fourCc)
|
|
|
|
|
|| (AviRiffData.ckidINFOList == fourCc))
|
2015-08-26 22:42:40 +02:00
|
|
|
|
{
|
|
|
|
|
while (length > 0)
|
|
|
|
|
{
|
2019-01-19 14:40:37 +01:00
|
|
|
|
if (false == rp.ReadElement(ref length, pac, pal))
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
2015-08-26 22:42:40 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Unknown lists - ignore
|
|
|
|
|
rp.SkipData(length);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-20 10:31:30 +02:00
|
|
|
|
public void ProcessMainAvi()
|
2015-08-26 22:42:40 +02:00
|
|
|
|
{
|
|
|
|
|
Clear();
|
|
|
|
|
int length = Parser.DataSize;
|
|
|
|
|
|
2017-08-20 10:31:30 +02:00
|
|
|
|
RiffParser.ProcessChunkElement pdc = ProcessAviChunk;
|
|
|
|
|
RiffParser.ProcessListElement pal = ProcessAviList;
|
2015-08-26 22:42:40 +02:00
|
|
|
|
|
|
|
|
|
while (length > 0)
|
|
|
|
|
{
|
2019-01-19 14:40:37 +01:00
|
|
|
|
if (false == Parser.ReadElement(ref length, pdc, pal))
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
2015-08-26 22:42:40 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-20 10:31:30 +02:00
|
|
|
|
public static int GetInt(byte[] buffer, int index)
|
2015-08-26 22:42:40 +02:00
|
|
|
|
{
|
2017-08-20 10:31:30 +02:00
|
|
|
|
byte[] bytes = { buffer[index + 0], buffer[index + 1], buffer[index + 2], buffer[index + 3] };
|
2015-08-26 22:42:40 +02:00
|
|
|
|
|
2017-08-20 10:31:30 +02:00
|
|
|
|
if (!BitConverter.IsLittleEndian)
|
2019-01-19 14:40:37 +01:00
|
|
|
|
{
|
2017-08-20 10:31:30 +02:00
|
|
|
|
Array.Reverse(bytes);
|
2019-01-19 14:40:37 +01:00
|
|
|
|
}
|
2015-08-26 22:42:40 +02:00
|
|
|
|
|
2017-08-20 10:31:30 +02:00
|
|
|
|
return BitConverter.ToInt32(bytes, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Int16 GetShort(byte[] buffer, int index)
|
|
|
|
|
{
|
|
|
|
|
byte[] bytes = { buffer[index + 0], buffer[index + 1] };
|
|
|
|
|
|
|
|
|
|
if (!BitConverter.IsLittleEndian)
|
2019-01-19 14:40:37 +01:00
|
|
|
|
{
|
2017-08-20 10:31:30 +02:00
|
|
|
|
Array.Reverse(bytes);
|
2019-01-19 14:40:37 +01:00
|
|
|
|
}
|
2017-08-20 10:31:30 +02:00
|
|
|
|
|
|
|
|
|
return BitConverter.ToInt16(bytes, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DecodeAviHeader(RiffParser rp, int length)
|
|
|
|
|
{
|
|
|
|
|
var ba = new byte[length];
|
2015-08-26 22:42:40 +02:00
|
|
|
|
if (rp.ReadData(ba, 0, length) != length)
|
|
|
|
|
{
|
|
|
|
|
throw new RiffParserException("Problem reading AVI header.");
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-20 10:31:30 +02:00
|
|
|
|
_frameRate = GetInt(ba, 0);
|
|
|
|
|
_maxBitRate = GetInt(ba, 4);
|
|
|
|
|
_totalFrames = GetInt(ba, 16);
|
|
|
|
|
_numStreams = GetInt(ba, 24);
|
|
|
|
|
_width = GetInt(ba, 32);
|
|
|
|
|
_height = GetInt(ba, 36);
|
2015-08-26 22:42:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-20 10:31:30 +02:00
|
|
|
|
private void DecodeAviStream(RiffParser rp, int length)
|
2015-08-26 22:42:40 +02:00
|
|
|
|
{
|
2017-08-20 10:31:30 +02:00
|
|
|
|
var ba = new byte[length];
|
2015-08-26 22:42:40 +02:00
|
|
|
|
if (rp.ReadData(ba, 0, length) != length)
|
|
|
|
|
{
|
|
|
|
|
throw new RiffParserException("Problem reading AVI header.");
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-20 10:31:30 +02:00
|
|
|
|
var aviStreamHeader = new AVISTREAMHEADER
|
2015-08-26 22:42:40 +02:00
|
|
|
|
{
|
2017-08-20 10:31:30 +02:00
|
|
|
|
fccType = GetInt(ba, 0),
|
|
|
|
|
fccHandler = GetInt(ba, 4),
|
|
|
|
|
dwScale = GetInt(ba, 20),
|
|
|
|
|
dwRate = GetInt(ba, 24),
|
|
|
|
|
dwStart = GetInt(ba, 28),
|
|
|
|
|
dwLength = GetInt(ba, 32),
|
|
|
|
|
dwSampleSize = GetInt(ba, 44),
|
|
|
|
|
};
|
2015-08-26 22:42:40 +02:00
|
|
|
|
|
2017-08-20 10:31:30 +02:00
|
|
|
|
if (AviRiffData.streamtypeVIDEO == aviStreamHeader.fccType)
|
|
|
|
|
{
|
|
|
|
|
_vidHandler = RiffParser.FromFourCc(aviStreamHeader.fccHandler);
|
|
|
|
|
if (aviStreamHeader.dwScale > 0)
|
2015-08-26 22:42:40 +02:00
|
|
|
|
{
|
2017-08-20 10:31:30 +02:00
|
|
|
|
_vidDataRate = (double)aviStreamHeader.dwRate / aviStreamHeader.dwScale;
|
2015-08-26 22:42:40 +02:00
|
|
|
|
}
|
2017-08-20 10:31:30 +02:00
|
|
|
|
else
|
2015-08-26 22:42:40 +02:00
|
|
|
|
{
|
2017-08-20 10:31:30 +02:00
|
|
|
|
_vidDataRate = 0.0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (AviRiffData.streamtypeAUDIO == aviStreamHeader.fccType)
|
|
|
|
|
{
|
|
|
|
|
if (AviRiffData.ckidMP3 == aviStreamHeader.fccHandler)
|
|
|
|
|
{
|
|
|
|
|
_audHandler = "MP3";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_audHandler = RiffParser.FromFourCc(aviStreamHeader.fccHandler);
|
|
|
|
|
}
|
|
|
|
|
if (aviStreamHeader.dwScale > 0)
|
|
|
|
|
{
|
|
|
|
|
_audDataRate = 8.0 * aviStreamHeader.dwRate / aviStreamHeader.dwScale;
|
|
|
|
|
if (aviStreamHeader.dwSampleSize > 0)
|
2015-08-26 22:42:40 +02:00
|
|
|
|
{
|
2017-08-20 10:31:30 +02:00
|
|
|
|
_audDataRate /= aviStreamHeader.dwSampleSize;
|
2015-08-26 22:42:40 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-08-20 10:31:30 +02:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_audDataRate = 0.0;
|
|
|
|
|
}
|
2015-08-26 22:42:40 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion Decode AVI
|
|
|
|
|
|
|
|
|
|
#region WAVE processing
|
|
|
|
|
|
2017-08-20 10:31:30 +02:00
|
|
|
|
private void ProcessWaveChunk(RiffParser rp, int fourCc, int unpaddedLength, int length)
|
2015-08-26 22:42:40 +02:00
|
|
|
|
{
|
|
|
|
|
// Is this a 'fmt' chunk?
|
2017-08-20 10:31:30 +02:00
|
|
|
|
if (AviRiffData.ckidWaveFMT == fourCc)
|
2015-08-26 22:42:40 +02:00
|
|
|
|
{
|
|
|
|
|
DecodeWave(rp, length);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
rp.SkipData(length);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-20 10:31:30 +02:00
|
|
|
|
private void DecodeWave(RiffParser rp, int length)
|
2015-08-26 22:42:40 +02:00
|
|
|
|
{
|
2017-08-20 10:31:30 +02:00
|
|
|
|
var ba = new byte[length];
|
2015-08-26 22:42:40 +02:00
|
|
|
|
rp.ReadData(ba, 0, length);
|
|
|
|
|
|
2017-08-20 10:31:30 +02:00
|
|
|
|
_numChannels = GetShort(ba, 2);
|
|
|
|
|
_bitsPerSec = GetInt(ba, 8);
|
|
|
|
|
_bitsPerSample = GetShort(ba, 14);
|
|
|
|
|
_samplesPerSec = GetInt(ba, 4);
|
2015-08-26 22:42:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-20 10:31:30 +02:00
|
|
|
|
public void ProcessMainWave()
|
2015-08-26 22:42:40 +02:00
|
|
|
|
{
|
|
|
|
|
Clear();
|
|
|
|
|
int length = Parser.DataSize;
|
|
|
|
|
|
|
|
|
|
RiffParser.ProcessChunkElement pdc = ProcessWaveChunk;
|
|
|
|
|
RiffParser.ProcessListElement pal = ProcessList;
|
|
|
|
|
|
|
|
|
|
while (length > 0)
|
|
|
|
|
{
|
2019-01-19 14:40:37 +01:00
|
|
|
|
if (false == Parser.ReadElement(ref length, pdc, pal))
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
2015-08-26 22:42:40 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion WAVE processing
|
|
|
|
|
|
|
|
|
|
}
|
2016-01-24 11:51:04 +01:00
|
|
|
|
}
|