Remove Vocal from audio file

Started by Cafony, 26 Mar '24 - 14:48

Cafony

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

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

Cafony

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

About this subject "Remove Vocal" I research a little and made this;

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

// Duplicate the audio stream
_invertedStream = BassFx.BASS_FX_TempoCreate(_stream, BASSFlag.BASS_FX_FREESOURCE);

// Apply phase inversion to one channel (e.g., the right channel)
            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
            _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

Quote from: Cafony on  2 Apr '24 - 14:43// Duplicate the audio stream
_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