static void RunSpeachFrequencyFilters(Vector it, int j, double vol = 0.01, int dbMin = -20, int dbMax = +20) { bool IsAudible(double f) { if ((f >= 8.1 && f <= 16743.9)) { return(true); } return(false); } bool pass = true; if (!IsAudible(it.Axis[j].Im)) { pass = false; } if (it.Axis[j].Re <= 0.01) { pass = false; } if (pass) { var n = Envelopes.MIDI2NOTE(Envelopes.FREQ2MIDI(it.Axis[j].Im)); if (string.IsNullOrWhiteSpace(n)) { pass = false; } if (n == null || (!n.Contains("3") && !n.Contains("4") && !n.Contains("5") && !n.Contains("6"))) { pass = false; } if (pass && it.Axis[j].Re > 0) { var dB = Envelopes.dB(it.Axis[j].Re); if (dB <= dbMin || dB >= dbMax) { pass = false; } } } if (!pass) { it.Axis[j].Re = 0; } }
public static void SaveMidi(Vector[] Model, string fmt, string outputFilePath, int offset, int len) { Console.Write($"\r\nSaving: {outputFilePath}...\r\n"); using (var stream = new FileStream(outputFilePath, FileMode.Create, FileAccess.Write, FileShare.Read)) { int i = 0; string s; s = $"{fmt} " + $"⁞ {System.Ai.CBOW.DIMS}\r\n"; byte[] bytes = Encoding.UTF8.GetBytes(s); stream.Write(bytes, 0, bytes.Length); for (int sample = offset; sample < (offset + len); sample++) { Vector it = Model[sample]; if (it == null) { // s = "𝆕 ⁞ 0.00000±i0\r\n"; // bytes = Encoding.UTF8.GetBytes(s); // stream.Write( // bytes, // 0, // bytes.Length); // i++; } else { var line = new StringBuilder(); Complex[] axis = it.Axis; if (axis != null) { for (var j = 0; j < axis.Length; j++) { var n = Envelopes.MIDI2NOTE(j); if (string.IsNullOrWhiteSpace(n)) { n = axis[j].Im.ToString(); } if (axis[j].Re > 0) { if (line.Length > 0) { line.Append(" "); } var dB = Envelopes.dB(axis[j].Re); var sign = dB < 0 ? "-" : "+"; line.Append(n + sign + "i" + Math.Abs(dB).ToString()); } } } string score = it.Score.ToString(); if (line.Length > 0) { s = $"{it.Id} ⁞ {score} ⁞ {line.ToString()}\r\n"; } else { s = $"{it.Id} ⁞ {score}\r\n"; } bytes = Encoding.UTF8.GetBytes(s); stream.Write( bytes, 0, bytes.Length); i++; } } } Console.Write("\r\nReady!\r\n"); }