3

I'm currently developing a karaoke system with c# and using LibVLCSharp. Can anyone please help me how to change audio pitch shifter with it?

There's libscaletempo_plugin and libscaletempo_pitch_plugin module in \libvlc\win-x86\plugins\audio_filter directory. How can I apply audio filter modules in LibVLCSharp ?

Had tried following but it doesn't work.

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);

and tried this, it doesn't work.

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

and tried this, it doesn't work also.

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);

I've searching through but cannot find the solution to apply audio filter with pitch shift. What i need is a function that can be called to pass in audio pitch shift value, from -12 to 12, when the media is playing.

Thanks in advance.

Wong
  • 86
  • 4
  • Since you didn't provide enough context, let me ask you a question : Did you add those options BEFORE the media is parsed? Otherwise, you could try to pass those options in the media constructor or in the libvlc constructor. – cube45 Feb 27 '20 at 20:22
  • Yes. Tried both options in libvlc constructor and also in media options before play. Both not work. – Wong Feb 28 '20 at 03:51
  • Did you manage to get these option working with the vlc command line? This is the fist step. If that doesn't work with VLC, it can't work with LVS – cube45 Feb 28 '20 at 07:04
  • 1
    Yes. I manage to get this option work via `vlc --pitch-shift=5 --audio-filter=scaletempo_pitch c:\testsong.mp4` at command prompt. But it does not work in code. – Wong Feb 28 '20 at 12:08
  • Can you try these options? `"--audio-filter", "scaletempo_pitch", "--pitch-shift", "5"` – cube45 Feb 28 '20 at 13:17
  • Tested with `string[] options = { "--audio-filter", "scaletempo_pitch", "--pitch-shift", "5" }; libVlc = new LibVLC(options);` also not working. – Wong Feb 28 '20 at 14:24
  • which libvlc versions and VLC versions have you tried? Can't get it to work in VLC desktop 3.0.8 – mfkl Mar 02 '20 at 02:42
  • I use `nuget VideoLAN.LibVLC.Windows` version `3.0.8.1`. Does not work. – Wong Mar 02 '20 at 10:16
  • Which VLC Desktop version works? – mfkl Mar 02 '20 at 11:14

1 Answers1

0

Below is my sample code to try out the VLC pitch shift. Does anyone know how to use PlayCallback() function in SetAudioCallbacks? Any sample or reference for 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) ???
        }

    }
}
Wong
  • 86
  • 4