Author Topic: Granularity of STREAMPROC_DEVICE streams  (Read 199 times)

saga

  • Posts: 2551
Granularity of STREAMPROC_DEVICE streams
« on: 21 Oct '21 - 14:41 »
I have a STREAMPROC_DEVICE stream on which I'd like to process the final device output in chunks of 20ms; I've tried all of the the following:

Code: [Select]
BASS_SetConfig(BASS_CONFIG_BUFFER, 60);
BASS_SetConfig(BASS_CONFIG_UPDATEPERIOD, 20);
BASS_SetConfig(BASS_CONFIG_DEV_BUFFER, 60);
BASS_SetConfig(BASS_CONFIG_DEV_PERIOD, 20);
BASS_ChannelSetAttribute(outputDeviceStream, BASS_ATTRIB_GRANULE, 960);

However, my DSPROC is still getting frames of 480 samples (@ 48000 Hz, tested on Windows only so far). Am I missing something, or is there no way to set the granule of the final output stream DSP?

Ian @ un4seen

  • Administrator
  • Posts: 23997
Re: Granularity of STREAMPROC_DEVICE streams
« Reply #1 on: 21 Oct '21 - 16:10 »
The BASS_ATTRIB_GRANULE option isn't available on DEVICE streams (it only applies to normal playback and recording channels). The device update period (BASS_CONFIG_DEV_PERIOD) will determine the amount of data that's processed each time by the DEVICE stream, but unfortunately that option isn't available on Windows either (except XP and older), as Windows' processing period is used automatically.

What you could do is have your DSPPROC move the data to another buffer that gets processed once there's enough, and then copy the output back to the stream's buffer. When there's no output (eg. on the first call) then you would clear (fill with 0) the stream's buffer.

saga

  • Posts: 2551
Re: Granularity of STREAMPROC_DEVICE streams
« Reply #2 on: 21 Oct '21 - 16:22 »
Ah, too bad. Yeah, I guess I'll have to add an additional buffer then.

By the way, while researching the various config values, I figured that the example for BASS_CONFIG_DEV_PERIOD should be fixed (it refers to a stream parameter that doesn't exist).

Ian @ un4seen

  • Administrator
  • Posts: 23997
Re: Granularity of STREAMPROC_DEVICE streams
« Reply #3 on: 21 Oct '21 - 16:40 »
Oops, that's been corrected now. Thanks for pointing it out.

saga

  • Posts: 2551
Re: Granularity of STREAMPROC_DEVICE streams
« Reply #4 on: 25 Oct '21 - 16:58 »
I think I'll hijack my own topic while we're talking about STREAMPROC_DEVICE.... ;D

I found the following using the latest BASS "stuff" version for Windows: Changing the sample rate in the control panel for the device currently used by BASS, say from 48 kHz to 44.1 kHz, doesn't cause a BASS_SYNC_DEV_FAIL on any of my streams, which is fine as streams continue playing as they should. However, the DSP callback function that I set for my STREAMPROC_DEVICE ceases to be called. I suppose that's a bug as otherwise there is no way to know when to recreate the device stream.

Ian @ un4seen

  • Administrator
  • Posts: 23997
Re: Granularity of STREAMPROC_DEVICE streams
« Reply #5 on: 26 Oct '21 - 16:52 »
Yeah, a rate change won't trigger BASS_SYNC_DEV_FAIL syncs but it will/should trigger BASS_SYNC_DEV_FORMAT syncs. In the case of a DEVICE stream, a BASS_SYNC_FREE sync is actually the best way to handle it. A DEVICE stream is freed when the device's format changes (that's why your DSP stops being called), and if you recreate the DEVICE stream within a BASS_SYNC_FREE callback then the new stream will immediately receive the data following the format change, so no data is missed.

saga

  • Posts: 2551
Re: Granularity of STREAMPROC_DEVICE streams
« Reply #6 on: 27 Oct '21 - 08:35 »
Thanks, using BASS_SYNC_FREE did the trick.