Skip to content

Commit

Permalink
Allow convolution filter generation for unfiltered channels
Browse files Browse the repository at this point in the history
  • Loading branch information
VoidXH committed Dec 13, 2023
1 parent 8694503 commit cd0a336
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,13 @@ public EqualizerFilterSet(ReferenceChannel[] channels, int sampleRate) : base(sa
public override MultichannelWaveform GetConvolutionFilter(int sampleRate, int convolutionLength) {
float[][] result = new float[Channels.Length][];
for (int i = 0; i < result.Length; i++) {
result[i] = ((EqualizerChannelData)Channels[i]).curve.GetConvolution(sampleRate, convolutionLength);
Equalizer curve = ((EqualizerChannelData)Channels[i]).curve;
if (curve != null) {
result[i] = curve.GetConvolution(sampleRate, convolutionLength);
} else {
result[i] = new float[convolutionLength];
result[i][0] = 1; // Dirac-delta, can be delayed
}
WaveformUtils.Delay(result[i], Channels[i].delaySamples);
}
return new MultichannelWaveform(result);
Expand Down
15 changes: 11 additions & 4 deletions Cavern.QuickEQ.Format/FilterSet/EqualizerAPOEqualizerFilterSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,21 @@ public override void Export(string path) {

for (int channel = 0; channel < Channels.Length; channel++) {
EqualizerChannelData channelRef = (EqualizerChannelData)Channels[channel];
result.Add("Channel: " + GetLabel(channel));
if (channelRef.gain != 0) {
bool hasGain = channelRef.gain != 0,
hasDelay = channelRef.delaySamples != 0,
hasEQ = channelRef.curve != null;
if (hasGain || hasDelay || hasEQ) {
result.Add("Channel: " + GetLabel(channel));
}
if (hasGain) {
result.Add($"Preamp: {channelRef.gain.ToString(CultureInfo.InvariantCulture)} dB");
}
if (channelRef.delaySamples != 0) {
if (hasDelay) {
result.Add($"Delay: {GetDelay(channel)} ms");
}
result.Add(channelRef.curve.ExportToEqualizerAPO());
if (hasEQ) {
result.Add(channelRef.curve.ExportToEqualizerAPO());
}
}

string polarity = EqualizerAPOUtils.GetPolarityLine(Channels.Select(x => ((EqualizerChannelData)x).switchPolarity).ToArray());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class IIRFilterSet_Tests {
public void Simulation() {
IIRFilterSet testSet = new IIRFilterSet(1, Consts.sampleRate);
Lowpass filter = new Lowpass(Consts.sampleRate, Consts.sampleRate >> 2, QFactor.reference);
testSet.SetupChannel(0, new BiquadFilter[] { filter });
testSet.SetupChannel(0, [filter]);
MultichannelWaveform fir = testSet.GetConvolutionFilter(Consts.sampleRate, Consts.convolutionLength);
fir[0].InPlaceFFT();
TestUtils.AssertDecrease(fir[0], 0, Consts.convolutionLength / 2, Consts.delta);
Expand Down

0 comments on commit cd0a336

Please sign in to comment.