|
|||
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 Regards |
|||
| ^ | Joined: 03 Feb 2013 Member: #297999 Location: San Pedro del Pinatar | ||
|
|||
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 | ||
|
|||
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 | ||
|
|||
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 |
|||
| ^ | Joined: 03 Feb 2013 Member: #297999 Location: San Pedro del Pinatar | ||
|
|||
ajimenez wrote: The code example of Antto's is pretty hard for me to understand Ironically - the SDK example looks much harder to me |
|||
| ^ | Joined: 08 Feb 2012 Member: #274678 Location: South - Africa | ||
|
|||
ajimenez wrote: The code example of Antto's is pretty hard for me to understand
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 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?) 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 | ||
|
|||
| ^ | Joined: 11 Apr 2003 Member: #6706 Location: now on the flat | ||
|
|||
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 |
|||
| ^ | Joined: 03 Feb 2013 Member: #297999 Location: San Pedro del Pinatar | ||
|
|||
| ^ | Joined: 16 Aug 2004 Member: #37236 Location: Vienna, Austria | ||
|
|||
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 |
| KVR Forum Index » DSP and Plug-in Development | All times are GMT - 8 Hours |
|
Printable version |
Disclaimer: All communications made available as part of this forum and any opinions, advice, statements, views or other information expressed in this forum are solely provided by, and the responsibility of, the person posting such communication and not of kvraudio.com (unless kvraudio.com is specifically identified as the author of the communication).
Powered by phpBB © phpBB Group












