Author Topic: Onsets  (Read 324 times)

rv

  • Posts: 291
Onsets
« on: 3 Jun '19 - 15:31 »
Hello,

I am trying to create a software that plays a wav drums loop , and changes the tempo of it.
I have the list of the onset sample position exp
0
14947
29193
44061
58659
73535
88011
102929
117495
132374
146939
154457
161547
176378
191246
205564...

What I want to do, is to play the wav from 0, and then stop precisely at 14947
then play from 14947 to 29193

This driven from an external timer

My sound card is 48000hz only
but the wave is 44100hz
I use a bass mixer into a wasapi exclusive output managed by bass
BASS_ATTRIB_SRC, 4  to get the best sound
BASS_MIXER_NORAMPIN so it plays the stream exactly like on the wav
wasapi buffer size 352

What I do is to add a sync on the next onset
NextSync = BASS_ChannelSetSync(_stream, BASS_SYNC_POS, Convert.ToUInt64(NextOnset), MySyncProc, 0)

And in the SyncProc I simply Pause the stream, waiting for the next onset to play
BASS_Mixer_ChannelFlags(_stream, BASS_MIXER_PAUSE, BASS_MIXER_PAUSE)

However, it seems that it does not sound as good as it should be, with some clicks at the end of some slices
Do you have an idea why slices STOPS does not sound good sometimes

Maybe when I ask BASS_MIXER_PAUSE, it still continue to play few samples more?





Ian @ un4seen

  • Administrator
  • Posts: 21986
Re: Onsets
« Reply #1 on: 3 Jun '19 - 16:44 »
The issue there is that the mixer won't see the BASS_MIXER_PAUSE flag until the next processing cycle. The mixer will complete the current cycle in which the BASS_SYNC_POS sync was triggered and then the pause will happen.

There are a couple of possible ways around that. You could set the BASS_SYNC_POS syncs on the mixer, which means they'll be triggered at the start of a processing cycle, hence the BASS_MIXER_PAUSE flag will take immediate effect. The other option is to call BASS_ChannelStop in the SYNCPROC so that the source ends at the sync's position, and then use BASS_Mixer_ChannelSetPosition on the source when you want to resume it. I would favour the 2nd option if the mixer is resampling the source.

edit: A 3rd option is to use BASS_Mixer_StreamAddChannelEx and its "length" parameter. This is similar to setting a BASS_SYNC_POS sync on the mixer and stopping/pausing in the SYNCPROC.
« Last Edit: 5 Jun '19 - 12:59 by Ian @ un4seen »

rv

  • Posts: 291
Re: Onsets
« Reply #2 on: 3 Jun '19 - 20:40 »
BASS_ChannelStop in the SYNCPROC seems working good
However, I have added a reverb on the mixer, so when I slow down the tempo, the reverb fill a bit the empty space between the slices
But the BASS_ChannelStop seems to stop the processing of the mixer reverb too, while the pause was still processing the reverb?

Ian @ un4seen

  • Administrator
  • Posts: 21986
Re: Onsets
« Reply #3 on: 4 Jun '19 - 16:11 »
Do you have the BASS_MIXER_END flag set on the mixer? If so, try removing that so that the mixer doesn't end when the source does (due to the BASS_ChannelStop call). If it's still not working as wanted, also try adding the BASS_MIXER_NONSTOP flag to the mixer.

rv

  • Posts: 291
Re: Onsets
« Reply #4 on: 4 Jun '19 - 18:05 »
The BASS_MIXER_NONSTOP flag was helpful

I have set a reverb on the mixer

I try to set the reverb wet = 0 just before to play the slice with the BASS_Mixer_ChannelSetPosition in my timer
and set the reverb wet = 1 inside the syncproc just before the BASS_ChannelStop

So we don't feel so much the blank space between slices

Are the call BASS_FXSetParameters(WavRev, rev) immediate, or are they delayed somewhere?

Ian @ un4seen

  • Administrator
  • Posts: 21986
Re: Onsets
« Reply #5 on: 5 Jun '19 - 13:00 »
DSP/FX changes applied to a mixer inside a source's mixtime BASS_SYNC_POS sync callback are likely to be heard to start a bit before the sync's position. That's because DSP/FX are applied after the mixer generates a block of output, to the entire block. For example, if the source reaches the sync position half way into a block, the sync's DSP/FX change will be heard from the start of that block (not half way into it). The only way to precisely time DSP/FX changes on a mixer is to set BASS_SYNC_POS syncs on the mixer itself, because a new processing block starts when a BASS_SYNC_POS sync is triggered.

rv

  • Posts: 291
Re: Onsets
« Reply #6 on: 5 Jun '19 - 13:21 »
Thank you, for your answer :) 
For now it sounds not so bad, even with I slow down a lot the tempo
The only thing I need to improve is that sometimes I hear a click (I still need to improve my slice positions)
Do the BASS_ChannelStop inside the SYNCPROC, will produce a click if the last value is not 0 ?

Ian @ un4seen

  • Administrator
  • Posts: 21986
Re: Onsets
« Reply #7 on: 5 Jun '19 - 13:54 »
Yes, if you stop the source on a sample value that isn't close to 0 then it is likely to produce a "click" sound. If needed, you could use the BASS_FX_VOLUME effect to apply a short fade-out to the source before stopping it (triggered by a slightly earlier sync).