Author Topic: Change music speed in realtime  (Read 789 times)

Cafony

  • Posts: 33
Change music speed in realtime
« on: 19 Apr '24 - 16:25 »
I made this funtion to change music tempo Speed:

Code: [Select]
        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:

Code: [Select]
        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
« Last Edit: 29 Apr '24 - 23:03 by Cafony »

Ian @ un4seen

  • Administrator
  • Posts: 26172
Re: Change music speed in realtime
« Reply #1 on: 19 Apr '24 - 17:39 »
You need to call BASS_ChannelSetAttribute again (with the same handle) to set the new BASS_ATTRIB_TEMPO value.

Cafony

  • Posts: 33
Re: Change music speed in realtime
« Reply #2 on: 21 Apr '24 - 11:23 »
Great Great !!
It works
Thanks !!!

Cafony

  • Posts: 33
Re: Change music speed in realtime
« Reply #3 on: 24 Apr '24 - 17:27 »
Sorry to come back...

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

For changind speed I start to use

Code: [Select]
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
« Last Edit: 29 Apr '24 - 23:04 by Cafony »

Ian @ un4seen

  • Administrator
  • Posts: 26172
Re: Change music speed in realtime
« Reply #4 on: 25 Apr '24 - 12:45 »
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

  • Posts: 33
Re: Change music speed in realtime
« Reply #5 on: 29 Apr '24 - 10:15 »
Here is wath I have so far:

Code: [Select]
            //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
Code: [Select]
            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

  • Administrator
  • Posts: 26172
Re: Change music speed in realtime
« Reply #6 on: 29 Apr '24 - 17:57 »
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

  • Posts: 33
Re: Change music speed in realtime
« Reply #7 on: 29 Apr '24 - 23:00 »
If I play my tempo stream  "_streamSpeed"
Code: [Select]
//===========Play file==============//
     Bass.BASS_ChannelPlay(_streamSpeed, false);           
I get no sound


If I play first stream "_stream"
Code: [Select]
//===========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.
Code: [Select]
_streamSpeed = BassFx.BASS_FX_TempoCreate(_stream, BASSFlag.BASS_STREAM_AUTOFREE);


but I get no sound on this _streamSpeed
Code: [Select]
     Bass.BASS_ChannelPlay(_streamSpeed, false);   

I dont understand the sequence of all these effect streams.
« Last Edit: 29 Apr '24 - 23:17 by Cafony »

Chris

  • Posts: 2217
Re: Change music speed in realtime
« Reply #8 on: 30 Apr '24 - 13:28 »
looks like your _stream was not created with the flag BASS_STREAM_DECODE

Ian @ un4seen

  • Administrator
  • Posts: 26172
Re: Change music speed in realtime
« Reply #9 on: 30 Apr '24 - 14:10 »
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

  • Posts: 33
Re: Change music speed in realtime
« Reply #10 on: 30 Apr '24 - 14:31 »
Im really realy "sorry"

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

but in my program I was still having
Code: [Select]
_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

  • Administrator
  • Posts: 26172
Re: Change music speed in realtime
« Reply #11 on: 30 Apr '24 - 17:42 »
That's OK, it's good to see you've got it working now.