Skip to content

Commit

Permalink
Added updated images.
Browse files Browse the repository at this point in the history
Changes to AudioHelper.
  • Loading branch information
William David Cossey committed Mar 20, 2018
1 parent 0b27d01 commit 209e06b
Show file tree
Hide file tree
Showing 15 changed files with 124 additions and 108 deletions.
Binary file added Images/Advanced.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Images/Filter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Images/Input.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/Joystick.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/Transmitter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
89 changes: 20 additions & 69 deletions SharpPropoPlus.Audio/AudioHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using CSCore.Win32;
using SharpPropoPlus.Audio.Enums;
using SharpPropoPlus.Audio.EventArguments;
using SharpPropoPlus.Audio.Interfaces;
using SharpPropoPlus.Audio.Models;
using SharpPropoPlus.Contracts.EventArguments;
using SharpPropoPlus.Events;
Expand All @@ -26,8 +27,8 @@ public class AudioHelper : IDisposable
//private bool _quitPolling;
private CancellationTokenSource _pollingCancellationTokenSource;
private readonly MMDeviceEnumerator _deviceEnumerator;
private string _deviceId;
private string _deviceName;
//private string _deviceId;
private IAudioEndPoint _device;
private readonly PeakValues _lastPeakValues;
private static readonly object _sync = new object();
private static volatile AudioHelper _instance;
Expand Down Expand Up @@ -61,8 +62,8 @@ private AudioHelper()

_currentDevice = GetDefaultDevice();

DeviceId = _currentDevice.DeviceID;
DeviceName = _currentDevice.FriendlyName;
//DeviceId = _currentDevice.DeviceID;
Device = new AudioEndPoint(_currentDevice.FriendlyName, _currentDevice.DeviceID, GetDeviceFormat(_currentDevice).Channels, _currentDevice.DeviceState != DeviceState.Active, (int?)((_currentDevice.GetJackDescriptions()?.FirstOrDefault())?.Color)?.Value); ;

_isStartUp = false;
}
Expand Down Expand Up @@ -153,17 +154,17 @@ public static AudioHelper Instance
}
}

public string DeviceName
public IAudioEndPoint Device
{
get { return _deviceName; }
private set { _deviceName = value; }
get { return _device; }
private set { _device = value; }
}

public string DeviceId
{
get { return _deviceId; }
private set { _deviceId = value; }
}
//public string DeviceId
//{
// get { return _deviceId; }
// private set { _deviceId = value; }
//}

public AudioChannel Channel
{
Expand Down Expand Up @@ -259,78 +260,31 @@ private WaveFormat GetDeviceFormat(MMDevice device)
return new WaveFormat();
}

private void StartRecording(MMDevice device)
private void StartRecording(MMDevice mmDevice)
{

StopRecording();

if (device == null || device.DataFlow != DataFlow.Capture)
throw new ArgumentNullException(nameof(device), "Selected Audio device is invalid.");

DeviceId = device.DeviceID;
DeviceName = device.FriendlyName;

//for (var i = 0; i < device.Properties.Count; i++)
//{
// object value = null;
// try
// {
// value = device.Properties[i].Value;
// }
// catch (Exception)
// {
// value = null;
// }

// if (value != null && value.GetType() == typeof(byte[]))
// {
// if (((byte[]) value).Any())
// {
// value = string.Join(":", ((byte[])value).Select(s => $"{s:X}"));

// }
// else
// {
// value = null;
// }
// }
// Debug.WriteLine("{0}: {1}\n\t{2}", i, device.Properties[i].Key.formatId, value);
//}

if (mmDevice == null || mmDevice.DataFlow != DataFlow.Capture)
throw new ArgumentNullException(nameof(mmDevice), "Selected Audio device is invalid.");

//device.AudioEndpointVolume.OnVolumeNotification += delegate(AudioVolumeNotificationData data)
//{
// GlobalEventAggregator.Instance.SendMessage(new PeakValueEventArgs(new PeakValues(data.Muted, data.MasterVolume, data.ChannelVolume[0], data.ChannelVolume[1])));
//};
Device = new AudioEndPoint(mmDevice.FriendlyName, mmDevice.DeviceID, GetDeviceFormat(mmDevice).Channels, mmDevice.DeviceState != DeviceState.Active, (int?)((mmDevice.GetJackDescriptions()?.FirstOrDefault())?.Color)?.Value);

var deviceFormat = GetDeviceFormat(mmDevice);

//var x = _deviceEnumerator.EnumerateAudioEndPoints(DataFlow.Capture, DeviceState.All)
// .FirstOrDefault(w => w.ID == _deviceId);



//deviceFormat = new WaveFormat(192000, 16, deviceFormat.Channels);

var deviceFormat = GetDeviceFormat(device);

//var channels = deviceFormat.Channels;

var jackDescription = device.GetJackDescriptions()?.FirstOrDefault();

var audioEndPointArgs = new AudioEndPointEventArgs(device.FriendlyName, device.DeviceID, deviceFormat.Channels, device.DeviceState != DeviceState.Active, (int?)(jackDescription?.Color)?.Value);
var audioEndPointArgs = new AudioEndPointEventArgs(Device.DeviceName, Device.DeviceId, deviceFormat.Channels, Device.Disabled, Device.JackColor);
AudioEndPointChanged?.Invoke(this, audioEndPointArgs);
GlobalEventAggregator.Instance.SendMessage(audioEndPointArgs);

_soundIn =
new WasapiCapture(false, AudioClientShareMode.Shared, 0, deviceFormat,
ThreadPriority.Highest)
{
Device = device
Device = mmDevice
};

_soundIn.Initialize();

//var soundInSource = new SoundInSource(_soundIn);
SoundInSource soundInSource = new SoundInSource(_soundIn)
{
FillWithZeros = false
Expand All @@ -347,9 +301,6 @@ private void StartRecording(MMDevice device)
//byte[] buffer = new byte[_finalSource.WaveFormat.BytesPerSecond / 2];
soundInSource.DataAvailable += SoundInSourceOnDataAvailable;


//singleBlockNotificationStream.SingleBlockRead += SingleBlockNotificationStreamOnSingleBlockRead;

_soundIn.Start();

PollAudioLevels();
Expand Down
12 changes: 6 additions & 6 deletions SharpPropoPlus.Audio/EventArguments/DeviceInfoEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ namespace SharpPropoPlus.Audio.EventArguments
{
public class AudioEndPointEventArgs : EventArgs, IAudioEndPoint
{
public string DeviceName { get; }
public string DeviceName { get; internal set; }

public string DeviceId { get; }
public string DeviceId { get; internal set; }

public int Channels { get; }
public int Channels { get; internal set; }

public bool Disabled { get; }
public bool Disabled { get; internal set; }

public int? DeviceColor { get; }
public int? JackColor { get; internal set; }

public AudioEndPointEventArgs()
{
Expand All @@ -26,7 +26,7 @@ public AudioEndPointEventArgs(string deviceName, string deviceId, int channels,
DeviceId = deviceId;
Channels = channels;
Disabled = disabled;
DeviceColor = deviceColor;
JackColor = deviceColor;
}
}
}
1 change: 1 addition & 0 deletions SharpPropoPlus.Audio/Interfaces/IAudioEndPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ public interface IAudioEndPoint
string DeviceId { get; }
int Channels { get; }
bool Disabled { get; }
int? JackColor { get; }
}
}
12 changes: 6 additions & 6 deletions SharpPropoPlus.Audio/Models/AudioEndPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ namespace SharpPropoPlus.Audio.Models
{
public class AudioEndPoint : IAudioEndPoint
{
public int? DeviceColor { get; }
public int? JackColor { get; internal set; }

public string DeviceName { get; }
public string DeviceName { get; internal set; }

public string DeviceId { get; }
public string DeviceId { get; internal set; }

public int Channels { get; }
public int Channels { get; internal set; }

public bool Disabled { get; }
public bool Disabled { get; internal set; }

public AudioEndPoint(string deviceName, string deviceId, int channels, bool disabled, int? deviceColor)
{
DeviceName = deviceName;
DeviceId = deviceId;
Channels = channels;
Disabled = disabled;
DeviceColor = deviceColor;
JackColor = deviceColor;
}
}
}
70 changes: 70 additions & 0 deletions SharpPropoPlus/Properties/app.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app" />
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<!-- UAC Manifest Options
If you want to change the Windows User Account Control level replace the
requestedExecutionLevel node with one of the following.
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
Specifying requestedExecutionLevel element will disable file and registry virtualization.
Remove this element if your application requires this virtualization for backwards
compatibility.
-->
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
</requestedPrivileges>
<applicationRequestMinimum>
<PermissionSet class="System.Security.PermissionSet" version="1" Unrestricted="true" ID="Custom" SameSite="site" />
<defaultAssemblyRequest permissionSetReference="Custom" />
</applicationRequestMinimum>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- A list of the Windows versions that this application has been tested on and is
is designed to work with. Uncomment the appropriate elements and Windows will
automatically selected the most compatible environment. -->
<!-- Windows Vista -->
<!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />-->
<!-- Windows 7 -->
<!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />-->
<!-- Windows 8 -->
<!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />-->
<!-- Windows 8.1 -->
<!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />-->
<!-- Windows 10 -->
<!--<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />-->
</application>
</compatibility>
<!-- Indicates that the application is DPI-aware and will not be automatically scaled by Windows at higher
DPIs. Windows Presentation Foundation (WPF) applications are automatically DPI-aware and do not need
to opt in. Windows Forms applications targeting .NET Framework 4.6 that opt into this setting, should
also set the 'EnableWindowsFormsHighDpiAutoResizing' setting to 'true' in their app.config. -->
<!--
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
</windowsSettings>
</application>
-->
<!-- Enable themes for Windows common controls and dialogs (Windows XP and later) -->
<!--
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
-->
</assembly>
9 changes: 8 additions & 1 deletion SharpPropoPlus/SharpPropoPlus.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
<ManifestKeyFile>SharpPropoPlus_TemporaryKey.pfx</ManifestKeyFile>
</PropertyGroup>
<PropertyGroup>
<GenerateManifests>true</GenerateManifests>
<GenerateManifests>false</GenerateManifests>
</PropertyGroup>
<PropertyGroup>
<SignManifests>false</SignManifests>
Expand All @@ -95,6 +95,12 @@
<PropertyGroup>
<RunPostBuildEvent>Always</RunPostBuildEvent>
</PropertyGroup>
<PropertyGroup>
<TargetZone>LocalIntranet</TargetZone>
</PropertyGroup>
<PropertyGroup>
<ApplicationManifest>Properties\app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<Reference Include="CommonServiceLocator, Version=2.0.3.0, Culture=neutral, PublicKeyToken=489b6accfaf20ef0, processorArchitecture=MSIL">
<HintPath>..\packages\Unity.5.7.3\lib\net46\CommonServiceLocator.dll</HintPath>
Expand Down Expand Up @@ -355,6 +361,7 @@
<Resource Include="Fonts\Montserrat-ExtraBold.otf" />
<Resource Include="Fonts\Montserrat-SemiBold.otf" />
<None Include="packages.config" />
<None Include="Properties\app.manifest" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
Expand Down
2 changes: 1 addition & 1 deletion SharpPropoPlus/ViewModels/AudioConfigViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public AudioConfigViewModel()
new ReadOnlyObservableCollection<AudioEndPoint>(new ObservableCollection<AudioEndPoint>(AudioHelper.Instance.Devices));

SelectedAudioEndPoint =
AudioEndPointCollection.FirstOrDefault(fd => fd.DeviceId == AudioHelper.Instance.DeviceId);
AudioEndPointCollection.FirstOrDefault(fd => fd.DeviceId == AudioHelper.Instance.Device.DeviceId);

_selectedBitrateItem = AudioHelper.Instance.Bitrate;
_selectedChannelItem = AudioHelper.Instance.Channel;
Expand Down
Loading

0 comments on commit 209e06b

Please sign in to comment.