Author Topic: Remove Vocal from audio file  (Read 373 times)

Cafony

  • Posts: 24
Remove Vocal from audio file
« on: 26 Mar '24 - 14:48 »
Using chatGPT code for inverting audio file, creating kind of remove vocals.

But this methods dont show on VisualStudio bass.dll

Bass.BASS_ChannelSplit
BASS_StreamToFile

Please Help
Thanks

Code: [Select]
            // Split the stereo stream into left and right channels
            int leftChannel = Bass.BASS_ChannelSplit(streamHandle, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_MONO);
            int rightChannel = Bass.BASS_ChannelSplit(streamHandle, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_MONO);

            // Apply phase inversion to one channel
            Bass.BASS_ChannelSetAttribute(leftChannel, BASSAttribute.BASS_ATTRIB_VOL, 1.0f);
            Bass.BASS_ChannelSetAttribute(rightChannel, BASSAttribute.BASS_ATTRIB_VOL, -1.0f);

            // Merge the modified channels back together
            int mixerHandle = BassMix.BASS_Mixer_StreamCreate(44100, 2, BASSFlag.BASS_MIXER_END);
            BassMix.BASS_Mixer_StreamAddChannel(mixerHandle, leftChannel, BASSFlag.BASS_MIXER_DOWNMIX);
            BassMix.BASS_Mixer_StreamAddChannel(mixerHandle, rightChannel, BASSFlag.BASS_MIXER_DOWNMIX);

            // Save the resulting audio to a new file
           
            Bass.BASS_StreamToFile(mixerHandle, outputFilePath, 0, null);
« Last Edit: 27 Mar '24 - 08:23 by Cafony »

Cafony

  • Posts: 24
Re: Remove Vocal from audio file
« Reply #1 on: 29 Mar '24 - 16:23 »
Ok Ive search a little and there is a way to remove (reduce) vocal :

- invert phase on left channel

- and then join the inverted channel with right channel, making a MONO MIX played in stereo.

Please how can I invert phase of one channel.

Thanks



Cafony

  • Posts: 24
Re: Remove Vocal from audio file
« Reply #2 on: 2 Apr '24 - 14:43 »
About this subject "Remove Vocal" I research a little and made this;

Load the original file
Code: [Select]
_stream = Bass.BASS_StreamCreateFile(@"c:\mp3\naosei.mp3", 0, 0, BASSFlag.BASS_DEFAULT);

// Duplicate the audio stream
Code: [Select]
_invertedStream = BassFx.BASS_FX_TempoCreate(_stream, BASSFlag.BASS_FX_FREESOURCE);

// Apply phase inversion to one channel (e.g., the right channel)
Code: [Select]
            BASS_CHANNELINFO info = new BASS_CHANNELINFO();
            Bass.BASS_ChannelGetInfo(_invertedStream, info);
            Bass.BASS_ChannelSetPosition(_invertedStream, 0, BASSMode.BASS_POS_BYTES); // Reset stream position
            Bass.BASS_ChannelGetData(_invertedStream, IntPtr.Zero, (int)info.freq * 2); // Decode initial data
            Bass.BASS_ChannelSetAttribute(_invertedStream, BASSAttribute.BASS_ATTRIB_PAN, 1);

// Create a mixer stream to combine the original and inverted streams and PLAY
Code: [Select]
            _mixerStream = BassMix.BASS_Mixer_StreamCreate(info.freq, 2, BASSFlag.BASS_DEFAULT);
            BassMix.BASS_Mixer_StreamAddChannel(_mixerStream, _stream, BASSFlag.BASS_DEFAULT);
            BassMix.BASS_Mixer_StreamAddChannel(_mixerStream, _invertedStream, BASSFlag.BASS_DEFAULT);
            // Play stream
            Bass.BASS_ChannelPlay(_mixerStream, false);

Can someone help me, cause cant get any sound from this.
Thanks

Ian @ un4seen

  • Administrator
  • Posts: 25780
Re: Remove Vocal from audio file
« Reply #3 on: 3 Apr '24 - 18:05 »
// Duplicate the audio stream
Code: [Select]
_invertedStream = BassFx.BASS_FX_TempoCreate(_stream, BASSFlag.BASS_FX_FREESOURCE);

BASS_FX_TempoCreate won't create a duplicate stream but rather enable tempo processing. This call will actually be failing (returning 0) because "_stream" doesn't have the BASS_STREAM_DECODE flag set on it. The later BASS_Mixer_StreamAddChannel calls would also be failing for the same reason. You should always check return values, especially when something isn't working.

I think it'd be better to use a DSP function (DSPPROC) for what you want to do. Here's one that another user posted:

   www.un4seen.com/forum/?topic=13404.msg93626#msg93626