public void TestSingDemoSong() { var beatmap = new KaraokeBeatmap(); var data = TestResources.OpenTrackResource("demo"); var generated = new KaraokeAutoGeneratorBySinger(beatmap, data).Generate(); // Get generated frame and compare frame var karaokeFrames = generated.Frames.OfType <KaraokeReplayFrame>().ToList(); var compareFrame = getCompareResultFromName("demo"); // Check total frames. Assert.AreEqual(karaokeFrames.Count, compareFrame.Count, $"Replay frame should have {compareFrame.Count}."); // Compare generated frame with result; for (int i = 0; i < compareFrame.Count; i++) { Assert.AreEqual(karaokeFrames[i].Time, compareFrame[i].Time); Assert.AreEqual(karaokeFrames[i].Sound, compareFrame[i].Sound); if (!compareFrame[i].Sound) { continue; } var convertedScale = beatmap.PitchToScale(compareFrame[i].Pitch); Assert.AreEqual(karaokeFrames[i].Scale, convertedScale); } }
public void TestNoteStair() { // | | // | - | // | - | var beatmap = new KaraokeBeatmap(); beatmap.HitObjects.Add(new Note { Display = true, StartTime = 1000, Duration = 50, Text = "kara", Tone = new Tone(0, true) }); beatmap.HitObjects.Add(new Note { Display = true, StartTime = 1050, Duration = 50, Text = "oke!", Tone = new Tone(1, true) }); var generated = new KaraokeAutoGenerator(beatmap).Generate(); Assert.IsTrue(generated.Frames.Count == 3, "Replay must have 3 frames, note1's start, note2's start and note2's end."); Assert.AreEqual(1000, generated.Frames[0].Time, "Incorrect time"); Assert.AreEqual(1050, generated.Frames[1].Time, "Incorrect time"); Assert.AreEqual(1101, generated.Frames[2].Time, "Incorrect time"); Assert.IsTrue(checkMatching(generated.Frames[0], new Tone(0, true)), "Frame1 should sing."); Assert.IsTrue(checkMatching(generated.Frames[1], new Tone(1, true)), "Frame2 should sing."); Assert.IsTrue(checkMatching(generated.Frames[2], null), "Frame3 should release sing."); }
public void TestSingleNoteWithLongTime() { // | | // | *** | // | | var beatmap = new KaraokeBeatmap(); beatmap.HitObjects.Add(new Note { Display = true, StartTime = 1000, Duration = 1000, Text = "karaoke!", Tone = new Tone(0, true) }); var generated = new KaraokeAutoGenerator(beatmap).Generate(); Assert.IsTrue(generated.Frames.Count == 11, "Replay must have 11 frames,Start, duration(9 frames) and end."); Assert.AreEqual(1000, generated.Frames[0].Time, "Incorrect hit time"); Assert.AreEqual(2001, generated.Frames[10].Time, "Incorrect time"); Assert.IsTrue(checkMatching(generated.Frames[0], new Tone(0, true)), "Fist frame should sing."); Assert.IsTrue(checkMatching(generated.Frames[10], null), "Last frame should not sing."); }
[TestCase(new[] { "[0,0]:か", "[0,0]:ら", "[0,0]:お", "[0,0]:け" }, "か\nら\nお\nけ")] // multi lyric. public void TestEncodeBeatmapToPureText(string[] lyrics, string actual) { var encoder = new LyricTextEncoder(); var beatmap = new KaraokeBeatmap { HitObjects = TestCaseTagHelper.ParseLyrics(lyrics).OfType <KaraokeHitObject>().ToList() }; var result = encoder.Encode(beatmap); Assert.AreEqual(result, actual); }
public void ApplyToDrawableRuleset(DrawableRuleset <KaraokeHitObject> drawableRuleset) { beatmap = drawableRuleset.Beatmap as KaraokeBeatmap; if (drawableRuleset.Playfield is KaraokePlayfield karaokePlayfield) { karaokePlayfield.DisplayCursor = new BindableBool { Default = true, Value = true }; } }
/// <summary> /// Using audio's voice to generate replay frames /// Logic is copied from <see cref="Waveform"/> /// </summary> /// <param name="beatmap"></param> /// <param name="data"></param> public KaraokeAutoGeneratorBySinger(KaraokeBeatmap beatmap, Stream data) : base(beatmap) { if (data == null) { return; } readTask = Task.Run(() => { int decodeStream = 0; using (var fileCallbacks = new FileCallbacks(new DataStreamFileProcedures(data))) { decodeStream = Bass.CreateStream(StreamSystem.NoBuffer, BassFlags.Decode | BassFlags.Float, fileCallbacks.Callbacks, fileCallbacks.Handle); } Bass.ChannelGetInfo(decodeStream, out ChannelInfo info); var totalLength = Bass.ChannelGetLength(decodeStream); double trackLength = Bass.ChannelBytes2Seconds(decodeStream, totalLength) * 1000; var length = totalLength; long lengthSum = 0; // Microphone at period 10 var bytesPerIteration = 3276 * info.Channels * TrackBass.BYTES_PER_SAMPLE; var pitches = new Dictionary <double, float?>(); var sampleBuffer = new float[bytesPerIteration / TrackBass.BYTES_PER_SAMPLE]; // Read sample data while (length > 0) { length = Bass.ChannelGetData(decodeStream, sampleBuffer, bytesPerIteration); lengthSum += length; // usually sample 1 is vocal var channel0Sample = sampleBuffer.Where((x, i) => i % 2 == 0).ToArray(); //var channel1Sample = sampleBuffer.Where((x, i) => i % 2 != 0).ToArray(); // Convert buffer to pitch data var time = lengthSum * trackLength / totalLength; var pitch = Pitch.FromYin(channel0Sample, info.Frequency, low: 40, high: 1000); pitches.Add(time, pitch == 0 ? default(float?) : pitch); } return(pitches); }, cancelSource.Token); }
public void ApplyToBeatmap(IBeatmap beatmap) => this.beatmap = beatmap as KaraokeBeatmap;
public KaraokeAutoGenerator(KaraokeBeatmap beatmap) : base(beatmap) { }