Page 1 of 2

DSP code question

Posted: Wed Oct 19, 2016 6:12 pm
by tulamide
Ok, hopefully this is quickly answered.

I found a wave player module that uses a "precise counter"-module to play a wave file based on a boolean. if true there's no playing, if false it plays the wave in loop.
The dsp code of the counter-module is like that:

Code: Select all

streamin step;
streamin retrigger;
streamin length;
streamin loop;
streamout subInt;

subInt = ((indexInt+step)>length)&(loop>0)&length;
subInt = (retrigger!=1)&(step-subInt) - (retrigger==1)&(indexInt);


where
step == wave's rate / sample rate
retrigger either true or false
length is in samples
loop is !retrigger (boolean not)

I could set loop to always be false, and it then plays the wave one time while retrigger is false. But I can't find out what I would need to change so that the wave is played in its full length on a trigger and automatically resets the counter, so that the next trigger starts playing again at 0, no matter at what time I hit the trigger?

Ideas? Any help will get a big thank you!

EDIT:
If my question isn't really clear, here's what I look for
1) A trigger instead of a boolean starts playing the wave
2) If I do nothing the wave plays one time until its end
3) If I trigger again, no matter if the wave is currently playing or not, the wave starts again at sample 0

EDIT 2: There's a line missing

Code: Select all

streamin indexInt;

this is the feedback from subInt, after it has been processed.

Re: DSP code question

Posted: Wed Oct 19, 2016 6:32 pm
by KG_is_back
The code seems to be missing a few lines. Specifically, it misses the declaration of "indexInt" and misses the lines that give it value. Because of that It seems hard deciphering what the code actually does.

Re: DSP code question

Posted: Wed Oct 19, 2016 6:41 pm
by tulamide
I thought I'd narrowed it down, so that people don't have to look at a complete schematic. But maybe it's better. See attachment.

Re: DSP code question

Posted: Wed Oct 19, 2016 6:45 pm
by KG_is_back
The module is written in somewhat awkward way. It may be easier to just write new one from scratch:

Code: Select all

streamin step; //samplerate/wavSamplerate aka. how fast should the wave be played
streamboolin trigger;
streamin length;
streamboolin loop;
streamout index;

index=(index+step); //increase index by 1 step
//if index exceeds "length" and "loop" mode is on, subtract "length" to reset to start
//the line may be deleted if looping should be disabled at all time
index= index - length&(index>length)&loop;
//resets index to zero when trigger arrives. It also stays zero while trigger is on.
index=index & (trigger==0);



EDIT: disregard this.... I thought the code outputs index, but it really a bit more complicated... give me a minute to figure it out.

Re: DSP code question

Posted: Wed Oct 19, 2016 7:00 pm
by KG_is_back
as far as I can tell, the module should restart the wave from the beginning when retrigger is hit.

There seems to be some funny behaviour related to the selector... When I connected mono-to-float module to the counter, it does exactly what you expect. When I disconnect it, it does not retrigger - just continues where it ended... If I disable the selectors it works fine...

Re: DSP code question

Posted: Wed Oct 19, 2016 7:20 pm
by tulamide
Confirmed, sort of.

If I remove the selectors (why are they in there anyway?), I can start the wave from the beginning, whenever I set the boolean to false. However, whenever I set the boolean to true, it stops playing immediatly. A trigger doesn't work at all.

Re: DSP code question

Posted: Thu Oct 20, 2016 12:23 pm
by adamszabo
I think this is what you are after? You need an envelope with a bit of a release to keep the signal alive until the sample plays, and in the voicing set it to mono (1 voice) and retrigger, so that the sample starts again when you press a key again.

Re: DSP code question

Posted: Thu Oct 20, 2016 2:10 pm
by tulamide
adamszabo wrote:I think this is what you are after? You need an envelope with a bit of a release to keep the signal alive until the sample plays, and in the voicing set it to mono (1 voice) and retrigger, so that the sample starts again when you press a key again.

Almost done :)
But I really don't look for a rompler or so, I just need a preview option. Say, a list of samples, you click one and it plays (in its original pitch and length). But I think I can work it out with your example, and if not, I'll ask here again ;)

Re: DSP code question

Posted: Thu Oct 20, 2016 2:24 pm
by tulamide
Just tested it with a fixed note event sent by a trigger and a sample of about 3 seconds length. It doesn't even start to play. With the keyboard it plays if I hold the key long enough. Ah, I can't get it to work.
The example I posted plays the whole sample, no matter how long it is, but it only is controllable with a boolean.

The best of both worlds would be fine :mrgreen:

Re: DSP code question

Posted: Thu Oct 20, 2016 7:26 pm
by Nubeat7
here is a player which plays the sample just one time until the end just with one trigger
hope it helps..
it has no retrigger while it is playing, and also the trigger - playstart - thing could be done better i think..
its always tricky to use triggers in stream

EDIT: it has retrigger now too :)