Simple step sequencer

DSP, Plugin and Host development discussion.
Post Reply New Topic
RELATED
PRODUCTS

Post

Hi I am trying to do a simple four steps sequencer in SynthEdit, this is my code:

Test 1

Code: Select all

if (clock >= 0.2f){

			if (step == 1) result1 = input1; 
			
			if (step == 2) result1 = input2;
			
			if (step == 3) result1 = input3;
			
			if (step == 4){result1 = input4;step = stepReset;}
			step++;
		}
Test 1 seems to be near the solution, but seems to output the 'result1' too fast to hear something.

Test 2

Code: Select all

if (clock >= 0.2f){

			if (step == 1){
				for (int n = 0; n == noteLength; n++)
                      result1 = input1; 
			}
			
			if (step == 2){
				for (int n = 0; n == noteLength; n++) 
                      result1 = input2;
			}
			
			if (step == 3){
				for (int n = 0; n == noteLength; n++) 
                      result1 = input3;
			}
			
			if (step == 4){
				for (int n = 0; n == noteLength; n++){ 
                      result1 = input4;step = stepReset;}
			}
			step++;
		}
And here in test 2 I am using a for to slow down the loop.
But I have analyzed the output with a VU meter and it is always in 0 volts.
All that I need is to make work this simple sequencer :wink:

Regards

Post

no idea what this code is supposed to be doing
i'd do it like this:

Code: Select all

// store these as member variables
double omega, phase, ph2;
int step;

// initialize
phase = 0.0;
omega = 0.0;

// calculate tempo (make sure you do this before the "per-sample" code)
omega = (BPM/60.0)/Fs; // increment coefficient

// per sample:
phase -= floor(phase); // wrap around
ph2 = phase*4.0; // four step sequence?
step = static_cast<int>(floor(ph2));
// now "step" will go from 0 to 3
// do something with it here...
phase += omega;
It doesn't matter how it sounds..
..as long as it has BASS and it's LOUD!

irc.libera.chat >>> #kvr

Post

Hey, did you see that there is a step sequencer example in the SDK3 files? Or are you using SDK2?

Edit: Antto's method looks alot easier.

Post

Ichad.c wrote:Hey, did you see that there is a step sequencer example in the SDK3 files? Or are you using SDK2?

Edit: Antto's method looks alot easier.
Thanks, I have compiled the sequencer of the SDK3.
I was using an out dated SDK3 without sequencer

The code example of Antto's is pretty hard for me to understand :shock:

Post

ajimenez wrote: The code example of Antto's is pretty hard for me to understand :shock:
Ironically - the SDK example looks much harder to me :lol:

Post

ajimenez wrote:The code example of Antto's is pretty hard for me to understand :shock:
Oh really? Well, apart from the names that are intuitively understandable to mathematicians only, it's not complicated; let's dissect it...

Code: Select all

// store these as member variables
double omega, phase, ph2;
int step;
This assumes that you're creating a C++ class; ph2 and step, BTW, don't need to be class members; I would implement them as automatic variables in the processing code.

Code: Select all

// initialize
phase = 0.0;
omega = 0.0;
Has to be done when the class instance is initialized.

Code: Select all

// calculate tempo (make sure you do this before the "per-sample" code)
omega = (BPM/60.0)/Fs; // increment coefficient
This needs to be done each time the step sequencer speed (BPM) or sampling rate (Fs) changes. It calculates an increment value that's added to a variable (phase) which keeps the current phase for each sample.
BPM/60.0 determines the number of quarter notes per second. If you divide that through the number of samples per second, you get the increment factor that has to be added to the phase upon each sample so that the phase runs from 0..1 in one quarter note's duration.

The rest is intended to be run in a loop that's called for each sample:

Code: Select all

// per sample:
phase -= floor(phase); // wrap around
Assure that the phase variable stays in range 0..just a tiny little bit less than 1.

Code: Select all

ph2 = phase*4.0; // four step sequence?
ph2 is set to the phase variable, times four - replace the 4 with the number of steps your sequencer should have.

Here, I'm not absolutely sure whether this does what you need; this logic has the result that each step has the length of 1/4 of a quarter note. If you want each step to have a length of one quarter note, you'd need to adjust the increment calculation above accordingly, like, omega = (BPM/(60.0 * 4.0))/Fs;

Code: Select all

step = static_cast<int>(floor(ph2));
// now "step" will go from 0 to 3
Convert that into an integer variable that contains the step number in range 0..(#steps - 1)

Code: Select all

// do something with it here...
Self-explanatory 8-) - insert your processing here.

Code: Select all

phase += omega;
Prepare for the next sample by adding the increment value to the phase variable.

HTH

(how does it come that I'm always in "benevolent answering mood" and spend half an hour on an explanation when I should go to work instead?) 8-)
Last edited by arakula on Tue Feb 26, 2013 1:30 pm, edited 2 times in total.
"Until you spread your wings, you'll have no idea how far you can walk." Image

Post

(because, Hermann, what you shouldn't be doing is always more attractive than what you should be doing!)
Image

Post

Thanks arakula for you explanation.

It is very curious how different can be a sequencer programmed, the solution of antto is totaly different of the sdk of SE.

Regards :wink:

Post

ajimenez wrote:It is very curious how different can be a sequencer programmed, the solution of antto is totaly different of the sdk of SE.
You're absolutely right; it's obviously done with VST2 in mind.
"Until you spread your wings, you'll have no idea how far you can walk." Image

Post

thanks for the explanation
indeed it's a simplified version of the code i use for my actual sequencer
It doesn't matter how it sounds..
..as long as it has BASS and it's LOUD!

irc.libera.chat >>> #kvr

Post Reply

Return to “DSP and Plugin Development”