Example #1
0
        public static void ExportSongEvents(int songId, byte[] bankData)
        {
            string path = $@"C:\Depot\bb\ualbion\Data\Exported\SONGS{songId/100}.XLD\{songId%100:D2}.xmi";

            if (!File.Exists(path))
            {
                return;
            }

            using var player = AdlMidi.Init();

            NoteWriter.AppendLine($"Song {songId}");
            player.OpenBankData(bankData);
            player.SetNoteHook(NoteHook, IntPtr.Zero);
            player.OpenFile(path);
            player.SetLoopEnabled(false);
            double nextTime = 0;

            Time = 0;
            const double minTick = 1.0;

            while (player.AtEnd() == 0)
            {
                Time    += nextTime;
                nextTime = player.TickEvents(nextTime, minTick);
            }

            NoteWriter.AppendLine();
        }
Example #2
0
        protected override void Subscribed()
        {
            if (_player != null)
            {
                return;
            }

            var assets   = Resolve <IAssetManager>();
            var xmiBytes = assets.LoadSong(_songId);

            if ((xmiBytes?.Length ?? 0) == 0)
            {
                return;
            }

            _player = AdlMidi.Init();
            _player.SetNoteHook(_hook, IntPtr.Zero);
            _player.OpenBankData(assets.LoadSoundBanks());
            _player.OpenData(xmiBytes);
            _player.SetLoopEnabled(true);
        }
Example #3
0
        static void ExportAlbionSong(int songId, byte[] bankData)
        {
            string path = $@"C:\Depot\bb\ualbion\Data\Exported\SONGS{songId/100}.XLD\{songId%100:D2}.xmi";

            if (!File.Exists(path))
            {
                return;
            }

            using var outputFile = new WavFile(
                      $@"C:\Depot\bb\ualbion\re\Songs{songId/100}_{songId%100:D2}.wav",
                      SampleRate, 2, 2);

            using var player = AdlMidi.Init();

            NoteWriter.AppendLine($"Song {songId}");
            player.SetNoteHook(NoteHook, IntPtr.Zero);
            player.OpenBankData(bankData);
            player.OpenFile(path);
            player.SetLoopEnabled(false);
            short[] bufferArray  = new short[4096];
            long    totalSamples = 0;

            for (;;)
            {
                Time = (double)totalSamples / (2 * SampleRate);
                int samplesWritten = player.Play(bufferArray);
                totalSamples += samplesWritten;

                if (samplesWritten <= 0)
                {
                    break;
                }

                var byteSpan = MemoryMarshal.Cast <short, byte>(new ReadOnlySpan <short>(bufferArray, 0, samplesWritten));
                outputFile.Write(byteSpan);
            }
            NoteWriter.AppendLine();
        }