public void InvalidRateChangeNegative() { var r = new SoxResampler(2.0, 1.0, 1, QualityRecipe.SOXR_HQ, QualityFlags.SOXR_VR); // A negative ratio is impossible r.SetRatio(-1.0, 0); }
public void CheckDelay() { var r = new SoxResampler(44100, 96000, 2); // When no samples have been fed to the resampler, there can't be an output delay Assert.AreEqual(0, r.GetOutputDelay(), "unexpected output delay"); }
public void DisposeTest() { var r = new SoxResampler(1.0, 1.0, 1); r.Dispose(); r.Dispose(); // call a second time to check for repeated calls working }
public void InvalidRateChangeAboveMax() { var r = new SoxResampler(2.0, 1.0, 1, QualityRecipe.SOXR_HQ, QualityFlags.SOXR_VR); // This ratio is invalid because it is higher than the max ratio specified in the constructor r.SetRatio(3.0, 0); }
public void IllegalRateChange() { var r = new SoxResampler(1.0, 1.0, 1); // This call is illegal because a fixed-rate resampler was instantiated r.SetRatio(2.0, 0); }
public void ProcessRateHalf() { var r = new SoxResampler(1.0d, 0.5d, 1); int inSize = 4 * 10; int outSize = 12; var sampleDataIn = new byte[inSize]; var sampleDataOut = new byte[outSize]; int inputLengthUsed = 0; int outputLengthGenerated = 0; int remainingIn = inSize; int totalIn = 0, totalOut = 0; do { r.Process(sampleDataIn, 0, remainingIn, sampleDataOut, 0, outSize, remainingIn == 0, out inputLengthUsed, out outputLengthGenerated); totalIn += inputLengthUsed; totalOut += outputLengthGenerated; remainingIn -= inputLengthUsed; }while (inputLengthUsed > 0 || outputLengthGenerated > 0); Assert.AreEqual(inSize, totalIn, "not all data has been read"); Assert.AreEqual(inSize / 2, totalOut, "not all data has been put out"); }
public void EngineReturnsString() { var r = new SoxResampler(44100, 96000, 2); string e = r.Engine; Assert.IsNotNull(e, "no engine string returned"); Console.WriteLine(e); }
public void VersionReturnsString() { var r = new SoxResampler(44100, 96000, 2); string v = r.Version; StringAssert.StartsWith(v, "libsoxr-", "invalid version string returned"); Console.WriteLine(v); }
private void SetupResampler() { if (soxr != null) { soxr.Dispose(); // delete previous resampler instance } Soxr.QualityRecipe qr = QualityRecipe.SOXR_HQ; Soxr.QualityFlags qf = QualityFlags.SOXR_ROLLOFF_SMALL; switch (quality) { case ResamplingQuality.VeryLow: qr = QualityRecipe.SOXR_QQ; break; case ResamplingQuality.Low: qr = QualityRecipe.SOXR_LQ; break; case ResamplingQuality.Medium: qr = QualityRecipe.SOXR_MQ; break; case ResamplingQuality.High: qr = QualityRecipe.SOXR_HQ; break; case ResamplingQuality.VeryHigh: qr = QualityRecipe.SOXR_VHQ; break; case ResamplingQuality.VariableRate: qr = QualityRecipe.SOXR_HQ; qf = QualityFlags.SOXR_VR; break; } double inputRate = sourceStream.Properties.SampleRate; double outputRate = properties.SampleRate; if (qf == QualityFlags.SOXR_VR) { // set max variable rate inputRate = 10.0; outputRate = 1.0; } soxr = new SoxResampler(inputRate, outputRate, properties.Channels, qr, qf); }
public void CreateAndDestroyLotsOfInstancesAndProcess() { var r = new SoxResampler(44100, 96000, 2); int count = 1000; var instances = new SoxResampler[count]; var dataIn = new byte[80000]; var dataOut = new byte[80000]; int readIn = 0, readOut = 0; for (int i = 0; i < count; i++) { instances[i] = new SoxResampler(5.0, 1.0, 2, QualityRecipe.SOXR_HQ, QualityFlags.SOXR_VR); instances[i].Process(dataIn, 0, dataIn.Length, dataOut, 0, dataOut.Length, false, out readIn, out readOut); } for (int i = 0; i < count; i++) { instances[i].Dispose(); } }
public static bool CheckSampleRateRatio(double ratio) { return(SoxResampler.CheckRatio(ratio)); }
public void ClearInternalState() { var r = new SoxResampler(44100, 96000, 2); r.Clear(); }
public void CreateInstance() { var r = new SoxResampler(44100, 96000, 2); Assert.IsNotNull(r); }
public void CreateInvalidVariableRateInstance() { var r = new SoxResampler(2.0, 1.0, 1, QualityRecipe.SOXR_LQ, QualityFlags.SOXR_VR); }
public void RateChange() { var r = new SoxResampler(2.0, 1.0, 1, QualityRecipe.SOXR_HQ, QualityFlags.SOXR_VR); r.SetRatio(1.5, 0); }