What is KVR Audio? | Submit News | Advertise | Developer Account

Options (Affects News & Product results only):

OS:
Format:
Include:
Quick Search KVR

"Quick Search" KVR Audio's Product Database, News Items, Developer Listings, Forum Topics and videos here. For advanced Product Database searching please use the full product search. For the forum you can use the phpBB forum search.

To utilize the power of Google you can use the integrated Google Site Search.

Products 0

Developers 0

News 0

Forum 0

Videos 0

Search  

Simple step sequencer

DSP, Plug-in and Host development discussion.

Moderator: Moderators (Main)

User avatar
ZenSound
KVRist
 
154 posts since 3 Feb, 2013

Postby ZenSound; Fri Feb 22, 2013 11:26 am Simple step sequencer

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
Image
User avatar
antto
KVRAF
 
2260 posts since 4 Sep, 2006, from 127.0.0.1

Postby antto; Fri Feb 22, 2013 12:36 pm

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!
User avatar
Ichad.c
KVRian
 
671 posts since 8 Feb, 2012, from South - Africa

Postby Ichad.c; Fri Feb 22, 2013 12:40 pm

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.
User avatar
ZenSound
KVRist
 
154 posts since 3 Feb, 2013

Postby ZenSound; Mon Feb 25, 2013 11:19 am

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:
Image
User avatar
Ichad.c
KVRian
 
671 posts since 8 Feb, 2012, from South - Africa

Postby Ichad.c; Mon Feb 25, 2013 11:43 am

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:
arakula
KVRAF
 
1932 posts since 16 Aug, 2004, from Vienna, Austria

Postby arakula; Mon Feb 25, 2013 11:18 pm

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 5:30 am, edited 2 times in total.
"Until you spread your wings, you'll have no idea how far you can walk." Image
duncanparsons
KVRAF
 
8366 posts since 11 Apr, 2003, from now on the flat

Postby duncanparsons; Tue Feb 26, 2013 5:02 am

(because, Hermann, what you shouldn't be doing is always more attractive than what you should be doing!)
Image
User avatar
ZenSound
KVRist
 
154 posts since 3 Feb, 2013

Postby ZenSound; Thu Feb 28, 2013 5:01 am

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:
Image
arakula
KVRAF
 
1932 posts since 16 Aug, 2004, from Vienna, Austria

Postby arakula; Thu Feb 28, 2013 5:41 am

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
User avatar
antto
KVRAF
 
2260 posts since 4 Sep, 2006, from 127.0.0.1

Postby antto; Thu Feb 28, 2013 5:46 am

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!

Moderator: Moderators (Main)

Return to DSP and Plug-in Development