Skip to content

Commit

Permalink
Fixed some warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
filoe committed Feb 5, 2017
1 parent c63df15 commit 55aad5a
Show file tree
Hide file tree
Showing 13 changed files with 347 additions and 285 deletions.
7 changes: 7 additions & 0 deletions CSCore/CSCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,19 @@
<Compile Include="DMO\OutputStreamInfoFlags.cs" />
<Compile Include="DMO\ProcessOutputFlags.cs" />
<Compile Include="DMO\SetTypeFlags.cs" />
<Compile Include="DSP\BandpassFilter.cs" />
<Compile Include="DSP\BiQuad.cs" />
<Compile Include="DSP\ChannelMatrixElement.cs" />
<Compile Include="DSP\FastFourierTransformation.cs" />
<Compile Include="DSP\FftProvider.cs" />
<Compile Include="DSP\FftMode.cs" />
<Compile Include="DSP\FftSize.cs" />
<Compile Include="DSP\HighpassFilter.cs" />
<Compile Include="DSP\HighShelfFilter.cs" />
<Compile Include="DSP\LowpassFilter.cs" />
<Compile Include="DSP\LowShelfFilter.cs" />
<Compile Include="DSP\NotchFilter.cs" />
<Compile Include="DSP\PeakFilter.cs" />
<Compile Include="DSP\PitchShifterInternal.cs" />
<Compile Include="FluentExtensions.cs" />
<Compile Include="GlobalSuppressions.cs" />
Expand Down
4 changes: 2 additions & 2 deletions CSCore/Codecs/AIFF/AiffBinaryReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ private double ConvertFromIeeeExtended(byte[] bytes)
hiMant = ((ulong) (bytes[2] & 0xFF) << 24)
| ((ulong) (bytes[3] & 0xFF) << 16)
| ((ulong) (bytes[4] & 0xFF) << 8)
| ((ulong) (bytes[5] & 0xFF));
| (ulong) (bytes[5] & 0xFF);
loMant = ((ulong) (bytes[6] & 0xFF) << 24)
| ((ulong) (bytes[7] & 0xFF) << 16)
| ((ulong) (bytes[8] & 0xFF) << 8)
| ((ulong) (bytes[9] & 0xFF));
| (ulong) (bytes[9] & 0xFF);

if (expon == 0 && hiMant == 0 && loMant == 0)
f = 0;
Expand Down
5 changes: 3 additions & 2 deletions CSCore/Codecs/FLAC/FlacFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Runtime.InteropServices;

Expand All @@ -14,7 +13,9 @@ namespace CSCore.Codecs.FLAC
public sealed partial class FlacFrame : IDisposable
{
private List<FlacSubFrameData> _subFrameData;
private ReadOnlyCollection<FlacSubFrameBase> _subFrames;
#if FLAC_DEBUG
private System.Collections.ObjectModel.ReadOnlyCollection<FlacSubFrameBase> _subFrames;
#endif
private Stream _stream;
private FlacMetadataStreamInfo _streamInfo;

Expand Down
2 changes: 1 addition & 1 deletion CSCore/Codecs/WAV/WaveFileChunk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public WaveFileChunk(BinaryReader reader)
/// <summary>
/// Gets the data size of the chunk.
/// </summary>
public uint ChunkDataSize { get; private set; }
public long ChunkDataSize { get; private set; }

/// <summary>
/// Parses the <paramref name="stream" /> and returns a <see cref="WaveFileChunk" />. Note that the position of the
Expand Down
38 changes: 38 additions & 0 deletions CSCore/DSP/BandpassFilter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* These implementations are based on http://www.earlevel.com/main/2011/01/02/biquad-formulas/
*/

using System;

namespace CSCore.DSP
{
/// <summary>
/// Used to apply a bandpass-filter to a signal.
/// </summary>
public class BandpassFilter : BiQuad
{
/// <summary>
/// Initializes a new instance of the <see cref="BandpassFilter"/> class.
/// </summary>
/// <param name="sampleRate">The sample rate.</param>
/// <param name="frequency">The filter's corner frequency.</param>
public BandpassFilter(int sampleRate, double frequency)
: base(sampleRate, frequency)
{
}

/// <summary>
/// Calculates all coefficients.
/// </summary>
protected override void CalculateBiQuadCoefficients()
{
double k = Math.Tan(Math.PI * Frequency / SampleRate);
double norm = 1 / (1 + k / Q + k * k);
A0 = k / Q * norm;
A1 = 0;
A2 = -A0;
B1 = 2 * (k * k - 1) * norm;
B2 = (1 - k / Q + k * k) * norm;
}
}
}
280 changes: 0 additions & 280 deletions CSCore/DSP/BiQuad.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,284 +178,4 @@ public void Process(float[] input)
/// </summary>
protected abstract void CalculateBiQuadCoefficients();
}

/// <summary>
/// Used to apply a lowpass-filter to a signal.
/// </summary>
public class LowpassFilter : BiQuad
{
/// <summary>
/// Initializes a new instance of the <see cref="LowpassFilter"/> class.
/// </summary>
/// <param name="sampleRate">The sample rate.</param>
/// <param name="frequency">The filter's corner frequency.</param>
public LowpassFilter(int sampleRate, double frequency)
: base(sampleRate, frequency)
{
}

/// <summary>
/// Calculates all coefficients.
/// </summary>
protected override void CalculateBiQuadCoefficients()
{
double k = Math.Tan(Math.PI * Frequency / SampleRate);
var norm = 1 / (1 + k / Q + k * k);
A0 = k * k * norm;
A1 = 2 * A0;
A2 = A0;
B1 = 2 * (k * k - 1) * norm;
B2 = (1 - k / Q + k * k) * norm;
}
}

/// <summary>
/// Used to apply a highpass-filter to a signal.
/// </summary>
public class HighpassFilter : BiQuad
{
private int p1;
private double p2;

/// <summary>
/// Initializes a new instance of the <see cref="HighpassFilter"/> class.
/// </summary>
/// <param name="sampleRate">The sample rate.</param>
/// <param name="frequency">The filter's corner frequency.</param>
public HighpassFilter(int sampleRate, double frequency)
: base(sampleRate, frequency)
{
}

/// <summary>
/// Calculates all coefficients.
/// </summary>
protected override void CalculateBiQuadCoefficients()
{
double k = Math.Tan(Math.PI * Frequency / SampleRate);
var norm = 1 / (1 + k / Q + k * k);
A0 = 1 * norm;
A1 = -2 * A0;
A2 = A0;
B1 = 2 * (k * k - 1) * norm;
B2 = (1 - k / Q + k * k) * norm;
}
}

/// <summary>
/// Used to apply a bandpass-filter to a signal.
/// </summary>
public class BandpassFilter : BiQuad
{
/// <summary>
/// Initializes a new instance of the <see cref="BandpassFilter"/> class.
/// </summary>
/// <param name="sampleRate">The sample rate.</param>
/// <param name="frequency">The filter's corner frequency.</param>
public BandpassFilter(int sampleRate, double frequency)
: base(sampleRate, frequency)
{
}

/// <summary>
/// Calculates all coefficients.
/// </summary>
protected override void CalculateBiQuadCoefficients()
{
double k = Math.Tan(Math.PI * Frequency / SampleRate);
double norm = 1 / (1 + k / Q + k * k);
A0 = k / Q * norm;
A1 = 0;
A2 = -A0;
B1 = 2 * (k * k - 1) * norm;
B2 = (1 - k / Q + k * k) * norm;
}
}

/// <summary>
/// Used to apply a notch-filter to a signal.
/// </summary>
public class NotchFilter : BiQuad
{
/// <summary>
/// Initializes a new instance of the <see cref="NotchFilter"/> class.
/// </summary>
/// <param name="sampleRate">The sample rate.</param>
/// <param name="frequency">The filter's corner frequency.</param>
public NotchFilter(int sampleRate, double frequency)
: base(sampleRate, frequency)
{
}

/// <summary>
/// Calculates all coefficients.
/// </summary>
protected override void CalculateBiQuadCoefficients()
{
double k = Math.Tan(Math.PI * Frequency / SampleRate);
double norm = 1 / (1 + k / Q + k * k);
A0 = (1 + k * k) * norm;
A1 = 2 * (k * k - 1) * norm;
A2 = A0;
B1 = A1;
B2 = (1 - k / Q + k * k) * norm;
}
}

/// <summary>
/// Used to apply a lowshelf-filter to a signal.
/// </summary>
public class LowShelfFilter : BiQuad
{
/// <summary>
/// Initializes a new instance of the <see cref="LowShelfFilter"/> class.
/// </summary>
/// <param name="sampleRate">The sample rate.</param>
/// <param name="frequency">The filter's corner frequency.</param>
/// <param name="gainDB">Gain value in dB.</param>
public LowShelfFilter(int sampleRate, double frequency, double gainDB)
: base(sampleRate, frequency)
{
GainDB = gainDB;
}

/// <summary>
/// Calculates all coefficients.
/// </summary>
protected override void CalculateBiQuadCoefficients()
{
const double sqrt2 = 1.4142135623730951;
double k = Math.Tan(Math.PI * Frequency / SampleRate);
double v = Math.Pow(10, Math.Abs(GainDB) / 20.0);
double norm;
if (GainDB >= 0)
{ // boost
norm = 1 / (1 + sqrt2 * k + k * k);
A0 = (1 + Math.Sqrt(2 * v) * k + v * k * k) * norm;
A1 = 2 * (v * k * k - 1) * norm;
A2 = (1 - Math.Sqrt(2 * v) * k + v * k * k) * norm;
B1 = 2 * (k * k - 1) * norm;
B2 = (1 - sqrt2 * k + k * k) * norm;
}
else
{ // cut
norm = 1 / (1 + Math.Sqrt(2 * v) * k + v * k * k);
A0 = (1 + sqrt2 * k + k * k) * norm;
A1 = 2 * (k * k - 1) * norm;
A2 = (1 - sqrt2 * k + k * k) * norm;
B1 = 2 * (v * k * k - 1) * norm;
B2 = (1 - Math.Sqrt(2 * v) * k + v * k * k) * norm;
}
}
}

/// <summary>
/// Used to apply a highshelf-filter to a signal.
/// </summary>
public class HighShelfFilter : BiQuad
{
/// <summary>
/// Initializes a new instance of the <see cref="HighShelfFilter"/> class.
/// </summary>
/// <param name="sampleRate">The sample rate.</param>
/// <param name="frequency">The filter's corner frequency.</param>
/// <param name="gainDB">Gain value in dB.</param>
public HighShelfFilter(int sampleRate, double frequency, double gainDB)
: base(sampleRate, frequency)
{
GainDB = gainDB;
}

/// <summary>
/// Calculates all coefficients.
/// </summary>
protected override void CalculateBiQuadCoefficients()
{
const double sqrt2 = 1.4142135623730951;
double k = Math.Tan(Math.PI * Frequency / SampleRate);
double v = Math.Pow(10, Math.Abs(GainDB) / 20.0);
double norm;
if (GainDB >= 0)
{ // boost
norm = 1 / (1 + sqrt2 * k + k * k);
A0 = (v + Math.Sqrt(2 * v) * k + k * k) * norm;
A1 = 2 * (k * k - v) * norm;
A2 = (v - Math.Sqrt(2 * v) * k + k * k) * norm;
B1 = 2 * (k * k - 1) * norm;
B2 = (1 - sqrt2 * k + k * k) * norm;
}
else
{ // cut
norm = 1 / (v + Math.Sqrt(2 * v) * k + k * k);
A0 = (1 + sqrt2 * k + k * k) * norm;
A1 = 2 * (k * k - 1) * norm;
A2 = (1 - sqrt2 * k + k * k) * norm;
B1 = 2 * (k * k - v) * norm;
B2 = (v - Math.Sqrt(2 * v) * k + k * k) * norm;
}
}
}

/// <summary>
/// Used to apply an peak-filter to a signal.
/// </summary>
public class PeakFilter : BiQuad
{
/// <summary>
/// Gets or sets the bandwidth.
/// </summary>
public double BandWidth
{
get { return Q; }
set
{
if (value <= 0)
throw new ArgumentOutOfRangeException("value");
Q = value;
}
}

/// <summary>
/// Initializes a new instance of the <see cref="PeakFilter"/> class.
/// </summary>
/// <param name="sampleRate">The sampleRate of the audio data to process.</param>
/// <param name="frequency">The center frequency to adjust.</param>
/// <param name="bandWidth">The bandWidth.</param>
/// <param name="peakGainDB">The gain value in dB.</param>
public PeakFilter(int sampleRate, double frequency, double bandWidth, double peakGainDB)
: base(sampleRate, frequency, bandWidth)
{
GainDB = peakGainDB;
}

/// <summary>
/// Calculates all coefficients.
/// </summary>
protected override void CalculateBiQuadCoefficients()
{
double norm;
double v = Math.Pow(10, Math.Abs(GainDB) / 20.0);
double k = Math.Tan(Math.PI * Frequency / SampleRate);
double q = Q;

if (GainDB >= 0) //boost
{
norm = 1 / (1 + 1 / q * k + k * k);
A0 = (1 + v / q * k + k * k) * norm;
A1 = 2 * (k * k - 1) * norm;
A2 = (1 - v / q * k + k * k) * norm;
B1 = A1;
B2 = (1 - 1 / q * k + k * k) * norm;
}
else //cut
{
norm = 1 / (1 + v / q * k + k * k);
A0 = (1 + 1 / q * k + k * k) * norm;
A1 = 2 * (k * k - 1) * norm;
A2 = (1 - 1 / q * k + k * k) * norm;
B1 = A1;
B2 = (1 - v / q * k + k * k) * norm;
}
}
}
}
Loading

0 comments on commit 55aad5a

Please sign in to comment.