Author Topic: Data needed for creating a BUFFERPUSH stream  (Read 322 times)

xandy

  • Posts: 17
Really need some advice on fine-tuning the creation of a BUFFERPUSH stream. All is happening on an old win32 (xp) system; sorry if the obsolete OS is to blame for my issues. The bass components are up to date. Device's min_buf is 40 ms; only flag used for BASS_StreamCreateFileUser is BASS_SAMPLE_FLOAT.

A basic DirectShow graph (DVBs things-callback filter-nullrenderer) pushes MP2 or AC3 audio payload to a bass stream. In the DVB world audio sampling-rate is 48k, depending on station the MP2 bitrate varies from 96 to 320 kbps; some broadcasts are AC3 with 448 kbps. The app is a simple dvb-sat radioplayer. After adjusting the "speed" of bass by lowering the BASS_ATTRIB_FREQ a little bit all is working well.

I really want the app to start playback as soon as possible after a station is tuned. On the DirectShow side of things the filtergraph runs "as fast as possible" (sync set to null). The first datapacket pushed is aligned to frame start, i.e. starts with a syncbyte.
For the creation of the stream the FILEREADPROC asks for 8192 bytes of data (320 kbps) or 4096 bytes (96 kbps). That are 8 (for 320 kbps) or 14 frames (for 96 kbps). Tried various things (BASS_CONFIG_VERIFY_NET, shorter NET- and/or playback buffers, updateperiod), but I can't get bass to recognize the audio and initialize the stream with less data (setting VERIFY_NET to minimum even increased the amount requested). Any advice?
BTW: After creation the stream plays happily with a nearly empty NET- and most likely never filled playback buffer (all settings default).

Finally two observations on AC3 streams:
- BASS_ATTRIB_BITRATE reports 3584 kbps when used in the BUFFERPUSH stream; the same data dumped and played from file shows the correct value of 448 kbps
- AC3 streams with more than 2 channels give lower FFT values over all bins compared to the MP2 stream (some broadcasters have both); the volume appears similar, the difference seems to be in the region of 8-10 dB; the effect can be reproduced with saved data played from file

Thanks in advance

Ian @ un4seen

  • Administrator
  • Posts: 20848
Re: Data needed for creating a BUFFERPUSH stream
« Reply #1 on: 10 Jan '17 - 17:15 »
Are you using the latest BASS release (2.4.12) or the latest "stuff" build? If the former, you can get the latter here:

   www.un4seen.com/stuff/bass.zip

With the current release, BASS will assume it's at the end of the file if your FILEREADPROC returns 0 and it will close the file, but the update allows a FILEREADPROC to return 0 without closing the file. That should allow you to call BASS_StreamCreateFileUser with less file data available. For some more info, here is where that change was introduced:

   www.un4seen.com/forum/?topic=17186.msg120470#msg120470

xandy

  • Posts: 17
Re: Data needed for creating a BUFFERPUSH stream
« Reply #2 on: 10 Jan '17 - 18:00 »
Thank you!

The new bass 2.4.12.14 is working for me.
StreamCreate needs less data; even the 448 kbps AC3 stream is created with only 4096 bytes of data for the FILEREADPROC - that's really snappy. Haven't tried lower values yet.

But - the code that worked with 2.4.12 didn't work with the update. Somehow the stream didn't accept the pushed data.
I checked the BASS_FILEPOS_BUFFER for every loop of the pushing routine (stream not playing). The FILEPOS value didn't change.
After some trial and error I found the culprit. After stream creation I push the pre-buffered data not used by the FILEREADPROC - without a check if any data is available at all. 2.4.12 accepts a push of length 0; 2.4.12.14 seems not; perhaps the stream is ended?
« Last Edit: 10 Jan '17 - 18:29 by xandy »

xandy

  • Posts: 17
Re: Data needed for creating a BUFFERPUSH stream
« Reply #3 on: 11 Jan '17 - 07:24 »
Okay - that was nonsense with the 0-length data push and bass 2.4.12. The event never happened with my old code as the prebuffer had always more than 8k of data.

Now for some rule-of-the-thumb observations (2.4.12.14):
- the FILEREADPROC needs at least one complete frame (incl header of the following frame) worth of data to create a MP2 push stream;
- for a AC3 stream the limit seems to be 2 complete frames.
Perhaps 1 frame is right for bass.dll codecs, and 2 frames for plugin codecs?

As now much less data is used for StreamCreate more data has to be buffered (filebuffer) before playback can start without risking stutter/stalls. On my rig the limit seems to be around 3.5% of the buffer - but ymmv. Overall the tune-start of playback latency is much better with 2.4.12.14; and doesn't vary with the bitrate of the data as it did with 2.4.12. Thank you for that.

The behavior with AC3 data is still irritating. Not only is the reported bitrate 8-times the real value, but the filebuffer created is oversized too: 2.240.000 bytes which should be 280.000 imho.

Thanks again!

Ian @ un4seen

  • Administrator
  • Posts: 20848
Re: Data needed for creating a BUFFERPUSH stream
« Reply #4 on: 11 Jan '17 - 15:14 »
There was indeed a problem with the bitrate calculation for buffered streams in BASS_AC3 (8x what it should be). Here's an update to fix that:

   www.un4seen.com/stuff/bass_ac3.zip

Let me know if you still see any bitrate problems with AC3 streams.

Regarding passing length=0 to BASS_StreamPutFileData, that will actually signal the end of file because BASS_FILEDATA_END=0.

xandy

  • Posts: 17
Re: Data needed for creating a BUFFERPUSH stream
« Reply #5 on: 11 Jan '17 - 16:57 »
What can I say other than "thank you". The new AC3 plugin works like a charm. Overall I'm very happy with the bass-powered sat-radio player.

Shouldn't bother you further for some time to come.
But - what about the FFT values of AC3 streams with more than 2 channels? I've recorded a minute of 6Ch AC3 and parallel the same broadcast in MP2 format. For me (and I may be wrong) the volume levels seem similar, the FFT values (I "judge" this with a spectrum visualization) for the AC3 stream are at least 6dB smaller compared to the MP2 stream. Other broadcasters have MP2/2Ch AC3 options, and with them volumes and spectrums are both similar.

I've uploaded an archive with the audio files:
http://www92.zippyshare.com/v/5R6iDZrR/file.html

Ian @ un4seen

  • Administrator
  • Posts: 20848
Re: Data needed for creating a BUFFERPUSH stream
« Reply #6 on: 12 Jan '17 - 14:27 »
Unless the BASS_DATA_FFT_INDIVIDUAL flag is used, BASS_ChannelGetData averages the levels across all channels in the FFT calculation. So if you have a 6 channel stream with 4 empty channels, then the level will be 33% of the level of a stereo stream with the same sound. If you are only using 2 channels in the AC3 file, perhaps you could create a stereo AC3 file instead of a 6 channel file? That would avoid the level drop in the FFT data. Another possibility could be to add a stereo downmix option in BASS_AC3 (that code is present but unused currently).

xandy

  • Posts: 17
Re: Data needed for creating a BUFFERPUSH stream
« Reply #7 on: 12 Jan '17 - 18:07 »
An absolute noob with this multi-channel thing, that's me. Thank you for the info; will check for an update of the AC3 plugin from time to time.