-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from LAGonauta/volume-meter-and-map-channels
Lots of desirable changes
- Loading branch information
Showing
11 changed files
with
824 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using NAudio.Wave; | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace ASIORecAndPlay | ||
{ | ||
internal enum ChannelType | ||
{ | ||
Input, | ||
Output | ||
} | ||
|
||
internal static class Asio | ||
{ | ||
public static string[] GetDevices() | ||
{ | ||
return AsioOut.GetDriverNames(); | ||
} | ||
|
||
public static void ShowControlPanel(string device) | ||
{ | ||
using (var asio = new AsioOut(device)) | ||
{ | ||
asio.ShowControlPanel(); | ||
} | ||
} | ||
|
||
public static string[] GetChannelNames(string device, ChannelType channelType) | ||
{ | ||
using (var asio = new AsioOut(device)) | ||
{ | ||
int count = asio.DriverOutputChannelCount; | ||
Func<int, string> getName = (i) => asio.AsioOutputChannelName(i); | ||
if (channelType == ChannelType.Input) | ||
{ | ||
count = asio.DriverInputChannelCount; | ||
getName = (i) => asio.AsioInputChannelName(i); | ||
} | ||
|
||
var nameList = new List<string>(); | ||
for (int i = 0; i < count; ++i) | ||
{ | ||
nameList.Add(getName(i)); | ||
} | ||
return nameList.ToArray(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace ASIORecAndPlay | ||
{ | ||
internal struct Mapping | ||
{ | ||
public int inputChannel; | ||
public int outputChannel; | ||
} | ||
|
||
internal class ChannelMapping | ||
{ | ||
private IDictionary<int, int> channelMapping; | ||
private object _lock = new object(); | ||
|
||
public IEnumerable<int> InputChannels => channelMapping.Values; | ||
|
||
public IEnumerable<int> OutputChannels => channelMapping.Keys; | ||
|
||
public ChannelMapping() | ||
{ | ||
channelMapping = new Dictionary<int, int>(); | ||
} | ||
|
||
public ChannelMapping(IDictionary<int, int> outputInputPairs) | ||
{ | ||
channelMapping = outputInputPairs; | ||
} | ||
|
||
/// <summary> | ||
/// While one input can send to various outputs, one output can receive only from one input. | ||
/// Thus, the output must be unique. | ||
/// </summary> | ||
/// <param name="inputChannel">Input channel number</param> | ||
/// <param name="outputChannel">Output channel number</param> | ||
/// <returns></returns> | ||
public bool Add(int inputChannel, int outputChannel) | ||
{ | ||
try | ||
{ | ||
lock (_lock) | ||
{ | ||
channelMapping.Add(outputChannel, inputChannel); | ||
} | ||
|
||
return true; | ||
} | ||
catch | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Remove the mapping to the set output channel. | ||
/// </summary> | ||
/// <param name="outputChannel"></param> | ||
/// <returns></returns> | ||
public bool Remove(int outputChannel) | ||
{ | ||
lock (_lock) | ||
{ | ||
return channelMapping.Remove(outputChannel); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Gets an ordered enumerable of a copy the mapping, ordered by input channel. | ||
/// </summary> | ||
/// <returns></returns> | ||
public IEnumerable<Mapping> GetMappingList() | ||
{ | ||
lock (_lock) | ||
{ | ||
return channelMapping | ||
.Select(e => new Mapping { inputChannel = e.Value, outputChannel = e.Key }) | ||
.OrderBy(e => e.inputChannel).ToList(); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Gets a copy of the internal dictionary. | ||
/// </summary> | ||
/// <returns></returns> | ||
public IDictionary<int, int> GetMappingDictionary() | ||
{ | ||
lock (_lock) | ||
{ | ||
return channelMapping.ToDictionary(e => e.Key, e => e.Value); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.