Skip to content

Commit

Permalink
some code cleanup of DMO
Browse files Browse the repository at this point in the history
  • Loading branch information
markheath committed Jan 31, 2017
1 parent 42ebd73 commit d557ac4
Show file tree
Hide file tree
Showing 40 changed files with 89 additions and 200 deletions.
2 changes: 0 additions & 2 deletions NAudio/Dmo/AudioMediaSubtypes.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace NAudio.Dmo
{
Expand Down
8 changes: 3 additions & 5 deletions NAudio/Dmo/DmoDescriptor.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace NAudio.Dmo
{
Expand All @@ -15,7 +13,7 @@ public class DmoDescriptor
public string Name { get; private set; }

/// <summary>
/// Clsid
/// CLSID
/// </summary>
public Guid Clsid { get; private set; }

Expand All @@ -24,8 +22,8 @@ public class DmoDescriptor
/// </summary>
public DmoDescriptor(string name, Guid clsid)
{
this.Name = name;
this.Clsid = clsid;
Name = name;
Clsid = clsid;
}
}
}
2 changes: 0 additions & 2 deletions NAudio/Dmo/DmoEnumFlags.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace NAudio.Dmo
{
Expand Down
7 changes: 3 additions & 4 deletions NAudio/Dmo/DmoEnumerator.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace NAudio.Dmo
Expand Down Expand Up @@ -40,13 +39,13 @@ public static IEnumerable<DmoDescriptor> GetAudioDecoderNames()
private static IEnumerable<DmoDescriptor> GetDmos(Guid category)
{
IEnumDmo enumDmo;
int hresult = DmoInterop.DMOEnum(ref category, DmoEnumFlags.None, 0, null, 0, null, out enumDmo);
var hresult = DmoInterop.DMOEnum(ref category, DmoEnumFlags.None, 0, null, 0, null, out enumDmo);
Marshal.ThrowExceptionForHR(hresult);
Guid guid;
int itemsFetched;
IntPtr namePointer;
do
{
Guid guid;
IntPtr namePointer;
enumDmo.Next(1, out guid, out namePointer, out itemsFetched);

if (itemsFetched == 1)
Expand Down
2 changes: 0 additions & 2 deletions NAudio/Dmo/DmoGuids.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace NAudio.Dmo
{
Expand Down
2 changes: 0 additions & 2 deletions NAudio/Dmo/DmoHResults.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace NAudio.Dmo
{
Expand Down
2 changes: 0 additions & 2 deletions NAudio/Dmo/DmoInputDataBufferFlags.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace NAudio.Dmo
{
Expand Down
2 changes: 0 additions & 2 deletions NAudio/Dmo/DmoInputStatusFlags.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace NAudio.Dmo
{
Expand Down
1 change: 0 additions & 1 deletion NAudio/Dmo/DmoInterop.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

Expand Down
59 changes: 16 additions & 43 deletions NAudio/Dmo/DmoMediaType.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using System;
using System.Collections.Generic;
using System.Text;
using NAudio.Wave;
using System.Runtime.InteropServices;
using System.Diagnostics;

namespace NAudio.Dmo
{
Expand All @@ -26,26 +23,17 @@ public struct DmoMediaType
/// <summary>
/// Major type
/// </summary>
public Guid MajorType
{
get { return majortype; }
}
public Guid MajorType => majortype;

/// <summary>
/// Major type name
/// </summary>
public string MajorTypeName
{
get { return MediaTypes.GetMediaTypeName(majortype); }
}
public string MajorTypeName => MediaTypes.GetMediaTypeName(majortype);

/// <summary>
/// Subtype
/// </summary>
public Guid SubType
{
get { return subtype; }
}
public Guid SubType => subtype;

/// <summary>
/// Subtype name
Expand All @@ -65,26 +53,17 @@ public string SubTypeName
/// <summary>
/// Fixed size samples
/// </summary>
public bool FixedSizeSamples
{
get { return bFixedSizeSamples; }
}
public bool FixedSizeSamples => bFixedSizeSamples;

/// <summary>
/// Sample size
/// </summary>
public int SampleSize
{
get { return lSampleSize; }
}
public int SampleSize => lSampleSize;

/// <summary>
/// Format type
/// </summary>
public Guid FormatType
{
get { return formattype; }
}
public Guid FormatType => formattype;

/// <summary>
/// Format type name
Expand All @@ -97,18 +76,15 @@ public string FormatTypeName
{
return "None";
}
else if (formattype == Guid.Empty)
if (formattype == Guid.Empty)
{
return "Null";
}
else if(formattype == DmoMediaTypeGuids.FORMAT_WaveFormatEx)
if(formattype == DmoMediaTypeGuids.FORMAT_WaveFormatEx)
{
return "WaveFormatEx";
}
else
{
return FormatType.ToString();
}
return FormatType.ToString();
}
}

Expand All @@ -121,10 +97,7 @@ public WaveFormat GetWaveFormat()
{
return WaveFormat.MarshalFromPtr(pbFormat);
}
else
{
throw new InvalidOperationException("Not a WaveFormat type");
}
throw new InvalidOperationException("Not a WaveFormat type");
}

/// <summary>
Expand All @@ -133,12 +106,12 @@ public WaveFormat GetWaveFormat()
/// <param name="waveFormat">Wave format structure</param>
public void SetWaveFormat(WaveFormat waveFormat)
{
this.majortype = MediaTypes.MEDIATYPE_Audio;
majortype = MediaTypes.MEDIATYPE_Audio;

WaveFormatExtensible wfe = waveFormat as WaveFormatExtensible;
var wfe = waveFormat as WaveFormatExtensible;
if (wfe != null)
{
this.subtype = wfe.SubFormat;
subtype = wfe.SubFormat;
}
else
{
Expand All @@ -154,11 +127,11 @@ public void SetWaveFormat(WaveFormat waveFormat)
subtype = AudioMediaSubtypes.WMMEDIASUBTYPE_MP3;
break;
default:
throw new ArgumentException(String.Format("Not a supported encoding {0}", waveFormat.Encoding));
throw new ArgumentException($"Not a supported encoding {waveFormat.Encoding}");
}
}
this.bFixedSizeSamples = (this.SubType == AudioMediaSubtypes.MEDIASUBTYPE_PCM || this.SubType == AudioMediaSubtypes.MEDIASUBTYPE_IEEE_FLOAT);
this.formattype = DmoMediaTypeGuids.FORMAT_WaveFormatEx;
bFixedSizeSamples = SubType == AudioMediaSubtypes.MEDIASUBTYPE_PCM || SubType == AudioMediaSubtypes.MEDIASUBTYPE_IEEE_FLOAT;
formattype = DmoMediaTypeGuids.FORMAT_WaveFormatEx;
if (cbFormat < Marshal.SizeOf(waveFormat))
throw new InvalidOperationException("Not enough memory assigned for a WaveFormat structure");
//Debug.Assert(cbFormat >= ,"Not enough space");
Expand Down
2 changes: 0 additions & 2 deletions NAudio/Dmo/DmoOutputDataBuffer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace NAudio.Dmo
Expand Down
2 changes: 0 additions & 2 deletions NAudio/Dmo/DmoOutputDataBufferFlags.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace NAudio.Dmo
{
Expand Down
2 changes: 0 additions & 2 deletions NAudio/Dmo/DmoPartialMediaType.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace NAudio.Dmo
{
Expand Down
2 changes: 0 additions & 2 deletions NAudio/Dmo/DmoProcessOutputFlags.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace NAudio.Dmo
{
Expand Down
2 changes: 0 additions & 2 deletions NAudio/Dmo/DmoSetTypeFlags.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace NAudio.Dmo
{
Expand Down
2 changes: 0 additions & 2 deletions NAudio/Dmo/IEnumDmo.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace NAudio.Dmo
Expand Down
2 changes: 0 additions & 2 deletions NAudio/Dmo/IMediaBuffer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace NAudio.Dmo
Expand Down
2 changes: 0 additions & 2 deletions NAudio/Dmo/IMediaObject.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace NAudio.Dmo
Expand Down
2 changes: 0 additions & 2 deletions NAudio/Dmo/IMediaParamInfo.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace NAudio.Dmo
Expand Down
2 changes: 0 additions & 2 deletions NAudio/Dmo/IWMResamplerProps.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace NAudio.Dmo
Expand Down
2 changes: 0 additions & 2 deletions NAudio/Dmo/InputStreamInfoFlags.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace NAudio.Dmo
{
Expand Down
10 changes: 4 additions & 6 deletions NAudio/Dmo/MediaBuffer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using NAudio.Utils;

Expand All @@ -12,17 +10,17 @@ namespace NAudio.Dmo
/// </summary>
public class MediaBuffer : IMediaBuffer, IDisposable
{
IntPtr buffer;
int length;
int maxLength;
private IntPtr buffer;
private int length;
private readonly int maxLength;

/// <summary>
/// Creates a new Media Buffer
/// </summary>
/// <param name="maxLength">Maximum length in bytes</param>
public MediaBuffer(int maxLength)
{
this.buffer = Marshal.AllocCoTaskMem(maxLength);
buffer = Marshal.AllocCoTaskMem(maxLength);
this.maxLength = maxLength;
}

Expand Down
7 changes: 3 additions & 4 deletions NAudio/Dmo/MediaObject.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Text;
using NAudio.Utils;
using System.Runtime.InteropServices;
using NAudio.Wave;
Expand All @@ -13,9 +12,9 @@ namespace NAudio.Dmo
/// </summary>
public class MediaObject : IDisposable
{
IMediaObject mediaObject;
int inputStreams;
int outputStreams;
private IMediaObject mediaObject;
private readonly int inputStreams;
private readonly int outputStreams;

#region Construction

Expand Down
9 changes: 3 additions & 6 deletions NAudio/Dmo/MediaObjectSizeInfo.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace NAudio.Dmo
{
Expand All @@ -17,12 +15,12 @@ public class MediaObjectSizeInfo
/// <summary>
/// Max Lookahead
/// </summary>
public int MaxLookahead { get; private set; }
public int MaxLookahead { get; }

/// <summary>
/// Alignment
/// </summary>
public int Alignment { get; private set; }
public int Alignment { get; }

/// <summary>
/// Media Object Size Info
Expand All @@ -39,8 +37,7 @@ public MediaObjectSizeInfo(int size, int maxLookahead, int alignment)
/// </summary>
public override string ToString()
{
return String.Format("Size: {0}, Alignment {1}, MaxLookahead {2}",
Size, Alignment, MaxLookahead);
return $"Size: {Size}, Alignment {Alignment}, MaxLookahead {MaxLookahead}";
}

}
Expand Down
2 changes: 0 additions & 2 deletions NAudio/Dmo/MediaParamInfo.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace NAudio.Dmo
Expand Down
Loading

0 comments on commit d557ac4

Please sign in to comment.