24 May '13 - 18:35 *
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]
  Reply  |  Print  
Author Topic: Unbuffered BASS_StreamCreate  (Read 255 times)
jasona
Posts: 21


« on: 13 Nov '12 - 13:03 »
Reply with quoteQuote

Hello,

I am trying to create a generic class that can take raw audio from some provider (a file, a net stream, a memory buffer) and write it to some output (WDM output, ASIO output, a file).

I've been using BASS_StreamCreate to pull the decoded data, but this creates a buffer which is a pain when I want to seek the source data - I have to wait for the buffer to run out before it actually seeks. I tried lowering the buffer via SetConfig, but this causes glitching below 100ms and will probably be risky on slow computers.

When seeking when using BASS_StreamCreateFile, the audio immediately seeks when I `SetPosition` - I would like to replicate this.

Looking at BASS_StreamCreateFileUser, the documentation says that STREAMFILE_NOBUFFER is what is used by BASS_StreamCreateFile. I tried creating a BASS_StreamCreateFileUser channel with PROC callbacks to get the correct length etc and pull in the decoded data for my audio provider. This didn't seem to work as it complained that BASS_ERROR_FILEFORM - I assume that it was requiring some header bytes to say that it was a raw WAV file?

Is there a way to have an unbuffered BASS_StreamCreate or an alternative work around.

Any help here would be appreciated,
Thanks,
Jason
Logged
Ian @ un4seen
Administrator
Posts: 15276


« Reply #1 on: 13 Nov '12 - 17:43 »
Reply with quoteQuote

It is possible to clear a custom stream's buffer(s) by calling BASS_ChannelSetPosition with pos=0, so you could do that after seeking. For example...

BASS_ChannelLock(handle, TRUE); // lock the stream to block updates while seeking
// seeking code here
BASS_ChannelSetPosition(handle, 0, BASS_POS_BYTE); // clear buffers
BASS_ChannelLock(handle, FALSE); // unlock the stream
Logged
jasona
Posts: 21


« Reply #2 on: 13 Nov '12 - 18:08 »
Reply with quoteQuote

Hi Ian,

Thank you for your response. I originally got around the problem by seeking to the position, then stopping and starting the stream - this seemed to work...

What you have suggested also seems to work. At first glimpse, setting the position to 0 is a little misleading but your documentation does say:

'User streams (created with BASS_StreamCreate) are not seekable, but it is possible to reset a user stream (including its buffer contents) by setting its position to byte 0. ' Smiley

I shall go with your solution as it is the documented one. Maybe it is worth adding that line to the BASS_StreamCreate documentation page Smiley. Thank you very much for your help.

Jason
Logged
Ian @ un4seen
Administrator
Posts: 15276


« Reply #3 on: 14 Nov '12 - 16:04 »
Reply with quoteQuote

Yep, stopping a custom stream (via BASS_ChannelStop) will clear its buffers, so that will work too. Yet another way of clearing the buffers is to call BASS_ChannelPlay with restart=TRUE. The BASS_ChannelSetPosition method has the advantage of not affecting the playback state, eg. it can be used while playing/paused/stopped.

Regarding the documentation, you're right. I'll get on it!
Logged
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.18 | SMF © 2013, Simple Machines