BASS_ChannelSetPosition is failing.

Started by jakob,

jakob

hi
i'm using BASS_ChannelSetPosition to set the position of my playback stream to the end.
the problem is that it failes with BASS_ERROR_POSITION even though i first calls BASS_ChannelGetLength and set it to that value.
This is what i do:

long length = Bass.BASS_ChannelGetLength(m_Stream,BASSMode.BASS_POS_BYTES);
Bass.BASS_ChannelSetPosition(m_Stream, length, BASSMode.BASS_POS_BYTES);
BASSError error = Bass.BASS_ErrorGetCode();
long pos = Bass.BASS_ChannelGetPosition(m_Stream, BASSMode.BASS_POS_BYTES);

i also try to get the position aftere setting it, and it is not setting it to the length.

there is no problem if i substract one byte from the length, but this, i would rather not do, be cause i'm also using a trackbar to show the position and then this would be incorrect.

can anybody help me with this?

 

Ian @ un4seen

BASS doesn't permit seeking right to the end, so you would need to go just before that, eg. subtract one. To get to the very end, you could then seek again with the BASS_POS_DECODETO flag...

BASS_ChannelSetPosition(handle, end-1, BASS_POS_BYTE); // seek to just before then end
BASS_ChannelSetPosition(handle, end, BASS_POS_BYTE|BASS_POS_DECODETO); // decode to the end

jakob

hi Ian

thanks for the quick reply.

this line works:
Bass.BASS_ChannelSetPosition(m_Stream, length-1, BASSMode.BASS_POS_BYTES);

unfortunately i get a BASS_ERROR_NOTAVAIL when i run this line, also if i try to set the position in the middle of the stream:
Bass.BASS_ChannelSetPosition(m_Stream, length, BASSMode.BASS_POS_BYTES | BASSMode.BASS_POS_DECODETO);

Do you have some idear as to what im doing wrong?

Ian @ un4seen

Please use BASS_GetVersion to check what BASS.DLL version is being loaded. The BASS_POS_DECODETO flag was introduced in 2.4.7, so it needs to be using at least that (0x02040700). If it is and you still get a BASS_ERROR_NOTAVAIL error, what sort of stream is it that you are playing?

jakob

hi Ian

I'm using version 0x02040801

I'm using a Tempo stream, this is the creation of it:

private void InitBassStream()
        {
            if (!string.IsNullOrEmpty(AudioFile))
            {
                m_DecodingStream = Bass.BASS_StreamCreateFile(AudioFile, 0, 0, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_PRESCAN);
                m_ReverseDecodingStream = BassFx.BASS_FX_ReverseCreate(m_DecodingStream, 2, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_STREAM_PRESCAN);
                if (m_ReverseDecodingStream != 0)
                {
                    m_Stream = BassFx.BASS_FX_TempoCreate(m_ReverseDecodingStream, BASSFlag.BASS_FX_FREESOURCE);
                    PositionInSeconds = 0;
                    PlayDirection = AudioPlayDirection.Forward;
                    m_syncProc = new SYNCPROC(PlayBackEndedCallback);
                    m_syncHandle = Bass.BASS_ChannelSetSync(m_Stream, BASSSync.BASS_SYNC_END, 0, m_syncProc, IntPtr.Zero);
                    m_dspProc = new DSPPROC(PlayingCallback);
                    m_dspHandle = Bass.BASS_ChannelSetDSP(m_Stream, m_dspProc, IntPtr.Zero, 0);
                }
            }
        }

Chris

#5
Quote from: Ian @ un4seenBASS doesn't permit seeking right to the end, so you would need to go just before that, eg. subtract one. To get to the very end, you could then seek again with the BASS_POS_DECODETO flag...

BASS_ChannelSetPosition(handle, end-1, BASS_POS_BYTE); // seek to just before then end
BASS_ChannelSetPosition(handle, end, BASS_POS_BYTE|BASS_POS_DECODETO); // decode to the end



BASS_ChannelSetPosition(handle, end-1, BASS_POS_BYTE); // will working fine
BASS_ChannelSetPosition(handle, end, BASS_POS_BYTE|BASS_POS_DECODETO); // // will working fine

// and Bass will me notice that the File has end and thats correct!!
Chris


Chris

#6
@ jakob after I have seen your source its a litttle bit more logic why your code will not work.
procedure TForm4.Button1Click(Sender: TObject);
begin
  if OpenDialog1.Execute then
  begin
    Bass_StreamFree(Chan);
    Chan := Bass_StreamCreateFile(false, PChar(OpenDialog1.FileName), 0, 0,BASS_SAMPLE_FLOAT or BASS_STREAM_PRESCAN or BASS_STREAM_DECODE or BASS_UNICODE);
    Chan := BASS_FX_ReverseCreate(Chan, 2, BASS_STREAM_DECODE or BASS_FX_FREESOURCE);
    Chan := BASS_FX_TempoCreate(Chan, BASS_FX_FREESOURCE);
    BASS_ChannelSetAttribute(BASS_FX_TempoGetSource(Chan), BASS_ATTRIB_REVERSE_DIR, BASS_FX_RVS_FORWARD);
    Bass_ChannelPlay(Chan, false);
  end;
end;


procedure TForm4.Button2Click(Sender: TObject);
var
  len: int64;
begin
  len := BASS_ChannelGetLength(Chan, BASS_POS_BYTE);
  BASS_ChannelSetPosition(Chan, len - 1, BASS_POS_BYTE);
  // seek to just before then end
  BASS_ChannelSetPosition(Chan, len, BASS_POS_BYTE or BASS_POS_DECODETO);
  // decode to the end
  ShowMessage(inttostr(Bass_ErrorGetCode()));
end;

will working here fine

If you don`t setting this
 BASS_ChannelSetAttribute(BASS_FX_TempoGetSource(Chan), BASS_ATTRIB_REVERSE_DIR, BASS_FX_RVS_FORWARD);so then of Cource you position call must be
BASS_ChannelSetPosition(Chan, 1, BASS_POS_BYTE);  // seek to just before then end
  BASS_ChannelSetPosition(Chan, 0, BASS_POS_BYTE or BASS_POS_DECODETO);
Chris

Ian @ un4seen

Quote from: jakobI'm using a Tempo stream

OK. I don't think tempo (or reverse) streams currently support the DECODETO flag, so that would explain it. I'll check with Arthur and see if we can do something about that.

jphilippe

Hi Ian,

Has this problem been sovled? i.e. DECODETO flags on tempo streams?

jakob

hi all
yes this has been solved, thank you for all the help