Plug-ins, Hosts, Apps,
Hardware, Soundware
Developers
(Brands)
Videos Groups
Whats's in?
Banks & Patches
Download & Upload
Music Search
KVR
   
KVR Forum » DSP and Plug-in Development
Thread Read
Simple step sequencer
ajimenez
KVRist
- profile
- pm
- www
PostPosted: Fri Feb 22, 2013 11:26 am reply with quote
Hi I am trying to do a simple four steps sequencer in SynthEdit, this is my code:

Test 1

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

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
^ Joined: 03 Feb 2013  Member: #297999  Location: San Pedro del Pinatar
antto
KVRAF
- profile
- pm
- www
PostPosted: Fri Feb 22, 2013 12:36 pm reply with quote
no idea what this code is supposed to be doing
i'd do it like this:

// 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!
^ Joined: 04 Sep 2006  Member: #118997  Location: 127.0.0.1
Ichad.c
KVRist
- profile
- pm
- e-mail
- www
PostPosted: Fri Feb 22, 2013 12:40 pm reply with quote
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.
^ Joined: 08 Feb 2012  Member: #274678  Location: South - Africa
ajimenez
KVRist
- profile
- pm
- www
PostPosted: Mon Feb 25, 2013 11:19 am reply with quote
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 Shocked
^ Joined: 03 Feb 2013  Member: #297999  Location: San Pedro del Pinatar
Ichad.c
KVRist
- profile
- pm
- e-mail
- www
PostPosted: Mon Feb 25, 2013 11:43 am reply with quote
ajimenez wrote:

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


Ironically - the SDK example looks much harder to me Laughing
^ Joined: 08 Feb 2012  Member: #274678  Location: South - Africa
arakula
KVRAF
- profile
- pm
- e-mail
- www
PostPosted: Mon Feb 25, 2013 11:18 pm reply with quote
ajimenez wrote:
The code example of Antto's is pretty hard for me to understand Shocked

Oh really? Well, apart from the names that are intuitively understandable to mathematicians only, it's not complicated; let's dissect it...
// 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.
// initialize
phase = 0.0;
omega = 0.0;
Has to be done when the class instance is initialized.
// 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:
// per sample:
phase -= floor(phase); // wrap around
Assure that the phase variable stays in range 0..just a tiny little bit less than 1.
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;
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)
// do something with it here... Self-explanatory Cool - insert your processing here.
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?) Cool
----
"Until you spread your wings, you'll have no idea how far you can walk."

Last edited by arakula on Tue Feb 26, 2013 5:30 am; edited 2 times in total
^ Joined: 16 Aug 2004  Member: #37236  Location: Vienna, Austria
duncanparsons
KVRAF
- profile
- pm
- e-mail
- www
PostPosted: Tue Feb 26, 2013 5:02 am reply with quote
(because, Hermann, what you shouldn't be doing is always more attractive than what you should be doing!)
----
^ Joined: 11 Apr 2003  Member: #6706  Location: now on the flat
ajimenez
KVRist
- profile
- pm
- www
PostPosted: Thu Feb 28, 2013 5:01 am reply with quote
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
^ Joined: 03 Feb 2013  Member: #297999  Location: San Pedro del Pinatar
arakula
KVRAF
- profile
- pm
- e-mail
- www
PostPosted: Thu Feb 28, 2013 5:41 am reply with quote
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."
^ Joined: 16 Aug 2004  Member: #37236  Location: Vienna, Austria
antto
KVRAF
- profile
- pm
- www
PostPosted: Thu Feb 28, 2013 5:46 am reply with quote
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!
^ Joined: 04 Sep 2006  Member: #118997  Location: 127.0.0.1
All times are GMT - 8 Hours

Printable version
Page 1 of 1
Display posts from previous:   
ReplyNew TopicPrevious TopicNext Topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Username: Password:  
KVR Developer Challenge 2012