Skip to content

Commit

Permalink
Fixed 7-band YPAO filter set variant
Browse files Browse the repository at this point in the history
  • Loading branch information
VoidXH committed Mar 30, 2024
1 parent 49f4ec7 commit 3c4c9ba
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 33 deletions.
2 changes: 2 additions & 0 deletions Cavern.QuickEQ.Format/FilterSet/BaseClasses/FilterSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public static FilterSet Create(FilterSetTarget device, int channels, int sampleR
FilterSetTarget.MultEQXRaw => new MultEQXRawFilterSet(channels, sampleRate),
FilterSetTarget.MultEQXTarget => new MultEQXTargetFilterSet(channels, sampleRate),
FilterSetTarget.YPAO => new YPAOFilterSet(channels, sampleRate),
FilterSetTarget.YPAOLite => new YPAOLiteFilterSet(channels, sampleRate),
_ => throw new NotSupportedException()
};
}
Expand Down Expand Up @@ -137,6 +138,7 @@ public static FilterSet Create(FilterSetTarget device, ReferenceChannel[] channe
FilterSetTarget.MultEQXRaw => new MultEQXRawFilterSet(channels, sampleRate),
FilterSetTarget.MultEQXTarget => new MultEQXTargetFilterSet(channels, sampleRate),
FilterSetTarget.YPAO => new YPAOFilterSet(channels, sampleRate),
FilterSetTarget.YPAOLite => new YPAOLiteFilterSet(channels, sampleRate),
_ => throw new NotSupportedException()
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ public enum FilterSetTarget {
/// Processors supporting the latest YPAO with additional fine tuning PEQs.
/// </summary>
YPAO,
/// <summary>
/// Older Yamaha processors with fixed 7 bands.
/// </summary>
YPAOLite,
}

/// <summary>
Expand Down Expand Up @@ -161,7 +165,8 @@ public static class FilterSetTargetExtensions {
FilterSetTarget.MultEQX => "MultEQ-X - MQX file",
FilterSetTarget.MultEQXRaw => "MultEQ-X - Peaking EQ",
FilterSetTarget.MultEQXTarget => "MultEQ-X - Filter curves",
FilterSetTarget.YPAO => "YPAO",
FilterSetTarget.YPAO => "YPAO - free bands",
FilterSetTarget.YPAOLite => "YPAO - fixed bands",
_ => throw new NotSupportedException()
};
}
Expand Down
19 changes: 11 additions & 8 deletions Cavern.QuickEQ.Format/FilterSet/DiracLiveBassControlFilterSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,20 @@ public override void Export(string path) {
}
}

/// <summary>
/// Extracted channel pairs are for memory optimization.
/// </summary>
static readonly (string name, ReferenceChannel[] channels)
fronts = ("Fronts", new[] { ReferenceChannel.FrontLeft, ReferenceChannel.FrontRight }),
wides = ("Wide Surrounds", new[] { ReferenceChannel.WideLeft, ReferenceChannel.WideRight }),
sides = ("Side Surrounds", new[] { ReferenceChannel.SideLeft, ReferenceChannel.SideRight }),
rears = ("Rear Surrounds", new[] { ReferenceChannel.RearLeft, ReferenceChannel.RearRight });

/// <summary>
/// The channels that are combined into one EQ group for DLBC versions where the height pairs are separate groups.
/// </summary>
static readonly (string name, ReferenceChannel[] channels)[] groupsWithSeparateHeights = {
("Fronts", new[] { ReferenceChannel.FrontLeft, ReferenceChannel.FrontRight }),
("Wide Surrounds", new[] { ReferenceChannel.WideLeft, ReferenceChannel.WideRight }),
("Side Surrounds", new[] { ReferenceChannel.SideLeft, ReferenceChannel.SideRight }),
("Rear Surrounds", new[] { ReferenceChannel.RearLeft, ReferenceChannel.RearRight }),
fronts, wides, sides, rears,
("Front Heights", new[] { ReferenceChannel.TopFrontLeft, ReferenceChannel.TopFrontRight }),
("Side Heights", new[] { ReferenceChannel.TopSideLeft, ReferenceChannel.TopSideRight }),
("Rear Heights", new[] { ReferenceChannel.TopRearLeft, ReferenceChannel.TopRearRight })
Expand All @@ -85,10 +91,7 @@ static readonly (string name, ReferenceChannel[] channels)[] groupsWithSeparateH
/// The channels that are combined into one EQ group for DLBC versions where there are no different height pair groups.
/// </summary>
static readonly (string name, ReferenceChannel[] channels)[] groupsWithCombinedHeights = {
("Fronts", new[] { ReferenceChannel.FrontLeft, ReferenceChannel.FrontRight }),
("Wide Surrounds", new[] { ReferenceChannel.WideLeft, ReferenceChannel.WideRight }),
("Side Surrounds", new[] { ReferenceChannel.SideLeft, ReferenceChannel.SideRight }),
("Rear Surrounds", new[] { ReferenceChannel.RearLeft, ReferenceChannel.RearRight }),
fronts, wides, sides, rears,
("Heights", new[] { ReferenceChannel.TopFrontLeft, ReferenceChannel.TopFrontCenter, ReferenceChannel.TopFrontRight,
ReferenceChannel.TopSideLeft, ReferenceChannel.GodsVoice, ReferenceChannel.TopSideRight,
ReferenceChannel.TopRearLeft, ReferenceChannel.TopRearCenter, ReferenceChannel.TopRearRight }),
Expand Down
45 changes: 38 additions & 7 deletions Cavern.QuickEQ.Format/FilterSet/MultibandPEQFilterSet.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.IO;

using Cavern.Channels;
using Cavern.Filters;
using Cavern.QuickEQ.Equalization;

Expand All @@ -9,6 +10,17 @@ namespace Cavern.Format.FilterSet {
/// Exports a traditional multiband eqalizer with constant bandwidth bands.
/// </summary>
public class MultibandPEQFilterSet : IIRFilterSet {
/// <inheritdoc/>
public override double MinGain => -12;

/// <inheritdoc/>
public override double MaxGain => 6;

/// <summary>
/// Limit the number of bands exported for the LFE channel.
/// </summary>
protected int LFEBands { get; set; }

/// <summary>
/// Frequency of the first exported band.
/// </summary>
Expand All @@ -17,7 +29,7 @@ public class MultibandPEQFilterSet : IIRFilterSet {
/// <summary>
/// Number of bands for each octave.
/// </summary>
readonly int bandsPerOctave;
readonly double bandsPerOctave;

/// <summary>
/// Number of total bands.
Expand All @@ -32,20 +44,37 @@ public class MultibandPEQFilterSet : IIRFilterSet {
/// <param name="firstBand">Frequency of the first exported band</param>
/// <param name="bandsPerOctave">Number of bands for each octave</param>
/// <param name="bandCount">Number of total bands</param>
public MultibandPEQFilterSet(int channels, int sampleRate, double firstBand, int bandsPerOctave, int bandCount) :
public MultibandPEQFilterSet(int channels, int sampleRate, double firstBand, double bandsPerOctave, int bandCount) :
base(channels, sampleRate) {
this.firstBand = firstBand;
this.bandsPerOctave = bandsPerOctave;
this.bandCount = bandCount;
LFEBands = bandCount;
}

/// <summary>
/// Construct a traditional multiband eqalizer with constant bandwidth bands.
/// </summary>
/// <param name="channels">Channels in the target system</param>
/// <param name="sampleRate">Filter sample rate</param>
/// <param name="firstBand">Frequency of the first exported band</param>
/// <param name="bandsPerOctave">Number of bands for each octave</param>
/// <param name="bandCount">Number of total bands</param>
public MultibandPEQFilterSet(ReferenceChannel[] channels, int sampleRate, double firstBand, double bandsPerOctave, int bandCount) :
base(channels, sampleRate) {
this.firstBand = firstBand;
this.bandsPerOctave = bandsPerOctave;
this.bandCount = bandCount;
LFEBands = bandCount;
}

/// <summary>
/// Create the filters that should be used when setting up a channel.
/// </summary>
public PeakingEQ[] CalculateFilters(Equalizer targetToReach) {
PeakingEQ[] result = new PeakingEqualizer(targetToReach) {
MinGain = -12,
MaxGain = 6
MinGain = MinGain,
MaxGain = MaxGain
}.GetPeakingEQ(SampleRate, firstBand, bandsPerOctave, bandCount);

IReadOnlyList<Band> bands = targetToReach.Bands;
Expand All @@ -69,14 +98,16 @@ public override void Export(string path) {
for (int i = 0; i < Channels.Length; i++) {
IIRChannelData channelRef = (IIRChannelData)Channels[i];
result.Add(string.Empty);
result.Add(channelRef.name);
result.Add(new string('=', channelRef.name.Length));
string chName = GetLabel(i);
result.Add(chName);
result.Add(new string('=', chName.Length));
RootFileExtension(i, result);
if (channelRef.delaySamples != 0) {
result.Add("Delay: " + GetDelay(i).ToString("0.00 ms"));
}
BiquadFilter[] bands = channelRef.filters;
for (int j = 0; j < bands.Length; j++) {
int bandc = channelRef.reference != ReferenceChannel.ScreenLFE ? bands.Length : LFEBands;
for (int j = 0; j < bandc; j++) {
result.Add($"{bands[j].CenterFreq:0} Hz:\t{bands[j].Gain:0.00} dB");
}
}
Expand Down
25 changes: 11 additions & 14 deletions Cavern.QuickEQ.Format/FilterSet/YPAOFilterSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,28 @@

namespace Cavern.Format.FilterSet {
/// <summary>
/// Filter set to fine tune an existing YPAO calibration with.
/// Filter set limited to 1/3 octave band choices for some versions of YPAO.
/// </summary>
public class YPAOFilterSet : IIRFilterSet {
/// <summary>
/// Maximum number of peaking EQ filters per channel.
/// </summary>
/// <inheritdoc/>
public override int Bands => 7;

/// <summary>
/// Maximum gain of a single peaking EQ band in decibels.
/// </summary>
/// <inheritdoc/>
public override double MaxGain => 6;

/// <summary>
/// Round the gains to this precision.
/// </summary>
/// <inheritdoc/>
public override double MinGain => -6;

/// <inheritdoc/>
public override double GainPrecision => .5f;

/// <summary>
/// Filter set to fine tune an existing YPAO calibration with.
/// Filter set limited to 1/3 octave band choices for some versions of YPAO.
/// </summary>
public YPAOFilterSet(int channels, int sampleRate) : base(channels, sampleRate) { }

/// <summary>
/// Filter set to fine tune an existing YPAO calibration with.
/// Filter set limited to 1/3 octave band choices for some versions of YPAO.
/// </summary>
public YPAOFilterSet(ReferenceChannel[] channels, int sampleRate) : base(channels, sampleRate) { }

Expand All @@ -46,7 +43,7 @@ public override void Export(string path) {
BiquadFilter[] filters = ((IIRChannelData)Channels[i]).filters;
for (int j = 0; j < filters.Length;) {
BiquadFilter filter = filters[j];
result.Add($"Filter {++j} - Frequency: {bands.Nearest((float)filter.CenterFreq)}, Q factor: " +
result.Add($"Filter {++j} - Frequency: {frequencies.Nearest((float)filter.CenterFreq)}, Q factor: " +
$"{qFactors.Nearest((float)filter.Q)}, gain: {filter.Gain}");
}
}
Expand All @@ -56,7 +53,7 @@ public override void Export(string path) {
/// <summary>
/// All the possible bands that can be selected for YPAO. These are 1/3 octaves apart.
/// </summary>
static readonly float[] bands = {
static readonly float[] frequencies = {
39.4f, 49.6f, 62.5f, 78.7f, 99.2f, 125.0f, 157.5f, 198.4f, 250, 315, 396.9f, 500, 630, 793.7f,
1000, 1260, 1590, 2000, 2520, 3170, 4000, 5040, 6350, 8000, 10100, 12700, 16000
};
Expand Down
21 changes: 21 additions & 0 deletions Cavern.QuickEQ.Format/FilterSet/YPAOLiteFilterSet.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Cavern.Channels;

namespace Cavern.Format.FilterSet {
/// <summary>
/// Filter set limited to 4/3 octave band choices for some versions of YPAO.
/// </summary>
public class YPAOLiteFilterSet : MultibandPEQFilterSet {
/// <inheritdoc/>
public override double MinGain => -6;

/// <summary>
/// Filter set limited to 4/3 octave band choices for some versions of YPAO.
/// </summary>
public YPAOLiteFilterSet(int channels, int sampleRate) : base(channels, sampleRate, 62.5, .75, 7) => LFEBands = 2;

/// <summary>
/// Filter set limited to 4/3 octave band choices for some versions of YPAO.
/// </summary>
public YPAOLiteFilterSet(ReferenceChannel[] channels, int sampleRate) : base(channels, sampleRate, 62.5, .75, 7) => LFEBands = 2;
}
}
2 changes: 1 addition & 1 deletion Cavern.QuickEQ/Equalization/PeakingEqualizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public PeakingEQ[] GetPeakingEQ(int sampleRate) {
/// <summary>
/// Create a peaking EQ filter set with constant bandwidth between the frequencies. This mimics legacy x-band EQs.
/// </summary>
public PeakingEQ[] GetPeakingEQ(int sampleRate, double firstBand, int bandsPerOctave, int bands) {
public PeakingEQ[] GetPeakingEQ(int sampleRate, double firstBand, double bandsPerOctave, int bands) {
float[] target = source.Visualize(MinFrequency, MaxFrequency, 1024);
PeakingEQ[] result = new PeakingEQ[bands];
double bandwidth = 1.0 / bandsPerOctave;
Expand Down
5 changes: 3 additions & 2 deletions Cavern/Remapping/DisassemblerUpmixer.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Cavern.Filters;
using System.Numerics;
using System.Numerics;

using Cavern.Filters;

namespace Cavern.Remapping {
/// <summary>
Expand Down

0 comments on commit 3c4c9ba

Please sign in to comment.