-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
252 additions
and
35 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
90 changes: 90 additions & 0 deletions
90
Cavern.QuickEQ.Format/ConfigurationFile/Presets/CrossoverFilterSet.cs
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,90 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
using Cavern.Channels; | ||
using Cavern.Filters; | ||
using Cavern.Filters.Utilities; | ||
using Cavern.QuickEQ.Crossover; | ||
using Cavern.Utilities; | ||
|
||
using Crossover = Cavern.QuickEQ.Crossover.Crossover; | ||
|
||
namespace Cavern.Format.ConfigurationFile.Presets { | ||
/// <summary> | ||
/// An added crossover step to a <see cref="ConfigurationFile"/> filter graph. | ||
/// </summary> | ||
public class CrossoverFilterSet : FilterSetPreset { | ||
/// <summary> | ||
/// User-defined name of this crossover that will be given to the created split point. | ||
/// </summary> | ||
readonly string name; | ||
|
||
/// <summary> | ||
/// Crossover implementation algorithm. | ||
/// </summary> | ||
readonly CrossoverType type; | ||
|
||
/// <summary> | ||
/// Sample rate of the DSP this filter set is applied to. | ||
/// </summary> | ||
readonly int sampleRate; | ||
|
||
/// <summary> | ||
/// If the crossover <see cref="type"/> can only be implemented as a convolution, this will be its sample count. | ||
/// </summary> | ||
readonly int filterLength; | ||
|
||
/// <summary> | ||
/// The target channel to cross over to. | ||
/// </summary> | ||
readonly ReferenceChannel targetChannel; | ||
|
||
/// <summary> | ||
/// The channels to cross over to the <see cref="targetChannel"/>. | ||
/// </summary> | ||
readonly (ReferenceChannel channel, float frequency)[] sourceChannels; | ||
|
||
/// <summary> | ||
/// An added crossover step to a <see cref="ConfigurationFile"/> filter graph. | ||
/// </summary> | ||
/// <param name="name">User-defined name of this crossover that will be given to the created split point</param> | ||
/// <param name="type">Crossover implementation algorithm</param> | ||
/// <param name="sampleRate">Sample rate of the DSP this filter set is applied to</param> | ||
/// <param name="filterLength">If the crossover <see cref="type"/> can only be implemented as a convolution, | ||
/// this will be its sample count</param> | ||
/// <param name="targetChannel">The target channel to cross over to</param> | ||
/// <param name="sourceChannels">The channels to cross over to the <see cref="targetChannel"/></param> | ||
public CrossoverFilterSet(string name, CrossoverType type, int sampleRate, int filterLength, ReferenceChannel targetChannel, | ||
params (ReferenceChannel channel, float frequency)[] sourceChannels) { | ||
this.name = name; | ||
this.type = type; | ||
this.sampleRate = sampleRate; | ||
this.filterLength = filterLength; | ||
this.targetChannel = targetChannel; | ||
this.sourceChannels = sourceChannels; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override void Add(ConfigurationFile file, int index) { | ||
file.AddSplitPoint(index, name); | ||
FilterGraphNode lowpassOut = file.GetSplitPointRoot(index, targetChannel).Children[0]; // OutputChannel filter for the target | ||
float[] freqsPerChannel = sourceChannels.GetItem2s(); | ||
float[] freqs = freqsPerChannel.Distinct().ToArray(); | ||
Crossover generator = Crossover.Create(type, freqsPerChannel, new bool[sourceChannels.Length]); | ||
Dictionary<float, FilterGraphNode> aggregators = new Dictionary<float, FilterGraphNode>(); | ||
for (int i = 0; i < freqs.Length; i++) { | ||
Filter lowpass = generator.GetLowpassOptimized(sampleRate, freqs[i], filterLength); | ||
FilterGraphNode node = new FilterGraphNode(lowpass); | ||
node.AddChild(lowpassOut); | ||
aggregators[freqs[i]] = node; | ||
} | ||
|
||
for (int i = 0; i < sourceChannels.Length; i++) { | ||
Filter highpass = generator.GetHighpassOptimized(sampleRate, freqsPerChannel[i], filterLength); | ||
FilterGraphNode root = file.GetSplitPointRoot(index, sourceChannels[i].channel); | ||
root.AddBeforeChildren(highpass); | ||
root.AddChild(aggregators[freqsPerChannel[i]]); | ||
} | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Cavern.QuickEQ.Format/ConfigurationFile/Presets/FilterSetPreset.cs
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,11 @@ | ||
namespace Cavern.Format.ConfigurationFile.Presets { | ||
/// <summary> | ||
/// An added preconfigured step to a <see cref="ConfigurationFile"/> filter graph. | ||
/// </summary> | ||
public abstract class FilterSetPreset { | ||
/// <summary> | ||
/// Add this preset to a work in progress configuration <paramref name="file"/> at the given split point <paramref name="index"/>. | ||
/// </summary> | ||
public abstract void Add(ConfigurationFile file, int index); | ||
} | ||
} |
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
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
6 changes: 6 additions & 0 deletions
6
CavernSamples/Cavern.WPF/Resources/CrossoverStrings.hu-HU.xaml
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,6 @@ | ||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:system="clr-namespace:System;assembly=mscorlib"> | ||
<system:String x:Key="TyBiq">Bikvadratikus</system:String> | ||
<system:String x:Key="TySBi">Szintetikus bikvadratikus</system:String> | ||
</ResourceDictionary> |
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,6 @@ | ||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:system="clr-namespace:System;assembly=mscorlib"> | ||
<system:String x:Key="TyBiq">Biquadratic</system:String> | ||
<system:String x:Key="TySBi">Synthetic biquadratic</system:String> | ||
</ResourceDictionary> |
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,17 @@ | ||
using Cavern.QuickEQ.Crossover; | ||
using Cavern.WPF.Consts; | ||
|
||
namespace Cavern.WPF.Utils { | ||
/// <summary> | ||
/// Used to display a crossover type's name on a UI in the user's language and contain which <see cref="CrossoverType"/> it is. | ||
/// </summary> | ||
public class CrossoverTypeOnUI(CrossoverType type) { | ||
/// <summary> | ||
/// The displayed channel. | ||
/// </summary> | ||
public CrossoverType Type => type; | ||
|
||
/// <inheritdoc/> | ||
public override string ToString() => Type.Translate(); | ||
} | ||
} |
Oops, something went wrong.