Skip to content

08 Bytebeats

Scott Wilson edited this page Nov 27, 2020 · 2 revisions

Had a couple of folks asking about bytebeats, bitcode, or whatever they are called which got me thinking about them.

Like most of my code, I have more hardware work to do before I can really concentrate on the software, so I have managed to only spend enough time to get a couple of POCs done.

I used some of mckenic’s code to build this sound… Whether that’s what he was looking for or not I can only guess:

Quick Demo of Bytebeats

Then I looked through some of clone45’s code for is upcoming Equation Composer module, and again, I was able to get something working, but I have no idea how close it is to what he’s actually doing:

Another Bytebeat Demo

So anyway, If you want to add some of your own, I’ve created a little bit of a framework:

ByteBeat::ByteBeat(PinAudioOut pinout, PinAnalogIn samplerate, int algorithm, PinAnalogIn param1, PinAnalogIn param2, PinAnalogIn param3, int offset) : VCO(pinout, samplerate)
{   
    this->currentvalue = 0;
    this->iterator = 0;
 
    this->algorithm = algorithm;
    this->param1 = param1;
    this->param2 = param2;
    this->param3 = param3;
    this->offset = offset;
}
 
 
int ByteBeat::nextVCOSample()
{
    if (this->phaseindex == 0)
    {
        int tp1 = analogReadmV(this->param1);
        int tp2 = analogReadmV(this->param2);
        int tp3 = analogReadmV(this->param3);   
 
        /* Really, these should be set by the input parameters, but they are very sensitive to specific values */
        unsigned int p1 = 2000;
        unsigned int p2 = 200;
        unsigned int p3 = 100;
 
        // unsigned int p1 = 2000;
        // unsigned int p2 = 500;
        // unsigned int p3 = 1;
 
        unsigned int t = this->iterator + this->offset;
 
        switch (this->algorithm)
        {
            /* 
                This is a demo of some bitcode oscillating kind of like the equation composer module. Many thanks for clone45 for most
                of the code that makes these work. You can see the original code here: https://github.com/clone45/EquationComposer
                and you can see more info about the module here: http://www.papernoise.net/microbe-modular-equation-composer/
            */
            case 0:
                /*  Filtered Triangles */
                this->currentvalue = ((t % (512 - (t * 351) + 16)) ^ ((t >> (p1 >> 5)))) * (2 + (t >> 14) % 6) | ((t * p2) & (t >> (p3 >> 5)));
                break;
 
            default:
                this->currentvalue = t;
        }
 
        this->iterator++;
    }   
 
    return this->currentvalue;
}

This is in Oscillator.cpp. You can easily add more algorithms if you want, simply by adding case statements.

The configuration parameters are:

samplerate – defines the sample rate at which the oscillators run pinout – an audio (AC coupled) output for the signal. algorithm – used to select an algorithm param1 – defines an analog input to drive algorithm parameter param2 – defines an analog input to drive algorithm parameter param3 – defines an analog input to drive algorithm parameter offset – provides a number of sample offset if you want to run two oscs in stereo without them being completely in sync.

To configure and run one of these oscs from a sketch of your own, the code looks like:

void setup() 
{
    Serial.begin(19200);
    Serial.print("\n\nStarting...\n");
 
    EventManager::initialize();
 
    VCO* bytebeat0 = ByteBeat::create(DUE_DAC0, DUE_IN_A00, 0, DUE_IN_A02, DUE_IN_A04, DUE_IN_A06, 0);
    VCO* bytebeat1 = ByteBeat::create(DUE_DAC1, DUE_IN_A00, 1, DUE_IN_A02, DUE_IN_A04, DUE_IN_A06, 0);
 
    EventManager::registerDevice(bytebeat0);
    EventManager::registerDevice(bytebeat1);
}

Or, if you’re running the no-code firmware, this is what the JSON configuration looks like:

{
    "program" :     
 
    {
        "name" :            "Byte Beat Demo",
 
        "devices" : [
 
            {
                "type" : "ByteBeat",
                "dacOutput" : 1,
                "analogInput1" : 1,
                "analogInput2" : 2,
                "analogInput3" : 3,
                "algorithm" : 1,
                "offset" : 1
            }       
        ]
    }
}

For those interested, let me know what you think. If you have any good ones that you’d like to share, please do, and if you want them in the library, I’ll be happy to add.