Author Topic: Correct use of BASS_ATTRIB_TEMPO(_PITCH)  (Read 1106 times)

kafffee

  • Posts: 185
Correct use of BASS_ATTRIB_TEMPO(_PITCH)
« on: 6 Feb '22 - 11:54 »
Hey there,

I am trying to change tempo and/or pitch of my played file.

Right now I got the following:

Code: [Select]
Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_SPEAKERS, Nothing)
stream = Bass.BASS_StreamCreateFile("C:\Test.mp3", 0, 0, BASSFlag.BASS_STREAM_AUTOFREE Or BASSFlag.BASS_STREAM_PRESCAN)
Bass.BASS_ChannelPlay(stream, False)

and when my trackbar is scrolled:
Code: [Select]
Bass.BASS_ChannelSetAttribute(stream, BASSAttribute.BASS_ATTRIB_TEMPO, CSng(TrackBar1.Value))
respectively:
Code: [Select]
Bass.BASS_ChannelSetAttribute(stream, BASSAttribute.BASS_ATTRIB_TEMPO_PITCH, CSng(TrackBar2.Value))
However, I always get error code 19 () An illegal parameter was specified...

What am I doing wrong? What add-ons do I need?

saga

  • Posts: 2648
Re: Correct use of BASS_ATTRIB_TEMPO(_PITCH)
« Reply #1 on: 6 Feb '22 - 13:25 »
BASS_ATTRIB_TEMPO requires a tempo stream which you don't appear to be using. This appears to be the exact same question, maybe you can try the answer from there: http://www.un4seen.com/forum/?topic=19567.0

kafffee

  • Posts: 185
Re: Correct use of BASS_ATTRIB_TEMPO(_PITCH)
« Reply #2 on: 7 Feb '22 - 08:22 »
OK, I did this:

Code: [Select]
Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_SPEAKERS, Nothing)
BassFx.LoadMe()
stream = Bass.BASS_StreamCreateFile("C:\Test.mp3", 0, 0, BASSFlag.BASS_STREAM_AUTOFREE Or BASSFlag.BASS_STREAM_PRESCAN)
Bass.BASS_ChannelPlay(stream, False)
streamfx = BassFx.BASS_FX_TempoCreate(stream, BASSFlag.BASS_STREAM_AUTOFREE)

and this:
Code: [Select]
Bass.BASS_ChannelSetAttribute(streamfx, BASSAttribute.BASS_ATTRIB_TEMPO, CSng(TrackBar1.Value))
MessageBox.Show(CStr(Bass.BASS_ErrorGetCode))

But now I get error no. 5 - Invalid handle...

what am I doing wrong?

Chris

  • Posts: 2132
Re: Correct use of BASS_ATTRIB_TEMPO(_PITCH)
« Reply #3 on: 7 Feb '22 - 11:12 »
hi,
should to be
Code: [Select]
stream = Bass.BASS_StreamCreateFile("C:\Test.mp3", 0, 0,  BASSFlag.BASS_STREAM_PRESCAN or BASSFlag.Bass_Stream_DECODE)
if (stream <> 0) then // valid stream
streamfx = BassFx.BASS_FX_TempoCreate(stream,BASSFlag.BASS_STREAM_AUTOFREE Or BASSFlag.BASS_FX_FREESOURCE)
if (streamfx <> 0) then // valid tempostream
Bass.BASS_ChannelPlay(streamfx, False)




« Last Edit: 7 Feb '22 - 13:22 by Chris »

kafffee

  • Posts: 185
Re: Correct use of BASS_ATTRIB_TEMPO(_PITCH)
« Reply #4 on: 7 Feb '22 - 11:35 »
Ok did this. But in this line:

Code: [Select]
streamfx = BassFx.BASS_FX_TempoCreate(stream)
the method wants to have another bassflag as argument passed in...

BASS_STREAM_DECODE won't work... Still getting error no. 5...
« Last Edit: 7 Feb '22 - 11:43 by kafffee »

Chris

  • Posts: 2132
Re: Correct use of BASS_ATTRIB_TEMPO(_PITCH)
« Reply #5 on: 7 Feb '22 - 12:03 »

Code: [Select]
streamfx = BassFx.BASS_FX_TempoCreate(stream,BASS_FX_FREESOURCE)

kafffee

  • Posts: 185
Re: Correct use of BASS_ATTRIB_TEMPO(_PITCH)
« Reply #6 on: 7 Feb '22 - 12:16 »
No still the same. I cant't hear anything either... When I use the slider to change tempo, error no 5...
And after this:
Code: [Select]
stream = Bass.BASS_StreamCreateFile("C:\Users\alpha\Music\hiphop\american\Beastie Boys\Beastie Boys - Ill Communication\01 Beastie Boys - Ill Communication - Sure Shot.mp3", 0, 0, BASSFlag.BASS_STREAM_AUTOFREE Or BASSFlag.BASS_STREAM_PRESCAN Or BASSFlag.BASS_STREAM_DECODE)
--> Error 37:Requested data is not available...

After this:
Code: [Select]
streamfx = BassFx.BASS_FX_TempoCreate(stream, BASSFlag.BASS_FX_FREESOURCE)
Also error no. 5


Edit: I just tried to use a different mp3 file (on a usb stick). Now I get error no.2 cant open the file instead of no. 37
« Last Edit: 7 Feb '22 - 12:52 by kafffee »

Chris

  • Posts: 2132
Re: Correct use of BASS_ATTRIB_TEMPO(_PITCH)
« Reply #7 on: 7 Feb '22 - 13:17 »
The BASS_STREAM_AUTOFREE flag cannot be combined with the BASS_STREAM_DECODE flag.


so you can try that
Code: [Select]
stream = Bass.BASS_StreamCreateFile("C:\Test.mp3", 0, 0,  BASSFlag.BASS_STREAM_PRESCAN or BASSFlag.Bass_Stream_DECODE)
if (stream <> 0) then // valid stream
streamfx = BassFx.BASS_FX_TempoCreate(stream,BASSFlag.BASS_STREAM_AUTOFREE Or BASSFlag.BASS_FX_FREESOURCE)
if (streamfx <> 0) then // valid tempostream
Bass.BASS_ChannelPlay(streamfx, False)

kafffee

  • Posts: 185
Re: Correct use of BASS_ATTRIB_TEMPO(_PITCH)
« Reply #8 on: 8 Feb '22 - 13:33 »
It works!!  ;D ;D

Thanks guys you're the best!

Bernardo S Martins

  • Guest
BASS_ATTRIB_TEMPO(_PITCH)
« Reply #9 on: 16 Nov '22 - 14:43 »
Hello friends!
my pitch still didn't work out.
 track bar does not change speed
 public
    channel:HSTREAM;
    channel2:HSTREAM;
      decoder :HSTREAM;
  tempostream :HSTREAM;
  streamfx :HSTREAM;
  end;

var
  FormPlayer : TFormPlayer;
  Chan : DWORD; // sample
  Channel : DWORD; // playlist
  Channel2 : DWORD; // playlist
      decoder :DWORD;
  tempostream :DWORD;
  streamfx :DWORD;


// play button
     begin
     if channel>0 then begin
     BASS_StreamFree(channel); //destroy any previous channel if it exists
     channel:=0;
    end;
    Timerch1.Enabled := false;

   channel:= BASS_StreamCreateFile(FALSE, PChar(ListBox1.Items[ListBox1.ItemIndex]), 0, 0, Bass.BASS_POS_BYTE or BASS_SAMPLE_LOOP or
                  BASS_FX_FREESOURCE or BASS_SAMPLE_FX or floatable or BASS_SAMPLE_LOOP {$IFDEF UNICODE}or BASS_UNICODE {$ENDIF});

   if (channel <> 0) then // valid stream
    streamfx := BASS_FX_TempoCreate(channel,BASS_STREAM_AUTOFREE Or BASS_FX_FREESOURCE);
   if (streamfx <> 0) then // valid tempostream

    fx[4] := BASS_ChannelSetFX(channel, BASS_FX_DX8_REVERB, 1);
    BASS_FXGetParameters(fx[4], @pR);
    pR.fReverbMix := -96;
    pR.fReverbTime := 1200;
    pR.fHighFreqRTRatio := 0.1;

    BASS_ChannelPlay(channel, true); // play the stream
    Timerch1.Enabled := true;
end;

// trackbar
  If (BASS_ChannelIsActive(channel) = 0) Then Exit;

  BASS_ChannelSetAttribute(streamFX, BASS_ATTRIB_TEMPO, tbTempo.Position);
  lblTempo.Caption := 'Tempo = ' + IntToStr(tbTempo.position) + '%';

Ian @ un4seen

  • Administrator
  • Posts: 25059
Re: Correct use of BASS_ATTRIB_TEMPO(_PITCH)
« Reply #10 on: 16 Nov '22 - 17:18 »
Your BASS_FX_TempoCreate call will currently be failing (with BASS_ERROR_DECODE) because the "channel" stream doesn't have the BASS_STREAM_DECODE flag set. You can fix that by adding the flag to the BASS_StreamCreateFile call. Also remove the BASS_FX_FREESOURCE flag from that call because it isn't a valid flag there.

You can then use the "streamfx" handle (rather than "channel") in the BASS_ChannelPlay call to play the tempo stream.

Code: [Select]
   channel:= BASS_StreamCreateFile(FALSE, PChar(ListBox1.Items[ListBox1.ItemIndex]), 0, 0, BASS_STREAM_DECODE or BASS_SAMPLE_LOOP or
                  BASS_SAMPLE_FLOAT {$IFDEF UNICODE}or BASS_UNICODE {$ENDIF});

   streamfx := BASS_FX_TempoCreate(channel,BASS_STREAM_AUTOFREE Or BASS_FX_FREESOURCE);

   BASS_ChannelPlay(streamfx, false); // play the stream

Bernardo S Martins

  • Guest
Re: Correct use of BASS_ATTRIB_TEMPO(_PITCH)
« Reply #11 on: 16 Nov '22 - 19:58 »
cool, it worked!
Now how do I make the label_bpm receive the value of
the bpm when I change the picth.

Ian @ un4seen

  • Administrator
  • Posts: 25059
Re: Correct use of BASS_ATTRIB_TEMPO(_PITCH)
« Reply #12 on: 17 Nov '22 - 13:03 »
Do you want to calculate the tempo processing's effect on the BPM? If so, this should give you that:

Code: [Select]
new_bpm := original_bpm * BASS_FX_TempoGetRateRatio(handle);

kafffee

  • Posts: 185
Re: Correct use of BASS_ATTRIB_TEMPO(_PITCH)
« Reply #13 on: 22 Nov '22 - 04:00 »
Oh cool, this is also interesting for me :)

kafffee

  • Posts: 185
Re: Correct use of BASS_ATTRIB_TEMPO(_PITCH)
« Reply #14 on: 28 Nov '22 - 23:07 »
Will I have to use channel or streamfx as a handle in the TempoGetRateRatio call?

Ian @ un4seen

  • Administrator
  • Posts: 25059
Re: Correct use of BASS_ATTRIB_TEMPO(_PITCH)
« Reply #15 on: 29 Nov '22 - 15:36 »
The handle used in the BASS_FX_TempoGetRateRatio call should be the one returned by BASS_FX_TempoCreate, so "streamfx" in the example above.