static void QuickPlay(TactUnit toPlay) { Sequencer sq = new Sequencer(1, 44100); sq.Push(toPlay); SoundPlayer sp = new SoundPlayer(); sp.Stream = sq.SnapshotStream; sp.Load(); sp.PlaySync(); }
public static void Process(string[] args, Byte speed, Note key, Byte keyOctave, Boolean ExporttoWAV = false, String ExportPath = "") { DefaultVowelLength = 0.125 / (1.0 * speed / 64); if (args.Length == 0) { Console.WriteLine("VOXEL v.0.3.1\n\nVOWELS:\n__ AH __ p(a)rk\n__ EH __ n(e)ck\n__ IY __ f(ee)l\n__ ER __ b(i)rd\n__ AE __ d(a)y\n__ AO __ t(a)lk\n__ AX __ b(u)dget\n__ IH __ p(i)ck\n__ UH __ p(u)t"); } else if (args.Length >= 3 && (args.Length - 1) % 2 == 0) { switch (args[0]) { case "-wav": { String ExportFile = args[1]; Process(CutArray <String>(args, 2), speed, key, keyOctave, true, ExportFile); break; } case "-speed": { Byte newSpeed = Byte.Parse(args[1]); Process(CutArray <String>(args, 2), newSpeed, key, keyOctave, ExporttoWAV, ExportPath); break; } } } else if (args.Length == 1) { Double plusTime = 0.0; List <TactUnit> tacts = new List <TactUnit>(); for (int i = 0; i < args[0].Length; i += 2) { Char first = args[0][i]; if (first == ' ') { TactUnit skip = new TactUnit(DefaultVowelLength / 2); tacts.Add(skip); i--; continue; } if (first == '.') { TactUnit skip = new TactUnit(DefaultVowelLength); tacts.Add(skip); i--; continue; } if (i == args[0].Length - 1) { break; } Char second = args[0][i + 1]; String phoneme = "" + first + second; TactUnit t = new TactUnit(phoneme, key, keyOctave, (Phonemes.IsVowel(phoneme) ? DefaultVowelLength : DefaultVowelLength / 4), 44100, 96); t.BeginningOffset = plusTime; plusTime += t.PlayTime; tacts.Add(t); } Sequencer sq = new Sequencer(1, 8000); for (int i = 0; i < tacts.Count; i++) { sq.Push(tacts[i]); if (i < tacts.Count - 1) { if (!tacts[i + 1].Blank && !tacts[i].Blank) { if (tacts[i + 1].Phoneme != tacts[1].Phoneme) { Transition conjoin = new Transition(tacts[i].Wave, tacts[i + 1].Wave, DefaultVowelLength / 8, tacts[i].BeginningOffset + tacts[i].PlayTime, tacts[i + 1].BeginningOffset - (DefaultVowelLength / 8)); sq.Push(conjoin); } } } } if (ExporttoWAV) { FileStream fs = new FileStream(ExportPath, FileMode.Create, FileAccess.Write); fs.Position = 0; WaveFormatter.WriteSequenceToFile(sq, fs); fs.Close(); } else { SoundPlayer sp = new SoundPlayer(); sp.Stream = sq.SnapshotStream; sp.Load(); sp.PlaySync(); } } }
public static void Main(string[] args) { String DefaultConsoleTitle = Console.Title; Int32 Position = 0; Byte CurrentOctave = 4; Boolean Uninterrupted = true; Boolean Harmonic = false; Boolean Square = false; List <TactUnit> Tacts = new List <TactUnit>(); Queue <Char> InitialEntries = new Queue <Char>(); ConsoleColor DefaultTextColor = Console.ForegroundColor; ConsoleColor DefaultBackgroundColor = Console.BackgroundColor; Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Black; if (args.Length >= 1) { foreach (Char i in args[0]) { InitialEntries.Enqueue(i); } } for (int i = 0; i < 12; i++) { if (i == 1 || i == 3 || i == 6 || i == 8 || i == 10) { Console.BackgroundColor = DefaultBackgroundColor; Console.ForegroundColor = DefaultTextColor; } else { Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Black; } Console.Write(Notes.StringForm((Note)i)); Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Black; Console.Write(" "); } Console.Write("\n"); List <Char> InputStack = new List <Char>(); TactUnit Last = new TactUnit(0.0); Console.BackgroundColor = DefaultBackgroundColor; Console.ForegroundColor = DefaultTextColor; while (Uninterrupted) { UpdateConsoleTitle(CurrentOctave, Position, Harmonic, Square); Char cki = (InitialEntries.Count > 0 ? InitialEntries.Dequeue() : Console.ReadKey(true).KeyChar); if (cki == ' ' || cki == '1' || cki == '2' || cki == '3' || cki == '4' || cki == '5' || cki == '6' || cki == '7' || cki == '8' || cki == '9' || cki == '0' || cki == '-' || cki == '=' || cki == ',' || cki == '.' || cki == '`' || cki == 'v' || cki == 'q') { InputStack.Add(cki); } switch (cki) { case ' ': Console.Write("____"); Console.Write(" "); Tacts.Add(new TactUnit(0.125)); break; case 'z': Uninterrupted = false; Console.Write("\n"); break; case ' ': { Sequencer sq = new Sequencer(1, 44100); foreach (TactUnit i in Tacts) { sq.Push(i); } if (sq.Length != 0) { SoundPlayer sp = new SoundPlayer(); sp.Stream = sq.SnapshotStream; sp.Load(); sp.PlaySync(); } break; } case ',': { if (CurrentOctave > 4) { CurrentOctave--; } break; } case '.': { if (CurrentOctave < 9) { CurrentOctave++; } break; } case '\r': case '\n': { SaveFileDialog sfd = new SaveFileDialog(); sfd.Title = "Save wave file to needed location..."; sfd.Filter = "WAV file (*.wav)|*.wav"; DialogResult dr = sfd.ShowDialog(); if (dr == DialogResult.OK) { FileStream fs = new FileStream(sfd.FileName, FileMode.Create, FileAccess.Write); Sequencer sq = new Sequencer(1, 44100); foreach (TactUnit i in Tacts) { sq.Push(i); } WaveFormatter.WriteSequenceToFile(sq, fs); fs.Close(); } break; } case 'r': { if (Position > 0) { List <TactUnit> tu = new List <TactUnit>(); for (int i = 0; i < Position - 1; i++) { tu.Add(Tacts[i]); } Tacts.Clear(); foreach (TactUnit x in tu) { Tacts.Add(x); } Int32 CharsEnlisted = InputStack.Count; Int32 CutHere = CharsEnlisted; while (CutHere > 0) { Char last = InputStack[CutHere - 1]; Boolean pop = false; switch (last) { case ',': if (CurrentOctave < 9) { CurrentOctave++; } CutHere--; break; case '.': if (CurrentOctave > 4) { CurrentOctave--; } CutHere--; break; case '~': Harmonic = false; CutHere--; break; case 'v': Harmonic = true; CutHere--; break; case 'q': Square = !Square; CutHere--; break; default: pop = true; CutHere--; break; } if (pop) { break; } } if (CharsEnlisted > 0) { List <Char> cl = new List <char>(); for (int i = 0; i < CutHere; i++) { cl.Add(InputStack[i]); } InputStack.Clear(); foreach (Char i in cl) { InputStack.Add(i); } } if (Console.CursorLeft == 0) { Console.CursorTop -= 1; Console.CursorLeft = 75; } else { Console.CursorLeft -= 5; } Console.Write(" "); Console.CursorLeft -= 5; } break; } case '`': { Harmonic = true; break; } case 'v': { Harmonic = false; break; } case 'q': { Square = !Square; break; } default: { Int32 x = GetNoteFromChar(cki); if (x != -1) { Note a = (Note)x; Console.Write("{0}{1}", (Harmonic ? (Square ? "+" : "~") : "-"), Notes.StringForm(a, CurrentOctave)); TactUnit tact = new TactUnit(new AmplifiedWave(Phonemes.Get((Harmonic ? (Square ? "__" : "AH") : "/R"), a, CurrentOctave, 64, 44100), 0.75), 0.125); if (Position > 1) { if (Tacts[Position - 1].Frequency == tact.Frequency) { tact.BeginningOffset = Tacts[Position - 1].BeginningOffset + 0.125; } } Tacts.Add(tact); // QuickPlay(tact); Console.Write(" "); } break; } } Position = Tacts.Count; if ((Console.CursorLeft != 0) && (Position % 16 == 0)) { Console.Write("\n"); } } Console.Title = DefaultConsoleTitle; foreach (Char i in InputStack) { Console.Write(i); } Console.WriteLine(); Console.ReadLine(); }