23 May '13 - 03:47 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1] 2  All
  Reply  |  Print  
Author Topic: BASS_StreamGetFilePosition(BASS_FILEPOS_CURRENT) returns 0  (Read 1467 times)
jakob
Posts: 69


« on: 10 Sep '12 - 09:49 »
Reply with quoteQuote

hi
i am playing an Ogg file and usign BASS_StreamGetFilePosition to get the current file position.
BASS_StreamGetFilePosition returns correct if i play the file to the end (it stops by it self)
BASS_StreamGetFilePosition returns 0 if i stop or pause the playback in the middle.
BASS_StreamGetFilePosition also returns 0 if i set a position in the middle via BASS_ChannelSetPosition.
It is very important for me to be able to get the current file position after setting a channel position or after stopping playback.
I'v tried to force it to update the file position by:
Bass.BASS_ChannelSetPosition(m_DecodingStream, pos, BASSMode.BASS_POS_BYTES | BASSMode.BASS_POS_DECODETO);
and also tried to read decoded data to trigger a change in current file position:
Bass.BASS_ChannelGetData(m_DecodingStream, dummy, (int)toRead);
nothing i can think of seems to work
I would be very grateful if somone could help me with this.

the streams or channels im using for playback are:
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.0f, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_STREAM_PRESCAN);
m_Stream = BassFx.BASS_FX_TempoCreate(m_ReverseDecodingStream, BASSFlag.BASS_FX_FREESOURCE);
Logged
Ian @ un4seen
Administrator
Posts: 15269


« Reply #1 on: 10 Sep '12 - 14:58 »
Reply with quoteQuote

That sounds strange. Please confirm what handle you're using in the BASS_StreamGetFilePosition call? It should be the "m_DecodingStream" handle, not the tempo or reverse stream handle.
Logged
jakob
Posts: 69


« Reply #2 on: 11 Sep '12 - 08:06 »
Reply with quoteQuote

hi

it was actually the tempo stream that i used, i tried the right stream, but still the same result.
i set the position BASS_ChannelSetPosition using the tempo stream to the length of the audio but
Bass.BASS_StreamGetFilePosition(m_DecodingStream, BASSStreamFilePosition.BASS_FILEPOS_START) + Bass.BASS_StreamGetFilePosition(m_DecodingStream, BASSStreamFilePosition.BASS_FILEPOS_CURRENT)
returns 0
Logged
Ian @ un4seen
Administrator
Posts: 15269


« Reply #3 on: 11 Sep '12 - 17:59 »
Reply with quoteQuote

Do you have reverse playback enabled, ie. BASS_ATTRIB_REVERSE_DIR set to BASS_FX_RVS_REVERSE? If so, that will affect how seeking works and a BASS_ChannelSetPosition call won't change the file position. Seeking will occur during the reverse processing, as it advances (backwards) to the next block of data.
Logged
jakob
Posts: 69


« Reply #4 on: 12 Sep '12 - 07:52 »
Reply with quoteQuote

hi Ian

no, it set to BASS_FX_RVS_FORWARD. I did though find another way to get the file pos in ogg.
BASS returns the position in seconds and from the ogg headers i can calculate the file position from the time position.
So i think i'm god.
Logged
jakob
Posts: 69


« Reply #5 on: 12 Sep '12 - 14:33 »
Reply with quoteQuote

hej Ian

there is another problem now with the player when playing ogg files.
it seems that if i play it to the end more than one time then the length in bytes is growing by the length of the recording each time. file size is still okay but bass returns a length that is teh real audio length multiplied by the number of time i play to the end.
i use the tempo stream to get the length because this has been working with mp3. i also tried the stream from BASS_StreamCreateFile
do you have an idear to what is going on?
Logged
Ian @ un4seen
Administrator
Posts: 15269


« Reply #6 on: 12 Sep '12 - 15:43 »
Reply with quoteQuote

That sounds strange. To confirm, are you saying that the BASS_ChannelGetLength return value is multiplying by the number of playbacks, eg. it'll be 2x normal after a 2nd playback, and 3x after a 3rd playback, etc? Please post the code that you are using to create the stream(s) and get the length.
Logged
jakob
Posts: 69


« Reply #7 on: 12 Sep '12 - 18:55 »
Reply with quoteQuote

your are right
if i play it to the end one time it will give me back the right length. if i play to the end two times it will give me back the right length x 2, and so forth.
i'm at home now, but i will post the code to morrow.
Logged
jakob
Posts: 69


« Reply #8 on: 13 Sep '12 - 08:33 »
Reply with quoteQuote

hi Ian
this is the code:

Creating streams:
private void InitBassStream()
        {
            if (!string.IsNullOrEmpty(AudioFile))
            {
                try
                {
                    log.Info("Creating player stream: " + AudioFile);
                    m_DecodingStream = Bass.BASS_StreamCreateFile(AudioFile, 0, 0, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_PRESCAN);
                    if (m_DecodingStream == 0)
                    {
                        BASSError error = Bass.BASS_ErrorGetCode();
                        if (error == BASSError.BASS_ERROR_FILEFORM)
                            log.Error("Audio file is empty");
                        else
                            log.Error("Bass error " + error.ToString() + " when creating file stream: " + AudioFile);
                    }
                    else
                    {
                        m_ReverseDecodingStream = BassFx.BASS_FX_ReverseCreate(m_DecodingStream, 2.0f, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_STREAM_PRESCAN);
                        if (m_ReverseDecodingStream == 0)
                        {
                            BASSError error = Bass.BASS_ErrorGetCode();
                            log.Error("Bass error " + error.ToString() + " when creating reverse stream: " + AudioFile);
                        }
                        else
                        {
                            m_Stream = BassFx.BASS_FX_TempoCreate(m_ReverseDecodingStream, BASSFlag.BASS_FX_FREESOURCE);
                            if (m_Stream == 0)
                            {
                                BASSError error = Bass.BASS_ErrorGetCode();
                                log.Error("Bass error " + error.ToString() + " when creating tempo stream: " + AudioFile);
                            }
                            else
                            {
                                PositionInSeconds = 0;
                                PlayDirection = AudioPlayDirection.Forward;
                                m_syncProc = new SYNCPROC(PlayBackEndedCallback);
                                m_PlaybackEndedEventHandle = Bass.BASS_ChannelSetSync(m_Stream, BASSSync.BASS_SYNC_END, 0, m_syncProc, IntPtr.Zero);
                                if (m_PlaybackEndedEventHandle == 0)
                                {
                                    BASSError error = Bass.BASS_ErrorGetCode();
                                    log.Error("Bass error " + error.ToString() + " when creating playback ended event");
                                }
                                m_dspProc = new DSPPROC(PlayingCallback);
                                m_PlaybackEventHandle = Bass.BASS_ChannelSetDSP(m_Stream, m_dspProc, IntPtr.Zero, 0);
                                if (m_PlaybackEventHandle == 0)
                                {
                                    BASSError error = Bass.BASS_ErrorGetCode();
                                    log.Error("Bass error " + error.ToString() + " when creating playback event");
                                }
                            }
                        }
                    }
                    log.Info("Player stream created");
                }
                catch (Exception ex)
                {
                    log.Error("Error initializing player stream: " + AudioFile, ex);
                }
            }
        }
this is teh code to get the length:
public long LengthInBytes
        {
            get
            {
                if (m_Stream != 0)
                {
                    try
                    {
                        long length = Bass.BASS_ChannelGetLength(m_Stream, BASSMode.BASS_POS_BYTES);
                        if (length == -1)
                        {
                            BASSError error = Bass.BASS_ErrorGetCode();
                            log.Error("Bass error " + error.ToString() + " when getting player length in bytes");
                        }
                        return length;
                    }
                    catch (Exception ex)
                    {
                        log.Error("Error getting player length in bytes", ex);
                    }
                }
                return 0;
            }
        }
i'v verifide with ogginfo.exe and oggz-info.exe that the ogg file is fine.
Logged
Ian @ un4seen
Administrator
Posts: 15269


« Reply #9 on: 13 Sep '12 - 15:03 »
Reply with quoteQuote

I don't seem to be able to reproduce the problem with similar code to that, so perhaps there is something else that is influencing things. Do the repeat playbacks actually last longer than the first playback, like BASS_ChannelGetLength says? If so, are you playing the file while it is being written? If that's not it, please try removing/disabling stuff in your code to narrow down what is causing the problem, eg. does it happen without the tempo or reverse streams? Also, is the problem only happening with OGG files, and not with any other file format when using the exact same code?
Logged
jakob
Posts: 69


« Reply #10 on: 13 Sep '12 - 15:32 »
Reply with quoteQuote

hi Ian
the repeated playbacks does not last longer it is only the get length call that returns wrong length.
i'm not recording during playback.
I'v only seen it with ogg files. MP3 is fine.
Could i send you a ogg file?
Logged
Ian @ un4seen
Administrator
Posts: 15269


« Reply #11 on: 13 Sep '12 - 15:57 »
Reply with quoteQuote

Yep, please upload the file here:

   ftp.un4seen.com/incoming/
Logged
jakob
Posts: 69


« Reply #12 on: 13 Sep '12 - 16:11 »
Reply with quoteQuote

okay it's there
Logged
Ian @ un4seen
Administrator
Posts: 15269


« Reply #13 on: 13 Sep '12 - 17:08 »
Reply with quoteQuote

Got it, thanks. It is actually a Speex file, and there does indeed appear to be a bug in the BASS_SPX add-on. Here's an update that should fix it...

   www.un4seen.com/stuff/bass_spx.dll

Let me know if the problem still happens with that.
Logged
jakob
Posts: 69


« Reply #14 on: 14 Sep '12 - 12:18 »
Reply with quoteQuote

hi Ian

It worked, thank you very much. Cheesy
Logged
jakob
Posts: 69


« Reply #15 on: 17 Sep '12 - 11:17 »
Reply with quoteQuote

hi Ian

there is actualy still a problem with the player.
it seems that when loading the file into the player it has a certain length. but when i play it to the end it has a sligthly different length (longer).
i think there might still be a problem in the bass_spx.dll
i compare the length when the stream has been created with the length then i get the BASS_SYNC_END event.
By the way i don't know if this is correct implementation but as you know i use both a file stream, reverse stream and a tempo stream.
I use the tempo stream to get the length.
Should i rather use the file stream to get the length and position?
Logged
Ian @ un4seen
Administrator
Posts: 15269


« Reply #16 on: 17 Sep '12 - 14:19 »
Reply with quoteQuote

it seems that when loading the file into the player it has a certain length. but when i play it to the end it has a sligthly different length (longer).
i think there might still be a problem in the bass_spx.dll

Yeah, I noticed that too. I'll see if something can be done about that.

Regarding the stream handle to use in a BASS_ChannelGetLength call, a tempo or reverse stream will forward the request to its source stream, so it won't matter which handle you use. The same is actually true for BASS_StreamGetFilePosition too, despite what I said about that earlier in this thread Smiley
Logged
jakob
Posts: 69


« Reply #17 on: 19 Sep '12 - 08:00 »
Reply with quoteQuote

hi Ian

thank's for the info and i realy hope you can work your magic on the length problem.
i'll be waiting Cheesy
Logged
jakob
Posts: 69


« Reply #18 on: 20 Sep '12 - 13:09 »
Reply with quoteQuote

hi Ian
How goes. Not to stress you to much, but do you have an idear when a fix is ready. The reason i'm asking is that we have a deadline very soon.
Logged
Ian @ un4seen
Administrator
Posts: 15269


« Reply #19 on: 20 Sep '12 - 17:32 »
Reply with quoteQuote

Here's something to try...

   www.un4seen.com/stuff/bass_spx.dll

The modifications haven't been tested very much yet, so please let me know how you get on.
Logged
Pages: [1] 2  All
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.18 | SMF © 2013, Simple Machines