Correct use of BASS_ATTRIB_TEMPO(_PITCH)

Started by kafffee,

kafffee

Hey there,

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

Right now I got the following:

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:
Bass.BASS_ChannelSetAttribute(stream, BASSAttribute.BASS_ATTRIB_TEMPO, CSng(TrackBar1.Value))
respectively:
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

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: https://www.un4seen.com/forum/?topic=19567.0

kafffee

OK, I did this:

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:
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

#3
hi,
should to be
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

#4
Ok did this. But in this line:

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...

Chris


streamfx = BassFx.BASS_FX_TempoCreate(stream,BASS_FX_FREESOURCE)

kafffee

#6
No still the same. I cant't hear anything either... When I use the slider to change tempo, error no 5...
And after this:
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:
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

Chris

The BASS_STREAM_AUTOFREE flag cannot be combined with the BASS_STREAM_DECODE flag.


so you can try that
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)


Bernardo S Martins

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

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.

   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

cool, it worked!
Now how do I make the label_bpm receive the value of
the bpm when I change the picth.

Ian @ un4seen

Do you want to calculate the tempo processing's effect on the BPM? If so, this should give you that:

new_bpm := original_bpm * BASS_FX_TempoGetRateRatio(handle);


kafffee

Will I have to use channel or streamfx as a handle in the TempoGetRateRatio call?

Ian @ un4seen

The handle used in the BASS_FX_TempoGetRateRatio call should be the one returned by BASS_FX_TempoCreate, so "streamfx" in the example above.