Skip to content
This repository has been archived by the owner on Mar 30, 2019. It is now read-only.

fix initialization of local blockAlign with default values. #793

Merged
merged 2 commits into from
Sep 5, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions Source/SharpDX/Multimedia/WaveFormatAdpcm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,24 @@ internal WaveFormatAdpcm()
/// <param name="blockAlign">The block align. If 0, then 256 for [0, 11KHz], 512 for ]11KHz, 22Khz], 1024 for ]22Khz, +inf]</param>
public WaveFormatAdpcm(int rate, int channels, int blockAlign = 0) : base(rate, 4, channels)
{
waveFormatTag = WaveFormatEncoding.Adpcm;
this.blockAlign = (short)blockAlign;

if (blockAlign == 0)
{
if (rate <= 11025)
{
blockAlign = 256;
}
else if (rate <= 22050)
{
blockAlign = 512;
}
else
{
blockAlign = 1024;
}
}

if (rate <= 0) throw new ArgumentOutOfRangeException("rate", "Must be > 0");
if (channels <= 0) throw new ArgumentOutOfRangeException("channels", "Must be > 0");
if (blockAlign <= 0) throw new ArgumentOutOfRangeException("blockAlign", "Must be > 0");
if (blockAlign > Int16.MaxValue) throw new ArgumentOutOfRangeException("blockAlign", "Must be < 32767");

waveFormatTag = WaveFormatEncoding.Adpcm;
this.blockAlign = (short)blockAlign;

SamplesPerBlock = (ushort)(blockAlign * 2 / channels - 12);
averageBytesPerSecond = (SampleRate * blockAlign) / SamplesPerBlock;

Expand Down