How to correctly reset my Pitch funtion

Started by Cafony, 20 Jun '24 - 10:28

Cafony

Hello I got this trackbar controling my pitch value;
        private void trackBarTransp2_Scroll(object sender, EventArgs e)
        {
            _trackBarPitch = trackBarTranspose.Value; // define pitch value
            if (_trackBarPitch == 0)
            {
                Bass.BASS_FXReset(_streamPitch);    // This reset Is not working !!
                labelTranspose.Text = "Transpose: " + trackBarTranspose.Value.ToString();
                labelTranspose.ForeColor = Color.Black;
            }
            else
            {
                labelTranspose.Text = "Transpose: " + trackBarTranspose.Value.ToString();
                labelTranspose.ForeColor = Color.Red;
                pitchShift(_trackBarPitch);
            }           
        }

My pitch funtion:
            _stream = Bass.BASS_StreamCreateFile(_musicFile, 0L, 0L, BASSFlag.BASS_STREAM_DECODE);
            _streamPitch = Bass.BASS_ChannelSetFX(_stream, BASSFXType.BASS_FX_BFX_PITCHSHIFT, 0);

            BASS_BFX_PITCHSHIFT parametros = new BASS_BFX_PITCHSHIFT();
            Bass.BASS_FXGetParameters(_streamPitch, parametros);


            parametros.fPitchShift = _pitchArrayValue;             //this is ZERO
            parametros.fSemitones = _pitch;           //(0 won't change the pitch). Default = 0.)
            Bass.BASS_FXSetParameters(_streamPitch, parametros);

The problem is:
Everytime I make trackbar on ZERO value the funtion wont reset, It makes strange pitch values.
It seams like i got crazy on pitch values.
Please a little help to reset pitch.
Thanks

Ian @ un4seen

BASS_FXReset will reset the FX state (eg. clear internal buffers) but not its parameters. If you want to reset the parameters then you should call BASS_FXSetParameters again to do that. Basically remove the "if (_trackBarPitch == 0)" block, it looks like.

Cafony

Thanks alot, I remove the if condition, and works fine.
thanks