Author Topic: Question about the resampler with a mixer.  (Read 354 times)

AndyMK

  • Posts: 211
Question about the resampler with a mixer.
« on: 27 Jan '24 - 15:18 »
Hi,

When using BASS_Mixer_ChannelSetEnvelope the docs say,
Quote
The position of the node in bytes. This is based on the mixer's sample format, not the source channel's format.

My mixer is 2 channel, 48000hz, Decoding. Am i right in thinking that when i change the source channels frequency, the mixer format stays the same?
Also, internally, does the frequency change happen immediatly on the sample position i choose or at the start of a block of samples?
Thanks
« Last Edit: 27 Jan '24 - 17:41 by AndyMK »

Ian @ un4seen

  • Administrator
  • Posts: 26093
Re: Question about the resampler with a mixer.
« Reply #1 on: 29 Jan '24 - 15:05 »
When using BASS_Mixer_ChannelSetEnvelope the docs say,
Quote
The position of the node in bytes. This is based on the mixer's sample format, not the source channel's format.

My mixer is 2 channel, 48000hz, Decoding. Am i right in thinking that when i change the source channels frequency, the mixer format stays the same?

Yes, that's correct. It means changing a source's sample rate won't affect envelope timing relative to the mixer output, but it will affect the timing relative to the source's position. If you happen to need an envelope that's relative to the source's position then you could use the BASS_FX add-on's BASS_FX_BFX_VOLUME_ENV effect instead, or perhaps the BASS_FX_VOLUME effect if it's just a fade-in/out.

Also, internally, does the frequency change happen immediatly on the sample position i choose or at the start of a block of samples?

The change will happen immediately from the mixer's next update cycle, but output/playback buffering may mean the change isn't heard immediately. If that's an issue, playback buffering can be disabled on the mixer by setting BASS_ATTRIB_BUFFER to 0 on it.

AndyMK

  • Posts: 211
Re: Question about the resampler with a mixer.
« Reply #2 on: 15 Aug '24 - 13:04 »
Hi Ian, how often is the mixer updated when using decoding and is that adjustable?

Ian @ un4seen

  • Administrator
  • Posts: 26093
Re: Question about the resampler with a mixer.
« Reply #3 on: 15 Aug '24 - 13:15 »
Do you mean the mixer has the BASS_STREAM_DECODE flag set? If so, the update rate will depend on how frequently BASS_ChannelGetData is called on it. Changes made to the mixer (eg. sources/envelopes/etc) would take effect in the next BASS_ChannelGetData call.

AndyMK

  • Posts: 211
Re: Question about the resampler with a mixer.
« Reply #4 on: 15 Aug '24 - 16:29 »
Thanks. I think i need more granularity. I need to process volume and pitch changes in multiples of 20ms and it needs to be accurate. If i was to design my own mixer using a custom dsp function, would i be able to take advantage of multiple threads by creating new streams in new threads? Not sure how the bass and the mixer implemented does multiple threads. Thanks

Ian @ un4seen

  • Administrator
  • Posts: 26093
Re: Question about the resampler with a mixer.
« Reply #5 on: 15 Aug '24 - 17:58 »
You can have a mixer process 20ms blocks via the BASS_ChannelGetData "length" parameter. For example:

Code: [Select]
DWORD need = BASS_ChannelSeconds2Bytes(mixer, 0.02); // 20ms
BYTE *buf = (BYTE*)alloca(need); // allocate a buffer (it'd be better to pre-allocate and reuse a buffer)
DWORD got = BASS_ChannelGetData(mixer, buf, need); // process the mixer

The thread that a stream is created in doesn't really matter. It's more about where the stream is processed, eg. BASS_ChannelGetData called. It's fine to have multiple threads processing multiple streams simultaneously.

AndyMK

  • Posts: 211
Re: Question about the resampler with a mixer.
« Reply #6 on: 16 Aug '24 - 09:18 »
Thanks.