Author Topic: Create stream from sample  (Read 273 times)

QuentinC

  • Posts: 39
Create stream from sample
« on: 14 Aug '17 - 04:10 »
Hello,

This is known, it's impossible to add effects to channels created from samples.

Thus I would like to know what is the best / most efficient way to create a stream from a sample or from an in-memory buffer. The stream must be loopable.
It's for a game, so it will potentially happen a lot of times, and the time taken to create streams and make them play must be short (hance the performance question).

I see several solutions for this, but none seem to be really ideal:
1. Create an in-memory stream with BASS_StreamCreateFile ? but since it can't load raw data, I need to prepend some file header (probably the easiest and quickest in load time is WAV) ? and is it possible to have float data with WAV header ? Looks a bit like a bad hack
2. Create a push stream and push data afterwards ? but can push streams be looped ?
3. Create a stream via BASS_StreamCreate, but how could I handle loop ? and seeking ?
4. Use the internal BASS API (the one of bass_addon.h) ? But is there a way to create a stream with finite length data without the need to handle looping yourself ?
5. Another mean I didn't think of ?

I also have additional bonus questions:
1. Given that I want to be able to use effects and create streams instead of samples, is it still interesting / useful to load sounds into samples, rather than reading data myself using decode streams ?
2. How to make a channel (stream or sample) loop exactly n times ?

Thank you for your answers !

Ian @ un4seen

  • Administrator
  • Posts: 20401
Re: Create stream from sample
« Reply #1 on: 14 Aug '17 - 18:15 »
Do you also need to be able to retrieve the current position, as well as looping and seeking? If so, putting a WAV header in front of the data (and passing the whole thing to BASS_StreamCreateFile with mem=TRUE) would probably be simplest, as BASS will handle the position stuff then. The RECTEST example included in the BASS package shows how you can generate a WAV header. For floating-point data, you would set "wFormatTag" to 3 (WAVE_FORMAT_IEEE_FLOAT).

QuentinC

  • Posts: 39
Re: Create stream from sample
« Reply #2 on: 15 Aug '17 - 19:56 »
Ok, that's what I though but I wanted to  be sure that I didn't miss another simpler way.


Is the time overhead at stream creation negligible, compared to the creation of a sample channel ?

In fact is it problematic if there are 100+ streams playing at the same time ? For sample channels it works fine.

Thank you

Ian @ un4seen

  • Administrator
  • Posts: 20401
Re: Create stream from sample
« Reply #3 on: 16 Aug '17 - 15:41 »
Is the time overhead at stream creation negligible, compared to the creation of a sample channel ?

Stream creation from a WAV file in memory should be very quick. Still, if there are some sounds that you will be playing very often, you could keep a pool of them ready to go. Each stream will have its own playback buffer, which means it will use more memory than a sample would (a sample's channels all share the same data/buffer), but you could reduce that via the BASS_CONFIG_BUFFER option. The default is 500ms; 300ms should be fine (with the default BASS_CONFIG_UPDATEPERIOD setting of 100ms).

In fact is it problematic if there are 100+ streams playing at the same time ? For sample channels it works fine.

There is no fixed limit to the number of streams that you can play, but stream playback will use a bit more CPU than sample playback would, particularly if you apply effects.

QuentinC

  • Posts: 39
Re: Create stream from sample
« Reply #4 on: 12 Sep '17 - 17:58 »
Hello,

Thank you very much, it works great with a WAV header at the beginning of the data, and the delay isn't noticible at all.