mirror of
https://github.com/claunia/cuetools.net.git
synced 2025-12-16 10:04:24 +00:00
154 lines
4.2 KiB
C#
154 lines
4.2 KiB
C#
// The following code was generated by Microsoft Visual Studio 2005.
|
|
// The test owner should check each test for validity.
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
using System;
|
|
using System.Text;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using CUETools.Codecs;
|
|
using CUETools.Codecs.FLAKE;
|
|
namespace CUETools.TestCodecs
|
|
{
|
|
/// <summary>
|
|
///This is a test class for CUETools.Codecs.FLAKE.FlakeWriter and is intended
|
|
///to contain all CUETools.Codecs.FLAKE.FlakeWriter Unit Tests
|
|
///</summary>
|
|
[TestClass()]
|
|
public class FlakeWriterTest
|
|
{
|
|
|
|
|
|
private TestContext testContextInstance;
|
|
|
|
/// <summary>
|
|
///Gets or sets the test context which provides
|
|
///information about and functionality for the current test run.
|
|
///</summary>
|
|
public TestContext TestContext
|
|
{
|
|
get
|
|
{
|
|
return testContextInstance;
|
|
}
|
|
set
|
|
{
|
|
testContextInstance = value;
|
|
}
|
|
}
|
|
#region Additional test attributes
|
|
//
|
|
//You can use the following additional attributes as you write your tests:
|
|
//
|
|
//Use ClassInitialize to run code before running the first test in the class
|
|
//
|
|
//[ClassInitialize()]
|
|
//public static void MyClassInitialize(TestContext testContext)
|
|
//{
|
|
//}
|
|
//
|
|
//Use ClassCleanup to run code after all tests in a class have run
|
|
//
|
|
//[ClassCleanup()]
|
|
//public static void MyClassCleanup()
|
|
//{
|
|
//}
|
|
//
|
|
//Use TestInitialize to run code before running each test
|
|
//
|
|
//[TestInitialize()]
|
|
//public void MyTestInitialize()
|
|
//{
|
|
//}
|
|
//
|
|
//Use TestCleanup to run code after each test has run
|
|
//
|
|
//[TestCleanup()]
|
|
//public void MyTestCleanup()
|
|
//{
|
|
//}
|
|
//
|
|
#endregion
|
|
|
|
|
|
/// <summary>
|
|
///A test for FlakeWriter (string, int, int, int, Stream)
|
|
///</summary>
|
|
[TestMethod()]
|
|
public void ConstructorTest()
|
|
{
|
|
AudioBuffer buff = WAVReader.ReadAllSamples("test.wav", null);
|
|
FlakeWriter target;
|
|
|
|
target = new FlakeWriter("flakewriter0.flac", null, buff.PCM);
|
|
target.Padding = 1;
|
|
target.DoSeekTable = false;
|
|
//target.Vendor = "CUETools";
|
|
//target.CreationTime = DateTime.Parse("15 Aug 1976");
|
|
target.FinalSampleCount = buff.Length;
|
|
target.Write(buff);
|
|
target.Close();
|
|
CollectionAssert.AreEqual(File.ReadAllBytes("flake.flac"), File.ReadAllBytes("flakewriter0.flac"), "flakewriter0.flac doesn't match.");
|
|
|
|
target = new FlakeWriter("flakewriter1.flac", null, buff.PCM);
|
|
target.Padding = 1;
|
|
target.DoSeekTable = false;
|
|
//target.Vendor = "CUETools";
|
|
//target.CreationTime = DateTime.Parse("15 Aug 1976");
|
|
target.Write(buff);
|
|
target.Close();
|
|
CollectionAssert.AreEqual(File.ReadAllBytes("flake.flac"), File.ReadAllBytes("flakewriter1.flac"), "flakewriter1.flac doesn't match.");
|
|
}
|
|
|
|
public static unsafe void
|
|
compute_schur_reflection(/*const*/ double* autoc, uint max_order,
|
|
double* dreff/*[][MAX_LPC_ORDER]*/, double* err)
|
|
{
|
|
float* gen0 = stackalloc float[lpc.MAX_LPC_ORDER];
|
|
float* gen1 = stackalloc float[lpc.MAX_LPC_ORDER];
|
|
|
|
// Schur recursion
|
|
for (uint i = 0; i < max_order; i++)
|
|
gen0[i] = gen1[i] = (float)autoc[i + 1];
|
|
float error = (float)autoc[0];
|
|
|
|
for (uint i = 0; i < max_order; i++)
|
|
{
|
|
float reff = -gen1[0] / error;
|
|
error += gen1[0] * reff;
|
|
|
|
for (uint j = 0; j < max_order - i - 1; j++)
|
|
{
|
|
gen1[j] = gen1[j + 1] + reff * gen0[j];
|
|
gen0[j] = gen1[j + 1] * reff + gen0[j];
|
|
}
|
|
|
|
dreff[i] = reff;
|
|
err[i] = error;
|
|
}
|
|
}
|
|
|
|
|
|
[TestMethod()]
|
|
public unsafe void LPCTest()
|
|
{
|
|
double* autoc = stackalloc double[9];
|
|
double* reff = stackalloc double[8];
|
|
double* err = stackalloc double[8];
|
|
float* lpcs = stackalloc float[9 * lpc.MAX_LPC_ORDER];
|
|
autoc[0] = 177286873088.0;
|
|
autoc[1] = 177010016256.0;
|
|
autoc[2] = 176182624256.0;
|
|
autoc[3] = 174806581248.0;
|
|
autoc[4] = 172888768512.0;
|
|
autoc[5] = 170436820992.0;
|
|
autoc[6] = 167460765696.0;
|
|
autoc[7] = 163973169152.0;
|
|
autoc[8] = 159987859456.0;
|
|
|
|
compute_schur_reflection(autoc, 8, reff, err);
|
|
lpc.compute_lpc_coefs(8, reff, lpcs);
|
|
Assert.IsTrue(lpcs[7 * lpc.MAX_LPC_ORDER] < 3000);
|
|
}
|
|
}
|
|
}
|