igorski / MWEngine

Audio engine and DSP library for Android, written in C++ providing low latency performance within a musical context, while providing a Java/Kotlin API. Supports both OpenSL and AAudio.
MIT License
259 stars 45 forks source link

Arpeggiator - How To #81

Closed teotigraphix closed 5 years ago

teotigraphix commented 5 years ago

Hey!

I have been studying this code and cannot seem to understand how or what triggers the Arppegiator.

Simple setup;

       synth1.setArpeggiatorActive(true);
        synth1.getArpeggiator().setAmountOfSteps(16);
        synth1.getArpeggiator().setShiftForStep(0, 1);
        synth1.getArpeggiator().setShiftForStep(1, 1);
        synth1.getArpeggiator().setShiftForStep(2, 5);
        synth1.getArpeggiator().setShiftForStep(3, 1);
        synth1.getArpeggiator().setShiftForStep(4, 1);
        synth1.getArpeggiator().setShiftForStep(5, 7);
        synth1.getArpeggiator().setShiftForStep(6, 1);
        synth1.getArpeggiator().setShiftForStep(7, 1);
        synth1.getArpeggiator().setShiftForStep(8, 10);
        synth1.getArpeggiator().setShiftForStep(9, 1);
        synth1.getArpeggiator().setShiftForStep(10, 1);
        synth1.getArpeggiator().setShiftForStep(11, 6);
        synth1.getArpeggiator().setShiftForStep(12, 1);
        synth1.getArpeggiator().setShiftForStep(13, 1);
        synth1.getArpeggiator().setShiftForStep(14, 1);
        synth1.getArpeggiator().setShiftForStep(15, 1);

I get what it's doing but I can't get it to do it. :) I have sequenced 1 audio event for a synth for 8 steps in a 16 step grid for tests.

I also have the sequencer controller playing.

igorski commented 5 years ago

You forgot to set a step size (note how I totally rephrased "I forgot to document this thing properly" ;) )

What you did so far is absolutely correct:

Now the missing bit is setStepSize() which accepts an integer value describing the amount of buffer samples to process before shifting to the next step. This is the same value as used for event position and duration (you can similarly use the "float beat"-logic here). E.g. at a 44.1 kHz sample rate and tempo of 120 BPM, to make the arpeggiator step once per beat / quarter note you specify the step size as:

arpeggiator.setStepSize(( 44100 * 60 ) / 120 );
teotigraphix commented 5 years ago

Thanks Igor, that makes sense. :)

igorski commented 5 years ago

Moved discussion here into its own Wiki article for future reference.