<commit_before>// clear audio block
for (int sample = 0; sample < MZK_BLOCK_SIZE * 2; sample++) {
    // Stereo! --> 2 values
    floatOutput[0][sample] = 0;
}

//int on[18] = {1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};

for (int instrument = 0; instrument < NUM_INSTRUMENTS; instrument++)
{
    int note_pos = savedNotePos[instrument];
    //if (!on[instrument])continue;

    // Volume?
    // Get parameters locally
    float vol = float_instrument_parameters_[instrument][F_MASTER_VOLUME];
    //float panning = float_instrument_parameters_[instrument][K_MASTER_PANNING];
    float panning = 0.785f - instrument * (1.0f / 24.0f);
    float invADSRSpeed = float_instrument_parameters_[instrument][K_ADSR_SPEED + iADSR[instrument]] * (1.0f / 1024.0f);

    // Check if we go to next note
    if (savedNoteTime__[note_pos /*+ currentNoteIndex[instrument]*/] == 0) {
        if (savedNote__[note_pos /*+ currentNoteIndex[instrument]*/] != -128) {
            // Key on
            iADSR[instrument] = 0; // attack
            fADSRVal[instrument] = 0.0f; // starting up

            for (int i = 0; i < NUM_ADSR_DATA; i++) {
                adsrData[instrument][i] = float_instrument_parameters_[instrument][i * 4 + iADSR[instrument]];
            }

            // Apply delta-note
            currentNote[instrument] += savedNote__[note_pos /*+ currentNoteIndex[instrument]*/];
            i_midi_volume_[instrument] += savedVelocity__[/*currentNoteIndex[instrument] +*/ velocityPos[instrument]];

            // Set the oscillator phases to zero
            fPhase[instrument] = 0.f;
        }
        else {
            // NoteOff
            iADSR[instrument] = 2; // Release
        }

        invADSRSpeed = float_instrument_parameters_[instrument][K_ADSR_SPEED + iADSR[instrument]] * (1.0f / 1024.0f);

        // Go to next note location
        //currentNoteIndex[instrument]++;
        velocityPos[instrument]++;
        note_pos++;
    }
    savedNoteTime__[note_pos /*+ currentNoteIndex[instrument]*/]--;

    // ignore everything before the first note
    //if (currentNoteIndex[instrument] == 0) {
    //    continue;
    //}

    if (float_instrument_parameters_[instrument][K_VOLUME + iADSR[instrument] + 1] < (1.0f / 1024.0f) &&
        adsrData[instrument][adsrVolume] < (1.0f / 1024.0f)) continue;

    // Get audio frequency
    float baseFreq = 8.175f * (float)exp2jo((float)currentNote[instrument] * (1.0f / 12.0f)) * fScaler;

    float base_phase = fPhase[instrument];
    for (int sample = 0; sample < MZK_BLOCK_SIZE; sample++) {
        float deathVolume = 1.0f;

        // Process ADSR envelope
        if (iADSR[instrument] == 0) {
            fADSRVal[instrument] += (1.0f - fADSRVal[instrument]) *
                (float_instrument_parameters_[instrument][K_ADSR_SPEED + 0] * (1.0f / 1024.0f));
        }
        // Go from attack to decay
        if (iADSR[instrument] == 0 && fADSRVal[instrument] > 0.75f) {
            iADSR[instrument] = 1;
            invADSRSpeed = float_instrument_parameters_[instrument][K_ADSR_SPEED + iADSR[instrument]] * (1.0f / 1024.0f);
        }

        // interpolate volume according to ADSR envelope
        for (int i = 0; i < NUM_ADSR_DATA; i++) {
            adsrData[instrument][i] += (float_instrument_parameters_[instrument][i * 4 + iADSR[instrument] + 1] - adsrData[instrument][i]) * invADSRSpeed;
        }

        if (savedNoteTime__[note_pos /*+ currentNoteIndex[instrument]*/] == 0 &&
            sample >= MZK_BLOCK_SIZE - 1024 &&
            savedNote__[note_pos /*+ currentNoteIndex[instrument]*/] != -128) {
            deathVolume = (MZK_BLOCK_SIZE - sample) * (1.0f / 1024.0f);
        }

        float outAmplitude = 0;

        float overtoneLoudness = 1.0f;
        float phase = base_phase;
        float overtone_falloff = adsrData[instrument][adsrQuak] * 2.0f;
        for (int i = 0; i < NUM_OVERTONES; i++) {
            outAmplitude += sinf(phase) * overtoneLoudness;
            phase += base_phase;
            // Ring modulation with noise
            outAmplitude *= 1.0f + (lowNoise[sample % RANDOM_BUFFER_SIZE] - 1.0f) * adsrData[instrument][adsrNoise];
            overtoneLoudness *= overtone_falloff;
        }

        base_phase += baseFreq * (adsrData[instrument][adsrFreq] * 4.0f);
        while (base_phase > 2.0f * PI) base_phase -= 2.0f * (float)PI;

        // Ring modulation with noise
        float cur_vol = vol * adsrData[instrument][adsrVolume] * deathVolume * i_midi_volume_[instrument] * (1.0f / 128.0f);
        float distortMult = (float)exp2jo(8.0f*adsrData[instrument][adsrDistort]) + 8.0f;
        float current_pan = panning;
        for (int i = 0; i < 2; i++) {
            float output = outAmplitude * current_pan;
<commit_msg>Some overtone playback bugfix - more overtones not yet working<commit_after>// clear audio block
for (int sample = 0; sample < MZK_BLOCK_SIZE * 2; sample++) {
    // Stereo! --> 2 values
    floatOutput[0][sample] = 0;
}

//int on[18] = {1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};

for (int instrument = 0; instrument < NUM_INSTRUMENTS; instrument++)
{
    int note_pos = savedNotePos[instrument];
    //if (!on[instrument])continue;

    // Volume?
    // Get parameters locally
    float vol = float_instrument_parameters_[instrument][F_MASTER_VOLUME];
    //float panning = float_instrument_parameters_[instrument][K_MASTER_PANNING];
    float panning = 0.785f - instrument * (1.0f / 24.0f);
    float invADSRSpeed = float_instrument_parameters_[instrument][K_ADSR_SPEED + iADSR[instrument]] * (1.0f / 1024.0f);

    // Check if we go to next note
    if (savedNoteTime__[note_pos /*+ currentNoteIndex[instrument]*/] == 0) {
        if (savedNote__[note_pos /*+ currentNoteIndex[instrument]*/] != -128) {
            // Key on
            iADSR[instrument] = 0; // attack
            fADSRVal[instrument] = 0.0f; // starting up

            for (int i = 0; i < NUM_ADSR_DATA; i++) {
                adsrData[instrument][i] = float_instrument_parameters_[instrument][i * 4 + iADSR[instrument]];
            }

            // Apply delta-note
            currentNote[instrument] += savedNote__[note_pos /*+ currentNoteIndex[instrument]*/];
            i_midi_volume_[instrument] += savedVelocity__[/*currentNoteIndex[instrument] +*/ velocityPos[instrument]];

            // Set the oscillator phases to zero
            fPhase[instrument] = 0.f;
        }
        else {
            // NoteOff
            iADSR[instrument] = 2; // Release
        }

        invADSRSpeed = float_instrument_parameters_[instrument][K_ADSR_SPEED + iADSR[instrument]] * (1.0f / 1024.0f);

        // Go to next note location
        //currentNoteIndex[instrument]++;
        velocityPos[instrument]++;
        note_pos++;
    }
    savedNoteTime__[note_pos /*+ currentNoteIndex[instrument]*/]--;

    // ignore everything before the first note
    //if (currentNoteIndex[instrument] == 0) {
    //    continue;
    //}

    if (float_instrument_parameters_[instrument][K_VOLUME + iADSR[instrument] + 1] < (1.0f / 1024.0f) &&
        adsrData[instrument][adsrVolume] < (1.0f / 1024.0f)) continue;

    // Get audio frequency
    float baseFreq = 8.175f * (float)exp2jo((float)currentNote[instrument] * (1.0f / 12.0f)) * fScaler;

    float base_phase = fPhase[instrument];
    float phase_update = baseFreq * (adsrData[instrument][adsrFreq] * 4.0f);
    for (int sample = 0; sample < MZK_BLOCK_SIZE; sample++) {
        float deathVolume = 1.0f;

        // Process ADSR envelope
        if (iADSR[instrument] == 0) {
            fADSRVal[instrument] += (1.0f - fADSRVal[instrument]) *
                (float_instrument_parameters_[instrument][K_ADSR_SPEED + 0] * (1.0f / 1024.0f));
        }
        // Go from attack to decay
        if (iADSR[instrument] == 0 && fADSRVal[instrument] > 0.75f) {
            iADSR[instrument] = 1;
            invADSRSpeed = float_instrument_parameters_[instrument][K_ADSR_SPEED + iADSR[instrument]] * (1.0f / 1024.0f);
        }

        // interpolate volume according to ADSR envelope
        for (int i = 0; i < NUM_ADSR_DATA; i++) {
            adsrData[instrument][i] += (float_instrument_parameters_[instrument][i * 4 + iADSR[instrument] + 1] - adsrData[instrument][i]) * invADSRSpeed;
        }

        if (savedNoteTime__[note_pos /*+ currentNoteIndex[instrument]*/] == 0 &&
            sample >= MZK_BLOCK_SIZE - 1024 &&
            savedNote__[note_pos /*+ currentNoteIndex[instrument]*/] != -128) {
            deathVolume = (MZK_BLOCK_SIZE - sample) * (1.0f / 1024.0f);
        }

        float outAmplitude = 0;

        float overtoneLoudness = 1.0f;
        float phase = base_phase;
        float overtone_falloff = adsrData[instrument][adsrQuak] * 2.0f;
        for (int i = 0; i < NUM_OVERTONES; i++) {
            outAmplitude += sinf(phase) * overtoneLoudness *
                (1.0f + (lowNoise[(sample + i * 4096) % RANDOM_BUFFER_SIZE] - 1.0f) * adsrData[instrument][adsrNoise]);
            phase += base_phase;
            // Ring modulation with noise
            //outAmplitude *= 1.0f + (lowNoise[sample % RANDOM_BUFFER_SIZE] - 1.0f) * adsrData[instrument][adsrNoise];
            overtoneLoudness *= overtone_falloff;
        }

        base_phase += phase_update;
        while (base_phase > 2.0f * PI) base_phase -= 2.0f * (float)PI;

        // Ring modulation with noise
        float cur_vol = vol * adsrData[instrument][adsrVolume] * deathVolume * i_midi_volume_[instrument] * (1.0f / 128.0f);
        float distortMult = (float)exp2jo(8.0f*adsrData[instrument][adsrDistort]) + 8.0f;
        float current_pan = panning;
        for (int i = 0; i < 2; i++) {
            float output = outAmplitude * current_pan;

{'fraction_non_alphanumeric': 0.13548852053948315, 'fraction_numerical': 0.03356326572634613, 'mean_word_length': 2.553035844915874, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4027', 'n_tokens_mistral': 3527, 'n_tokens_neox': 3273, 'n_words': 640}