Example #1
0
void pdsp::BLEPSaw::oscillate( float* outputBuffer, const float* phaseBuffer, int bufferSize) noexcept {
    //TRIVIAL SAW

    genSaw(outputBuffer, phaseBuffer, bufferSize);
    //trivialSawDSP(bufferSize, outputBuffer, phaseBuffer);


    //BLEP CORRECTION
    int incBufferState;
    const float* incBuffer = processInput(input_inc, incBufferState);

    //float tableCenter = blepTable->length_f * 0.5 - 1.0;
    //Logger::writeToLog(String(tableCenter));


    if (incBufferState == AudioRate){ //phase increment is always changing

            BLEPFMWaveformDSP(bufferSize, outputBuffer, phaseBuffer, incBuffer,
                              blepTable->buffer, blepTable->points, blepTable->length_f, interpolateBLEP);

    }else { //phase increment is always the same

            BLEPWaveformDSP(bufferSize, outputBuffer, phaseBuffer, incBuffer[0],
                            blepTable->buffer, blepTable->points, blepTable->length_f, interpolateBLEP);

    }

}
Example #2
0
void interpret(unsigned char *bfr, unsigned int in, const unsigned long &len)
{
    //0000 0000 0000 0000 0000 0000 0000 0000

    //1000 0000 0000 0000 0000 0000 0000 0000 active
    //0111 0000 0000 0000 0000 0000 0000 0000 octave
    //0000 1111 0000 0000 0000 0000 0000 0000 note C C# D D# E F F# G G# A A# B
    //0000 0000 1111 1100 0000 0000 0000 0000 instrument
    //0000 0000 0000 0011 1111 0000 0000 0000 volume 64
    //0000 0000 0000 0000 0000 1111 1111 1111 effect

    const bool on             = (in & 0x80000000) >> (4*7)+3;
    if(!on)
        return;

    unsigned char  oct  = ((in & R_OCTAVE) >> (4*7)) + 1;
    unsigned char  note = (in & R_NOTE) >> (4*6);
    unsigned char  inst = (in & R_INSTRUMENT) >> (4*4+2);
    unsigned char  vol  = (in & R_VOLUME) >> (4*3);

    unsigned char  fx   = (in & R_EFFECT) >> (4*2);
    unsigned char  fxp1 = (in & R_FXPARAM1) >> (4);
    unsigned char  fxp2 = (in & R_FXPARAM2);

    unsigned int period = 128 / (oct);
    //period = period - note*(period - 128/(oct+1))/12.0;
    period = period - note*(period/24.0);
    unsigned char amplitude = (vol/63.0f)*255;

    switch(inst)
    {
        case INST_SILENCE: //silence
            genSilence(bfr, 128, len);
            std::cerr << "Silence length=" << len << '\n';
            break;
        case INST_SQR: //sqr
            genSqr(bfr, period, amplitude, len);
            std::cerr << "Square [" << int(oct) << ',' << int(note) << "] period=" << period << " amplitude=" << static_cast<int>(amplitude) << " length=" << len << '\n';
            break;
        case INST_SAW: //saw
            genSaw(bfr, period, amplitude, len);
            std::cerr << "Saw [" << int(oct) << ',' << int(note) << "] period=" << period << " amplitude=" << static_cast<int>(amplitude) << " length=" << len << '\n';
            break;
        case INST_TRI: //tri
            genTri(bfr, period, amplitude, len);
            std::cerr << "Triangle [" << int(oct) << ',' << int(note) << "] period=" << period << " amplitude=" << static_cast<int>(amplitude) << " length=" << len << '\n';
            break;
        case INST_SINE: // sine
            genSine(bfr, period, amplitude, len);
            std::cerr << "Sine [" << int(oct) << ',' << int(note) << "] period=" << period << " amplitude=" << static_cast<int>(amplitude) << " length=" << len << '\n';
            break;
        default:
            std::cerr << "Instrument " << inst << " does not exist!\n";
    }
}