Exemplo n.º 1
0
        static void SaveReverse(string FilePath)
        {
            try
            {
                var sfd = ReverseSaveDialog.Value;
                sfd.FileName = Path.GetFileNameWithoutExtension(FilePath) + ".Reverse";

                if (!sfd.ShowDialog().Value)
                {
                    return;
                }

                var fc = Bass.CreateStream(FilePath, Flags: BassFlags.Decode);
                var rc = BassFx.ReverseCreate(fc, 2, BassFlags.Decode | BassFlags.FxFreeSource);

                var wf = WaveFormat.FromChannel(fc);

                var writer = new WaveFileWriter(new FileStream(sfd.FileName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read), wf);

                var blockLength = (int)Bass.ChannelSeconds2Bytes(rc, 2);

                var buffer = new byte[blockLength];

                var gch = GCHandle.Alloc(buffer, GCHandleType.Pinned);

                while (Bass.ChannelIsActive(rc) == PlaybackState.Playing)
                {
                    var bytesReceived = Bass.ChannelGetData(rc, gch.AddrOfPinnedObject(), blockLength);
                    writer.Write(buffer, bytesReceived);
                }

                gch.Free();

                writer.Dispose();

                Bass.StreamFree(rc);

                MessageBox.Show("Saved");
            }
            catch (Exception e) { MessageBox.Show($"Failed\n\n{e}"); }
        }