<commit_before>/* Copyright (c) 2018 <NAME> */

#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SerialFlash.h>

#include "amfm_audio.h"
#include "manual.h"
#include "monitor_audio.h"
#include "preamp_audio.h"
#include "tonewheel_osc_audio.h"
#include "vibrato_audio.h"

// Hammond B-3.
AudioMixer4 organOut;
TonewheelOsc tonewheels;
Monitor tonewheelsMonitor;
Vibrato vibrato;

AudioConnection patchCord0(tonewheels, 0, tonewheelsMonitor, 0);
AudioConnection patchCord1(tonewheelsMonitor, 0, vibrato, 0);
AudioConnection patchCord2(vibrato, 0, organOut, 0);

TonewheelOsc percussion;
AudioEffectEnvelope percussionEnv;

AudioConnection patchCord3(percussion, 0, percussionEnv, 0);
AudioConnection patchCord4(percussionEnv, 0, organOut, 1);

AudioAmplifier swell;
AudioConnection patchCord5(organOut, 0, swell, 0);

// This antialias filter is here to band limit the organ signal, in
// case key click transients are too high frequency, and also to give
// a slight reduction in key click.
AudioFilterBiquad antialias;
AudioConnection patchCord6(swell, 0, antialias, 0);

// Leslie 122
Preamp preamp;
AudioFilterStateVariable crossover;
AmFm leslieBassR;
AmFm leslieTrebleR;
AudioMixer4 leslieR;
AmFm leslieBassL;
AmFm leslieTrebleL;
AudioMixer4 leslieL;

AudioConnection patchCord7(antialias, 0, preamp, 0);
AudioConnection patchCord8(preamp, 0, crossover, 0);

AudioConnection patchCord9(crossover, 0, leslieBassR, 0);
AudioConnection patchCord10(crossover, 2, leslieTrebleR, 0);
AudioConnection patchCord11(leslieBassR, 0, leslieR, 0);
AudioConnection patchCord12(leslieTrebleR, 0, leslieR, 1);

AudioConnection patchCord13(crossover, 0, leslieBassL, 0);
AudioConnection patchCord14(crossover, 2, leslieTrebleL, 0);
AudioConnection patchCord15(leslieBassL, 0, leslieL, 0);
AudioConnection patchCord16(leslieTrebleL, 0, leslieL, 1);

// Teensy audio board output.
AudioOutputI2S i2s1;
AudioControlSGTL5000 audioShield;
AudioConnection patchCord17(leslieR, 0, i2s1, 0);
AudioConnection patchCord18(leslieL, 0, i2s1, 1);

#ifdef AUDIO_INTERFACE
// If the board is configured for USB audio, mirror the i2s output to USB.
AudioOutputUSB usbAudio;
AudioConnection patchCord19(leslieR, 0, usbAudio, 0);
AudioConnection patchCord20(leslieL, 0, usbAudio, 1);
#endif

uint8_t keys[62] = {0};
uint8_t drawbars[10] = {0};
uint16_t volumes[92] = {0};
uint16_t percVolumes[92] = {0};

// Current state of the percussion settings.
uint8_t percOn = 1;
uint8_t percThird = 0;
uint8_t percFast = 0;
uint8_t percSoft = 0;

// numKeysDown is used to keep the percussion effect single triggered:
// only the first key down affects the percussion setting.
uint8_t numKeysDown = 0;

void handleNoteOn(byte chan, byte note, byte vel);
void handleNoteOff(byte chan, byte note, byte vel);
void handleControlChange(byte chan, byte ctrl, byte val);

void setup() {
    Serial.begin(115200);

    AudioMemory(10);

    tonewheels.init();
    percussion.init();
    vibrato.init();

    swell.gain(1.0);

    preamp.init();
    preamp.setK(50.0);

    crossover.frequency(800);
    crossover.resonance(0.707);
    leslieBassR.init();
    leslieTrebleR.init();
    leslieBassL.init();
    leslieTrebleL.init();

    leslieBassR.setTremoloDepth(0.5);
    leslieTrebleR.setTremoloDepth(0.3);
    leslieBassL.setTremoloDepth(0.5);
    leslieTrebleL.setTremoloDepth(0.3);

    leslieBassR.setPhase(0.25);
    leslieTrebleL.setPhase(0.25);

    // Slow: http://www.dairiki.org/HammondWiki/LeslieRotationSpeed
    leslieBassR.setRotationRate(0.666);
    leslieTrebleR.setRotationRate(0.8);
    leslieBassL.setRotationRate(0.666);
    leslieTrebleL.setRotationRate(0.8);

    // Fast
    leslieBassR.setRotationRate(5.7);
    leslieTrebleR.setRotationRate(6.66);
    leslieBassL.setRotationRate(5.7);
    leslieTrebleL.setRotationRate(6.66);

    drawbars[1] = 8;
    drawbars[2] = 8;
    drawbars[3] = 8;
    drawbars[4] = 8;

    updatePercussion();
    updateTonewheels();

    organOut.gain(0, 0.50); // tonewheels + vibrato
    organOut.gain(1, 0.50); // percussionEnv
    organOut.gain(2, 0);
    organOut.gain(3, 0);

    leslieR.gain(0, 0.50); // bass
    leslieR.gain(1, 0.50); // treble
    leslieL.gain(0, 0.50); // bass
    leslieL.gain(1, 0.50); // treble

    vibrato.setMode(C3);
    antialias.setLowpass(0, 6000, 0.707);<commit_msg>Boost bass output from the Leslie<commit_after>/* Copyright (c) 2018 <NAME> */

#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SerialFlash.h>

#include "amfm_audio.h"
#include "manual.h"
#include "monitor_audio.h"
#include "preamp_audio.h"
#include "tonewheel_osc_audio.h"
#include "vibrato_audio.h"

// Hammond B-3.
AudioMixer4 organOut;
TonewheelOsc tonewheels;
Monitor tonewheelsMonitor;
Vibrato vibrato;

AudioConnection patchCord0(tonewheels, 0, tonewheelsMonitor, 0);
AudioConnection patchCord1(tonewheelsMonitor, 0, vibrato, 0);
AudioConnection patchCord2(vibrato, 0, organOut, 0);

TonewheelOsc percussion;
AudioEffectEnvelope percussionEnv;

AudioConnection patchCord3(percussion, 0, percussionEnv, 0);
AudioConnection patchCord4(percussionEnv, 0, organOut, 1);

AudioAmplifier swell;
AudioConnection patchCord5(organOut, 0, swell, 0);

// This antialias filter is here to band limit the organ signal, in
// case key click transients are too high frequency, and also to give
// a slight reduction in key click.
AudioFilterBiquad antialias;
AudioConnection patchCord6(swell, 0, antialias, 0);

// Leslie 122
Preamp preamp;
AudioFilterStateVariable crossover;
AmFm leslieBassR;
AmFm leslieTrebleR;
AudioMixer4 leslieR;
AmFm leslieBassL;
AmFm leslieTrebleL;
AudioMixer4 leslieL;

AudioConnection patchCord7(antialias, 0, preamp, 0);
AudioConnection patchCord8(preamp, 0, crossover, 0);

AudioConnection patchCord9(crossover, 0, leslieBassR, 0);
AudioConnection patchCord10(crossover, 2, leslieTrebleR, 0);
AudioConnection patchCord11(leslieBassR, 0, leslieR, 0);
AudioConnection patchCord12(leslieTrebleR, 0, leslieR, 1);

AudioConnection patchCord13(crossover, 0, leslieBassL, 0);
AudioConnection patchCord14(crossover, 2, leslieTrebleL, 0);
AudioConnection patchCord15(leslieBassL, 0, leslieL, 0);
AudioConnection patchCord16(leslieTrebleL, 0, leslieL, 1);

// Teensy audio board output.
AudioOutputI2S i2s1;
AudioControlSGTL5000 audioShield;
AudioConnection patchCord17(leslieR, 0, i2s1, 0);
AudioConnection patchCord18(leslieL, 0, i2s1, 1);

#ifdef AUDIO_INTERFACE
// If the board is configured for USB audio, mirror the i2s output to USB.
AudioOutputUSB usbAudio;
AudioConnection patchCord19(leslieR, 0, usbAudio, 0);
AudioConnection patchCord20(leslieL, 0, usbAudio, 1);
#endif

uint8_t keys[62] = {0};
uint8_t drawbars[10] = {0};
uint16_t volumes[92] = {0};
uint16_t percVolumes[92] = {0};

// Current state of the percussion settings.
uint8_t percOn = 1;
uint8_t percThird = 0;
uint8_t percFast = 0;
uint8_t percSoft = 0;

// numKeysDown is used to keep the percussion effect single triggered:
// only the first key down affects the percussion setting.
uint8_t numKeysDown = 0;

void handleNoteOn(byte chan, byte note, byte vel);
void handleNoteOff(byte chan, byte note, byte vel);
void handleControlChange(byte chan, byte ctrl, byte val);

void setup() {
    Serial.begin(115200);

    AudioMemory(10);

    tonewheels.init();
    percussion.init();
    vibrato.init();

    swell.gain(1.0);

    preamp.init();
    preamp.setK(50.0);

    crossover.frequency(800);
    crossover.resonance(0.707);
    leslieBassR.init();
    leslieTrebleR.init();
    leslieBassL.init();
    leslieTrebleL.init();

    leslieBassR.setTremoloDepth(0.5);
    leslieTrebleR.setTremoloDepth(0.3);
    leslieBassL.setTremoloDepth(0.5);
    leslieTrebleL.setTremoloDepth(0.3);

    leslieBassR.setPhase(0.25);
    leslieTrebleL.setPhase(0.25);

    // Slow: http://www.dairiki.org/HammondWiki/LeslieRotationSpeed
    leslieBassR.setRotationRate(0.666);
    leslieTrebleR.setRotationRate(0.8);
    leslieBassL.setRotationRate(0.666);
    leslieTrebleL.setRotationRate(0.8);

    // Fast
    leslieBassR.setRotationRate(5.7);
    leslieTrebleR.setRotationRate(6.66);
    leslieBassL.setRotationRate(5.7);
    leslieTrebleL.setRotationRate(6.66);

    drawbars[1] = 8;
    drawbars[2] = 8;
    drawbars[3] = 8;
    drawbars[4] = 8;

    updatePercussion();
    updateTonewheels();

    organOut.gain(0, 0.50); // tonewheels + vibrato
    organOut.gain(1, 0.50); // percussionEnv
    organOut.gain(2, 0);
    organOut.gain(3, 0);

    leslieR.gain(0, 0.70); // bass
    leslieR.gain(1, 0.30); // treble
    leslieL.gain(0, 0.70); // bass
    leslieL.gain(1, 0.30); // treble

    vibrato.setMode(C3);
    antialias.setLowpass(0, 6000, 0.707);
{'fraction_non_alphanumeric': 0.11825726141078838, 'fraction_numerical': 0.05232826187183034, 'mean_word_length': 4.8549257759784075, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4340429', 'n_tokens_mistral': 3594, 'n_tokens_neox': 3236, 'n_words': 736}