public void WavOpusSimilarity() { string opusFingerprint; string pcmFingerprint; // cut out 30 second from the middle of the file var opusDataSection = new short[330750]; var pcmDataSection = new short[330750]; Buffer.BlockCopy(opusData, 330750, opusDataSection, 0, 330750); Buffer.BlockCopy(pcmData, 340775, pcmDataSection, 0, 330750); // starts 1 sec later than opus section // generate fingerprints var echoPrint = new CodeGen(); opusFingerprint = echoPrint.Generate(opusDataSection); pcmFingerprint = echoPrint.Generate(pcmDataSection); byte[] unbase64edOpusFingerprint = Convert.FromBase64String(opusFingerprint.Replace('-', '+').Replace('_', '/')); string unzippedOpusFingerprint = ZlibStream.UncompressString(unbase64edOpusFingerprint); byte[] unbase64edPcmFingerprint = Convert.FromBase64String(pcmFingerprint.Replace('-', '+').Replace('_', '/')); string unzippedPcmFingerprint = ZlibStream.UncompressString(unbase64edPcmFingerprint); // compute Damereau-Levenshein Distance in absence of actual fingerprint matching algorithm int similarity = ComputeLevenshteinDistance(unzippedOpusFingerprint, unzippedPcmFingerprint); float averageDifferencePerCharacter = (float)similarity / (unzippedOpusFingerprint.Length + unzippedPcmFingerprint.Length / 2); Assert.Less(averageDifferencePerCharacter, 0.4); Assert.Greater(averageDifferencePerCharacter, 0.001); }
public void PcmDataFingerprintingGeneratedSomeData() { string pcmFingerprint; var echoPrint = new CodeGen(); pcmFingerprint = echoPrint.Generate(pcmData); Assert.Greater(pcmFingerprint.Length, 5000); }
public void OpusDataFingerprintingGeneratedSomeData() { string opusFingerprint; var echoPrint = new CodeGen(); opusFingerprint = echoPrint.Generate(opusData); Assert.Greater(opusFingerprint.Length, 5000); }
public static void Compile(string code, string outFileName) { //System.IO.DirectoryInfo d = new DirectoryInfo("E:\\Universidad\\4to\\compilacion 2\\testing"); //var files=d.GetFiles("*.cl"); //foreach (var file in files) //{ var t = Parse(code); if (t == null) { Console.ReadLine(); return; } var ast1 = t.GetAST1(); var semanticResults = SemantickCheck((COOLLenguage.SemanticCheck.AST1.Program)ast1); if (semanticResults.Item1 > 0) { Console.WriteLine("Compilation terminated because of semantic errors"); Console.ReadLine(); return; } var Context = semanticResults.Item2; //build ast to generate var table = MIPSCodeGenerator.SymbolUtils.IdTable; var astgenerator = (MIPSCodeGenerator.Program)ast1.GetAstCodeGenerator(table); var inheritance = new InheritanceTree(astgenerator); var Cg = new CodeGen(astgenerator, inheritance, new StreamWriter(outFileName)); Cg.Generate(); Console.WriteLine("Compilation terminated sucessfully"); Console.ReadLine(); }
public static void Main(string[] args) { if (args.Length == 0) { var assembly = Assembly.GetExecutingAssembly(); var resourceName = "ConsoleEchoPrintSharp.Resources.NIN-999999-11025.wav"; using (Stream stream = assembly.GetManifestResourceStream(resourceName)) using (BinaryReader reader = new BinaryReader(stream, System.Text.Encoding.ASCII)) { string chunkId = new string(reader.ReadChars(4)); UInt32 chunkSize = reader.ReadUInt32(); string riffType = new string(reader.ReadChars(4)); string fmtId = new string(reader.ReadChars(4)); UInt32 fmtSize = reader.ReadUInt32(); UInt16 formatTag = reader.ReadUInt16(); UInt16 channels = reader.ReadUInt16(); UInt32 samplesPerSec = reader.ReadUInt32(); UInt32 avgBytesPerSec = reader.ReadUInt32(); UInt16 blockAlign = reader.ReadUInt16(); UInt16 bitsPerSample = reader.ReadUInt16(); string dataID = new string(reader.ReadChars(4)); UInt32 dataSize = reader.ReadUInt32(); if (chunkId != "RIFF" || riffType != "WAVE" || fmtId != "fmt " || dataID != "data" || fmtSize != 16) { Console.WriteLine("Malformed WAV header"); return; } if (channels != 1 || samplesPerSec != 11025 || avgBytesPerSec != 22050 || blockAlign != 2 || bitsPerSample != 16 || formatTag != 1 || chunkSize < 48) { Console.WriteLine("Unexpected WAV format, need 11025 Hz mono 16 bit (little endian integers)"); return; } uint numberOfsamples = Math.Min(dataSize / 2, 330750); // max 30 seconds var pcmData = new Int16[numberOfsamples]; for (int i = 0; i < numberOfsamples; i++) { pcmData[i] = reader.ReadInt16(); } var echoPrint = new CodeGen(); Console.WriteLine(echoPrint.Generate(pcmData)); Console.WriteLine(""); Console.WriteLine("The above is the EchoPrint code for the song '999,999' by Nine Inch Nails."); Console.WriteLine("To generate codes for your own mp3s or wavs add them as parameters to "); Console.WriteLine("ConsoleEchoPrintSharp.exe in a command line or in the debug settings"); Console.WriteLine("or execution setting of the ConsoleEchoPrintSharp project."); Console.WriteLine("(mp3s only work on Windows, because NAudio depends on Msacm32.dll.)"); } } else { foreach (string audioFile in args) { if (audioFile.Length >= 4 && audioFile.Substring(audioFile.Length - 4).Equals(".wav", StringComparison.InvariantCultureIgnoreCase)) { using (WaveFileReader wav = new WaveFileReader(audioFile)) { using (WaveStream pcm = WaveFormatConversionStream.CreatePcmStream(wav)) { using (BinaryReader reader = new BinaryReader(pcm, System.Text.Encoding.ASCII)) { HandleFile(pcm, audioFile); } } } } else if (audioFile.Length >= 4 && audioFile.Substring(audioFile.Length - 4).Equals(".mp3", StringComparison.InvariantCultureIgnoreCase)) { try { using (Mp3FileReader mp3 = new Mp3FileReader(audioFile)) { using (WaveStream pcm = WaveFormatConversionStream.CreatePcmStream(mp3)) { HandleFile(pcm, audioFile); } } } catch (DllNotFoundException e) { Console.WriteLine("Sorry, a necessary dll is not found on your system. Here come the details:\r\n\r\n{0}", e); } }
public void CodeGen(String filename) { cg = new CodeGen(p.e, p.Functions, p.GlobalVars); cg.Generate(filename); }