Change music speed in realtime

Started by Cafony, 19 Apr '24 - 16:25

Cafony

I made this funtion to change music tempo Speed:

        private void buttonPlay_Click(object sender, EventArgs e)
        {
            // create the stream           
            _stream = Bass.BASS_StreamCreateFile(@"c:\mp3\guerra.mp3", 0L, 0L, BASSFlag.BASS_STREAM_DECODE);
            // Tempo Channel           
            int _streamSpeed = BassFx.BASS_FX_TempoCreate(_stream, BASSFlag.BASS_FX_FREESOURCE);           
            Bass.BASS_ChannelSetAttribute(_streamSpeed, BASSAttribute.BASS_ATTRIB_TEMPO, _speed);         
            Bass.BASS_ChannelPlay(_streamSpeed, false);         
        }

Works fine.

But I need to make this change in realtime using a trackbar:

        private void trackBarSpeed_Scroll(object sender, EventArgs e)
        {
            _speed =(int) trackBar1.Value;
            labelSpeed.Text=_speed.ToString();
        }

When I move trackbar there is no change in stream/music speed.

Please a little help on making this work in realtime.

Thanks

Ian @ un4seen

You need to call BASS_ChannelSetAttribute again (with the same handle) to set the new BASS_ATTRIB_TEMPO value.

Cafony


Cafony

#3
Sorry to come back...

Im using this stream on my player (with other effects)
_stream = Bass.BASS_StreamCreateFile(@"c:\mp3\guerra.mp3", 0L, 0L, BASSFlag.BASS_STREAM_DECODE);

For changind speed I start to use

int _streamSpeed= BassFx.BASS_FX_TempoCreate(_stream, BASSFlag.BASS_FX_FREESOURCE);

If I play the second _streamfx, how can I use the other effects, if the original one is _stream?

I want to play my file stream trought:  Pitchshift ==> Tempo Speed ==> PeakEQ

Thanks

Ian @ un4seen

Any effects set on the source will be applied before the tempo processing, while effects set on the tempo stream will be applied after the tempo processing. So in your example, you would set the "Pitchshift" effect on the source (_stream) and the "PeakEQ" effect on the tempo stream (_streamfx).

Cafony

Here is wath I have so far:

            //Stream for PITCHSHIFT
            _streamPitch = Bass.BASS_ChannelSetFX(_stream, BASSFXType.BASS_FX_BFX_PITCHSHIFT, 0);
            //Stream for MONO STEREO
            _streamMono = Bass.BASS_ChannelSetFX(_stream, BASSFXType.BASS_FX_BFX_MIX, 0);
            // Stream for EQ
            _streamEQ = Bass.BASS_ChannelSetFX(_stream, BASSFXType.BASS_FX_BFX_PEAKEQ, 0);           
            //Stream for TEMPO
            _streamSpeed = BassFx.BASS_FX_TempoCreate(_stream, BASSFlag.BASS_STREAM_AUTOFREE);
            //===========Play file==============//           
            Bass.BASS_ChannelPlay(_stream, false);   

In my trackbar to control the tempo speed I got
            if (trackBarSpeed.Value >= -50 && trackBarSpeed.Value<=50)
            {                         
                Bass.BASS_ChannelSetAttribute(_streamSpeed, BASSAttribute.BASS_ATTRIB_TEMPO, _speed);
            }

Question is that:
- I can not make the tempo change while Im playing inicial _stream,
- But MONO, PITCH and EQ are working, but sometimes "program crashes".

Please a little help on making tempo work.

And "am I making all thouse extra stream ok" ? (_streamMono,_streamEQ,_streamPitch,_streamSpeed)

Ian @ un4seen

BASS_ChannelSetFX doesn't create a new stream, but rather applies an effect to a stream. There are 2 streams in your case: the decoder (with BASS_STREAM_DECODE flag set) and the tempo stream (which gets its data from the decoder). You only play the tempo stream. When you don't want any tempo change, you can set BASS_ATTRIB_TEMPO to 0 (via BASS_ChannelSetAttribute).

Regarding the crashes, please try catching them in the debugger and see where it says they are.

Cafony

#7
If I play my tempo stream  "_streamSpeed"
//===========Play file==============//
     Bass.BASS_ChannelPlay(_streamSpeed, false);           
I get no sound


If I play first stream "_stream"
//===========Play file==============//
     Bass.BASS_ChannelPlay(_stream, false);   
I get sound (with EQ and PITCH, MONO working)


If I understood, if _stream enters "TempoCreate" the output is on _streamSpeed.
_streamSpeed = BassFx.BASS_FX_TempoCreate(_stream, BASSFlag.BASS_STREAM_AUTOFREE);


but I get no sound on this _streamSpeed
     Bass.BASS_ChannelPlay(_streamSpeed, false);   

I dont understand the sequence of all these effect streams.

Chris

looks like your _stream was not created with the flag BASS_STREAM_DECODE

Ian @ un4seen

Yes, you need to include the BASS_STREAM_DECODE flag when creating "_stream". Without that, the BASS_FX_TempoCreate call will fail (return 0). Whenever there's a problem, you should check all return values to find out if any calls are failing, and if they are then use BASS_ErrorGetCode to find out why.

Cafony

Im really realy "sorry"

You are right:
- in this topic I wrote
_stream = Bass.BASS_StreamCreateFile(@"c:\mp3\guerra.mp3", 0L, 0L, BASSFlag.BASS_STREAM_DECODE);

but in my program I was still having
_stream = Bass.BASS_StreamCreateFile(@"c:\mp3\guerra.mp3", 0L, 0L, BASSFlag.BASS_DEFAULT);

So now "I got my tempo/speed" working fine.

Thanks a lot !
Im a beginner, still learning.
Please "my humble apologies" :-)

Ian @ un4seen

That's OK, it's good to see you've got it working now.