Author Topic: reverse play with tempo and pitch  (Read 158 times)

djshahar

  • Posts: 18
reverse play with tempo and pitch
« on: 2 Dec '18 - 12:58 »
after testing over and over again, i am lost.

is there a way to play a song forward or backward .. while applying tempo and pitch?

i need this feature in order to scratch songs.

thank you.

morknotmindy

  • Posts: 12
Re: reverse play with tempo and pitch
« Reply #1 on: 2 Dec '18 - 17:48 »
Something along these lines for an mp3...(in Lazarus/Pascal I'm afraid):

{chan is global HSTREAM}

chan:=BASS_StreamCreateFile(false, Pchar(filename), 0, 0, BASS_STREAM_PRESCAN or BASS_STREAM_DECODE or BASS_UNICODE);

chan := BASS_FX_ReverseCreate(chan, 2 ,BASS_STREAM_DECODE Or BASS_FX_FREESOURCE);
     
BASS_ChannelSetAttribute(chan, BASS_ATTRIB_REVERSE_DIR, BASS_FX_RVS_FORWARD);

 chan := BASS_FX_TempoCreate(chan, BASS_SPEAKER xxx or BASS_FX_FREESOURCE);

To change direction using a button, for example:

procedure Button1Click();
var
srcChan:HSTREAM;
begin
srcChan:=0;
If BASS_ChannelIsActive(chan)=BASS_ACTIVE_PLAYING then
begin
srcChan:= BASS_FX_TempoGetSource(chan);
If srcChan<>0 then
begin
If Button1.Down then
BASS_ChannelSetAttribute(srcChan, BASS_ATTRIB_REVERSE_DIR, BASS_FX_RVS_REVERSE)
  else     
BASS_ChannelSetAttribute(srcChan, BASS_ATTRIB_REVERSE_DIR, BASS_FX_RVS_FORWARD);
end;
end;
end;

For both forward and reverse states you can then apply a tempo change with:

 BASS_ChannelSetAttribute(chan, BASS_ATTRIB_TEMPO, tempoValue);

a pitch change with

BASS_ChannelSetAttribute(chan, BASS_ATTRIB_TEMPO_PITCH, pitchValue); 
 
or both together with

BASS_ChannelSetAttribute(chan, BASS_ATTRIB_TEMPO_FREQ, samplerate*(tempoandpitchValue)); 

end;

Have a look at the BASS_FX documentation for specifics. Hope this helps. 
« Last Edit: 2 Dec '18 - 18:01 by morknotmindy »

djshahar

  • Posts: 18
Re: reverse play with tempo and pitch
« Reply #2 on: 5 Dec '18 - 17:47 »
Why won't this work? .. c# bass.net
Code: [Select]
   int stream = 0;
            var flags = BASSFlag.BASS_STREAM_PRESCAN | BASSFlag.BASS_STREAM_DECODE;
            stream = Bass.BASS_StreamCreateFile(file, 0L, 0L, flags);
            if (stream == 0)
                switch (Path.GetExtension(file).ToLower()) //switch file extension type
                {
                    case ".wmv":
                    case ".wma": stream = BassWma.BASS_WMA_StreamCreateFile(file, 0L, 0L, flags); break;
                    case ".wv": stream = BassWv.BASS_WV_StreamCreateFile(file, 0L, 0L, flags); break;
                    case ".midi": stream = BassMidi.BASS_MIDI_StreamCreateFile(file, 0L, 0L, flags, 0); break;
                    case ".flac": stream = BassFlac.BASS_FLAC_StreamCreateFile(file, 0L, 0L, flags); break;
                    case ".aac": stream = BassAac.BASS_AAC_StreamCreateFile(file, 0L, 0L, flags); break;
                    case ".mp4": stream = BassAac.BASS_MP4_StreamCreateFile(file, 0L, 0L, flags); break;
                    case ".hls": stream = BassHls.BASS_HLS_StreamCreateFile(file, 0L, 0L, flags); break;
                    case ".dsd": stream = BassDsd.BASS_DSD_StreamCreateFile(file, 0L, 0L, flags, 0); break;
                    case ".cda": stream = BassCd.BASS_CD_StreamCreateFile(file, flags); break;
                    case ".alac": stream = BassAlac.BASS_ALAC_StreamCreateFile(file, 0L, 0L, flags); break;
                    case ".tas": stream = Bass.BASS_StreamCreateFile(file, 0L, 0L, flags); break; //
                    case ".spx": stream = BassSpx.BASS_SPX_StreamCreateFile(file, 0L, 0L, flags); break;
                    case ".mpc": stream = BassMpc.BASS_MPC_StreamCreateFile(file, 0L, 0L, flags); break;
                    case ".ape": stream = BassApe.BASS_APE_StreamCreateFile(file, 0L, 0L, flags); break;
                    case ".aix": stream = Bass.BASS_StreamCreateFile(file, 0L, 0L, flags); break;//
                    case ".adx": stream = BassAdx.BASS_ADX_StreamCreateFile(file, 0L, 0L, flags); break;
                    case ".ac-3":
                    case ".ac3": stream = BassAc3.BASS_AC3_StreamCreateFile(file, 0L, 0L, flags); break;
                        /*
                         case ".mp3":
                         case ".mp2":
                         case ".mp1":
                         case ".ogg":
                         case ".wav":
                         default: stream = Bass.BASS_StreamCreateFile(file, 0L, 0L, flags); break;
                         */
                }
            stream = BassFx.BASS_FX_ReverseCreate(stream, 2f, BASSFlag.BASS_STREAM_PRESCAN | BASSFlag.BASS_STREAM_DECODE|BASSFlag.BASS_FX_FREESOURCE);
            Bass.BASS_ChannelSetAttribute(stream, BASSAttribute.BASS_ATTRIB_REVERSE_DIR, 1f);
            stream = BassFx.BASS_FX_TempoCreate(stream, BASSFlag.BASS_FX_FREESOURCE);
            return stream;

Ian @ un4seen

  • Administrator
  • Posts: 21370
Re: reverse play with tempo and pitch
« Reply #3 on: 5 Dec '18 - 18:05 »
That code looks mostly fine, but BASS_STREAM_PRESCAN isn't a valid flag for BASS_FX_ReverseCreate, so you should remove that flag from that call.

What exactly isn't working? If a call is failing (returning 0), please check the error code immediately after with BASS_ErrorGetCode.

djshahar

  • Posts: 18
Re: reverse play with tempo and pitch
« Reply #4 on: 5 Dec '18 - 18:40 »
at best: it cracks and pops. at worst: it's static hiss all over.

either way, it won't play in reverse

here is my code to switch direction
Code: [Select]
//reverse
Bass.BASS_ChannelSetAttribute(stream, BASSAttribute.BASS_ATTRIB_REVERSE_DIR, -1f);
//forward
Bass.BASS_ChannelSetAttribute(stream, BASSAttribute.BASS_ATTRIB_REVERSE_DIR, 1f);

Ian @ un4seen

  • Administrator
  • Posts: 21370
Re: reverse play with tempo and pitch
« Reply #5 on: 6 Dec '18 - 16:25 »
To narrow down where the problem is coming from, are you getting it with all files (with differing file formats) that you try? If so, does it still happen if you remove the tempo processing or the reverse processing?

djshahar

  • Posts: 18
Re: reverse play with tempo and pitch
« Reply #6 on: 9 Dec '18 - 13:09 »
hello Ian,

I can apply either Tempo/Pitch OR Reverse.

Both work well when done alone.

it's the combination of both that causes issues

i only use mp3s for testing.

Ian @ un4seen

  • Administrator
  • Posts: 21370
Re: reverse play with tempo and pitch
« Reply #7 on: 10 Dec '18 - 14:48 »
What platform are you running on and are you using the standard or "mp3-free" BASS version? To eliminate the problem being something specific to MP3, please try with WAV files too.