2

我目前正在使用 c# 和使用 LibVLCSharp 开发一个卡拉 OK 系统。谁能帮我用它来改变音频变调器?

\libvlc\win-x86\plugins\audio_filter 目录中有 libscaletempo_plugin 和 libscaletempo_pitch_plugin 模块。如何在 LibVLCSharp 中应用音频过滤器模块?

曾尝试跟随,但它不起作用。

Core.Initialize();
LibVLC libVlc = new LibVLC();
mp1 = new MediaPlayer(libVlc);
mp1.Hwnd = pictureBox1.Handle;
Media media = new Media(libVlc, @"c:\testsong.mp4", FromType.FromPath);
media.AddOption("--audio-filter=scaletempo_pitch");
media.AddOption("--pitch-shift=5");
mp1.Play(media);

并尝试了这个,它不起作用。

...
...
media.AddOption(":audio-filter=scaletempo_pitch");
media.AddOption(":pitch-shift=5");
mp1.Play(media);

并尝试了这个,它也不起作用。

Core.Initialize();
string[] options = { "--audio-filter=scaletempo_pitch", "--pitch-shift=5" };
LibVLC libVlc = new LibVLC(options);
mp1 = new MediaPlayer(libVlc);
mp1.Hwnd = pictureBox1.Handle;
Media media = new Media(libVlc, @"c:\testsong.mp4", FromType.FromPath);
mp1.Play(media);

我一直在搜索,但找不到通过音调转换应用音频过滤器的解决方案。我需要的是一个函数,当媒体播放时,可以调用它来传递从-12 到 12 的音频音高偏移值。

提前致谢。

4

1 回答 1

0

下面是我尝试 VLC 音高转换的示例代码。有谁知道如何使用PlayCallback()函数SetAudioCallbacks?C# 的任何示例或参考?

using LibVLCSharp.Shared;
using LibVLCSharp.Shared.Structures;
using static LibVLCSharp.Shared.MediaPlayer;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {

        private MediaPlayer mp1;
        private LibVLC libVlc;
        private string filePath = @"C:\Users\user\Desktop\testsong.mp4";

        public Form1()
        {
            if (!DesignMode) Core.Initialize();
            InitializeComponent();
        }

        private void TrackVolume_Scroll(object sender, EventArgs e)
        {
            mp1.Volume = trackVolume.Value;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string[] options = { "--audio-filter=scaletempo_pitch" };
            libVlc = new LibVLC(options);
            mp1 = new MediaPlayer(libVlc);
            mp1.SetAudioCallbacks(playCallBack, null, null, null, null);
            mp1.Hwnd = pictureBox1.Handle;
        }

        private void BtnPlay_Click(object sender, EventArgs e)
        {
            Media media = new Media(libVlc, filePath, FromType.FromPath);
            mp1.Play(media);
            mp1.Volume = trackVolume.Value;
        }


        private void playCallBack(IntPtr data, IntPtr samples, uint count, long pts)
        {
            // anyone know how to code in playCallBack to control scaletempo_pitch (-12.0 to 12.0) ???
        }

    }
}
于 2020-03-12T10:29:19.003 回答