Skip to content

Commit

Permalink
Resync (#1)
Browse files Browse the repository at this point in the history
* AudioFileReader supports filenames ending with .aif, resolves naudio#216

* v1.8.2 release

* Added "Data" property

Added "Data" property to allow for non Unicode decoding of text.

* Fixed typos

* With Directsound, when another playback is started after the playback has completely stopped, the problem of mixing noise is solved.

* Based on the advice of markheath, clearing processing of the secondary buffer is converted into a helper method.

* PropVariant fields now public

Changed field access modifiers from private to public to allow creation of custom variants for settings MMDevice instances property values.

* Addition of missing IPropertyStore methods for PropertyStore class.

Added SetValue and Commit methods to allow one to write new property values for MMDevice instance.

* Addition of new PropertyKeys class members

Declaration of new static PropertyKey fields:
- PKEY_Device_DeviceDesc, description property
- PKEY_Device_ControllerDeviceId, contains device id of controller device for given endpoint
- PKEY_Device_InterafaceKey, contains interface key path
for PropertyKeys static class.

* StorageAccessMode enum now public

* Blob struct now public

* Modified GetPropertyInformation for public use

Method GetPropertyInformation now public. Access flag can now be changed when accessing property store for given MMDevice.

* Fixed description

* Added XML documentation for new public members

* improved support for mono AAC, fixes naudio#223

* Improved support for mono AAC

Multiplying the SampleRate & ChannelCount will cause exception with aac_lc mono _(it's only required with HE-AAC)_.

* Fix different behavior between Win7 and Win10.

* fix NullReferenceException opening AsioOut by index. resolves naudio#234

* v1.8.3 release

* Prevent audio files from staying locked

Fixing an issue that caused audio files used by the MediaFoundationReader class to stay locked after the class instance is disposed, due to unreleased COM object.

* additional constructor for MultiplexingWaveProvider
  • Loading branch information
ArclightSA authored Sep 19, 2017
1 parent 3e94f21 commit 31a3aa1
Show file tree
Hide file tree
Showing 15 changed files with 304 additions and 92 deletions.
11 changes: 10 additions & 1 deletion NAudio/CoreAudioApi/Interfaces/Blob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,18 @@ 3. This notice may not be removed or altered from any source distribution.

namespace NAudio.CoreAudioApi.Interfaces
{
internal struct Blob
/// <summary>
/// Representation of binary large object container.
/// </summary>
public struct Blob
{
/// <summary>
/// Length of binary object.
/// </summary>
public int Length;
/// <summary>
/// Pointer to buffer storing data.
/// </summary>
public IntPtr Data;

//Code Should Compile at warning level4 without any warnings,
Expand Down
11 changes: 10 additions & 1 deletion NAudio/CoreAudioApi/Interfaces/StorageAccessMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,19 @@ namespace NAudio.CoreAudioApi.Interfaces
/// <summary>
/// MMDevice STGM enumeration
/// </summary>
enum StorageAccessMode
public enum StorageAccessMode
{
/// <summary>
/// Read-only access mode.
/// </summary>
Read,
/// <summary>
/// Write-only access mode.
/// </summary>
Write,
/// <summary>
/// Read-write access mode.
/// </summary>
ReadWrite
}
}
9 changes: 7 additions & 2 deletions NAudio/CoreAudioApi/MMDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,15 @@ public class MMDevice : IDisposable
#endregion

#region Init
private void GetPropertyInformation()
/// <summary>
/// Initializes the device's property store.
/// </summary>
/// <param name="stgmAccess">The storage-access mode to open store for.</param>
/// <remarks>Administrative client is required for Write and ReadWrite modes.</remarks>
public void GetPropertyInformation(StorageAccessMode stgmAccess = StorageAccessMode.Read)
{
IPropertyStore propstore;
Marshal.ThrowExceptionForHR(deviceInterface.OpenPropertyStore(StorageAccessMode.Read, out propstore));
Marshal.ThrowExceptionForHR(deviceInterface.OpenPropertyStore(stgmAccess, out propstore));
propertyStore = new PropertyStore(propstore);
}

Expand Down
105 changes: 84 additions & 21 deletions NAudio/CoreAudioApi/PropVariant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,35 +35,98 @@ namespace NAudio.CoreAudioApi.Interfaces
[StructLayout(LayoutKind.Explicit)]
public struct PropVariant
{
[FieldOffset(0)] private short vt;
[FieldOffset(2)] private short wReserved1;
[FieldOffset(4)] private short wReserved2;
[FieldOffset(6)] private short wReserved3;
[FieldOffset(8)] private sbyte cVal;
[FieldOffset(8)] private byte bVal;
[FieldOffset(8)] private short iVal;
[FieldOffset(8)] private ushort uiVal;
[FieldOffset(8)] private int lVal;
[FieldOffset(8)] private uint ulVal;
[FieldOffset(8)] private int intVal;
[FieldOffset(8)] private uint uintVal;
[FieldOffset(8)] private long hVal;
[FieldOffset(8)] private long uhVal;
[FieldOffset(8)] private float fltVal;
[FieldOffset(8)] private double dblVal;
/// <summary>
/// Value type tag.
/// </summary>
[FieldOffset(0)] public short vt;
/// <summary>
/// Reserved1.
/// </summary>
[FieldOffset(2)] public short wReserved1;
/// <summary>
/// Reserved2.
/// </summary>
[FieldOffset(4)] public short wReserved2;
/// <summary>
/// Reserved3.
/// </summary>
[FieldOffset(6)] public short wReserved3;
/// <summary>
/// cVal.
/// </summary>
[FieldOffset(8)] public sbyte cVal;
/// <summary>
/// bVal.
/// </summary>
[FieldOffset(8)] public byte bVal;
/// <summary>
/// iVal.
/// </summary>
[FieldOffset(8)] public short iVal;
/// <summary>
/// uiVal.
/// </summary>
[FieldOffset(8)] public ushort uiVal;
/// <summary>
/// lVal.
/// </summary>
[FieldOffset(8)] public int lVal;
/// <summary>
/// ulVal.
/// </summary>
[FieldOffset(8)] public uint ulVal;
/// <summary>
/// intVal.
/// </summary>
[FieldOffset(8)] public int intVal;
/// <summary>
/// uintVal.
/// </summary>
[FieldOffset(8)] public uint uintVal;
/// <summary>
/// hVal.
/// </summary>
[FieldOffset(8)] public long hVal;
/// <summary>
/// uhVal.
/// </summary>
[FieldOffset(8)] public long uhVal;
/// <summary>
/// fltVal.
/// </summary>
[FieldOffset(8)] public float fltVal;
/// <summary>
/// dblVal.
/// </summary>
[FieldOffset(8)] public double dblVal;
//VARIANT_BOOL boolVal;
[FieldOffset(8)] private short boolVal;
[FieldOffset(8)] private int scode;
/// <summary>
/// boolVal.
/// </summary>
[FieldOffset(8)] public short boolVal;
/// <summary>
/// scode.
/// </summary>
[FieldOffset(8)] public int scode;
//CY cyVal;
//[FieldOffset(8)] private DateTime date; - can cause issues with invalid value
[FieldOffset(8)] private System.Runtime.InteropServices.ComTypes.FILETIME filetime;
/// <summary>
/// Date time.
/// </summary>
[FieldOffset(8)] public System.Runtime.InteropServices.ComTypes.FILETIME filetime;
//CLSID* puuid;
//CLIPDATA* pclipdata;
//BSTR bstrVal;
//BSTRBLOB bstrblobVal;
[FieldOffset(8)] private Blob blobVal;
/// <summary>
/// Binary large object.
/// </summary>
[FieldOffset(8)] public Blob blobVal;
//LPSTR pszVal;
[FieldOffset(8)] private IntPtr pointerValue; //LPWSTR
/// <summary>
/// Pointer value.
/// </summary>
[FieldOffset(8)] public IntPtr pointerValue; //LPWSTR
//IUnknown* punkVal;
/*IDispatch* pdispVal;
IStream* pStream;
Expand Down
12 changes: 12 additions & 0 deletions NAudio/CoreAudioApi/PropertyKeys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,17 @@ public static class PropertyKeys
/// PKEY _Device_IconPath
/// </summary>
public static readonly PropertyKey PKEY_Device_IconPath = new PropertyKey(new Guid(unchecked((int)0x259abffc), unchecked((short)0x50a7), 0x47ce, 0xaf, 0x8, 0x68, 0xc9, 0xa7, 0xd7, 0x33, 0x66), 12);
/// <summary>
/// Device description property.
/// </summary>
public static readonly PropertyKey PKEY_Device_DeviceDesc = new PropertyKey(new Guid(unchecked((int)0xa45c254e), unchecked((short)0xdf1c), 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0), 2);
/// <summary>
/// Id of controller device for endpoint device property.
/// </summary>
public static readonly PropertyKey PKEY_Device_ControllerDeviceId = new PropertyKey(new Guid(unchecked((int)0xb3f8fa53), unchecked((short)0x0004), 0x438e, 0x90, 0x03, 0x51, 0xa4, 0x6e, 0x13, 0x9b, 0xfc), 2);
/// <summary>
/// Device interface key property.
/// </summary>
public static readonly PropertyKey PKEY_Device_InterfaceKey = new PropertyKey(new Guid(unchecked((int)0x233164c8), unchecked((short)0x1b2c), 0x4c7d, 0xbc, 0x68, 0xb6, 0x71, 0x68, 0x7a, 0x25, 0x67), 1);
}
}
18 changes: 18 additions & 0 deletions NAudio/CoreAudioApi/PropertyStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,24 @@ public PropVariant GetValue(int index)
return result;
}

/// <summary>
/// Sets property value at specified key.
/// </summary>
/// <param name="key">Key of property to set.</param>
/// <param name="value">Value to write.</param>
public void SetValue(PropertyKey key, PropVariant value)
{
Marshal.ThrowExceptionForHR(storeInterface.SetValue(ref key, ref value));
}

/// <summary>
/// Saves a property change.
/// </summary>
public void Commit()
{
Marshal.ThrowExceptionForHR(storeInterface.Commit());
}

/// <summary>
/// Creates a new property store
/// </summary>
Expand Down
39 changes: 27 additions & 12 deletions NAudio/Midi/TextEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace NAudio.Midi
/// </summary>
public class TextEvent : MetaEvent
{
private string text;
private byte[] data;

/// <summary>
/// Reads a new text event from a MIDI stream
Expand All @@ -18,8 +18,7 @@ public class TextEvent : MetaEvent
/// <param name="length">The data length</param>
public TextEvent(BinaryReader br,int length)
{
Encoding byteEncoding = NAudio.Utils.ByteEncoding.Instance;
text = byteEncoding.GetString(br.ReadBytes(length));
data = br.ReadBytes(length);
}

/// <summary>
Expand All @@ -32,7 +31,7 @@ public TextEvent(BinaryReader br,int length)
public TextEvent(string text, MetaEventType metaEventType, long absoluteTime)
: base(metaEventType, text.Length, absoluteTime)
{
this.text = text;
Text = text;
}

/// <summary>
Expand All @@ -47,12 +46,30 @@ public string Text
{
get
{
return text;
Encoding byteEncoding = NAudio.Utils.ByteEncoding.Instance;
return byteEncoding.GetString(data);
}
set
{
text = value;
metaDataLength = text.Length;
Encoding byteEncoding = NAudio.Utils.ByteEncoding.Instance;
data = byteEncoding.GetBytes(value);
metaDataLength = data.Length;
}
}

/// <summary>
/// The raw contents of this text event
/// </summary>
public byte[] Data
{
get
{
return data;
}
set
{
data = value;
metaDataLength = data.Length;
}
}

Expand All @@ -62,7 +79,7 @@ public string Text
/// <returns>A string describing this event</returns>
public override string ToString()
{
return String.Format("{0} {1}",base.ToString(),text);
return String.Format("{0} {1}",base.ToString(),Text);
}

/// <summary>
Expand All @@ -73,9 +90,7 @@ public override string ToString()
public override void Export(ref long absoluteTime, BinaryWriter writer)
{
base.Export(ref absoluteTime, writer);
Encoding byteEncoding = NAudio.Utils.ByteEncoding.Instance;
byte[] encoded = byteEncoding.GetBytes(text);
writer.Write(encoded);
writer.Write(data);
}
}
}
}
4 changes: 2 additions & 2 deletions NAudio/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.8.1.0")]
[assembly: AssemblyFileVersion("1.8.1.0")]
[assembly: AssemblyVersion("1.8.3.0")]
[assembly: AssemblyFileVersion("1.8.3.0")]
2 changes: 1 addition & 1 deletion NAudio/Wave/WaveOutputs/AsioOut.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public AsioOut(int driverIndex)
{
throw new ArgumentException(String.Format("Invalid device number. Must be in the range [0,{0}]", names.Length));
}
InitFromName(this.driverName);
InitFromName(names[driverIndex]);
}

/// <summary>
Expand Down
Loading

0 comments on commit 31a3aa1

Please sign in to comment.