From 1b8971ea2f17a891c5777a6ceb66eb4b05574560 Mon Sep 17 00:00:00 2001 From: gauthiier Date: Sat, 1 Dec 2018 12:33:53 +0100 Subject: [PATCH] haha! commit --- .gitignore | 1 + CFO Cheat Sheet.pdf | Bin 0 -> 23946 bytes CFO Cheat Sheet.rtf | 229 +++ FrictionHertzTable.inc | 129 ++ FrictionSineTable16bitHex.inc | 256 +++ FrictionWaveTable.inc | 272 +++ HaarnetPresets.h | 120 ++ Mcp4251.cpp | 218 +++ Mcp4251.h | 99 + Sampler.cpp | 46 + Sampler.h | 39 + Sequencer.cpp | 336 ++++ Sequencer.h | 203 ++ filterCoefficientTable.inc | 135 ++ filterCoefficientsMoogLadder.inc | 25 + filterCoefficients_1poleLP.inc | 8 + filterCoefficients_4stageLP.inc | 25 + filterCoefficients_4stageLPinFloats.inc | 25 + filterCutoffFrequenciesMoogLadder.inc | 3 + keywords.txt | 91 + uCFO.h | 67 + uSynth.cpp | 2375 +++++++++++++++++++++++ uSynth.h | 683 +++++++ 23 files changed, 5385 insertions(+) create mode 100644 .gitignore create mode 100644 CFO Cheat Sheet.pdf create mode 100644 CFO Cheat Sheet.rtf create mode 100644 FrictionHertzTable.inc create mode 100644 FrictionSineTable16bitHex.inc create mode 100644 FrictionWaveTable.inc create mode 100644 HaarnetPresets.h create mode 100644 Mcp4251.cpp create mode 100644 Mcp4251.h create mode 100644 Sampler.cpp create mode 100644 Sampler.h create mode 100644 Sequencer.cpp create mode 100644 Sequencer.h create mode 100644 filterCoefficientTable.inc create mode 100644 filterCoefficientsMoogLadder.inc create mode 100644 filterCoefficients_1poleLP.inc create mode 100644 filterCoefficients_4stageLP.inc create mode 100644 filterCoefficients_4stageLPinFloats.inc create mode 100644 filterCutoffFrequenciesMoogLadder.inc create mode 100644 keywords.txt create mode 100644 uCFO.h create mode 100644 uSynth.cpp create mode 100644 uSynth.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e43b0f9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store diff --git a/CFO Cheat Sheet.pdf b/CFO Cheat Sheet.pdf new file mode 100644 index 0000000000000000000000000000000000000000..69dfe3795111a1bb98dbb45c859bf8fd3b7cc591 GIT binary patch literal 23946 zcmcGWWmsNImZ*aVC%9{HcZcBa?(XjH?he5rxVyW%yAxc3yI+!X(&x^T5Nd zTDxSkzp8ghEg+QU7o?=6qK6>t-M!pBF1X5??CpnOz@@>p(lv$P;J~F8H?TCaH^yar z7s=vM3!0eQ8`!>I&2{Vz_zm=|^bK&ixFGE8Z4GoRAe;gER97rl1mQgPl}7cTdKsLW zTI-~WDDeQuFv?AU0iX~=#rw$g>5xe=4!v%@*u-SjZIe)ja(i2QV?ibkMwjS~3?Bd+ z&H-USf)2x%6G7_t0rko)S&954K4{_jhmCyg#0Lf10`Xj(ehipr#e^7HQaz*`Nw^@a=w^la34?g4l|Lg@ZAxgEUbsf9Yp`oZOLD5zy3F2oD; zm7C_GP7OQFunRg}Wt5&Is#ywOT9UtnNH?XEgETG-^6M*OQ(LCGmZzW8f|51k#aRV0 zOpHmc0ot z>|snL_=ElQo53~fc^dC;&UxIQzI}d?F(!blDwKpyEmWphnBtJ>oLuLD49V=RvyW?} z3Y;xw2r%&JT{=scJkvK?VJ@J;=1=}0EcF>Ot!HJ116?<wseo_|-AOSLQXW3I z=|V!dTAG1xAP$m}kVmtVTU5@Pgfghwcgg`FPt5fy?m}6zr-Y00kXp+v4$}5>p9Qih zv=$#HNc}zo4*TD+c+wM#J01^k=Z_i}fr&a9ahg7&HUH=-V|7wH0`_|eSI&>ur6=PY z$V(sSik|M;+^W+fHBIst)w!3{pJOG9FGejo38 z`Eg-%AX~DCc*5K_N*9JT{f;QV#I622fDC*IUT*zepwJ$#OAjArF-ByFhIm&;U^Hhv zy9J++sPHa30UkKaWC?0z4PUMBUImY+h{YBxJq7`d>dX-&VJ!L+?7+G2K(@ogykdYZ z%Q$ahn}600`yOt5sOPeVG&}-(vfwF6(Uun95P@kfIu7XrXE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UH&0_+#HEQ-hDL3o0W znj%QihG<3x>DUm7WU*h}D6n5GBBB6#4ARg6=>vS{Im|g2NQ+|TN~VH}m)S75mrBvA?2i;@Y-kfKJ^!3xIi7ppb1yuAt5I zfhE9i+Yv3upv{zlH2}F=QY?UZ#hYgW2#Ua%;tfn27!tWT*kN;ROL9`$7|00!i>$|! zEVryL5Ix;Vt^l77-^h3)s)FW4>0c@f{7>ZjAG+Mbm1qUfzi=cA`0p18i9i5sxE1J6 z4GKkKfM^>pkkelp7=lCsk70`j0i!p7_bnQ**g)d9Y7pec8En%~NFd>@8VrmE(%qs# zz!(g0wYF$rI25xp2GH`f-3|u+j~I}R*6;29P&+gP61~G890t(F+x8-m$envpXyBS} zje&w7cKAb}cYZb$WTRzb+g>PQhd(q70TkjkI~a0DerOnMhaDQe^IR~9jeEJ(9~yz$ zaSt$vo#%%^!nenTfRWJc&k~G5!2ybTOANpcyxk50Mr|~sY_r4ci~&KSx91FjU^Y5Q zw(NyM;X85$w2g||ZU^w-+qI3#*r6f+!*0iY0qO|6{kZ`eVtdYjhWb~1kX_9H;@ov} zu8fW?6)1fGA=f66fT6R0mAIOd6$u#Ex>@dON + +//---------- constructor ---------------------------------------------------- + +MCP4251::MCP4251(uint8_t slave_select_pin, float rAB_ohms) +{ + setup_ss(slave_select_pin); + setup_resistance(rAB_ohms, 0.0); //rW_ohms_typical); +} + +MCP4251::MCP4251(uint8_t slave_select_pin, float rAB_ohms, float rW_ohms) +{ + setup_ss(slave_select_pin); + setup_resistance(rAB_ohms, rW_ohms); +} + +//------------------ protected ----------------------------------------------- + +uint16_t MCP4251::byte2uint16(byte high_byte, byte low_byte) +{ + return (uint16_t)high_byte<<8 | (uint16_t)low_byte; +} + +byte MCP4251::uint16_high_byte(uint16_t uint16) +{ + return (byte)(uint16>>8); +} + +byte MCP4251::uint16_low_byte(uint16_t uint16) +{ + return (byte)(uint16 & 0x00FF); +} + +void MCP4251::setup_ss(uint8_t slave_select_pin) +{ + // Set slave select (Chip Select) pin for SPI Bus, and start high (disabled) + ::pinMode(slave_select_pin,OUTPUT); + ::digitalWrite(slave_select_pin,HIGH); + this->slave_select_pin = slave_select_pin; +} + +void MCP4251::setup_resistance(float rAB_ohms, float rW_ohms) +{ + this->rAB_ohms = rAB_ohms; + this->rW_ohms = rW_ohms; + this->rAW_ohms_max = rAB_ohms - rW_ohms; + this->scale = rAW_ohms_max; +} + +float MCP4251::step_increment() +{ + return (rAW_ohms_max - rW_ohms) / resolution; +} + +unsigned int MCP4251::ohms2wiper_pos(float ohms) +{ + if(ohms <= 0.0) + return 0; + else if(scale != rAW_ohms_max) + ohms = ohms * rAW_ohms_max / scale; + + return (unsigned int)((ohms - rW_ohms) / step_increment() ) + 0.5; +} + +float MCP4251::wiper_pos2ohms(unsigned int wiper_pos) +{ + float ohms = rW_ohms + ( (float)wiper_pos * step_increment() ); + + if(scale != rAW_ohms_max) + ohms = ohms * scale / rAW_ohms_max; + + return ohms; +} + +void MCP4251::write(byte cmd_byte, byte data_byte) +{ + cmd_byte |= kCMD_WRITE; + ::digitalWriteFast(slave_select_pin, LOW); +// byte high_byte = spi4teensy3::send(cmd_byte); +// byte low_byte = spi4teensy3::send(data_byte); + spi4teensy3::send(cmd_byte); + spi4teensy3::send(data_byte); + ::digitalWriteFast(slave_select_pin, HIGH); + //bool result = ~low_byte; +} + +uint16_t MCP4251::read(byte cmd_byte) +{ + cmd_byte |= kCMD_READ; + ::digitalWrite(slave_select_pin, LOW); +// byte high_byte = spi4teensy3::receive(cmd_byte); +// byte low_byte = spi4teensy3::receive(0xFF); + spi4teensy3::send(cmd_byte); + spi4teensy3::send(0xFF); + ::digitalWrite(slave_select_pin, HIGH); +// return byte2uint16(high_byte, low_byte); +} + +void MCP4251::wiper_pos(byte pot, unsigned int wiper_pos) +{ + byte cmd_byte = 0x00; + byte data_byte = 0x00; + cmd_byte |= pot; + + // Calculate the 9-bit data value to send + if(wiper_pos > 255) + cmd_byte |= B00000001; // Table 5-1 (page 36) + else + data_byte = (byte)(wiper_pos & 0x00FF); + + write(cmd_byte|kADR_VOLATILE, data_byte); + + if(non_volatile) + { + // EEPROM write cycles take 4ms each. So we block with delay(5); after any NV Writes + write(cmd_byte|kADR_NON_VOLATILE, data_byte); + delay(5); + } +} + +//---------- public ---------------------------------------------------- + +float MCP4251::wiper0() +{ + return wiper_pos2ohms( wiper0_pos() ); +} + +float MCP4251::wiper1() +{ + return wiper_pos2ohms( wiper1_pos() ); +} + +unsigned int MCP4251::wiper0_pos() +{ + return (unsigned int)( 0x01FF & this->read(kADR_WIPER0|kADR_VOLATILE) ); +} + +unsigned int MCP4251::wiper1_pos() +{ + return 0x01FF & this->read(kADR_WIPER1|kADR_VOLATILE); +} + +void MCP4251::wiper0(float ohms) +{ + wiper0_pos( ohms2wiper_pos(ohms) ); +} + +void MCP4251::wiper1(float ohms) +{ + wiper1_pos( ohms2wiper_pos(ohms) ); +} + +void MCP4251::wiper0_pos(unsigned int wiper_pos) +{ + this->wiper_pos(kADR_WIPER0, wiper_pos); +} + +void MCP4251::wiper1_pos(unsigned int wiper_pos) +{ + this->wiper_pos(kADR_WIPER1, wiper_pos); +} + + +// // Not implemented +// bool MCP4251::pot0_connected(bool terminal_a, bool wiper, bool terminal_b) +// { +// +// } +// +// bool MCP4251::pot1_connected(bool terminal_a, bool wiper, bool terminal_b) +// { +// +// } +// +// void MCP4251::pot0_connect(bool terminal_a, bool wiper, bool terminal_b) +// { +// +// } +// +// void MCP4251::pot1_connect(bool terminal_a, bool wiper, bool terminal_b) +// { +// +// } +// +// bool MCP4251::pot0_shutdown() +// { +// +// } +// +// bool MCP4251::pot1_shutdown() +// { +// +// } +// +// void MCP4251::pot0_shutdown(bool shutdown) +// { +// +// } +// +// void MCP4251::pot1_shutdown(bool shutdown) +// { +// +// } +// +// bool MCP4251::hw_shutdown() +// { +// +// } + + diff --git a/Mcp4251.h b/Mcp4251.h new file mode 100644 index 0000000..88ab266 --- /dev/null +++ b/Mcp4251.h @@ -0,0 +1,99 @@ + +// MCP4251 2-channel Digital Potentiometer +// ww1.microchip.com/downloads/en/DeviceDoc/22059b.pdf + +#include +#include + +#ifndef Mcp4251_h +#define Mcp4251_h + +class MCP4251 +{ + public: + // You must at least specify the slave select pin and the rated resistance + MCP4251(uint8_t slave_select, float rAB_ohms); + + // If you have measured wiper resistance, rW + MCP4251(uint8_t slave_select, float rAB_ohms, float rW_ohms); + + // The resistance scaling, defaults to rAB_ohms + float scale; + + // Read potentiometer values + float wiper0(); + float wiper1(); + unsigned int wiper0_pos(); + unsigned int wiper1_pos(); + + // Write potentiometer values + void wiper0(float ohms); + void wiper1(float ohms); + + void wiper0_pos(unsigned int wiper_pos); + void wiper1_pos(unsigned int wiper_pos); + + // // Not implemented + // // Connect / disconnect potentiometers + // bool pot0_connected(bool terminal_a, bool wiper, bool terminal_b); + // bool pot1_connected(bool terminal_a, bool wiper, bool terminal_b); + // void pot0_connect(bool terminal_a, bool wiper, bool terminal_b); + // void pot1_connect(bool terminal_a, bool wiper, bool terminal_b); + // + // bool pot0_shutdown(); + // bool pot1_shutdown(); + // void pot0_shutdown(bool shutdown); + // void pot1_shutdown(bool shutdown); + // + // bool hw_shutdown(); + + protected: +// const static float rW_ohms_typical = 117.50f; + const static unsigned int resolution_7bit = 128; + const static unsigned int resolution_8bit = 256; + + // Other devices can be configured below vv as per the device numbering scheme: + // MCP4N-- N=1 single pot, N=2 dual pot + // MCP4--N N=1 potentiometer, N=2 rheostat + // MCP4-N- N=3 7-bit volatile, N=4 7-bit non-volatile, N=5 8-bit volatile, N=6 8-bit non-volatile + const static bool non_volatile = false; + const static unsigned int resolution = resolution_8bit; + + float rW_ohms; + float rAB_ohms; + float rAW_ohms_max; + + uint8_t slave_select_pin; + + const static uint8_t kADR_WIPER0 = B00000000; + const static uint8_t kADR_WIPER1 = B00010000; + + const static uint8_t kCMD_READ = B00001100; + const static uint8_t kCMD_WRITE = B00000000; + + const static uint8_t kADR_VOLATILE = B00000000; + const static uint8_t kADR_NON_VOLATILE = B00100000; + + const static uint8_t kTCON_REGISTER = B01000000; + const static uint8_t kSTATUS_REGISTER = B01010000; + + uint16_t byte2uint16(byte high_byte, byte low_byte); + byte uint16_high_byte(uint16_t uint16); + byte uint16_low_byte(uint16_t uint16); + + void setup_ss(uint8_t slave_select_pin); + void setup_resistance(float rAB_ohms, float rW_ohms); + + float step_increment(); + unsigned int ohms2wiper_pos(float ohms); + float wiper_pos2ohms(unsigned int wiper_pos); + + uint16_t read(byte cmd_byte); + void write(byte cmd_byte, byte data_byte); + void wiper_pos(byte pot, unsigned int wiper_pos); +}; + +#endif // Mcp4251_h + + + diff --git a/Sampler.cpp b/Sampler.cpp new file mode 100644 index 0000000..6f8cb90 --- /dev/null +++ b/Sampler.cpp @@ -0,0 +1,46 @@ +/* + Sampler.cpp - Friction Music library + Copyright (c) 2014 Science Friction. + All right reserved. + + This library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your optionosc1modShape_ptr) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser Public License for more details. + + You should have received a copy of the GNU Lesser Public License + along with Foobar. If not, see . + + +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + author: gauthiier + + contact: d@gauthiier.info + */ + +#include "Sampler.h" +#include + + +Sampler::Sampler(int len) { + _samples = (int*)malloc(len * 2); + _len = len; + memset(_samples, 0, len * 2); +} + +void Sampler::record(int in) { + _samples[_indx++] = in; + if(_indx > _len) _indx = 0; +} + +int Sampler::next() { + if(_indx > _len) _indx = 0; + return _samples[_indx++]; +} + +void Sampler::reset() { + _indx = 0; +} \ No newline at end of file diff --git a/Sampler.h b/Sampler.h new file mode 100644 index 0000000..b553a71 --- /dev/null +++ b/Sampler.h @@ -0,0 +1,39 @@ +/* + Sampler.h - Friction Music library + Copyright (c) 2014 Science Friction. + All right reserved. + + This library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your optionosc1modShape_ptr) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser Public License for more details. + + You should have received a copy of the GNU Lesser Public License + along with Foobar. If not, see . + + +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + author: gauthiier + + contact: d@gauthiier.info + */ + +#pragma once + + +class Sampler { + +public: + Sampler(int len); + + void record(int in); + int next(); + void reset(); + + int* _samples; + int _indx; + int _len; +}; diff --git a/Sequencer.cpp b/Sequencer.cpp new file mode 100644 index 0000000..0e8c7ce --- /dev/null +++ b/Sequencer.cpp @@ -0,0 +1,336 @@ +/* + Haarnet.h - Friction Music library + Copyright (c) 2014 Science Friction. + All right reserved. + + This library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your optionosc1modShape_ptr) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser Public License for more details. + + You should have received a copy of the GNU Lesser Public License + along with Foobar. If not, see . + + +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + author: gauthiier + + contact: d@gauthiier.info + */ + +#include "Sequencer.h" +#include +#include + +MSequencer Sequencer; +iSequencer iSeq; // instrument sequencer +//extern iSeq; +//int iSeq0,iSeq1; +//iSeq.iSeqInit(120); + +IntervalTimer sequencerTimer; +IntervalTimer iSeqTimer; + +boolean sequencerTimerRunning = false; +boolean iSeqTimerRunning = false; + +#ifndef SAMPLE_RATE +unsigned int sampleRate = 48000; +#endif + +void sequencer_isr(void) +{ + Sequencer.clockStep++; +} + +void iSeq_isr(void) +{ + iSeq.clockStep++; +} + + +void MSequencer::init(int bpm) +{ + setbpm(bpm); + for(int i = 0; i < MAX_SEQ; i++) { + _sequences[i] = NULL; + } + if(!sequencerTimerRunning) { + sequencerTimerRunning = true; + clockStep = 0; + sequencerTimer.begin(sequencer_isr, 60 * 1000000 / (_bpm * TICKS_PER_QUARTER_NOTE)); + } +} + + +void iSequencer::init(int bpm) +{ + for(int i = 0; i < ISEQ_NBR_STEPS; i++) { + // _notes[i] = i; + // _velocity[i] = 127; + // _CCnumbers[i] = 100; + // _CCvalues[i] = 0; + } + + + +// +// int iSeq_indx0 = 0; +// int iSeq_indx1 = 0; +//#define ISEQ_NBR_STEPS 32 +// const int iSeq_nbr_notes = 32; +// const int iSeq_nbr_steps = 32; +// +// int iSeq_notes[ISEQ_NBR_STEPS]; +// int iSeq_velocity[ISEQ_NBR_STEPS]; +// int iSeq_midi_numbers[ISEQ_NBR_STEPS]; +// int iSeq_midi_values[ISEQ_NBR_STEPS]; +// +// void iSeqNote() { +// // Music.noteOn(iSeq_notes[iSeq_indx0++] + Music.notePlayed, Music.velocityPlayed); +// // if(iSeq_indx0 >= iSeq_nbr_notes) iSeq_indx0 = 0; +// } +// +// void iSeqController() { +// // Midi.controller(MIDI_CHANNEL - 1, iSeq_midi_numbers[iSeq_indx1], iSeq_midi_values[iSeq_indx1]); +// // iSeq_indx1++; +// // if(iSeq_indx1 >= iSeq_nbr_steps) iSeq_indx1 = 0; +// } +// +// for(int i = 0; i < ISEQ_NBR_STEPS; i++) { +// // iSeq_notes[i] = i; +// // iSeq_velocity[i] = 127; +// // iSeq_midi_numbers[i] = 100; +// // iSeq_midi_values[i] = 0; +// } + + setbpm(bpm); + for(int i = 0; i < INSTR_SEQ; i++) { + _sequences[i] = NULL; + } + if(!iSeqTimerRunning) { + iSeqTimerRunning = true; + clockStep = 0; + iSeqTimer.begin(iSeq_isr, 60 * 1000000 / (_bpm * TICKS_PER_QUARTER_NOTE)); + } +} + + + +void MSequencer::update() +{ + for(int i = 0; i < MAX_SEQ; i++) { + seq* s = _sequences[i]; + if(s == NULL || s->_stopped) continue; + if(clockStep >= s -> step) { + //boom! + s->_callback(); // add to queue??? + s->step += s -> _subdiv; +// Serial.println(s -> step); + } + } + // queue goes here +} + + +void iSequencer::update() +{ + for(int i = 0; i < INSTR_SEQ; i++) { + iseq* s = _sequences[i]; + if(s == NULL || s->_stopped) continue; + if(clockStep >= s -> step) { + //boom! +// s->_callback(); // add to queue??? + s->step += s -> _subdiv; +// Serial.println(s -> step); + } + } + // queue goes here +} + + +int MSequencer::newSequence(func_cb cb, SUBDIV subdiv) +{ + int j = -1; + for(int i = 0; i < MAX_SEQ; i++) { + if(_sequences[i] == NULL) j = i; + } + + if(j >= 0) { + seq* s = new seq(j, cb, subdiv); + _sequences[j] = s; + Serial.print("Created sequence "); + Serial.println(j); + } + + return j; +} + + +int iSequencer::newSequence(SUBDIV subdiv, int steps, SEQ_LOOP_TYPE loop) +{ + int j = -1; + for(int i = 0; i < MAX_SEQ; i++) { + if(_sequences[i] == NULL) j = i; + } + + if(j >= 0) { + iseq* s = new iseq(j, subdiv, steps, loop); + _sequences[j] = s; + Serial.print("Created sequence "); + Serial.println(j); + } + + return j; +} + + +bool MSequencer::stopSequence(int index) +{ + if(index >= 0 && index < MAX_SEQ) { + _sequences[index]->_stopped = true; +// _sequences[index]-> step = 0; + return true; + } + return false; +} + +bool MSequencer::startSequence(int index) +{ + if(index >= 0 && index < MAX_SEQ && _sequences[index] != NULL) { + _sequences[index]->_stopped = false; + _sequences[index]-> step = 0; + return true; + } + return false; +} + + +void MSequencer::setbpm(int bpm) +{ + _bpm = bpm; + _bpmInClockSteps = _bpm * 24; +} + +int MSequencer::getbpm() +{ + return _bpm; +} + +void iSequencer::setbpm(int bpm) +{ + _bpm = bpm; + _bpmInClockSteps = _bpm * 24; +} + +int iSequencer::getbpm() +{ + return _bpm; +} + +bool MSequencer::setSequenceSubdiv(int index, SUBDIV subdiv) +{ + if(index >= 0 && index < MAX_SEQ && _sequences[index] != NULL) { + _sequences[index]->setsubdiv(subdiv); + return true; + } + return false; +} + +int MSequencer::getSequenceSubdiv(int index) +{ + if(index >= 0 && index < MAX_SEQ && _sequences[index] != NULL) { + return _sequences[index]->getsubdiv(); + } + return -1; +} + +bool MSequencer::setCallback(int index, func_cb cb) +{ + if(index >= 0 && index < MAX_SEQ && _sequences[index] != NULL) { + _sequences[index]->callback(cb); + return true; + } + return false; +} + +func_cb MSequencer::getCallback(int index) +{ + if(index >= 0 && index < MAX_SEQ && _sequences[index] != NULL) { + return _sequences[index]->_callback; + } + return NULL; +} + + +// seq + +seq::seq(int id, func_cb cb, SUBDIV subdiv) : _id(id), _stopped(true) +{ + setsubdiv(subdiv); + callback(cb); +} + +void seq::setsubdiv(SUBDIV v) +{ + _subdiv = v; + +} + +SUBDIV seq::getsubdiv() +{ + return _subdiv; +} + +void seq::callback(func_cb cb) +{ + _callback = cb; +} + +// iseq + +iseq::iseq(int id, SUBDIV subdiv, int steps, SEQ_LOOP_TYPE loop) : _id(id), _stopped(true) +{ + setsubdiv(subdiv); + setsteps(steps); + setlooptype(loop); +} + +void iseq::setsteps(int steps) +{ + _steps = steps; + +} + +int iseq::getsteps() +{ + return _steps; + +} + +void iseq::setsubdiv(SUBDIV v) +{ + _subdiv = v; + +} + +SUBDIV iseq::getsubdiv() +{ + return _subdiv; +} + +void iseq::setlooptype(SEQ_LOOP_TYPE loop) +{ + _loop = loop; +} + +SEQ_LOOP_TYPE iseq::getlooptype() +{ + return _loop; +} + + + diff --git a/Sequencer.h b/Sequencer.h new file mode 100644 index 0000000..9d1d507 --- /dev/null +++ b/Sequencer.h @@ -0,0 +1,203 @@ +/* + Sequencer.h - Friction Music library + Copyright (c) 2014 Science Friction. + All right reserved. + + This library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your optionosc1modShape_ptr) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser Public License for more details. + + You should have received a copy of the GNU Lesser Public License + along with Foobar. If not, see . + + +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + author: gauthiier + + contact: d@gauthiier.info + */ + +#pragma once + +#define MAX_SEQ 3 +#define INSTR_SEQ 4 +#define ISEQ_NBR_STEPS 32 + + +#define TICKS_PER_QUARTER_NOTE 96 // + +enum SUBDIV { + NOTE_1 = (TICKS_PER_QUARTER_NOTE * 4), + NOTE_1DOT = (TICKS_PER_QUARTER_NOTE * 3), + NOTE_2 = (TICKS_PER_QUARTER_NOTE * 2), + NOTE_3 = ((TICKS_PER_QUARTER_NOTE * 3) / 2), + NOTE_4 = (TICKS_PER_QUARTER_NOTE * 1), + NOTE_6 = ((TICKS_PER_QUARTER_NOTE * 2) / 3), + NOTE_8 = (TICKS_PER_QUARTER_NOTE / 2), + NOTE_12 = (TICKS_PER_QUARTER_NOTE / 3), + NOTE_16 = (TICKS_PER_QUARTER_NOTE / 4), + NOTE_24 = (TICKS_PER_QUARTER_NOTE / 6), + NOTE_32 = (TICKS_PER_QUARTER_NOTE / 8), + NOTE_48 = (TICKS_PER_QUARTER_NOTE / 12) +#if (TICKS_PER_QUARTER_NOTE > 64) + ,NOTE_64 = (TICKS_PER_QUARTER_NOTE / 16), + NOTE_96 = (TICKS_PER_QUARTER_NOTE / 24), + NOTE_128 = (TICKS_PER_QUARTER_NOTE / 32), + NOTE_192 = (TICKS_PER_QUARTER_NOTE / 48), +// NOTE_256 = (TICKS_PER_QUARTER_NOTE / 64), + NOTE_384 = (TICKS_PER_QUARTER_NOTE / 92) +#endif +}; + +enum SEQ_LOOP_TYPE { + NO_LOOP = 0, + FORWARD_LOOP = 1, + BACKWARD_LOOP = 2, + PINGPONG = 3 +}; + +typedef void (*func_cb)(void); + +class seq; +class iseq; + +class MSequencer { +public: + void init(int bpm); + void update(); + + int newSequence(func_cb cb, SUBDIV subdiv); + + bool stopSequence(int index); + bool startSequence(int index); + + bool setSequenceSubdiv(int index, SUBDIV subdiv); + + int getSequenceSubdiv(int index); + + bool setCallback(int index, func_cb cb); + func_cb getCallback(int index); + + unsigned long clockStep; + + void setbpm(int v); + int getbpm(); + + + +private: + seq* _sequences[MAX_SEQ]; + int _bpm; + int _bpmInClockSteps; + + +}; + + +class iSequencer { +public: + void init(int bpm); + void update(); + + int newSequence(SUBDIV subdiv, int steps, SEQ_LOOP_TYPE loop); + + bool stopSequence(int index); + bool startSequence(int index); + + bool setSequenceSubdiv(int index, SUBDIV subdiv); + + int getSequenceSubdiv(int index); + +// bool setCallback(int index, func_cb cb); +// func_cb getCallback(int index); + + unsigned long clockStep; + + void setbpm(int v); + int getbpm(); + + + +private: + iseq* _sequences[INSTR_SEQ]; + int _bpm; + int _bpmInClockSteps; + + +}; + + +class seq { + + friend class MSequencer; + +private: + + seq(int id, func_cb cb, SUBDIV subdiv); + + int _id; + SUBDIV _subdiv; + + unsigned long lastStep; + unsigned long stepNum; + unsigned long step; + + void setsubdiv(SUBDIV v); + SUBDIV getsubdiv(); + + bool _stopped; + + void callback(func_cb cb); + + func_cb _callback; +}; + + +class iseq { + + friend class iSequencer; + +private: + + iseq(int id, SUBDIV subdiv, int steps, SEQ_LOOP_TYPE loop); + + int _id; + int _steps; + int _length; + int _direction; + SUBDIV _subdiv; + SEQ_LOOP_TYPE _loop; + + int indx; + + int _notes[]; + int _velocity[]; + int _ccNumbers[]; + int _ccValues[]; + + unsigned long lastStep; + unsigned long stepNum; + unsigned long step; + + void setsubdiv(SUBDIV v); + SUBDIV getsubdiv(); + + void setsteps(int steps); + int getsteps(); + + void setlooptype(SEQ_LOOP_TYPE loop); + SEQ_LOOP_TYPE getlooptype(); + + + + bool _stopped; + +}; + + +extern MSequencer Sequencer; +extern iSequencer iSeq; diff --git a/filterCoefficientTable.inc b/filterCoefficientTable.inc new file mode 100644 index 0000000..73599ed --- /dev/null +++ b/filterCoefficientTable.inc @@ -0,0 +1,135 @@ +// value of x for implementation of single pole low pass filter +// in 32bit fixed integer calculation with coefficients +// a0 = 1 - x +// b1 = x +// x = EXP(-(2*PI()*fc)) +// where fc is a value between 0.0 and 0.5 of the sampling rate (in this case 48KHz) +// +4290373254, +4290100233, +4289810996, +4289504581, +4289179970, +4288836083, +4288471778, +4288085843, +4287676998, +4287243884, +4286785064, +4286299013, +4285784121, +4285238680, +4284660880, +4284048808, +4283400436, +4282713616, +4281986075, +4281215408, +4280399067, +4279534352, +4278618410, +4277648216, +4276620570, +4275532089, +4274379185, +4273158065, +4271864714, +4270494881, +4269044076, +4267507537, +4265880234, +4264156844, +4262331738, +4260398955, +4258352199, +4256184808, +4253889743, +4251459553, +4248886373, +4246161883, +4243277292, +4240223313, +4236990127, +4233567382, +4229944123, +4226108800, +4222049200, +4217752472, +4213205021, +4208392501, +4203299810, +4197911016, +4192209318, +4186177034, +4179795529, +4173045162, +4165905296, +4158354192, +4150369010, +4141925733, +4132999132, +4123562709, +4113588682, +4103047864, +4091909728, +4080142291, +4067712036, +4054583930, +4040721407, +4026086291, +4010638755, +3994337308, +3977138813, +3958998423, +3939869591, +3919704125, +3898452117, +3876062167, +3852481062, +3827654212, +3801525689, +3774038004, +3745132631, +3714749847, +3682829367, +3649309994, +3614130143, +3577228361, +3538543245, +3498014098, +3455581234, +3411186725, +3364774287, +3316290864, +3265686384, +3212914905, +3157935534, +3100712973, +3041218570, +2979431317, +2915339041, +2848938943, +2780239798, +2709261927, +2636039303, +2560620544, +2483069880, +2403468642, +2321915945, +2238530967, +2153452027, +2066839367, +1978873676, +1889758159, +1799717893, +1708999312, +1617870277, +1526617863, +1435548103, +1344982938, +1255257551, +1166718303, +1079717790, +994610846, +911750234, +831480728 \ No newline at end of file diff --git a/filterCoefficientsMoogLadder.inc b/filterCoefficientsMoogLadder.inc new file mode 100644 index 0000000..554e6ee --- /dev/null +++ b/filterCoefficientsMoogLadder.inc @@ -0,0 +1,25 @@ +// value of coefficients for implementation of Moog Ladder style resonant low pass filter +// in 32bit fixed integer calculation with coefficients +// g = (1 - x)^4 +// b1 = 4x +// b2 = -6x^2 +// b3 = 4x^3 +// b4 = -x^4 +// x = EXP(-(14.445 * fc)) +// where fc is a value between 0.0 and 0.5 of the sampling rate (in this case 48KHz) +// + +// g +7730393,7956911,8190067,8430055,8677075,8931333,9193043,9462420,9739690,10025087,10318845,10621212,10932438,11252784,11582517,11921914,12271254,12630830,13000945,13381904,13774027,14177639,14593080,15020692,15460836,15913877,16380194,16860175,17354220,17862745,18386170,18924934,19479484,20050284,20637809,21242556,21865018,22505724,23165206,23844011,24542710,25261881,26002132,26764071,27548340,28355589,29186497,30041754,30922075,31828195,32760865,33720874,34709012,35726109,36773013,37850601,38959772,40101444,41276577,42486152,43731176,45012690,46331764,47689495,49087025,50525515,52006173,53530223,55098946,56713656,58375693,60086452,61847358,63659885,65525548,67445905,69422566,71457166,73551427,75707092,77925956,80209887,82560785,84980619,87471425,90035275,92674310,95390762,98186887,101065027,104027599,107077090,110216037,113447099,116772968,120196439,123720382,127347756,131081629,134925093,138881416,142953919,147146006,151461256,155903251,160475754,165182630,170027814,175015454,180149716,185434966,190875690,196476463,202242051,208177322,214287380,220577347,227052624,233718714,240581292,247646284,254919670,262407680,270116787,278053595,286224953,294637873,303299699,312217887,321400231,330854639,340589422,350613094,360934464,371562610,382506856,393777000,405382984,417335149,429644299,442321370,455377944,468825746,482677110,496944728,511641719,526781782,542378866,558447751,575003583,592062139,609639593,627753073,646420287,665659424,685489529,705930641,727003191,748728900,771130064,794230170,818053830,842626179,867974307,894125997,921110611,948958631,977702385,1007375692,1038014044,1069654650,1102337124,1136102744,1170995524,1207061686,1244350164,1282912925,1322805006,1364084973,1406815195,1451061624,1496895349,1544391890,1593631939,1644702479,1697696804,1752714830,1809865105,1869264035,1931037925,1995324032,2062270847,2132040807,2204810956,2280774706,2360144704,2443154837,2530062428,2621152714,2716741893,2817182420,2922866347,3034233898,3151781638,3276065795,3407721513,3547467988,3696130526,3854655329,4024136766,4205846353,4401269145,4612154019,4840571078,5088993792,5360401603,5658414293,5987476367,6353111379,6762261327,7223785189,7749168552,8353573824,9057436956,9889002851,10888442000,12114878218,13659111791,15668055402,18396174389,22325770963,28495882501,39631229567,65894430866,204816793749,-175652025025,-60228320333,-35828969727,-25197653708,-19224318982,-15382805412,-12693055725,-10695206179,-9144803901,-7899806521,-6871970546,-6003501819,-5254884437,-4598105816,-4012652847,-3483069834,-2997374010,-2546008524,-2121116169,-1716013394,-1324789764, + +// gg +13914,14741,15618,16546,17530,18573,19677,20847,22087,23400,24791,26266,27828,29482,31235,33093,35060,37145,39354,41694,44174,46800,49583,52532,55655,58965,62471,66186,70121,74291,78709,83389,88348,93601,99167,105064,111311,117930,124943,132373,140244,148584,157419,166780,176698,187205,198337,210131,222627,235865,249891,264751,280495,297175,314846,333569,353405,374421,396687,420276,445269,471748,499802,529524,561014,594377,629724,667173,706849,748886,793422,840607,890599,943565,999681,1059135,1122126,1188863,1259570,1334484,1413854,1497945,1587040,1681434,1781446,1887407,1999672,2118619,2244642,2378165,2519633,2669520,2828328,2996587,3174861,3363747,3563876,3775920,4000588,4238631,4490849,4758086,5041237,5341254,5659141,5995964,6352854,6731008,7131698,7556267,8006144,8482842,8987961,9523203,10090367,10691369,11328227,12003094,12718243,13476088,14279197,15130275,16032204,16988041,18001022,19074586,20212372,21418256,22696333,24050965,25486758,27008623,28621764,30331706,32144313,34065799,36102796,38262309,40551793,42979192,45552895,48281874,51175612,54244230,57498473,60949765,64610281,68492916,72611470,76980591,81615890,86533938,91752485,97290423,103167833,109406164,116028374,123058827,130523687,138450781,146869934,155813077,165314152,175409810,186139089,197543939,209669229,222563267,236277884,250868768,266395759,282923490,300521367,319264484,339233762,360516675,383207941,407410107,433234454,460801877,490243509,521702619,555335151,591311314,629817659,671058529,715257897,762662780,813544735,868203926,926972831,990219658,1058354509,1131834311,1211169469,1296932582,1389767406,1490399216,1599649329,1718449991,1847864312,1989106573,2143572863,2312876167,2498879817,2703761196,2930064017,3180788100,3459483317,3770384171,4118574677,4510202000,4952765232,5455484699,6029814904,6690133676,7454690595,8346949063,9397516072,10646921175,12149818349,13981390104,16247433527,19100765745,22769062173,27603974843,34172617423,43439523997,57157119757,78794367644,116052117450,189062049498,365691808283,1010968354323,9767226642373,7183671438948,844581651071,298888206408,147829240284,86048254815,55094878737,37512198006,26632900166,19471030305,14530248724,10995189469,8391689997,6429341259,4922639833,3748895338,2824649091,2091808932,1509245346,1047536219,685616855,408633593, + +// ggg +25,27,30,32,35,39,42,46,50,55,60,65,71,77,84,92,100,109,119,130,142,154,168,184,200,218,238,260,283,309,337,367,401,437,477,520,567,618,674,735,801,874,953,1039,1133,1236,1348,1470,1603,1748,1906,2079,2267,2472,2696,2940,3206,3496,3812,4157,4534,4944,5392,5880,6412,6992,7625,8315,9068,9889,10784,11760,12825,13985,15251,16632,18138,19780,21570,23523,25652,27975,30507,33269,36281,39566,43148,47054,51315,55961,61028,66553,72580,79152,86319,94136,102661,111958,122097,133155,145215,158368,172713,188358,205421,224031,244328,266465,290609,316943,345665,376992,411161,448430,489081,533421,581786,634541,692087,754859,823333,898029,979512,1068403,1165375,1271167,1386583,1512503,1649885,1799778,1963324,2141775,2336494,2548974,2780842,3033877,3310025,3611410,3940353,4299396,4691309,5119131,5586176,6096076,6652801,7260694,7924512,8649451,9441216,10306043,11250767,12282868,13410557,14642836,15989561,17461548,19070689,20829998,22753807,24857828,27159353,29677405,32432851,35448747,38750423,42365822,46325714,50664096,55418489,60630335,66345432,72614538,79493772,87045431,95338578,104449918,114464765,125478052,137595602,150935511,165629560,181825418,199688390,219403905,241180571,265253224,291886535,321380038,354072525,390348655,430646158,475463721,525371870,581024375,643172462,712682624,790557116,877958503,976241468,1086989670,1212062979,1353652371,1514354126,1697261034,1906066829,2145223598,2420113493,2737298606,3104823596,3532632618,4033113896,4621830978,5318530852,6148512813,7144569096,8349726741,9821198837,11636214390,13900796486,16763169158,20435004924,25225837833,31600737810,40280628376,52424920898,69980574551,96391210910,138148971466,208509368587,337491493681,603253253254,1254372752245,3374371678766,15510521906258,465775850394381,-293791861126116,-11843567301560,-2493349951485,-867282507162,-385152897419,-197327183287,-110861011699,-66320495312,-41457534274,-26725734030,-17592361704,-11729897504,-7866286980,-5270079440,-3502474994,-2290692656,-1459832705,-894663743,-517337120,-273931703,-126043708, + +// G = gggg +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,2,2,2,2,3,3,3,4,4,5,5,6,6,7,8,9,10,12,13,15,16,18,21,23,26,29,33,37,41,46,52,58,65,73,82,92,104,116,131,147,165,185,207,233,261,293,329,369,415,465,522,586,658,739,829,931,1045,1173,1317,1478,1659,1863,2091,2347,2634,2957,3320,3726,4183,4696,5271,5917,6642,7457,8371,9397,10549,11842,13294,14924,16754,18809,21116,23706,26614,29879,33545,37661,42283,47473,53301,59845,67193,75446,84713,95121,106809,119937,134681,151241,169842,190736,214207,240574,270195,303474,340865,382878,430087,483139,542761,609770,685089,769755,864936,971949,1092274,1227582,1379757,1550921,1743464,1960089,2203841,2478157,2786915,3134502,3525865,3966604,4463042,5022338,5652596,6362975,7163873,8067060,9085892,10235511,11533128,12998292,14653229,16523222,18637092,21027655,23732383,26794045,30261528,34190790,38645928,43700471,49438879,55958214,63370360,71804302,81409018,92356997,104848191,119114728,135426995,154100134,175502630,200066396,228298588,260796925,298267442,341546601,391629087,449701548,517184339,595785206,687565276,795024101,921204910,1069834600,1245503352,1453887751,1702067583,1998915138,2355643766,2786522922,3309873118,3949426433,4736222811,5711308551,6929578562,8465412021,10421008012,12938960425,16221673847,20562044422,26392967093,34370013958,45513564077,61462422880,84945757885,120706435350,177412160472,271892124207,439349618992,760642890569,1445541245043,3135784986587,8322405293673,31136558075793,237966192290634,22211744516035900,12015256877698800,166082327562704,20799729956799,5088160811660,1723948436947,706744767506,327631132494,165149423120,88270991373,49157097929,28147872413,16396041262,9624387376,5642041313,3272252217,1857672466,1018788807,530346650,255492546,109446810,38878390, + +// Gstage +7716504,7942197,8174479,8413541,8659580,8912799,9173408,9441619,9717654,10001741,10294113,10595012,10904682,11223379,11551366,11888913,12236293,12593794,12961710,13340339,13729995,14130993,14543665,14968344,15405381,15855130,16317961,16794248,17284381,17788762,18307796,18841911,19391535,19957117,20539117,21138009,21754271,22388409,23040933,23712369,24403262,25114166,25845660,26598323,27372768,28169612,28989499,29833083,30701039,31594065,32512866,33458185,34430766,35431386,36460840,37519946,38609544,39730487,40883667,42069992,43290395,44545835,45837296,47165786,48532351,49938049,51383984,52871263,54401050,55974531,57592910,59257442,60969401,62730102,64540889,66403145,68318289,70287759,72313063,74395724,76537298,78739403,81003677,83331808,85725537,88186621,90716874,93318175,95992413,98741536,101567550,104472504,107458473,110527627,113682141,116924265,120256292,123680570,127199523,130815562,134531234,138349100,142271761,146301944,150442336,154695752,159065055,163553124,168162987,172897633,177760181,182753799,187881676,193147112,198553426,204104083,209802486,215652211,221656840,227820022,234145536,240637109,247298590,254133932,261147090,268342114,275723070,283294182,291059630,299023739,307190782,315565210,324151483,332954130,341977720,351226834,360706243,370420619,380374740,390573527,401021756,411724470,422686551,433913081,445409128,457179780,469230250,481565597,494191163,507112187,520333990,533861770,547701010,561857159,576335536,591141579,606280923,621758917,637581253,653753406,670281047,687169945,704425506,722053734,740060295,758451085,777231857,796408655,815987510,835974493,856375675,877197491,898446180,920128373,942250664,964819817,987842843,1011326899,1035279419,1059708129,1084620754,1110025732,1135931607,1162347239,1189282170,1216746363,1244750091,1273304642,1302421578,1332113360,1362393412,1393275766,1424775789,1456909849,1489695424,1523151574,1557298891,1592159423,1627757351,1664118871,1701272730,1739249752,1778083998,1817813274,1858477605,1900122518,1942796904,1986555550,2031458306,2077571776,2124969830,2173734255,2223956537,2275738290,2329193578,2384450539,2441653032,2500963392,2562566115,2626670049,2693514005,2763371812,2836558465,2913437519,2994432687,3080039626,3170840682,3267527014,3370921657,3482018158,3602020921,3732409626,3875018714,4032153473,4206752535,4402618211,4624765942,4879946767,5177473195,5530569783,5958658981,6491508120,7177163478,8098547824,9412184160,11453182589,15091789849,23511984362,65147491412,-61046159117,-18425566938,-9921154401,-6252304812,-4190776664,-2857833714,-1915686403 \ No newline at end of file diff --git a/filterCoefficients_1poleLP.inc b/filterCoefficients_1poleLP.inc new file mode 100644 index 0000000..364cd09 --- /dev/null +++ b/filterCoefficients_1poleLP.inc @@ -0,0 +1,8 @@ +// value of x for implementation of single pole low pass filter +// in 32bit fixed integer calculation with coefficients +// a0 = 1 - x +// b1 = x +// x = EXP(-(2*PI()*fc)) +// where fc is a value between 0.0 and 0.5 of the sampling rate (in this case 48KHz) +// +4279217041, 4278893259, 4278562833, 4278225627, 4277881504, 4277530322, 4277171937, 4276806201, 4276432966, 4276052078, 4275663377, 4275266708, 4274861908, 4274448809, 4274027242, 4273597039, 4273158019, 4272710004, 4272252807, 4271786247, 4271310131, 4270824262, 4270328440, 4269822472, 4269306140, 4268779240, 4268241554, 4267692866, 4267132948, 4266561575, 4265978512, 4265383523, 4264776365, 4264156790, 4263524548, 4262879380, 4262221026, 4261549219, 4260863681, 4260164139, 4259450309, 4258721905, 4257978620, 4257220163, 4256446223, 4255656484, 4254850636, 4254028346, 4253189285, 4252333114, 4251459486, 4250568054, 4249658451, 4248730312, 4247783273, 4246816942, 4245830935, 4244824861, 4243798308, 4242750868, 4241682119, 4240591639, 4239478990, 4238343723, 4237185386, 4236003522, 4234797658, 4233567307, 4232311988, 4231031200, 4229724432, 4228391157, 4227030868, 4225643010, 4224227034, 4222782384, 4221308495, 4219804783, 4218270641, 4216705473, 4215108686, 4213479625, 4211817657, 4210122143, 4208392419, 4206627794, 4204827577, 4202991098, 4201117609, 4199206394, 4197256727, 4195267822, 4193238938, 4191169264, 4189058020, 4186904401, 4184707556, 4182466664, 4180180844, 4177849247, 4175470962, 4173045097, 4170570716, 4168046881, 4165472643, 4162847034, 4160169043, 4157437673, 4154651906, 4151810674, 4148912960, 4145957624, 4142943595, 4139869729, 4136734929, 4133538012, 4130277799, 4126953089, 4123562666, 4120105272, 4116579668, 4112984576, 4109318655, 4105580601, 4101769070, 4097882680, 4093920065, 4089879767, 4085760375, 4081560417, 4077278404, 4072912845, 4068462164, 4063924852, 4059299319, 4054583930, 4049777075, 4044877097, 4039882311, 4034791009, 4029601465, 4024311932, 4018920607, 4013425694, 4007825337, 4002117707, 3996300890, 3990372963, 3984332097, 3978176178, 3971903323, 3965511417, 3958998490, 3952362489, 3945601242, 3938712674, 3931694620, 3924544917, 3917261408, 3909841789, 3902283847, 3894585353, 3886743918, 3878757267, 3870623016, 3862338854, 3853902344, 3845311080, 3836562636, 3827654518, 3818584224, 3809349306, 3799947238, 3790375493, 3780631341, 3770712425, 3760616026, 3750339570, 3739880391, 3729235830, 3718403355, 3707380220, 3696163712, 3684751155, 3673139962, 3661327297, 3649310519, 3637086937, 3624653724, 3612008302, 3599147960, 3586069915, 3572771543, 3559250155, 3545502997, 3531527490, 3517320911, 3502880673, 3488204192, 3473288756, 3458131940, 3442731112, 3427083848, 3411187619, 3395040065, 3378638607, 3361981114, 3345065329, 3327888844, 3310449536, 3292745187, 3274774007, 3256533607, 3238022468, 3219238453, 3200179919, 3180845259, 3161232827, 3141341156, 3121168802, 3100714475, 3079977210, 3058955764, 3037649200, 3016056968, 2994178354, 2972012619, 2949559517, 2926818948, 2903790851, 2880475148, 2856872243, 2832982802, 2808807134, 2784346313, 2759601414, 2734573489, 2709264197, 2683675160, 2657808232, 2631665649, 2605249687, 2578563127, 2551608749, 2524389787, 2496909503, 2469171697, 2441180289, 2412939590, 2384454024, 2355728676, 2326768121, 2297578440, 2268165045, 2238534044, 2208692047 \ No newline at end of file diff --git a/filterCoefficients_4stageLP.inc b/filterCoefficients_4stageLP.inc new file mode 100644 index 0000000..4b6975a --- /dev/null +++ b/filterCoefficients_4stageLP.inc @@ -0,0 +1,25 @@ +// value of x for implementation of four stage low pass filter +// in 32bit fixed integer calculation with coefficients +// a0 = (1 - x)^4 +// b1 = 4x +// b2 = -6x^2 +// b3 = 4x^3 +// b4 = -x^4 +// x = EXP(-(14.445 * fc)) +// where fc is a value between 0.0 and 0.5 of the sampling rate (in this case 48KHz) +// + +// a0 +20,22,25,28,31,35,40,44,50,56,63,70,79,88,99,111,125,140,157,176,197,221,248,278,312,350,392,440,493,553,620,695,779,873,979,1098,1231,1379,1546,1733,1942,2177,2439,2734,3063,3433,3846,4309,4828,5409,6059,6787,7602,8515,9536,10680,11959,13391,14994,16787,18793,21037,23547,26355,29494,33005,36931,41320,46226,51710,57838,64687,72338,80886,90434,101097,113004,126298,141139,157704,176189,196815,219825,245489,274110,306021,341593,381240,425419,474636,529456,590502,658464,734110,818288,911935,1016091,1131904,1260644,1403713,1562660,1739196,1935205,2152771,2394182,2661966,2958902,3288047,3652765,4056749,4504056,4999142,5546883,6152633,6822246,7562139,8379310,9281420,10276823,11374627,12584769,13918045,15386204,17002021,18779343,20733193,22879824,25236844,27823245,30659544,33767812,37171845,40897196,44971294,49423522,54285288,59590216,65374073,71674958,78533412,85992292,94097108,102895761,112438848,122779508,133973447,146079010,159156856,173270334,188484974,204868559,222490692,241423108,261739038,283512758,306819598,331735715,358336882,386699043,416896828,449003701,483091188,519227244,557477492,597902539,640558361,685494633,732754880,782374892,834381953,888793830,945618867,1004853643,1066483754,1130481855,1196807534,1265406920,1336211852,1409139855,1484093865,1560961173,1639615567,1719915608,1801705539,1884816876,1969068201,2054265615,2140205839,2226675027,2313451941,2400309450,2487015015,2573334323,2659031961,2743873426,2827628048,2910070486,2990982176,3070154485,3147389781,3222503817,3295325858,3365701888,3433495954,3498587958,3560879279,3620289028,3676757366,3730243444,3780726504,3828204945,3872695363,3914232296,3952866364,3988663721,4021704445,4052080758,4079895657,4105261554,4128297983,4149130507,4167888924,4184705587,4199713832,4213046939,4224836618,4235211728,4244297498,4252214336,4259077474,4264995979,4270072545,4274402998,4278076182,4281173865,4283770704,4285934433,4287726010,4289199913,4290404475,4291382228,4292170351,4292801069,4293302095,4293697081,4294006041,4294245772,4294430253,4294571010,4294677470,4294757264,4294816520,4294860104,4294891848,4294914734,4294931065, + +// b1 +17038279068,17034147808,17029896544,17025521801,17021020052,17016387642,17011620781,17006715662,17001668287,16996474564,16991130317,16985631212,16979972858,16974150663,16968159948,16961995879,16955653549,16949127860,16942413545,16935505290,16928397533,16921084639,16913560719,16905819871,16897855875,16889662455,16881233068,16872561100,16863639683,16854461730,16845020092,16835307279,16825315756,16815037656,16804464945,16793589302,16782402425,16770895477,16759059586,16746885620,16734364142,16721485583,16708239896,16694617142,16680606767,16666198178,16651380353,16636142089,16620471885,16604357892,16587788116,16570749976,16553230931,16535217865,16516697471,16497656006,16478079455,16457953627,16437263726,16415994700,16394131203,16371657456,16348557353,16324814475,16300411801,16275332217,16249557932,16223071183,16195853363,16167885627,16139148899,16109623408,16079289189,16048125758,16016112229,15983227336,15949449257,15914756166,15879125152,15842533346,15804957512,15766373600,15726757537,15686084632,15644329617,15601467239,15557471683,15512316280,15465974673,15418419822,15369624189,15319559923,15268199180,15215513067,15161473074,15106050020,15049214574,14990937081,14931187310,14869935869,14807151840,14742804881,14676864702,14609299821,14540080298,14469174989,14396552966,14322184034,14246036661,14168081107,14088286683,14006623153,13923061264,13837571386,13750124981,13660692692,13569247792,13475762396,13380210322,13282566132,13182804250,13080901918,12976836558,12870586133,12762130880,12651451934,12538532667,12423356602,12305910644,12186182273,12064162718,11939843495,11813219203,11684286654,11553045462,11419498603,11283649896,11145508389,11005085486,10862394590,10717455304,10570287775,10420918803,10269376941,10115695645,9959912867,9802069802,9642214712,9480397251,9316673738,9151104752,8983757849,8814702555,8644014503,8471776576,8298075897,8123003129,7946658088,7769142476,7590566329,7411043333,7230691978,7049640365,6868015988,6685955524,6503598818,6321092495,6138585531,5956232149,5774191022,5592625379,5411699564,5231583720,5052448349,4874467744,4697817807,4522675130,4349217443,4177622187,4008066093,3840726673,3675776951,3513389135,3353732669,3196971570,3043265692,2892770764,2745634125,2601998384,2461997652,2325757122,2193394338,2065015744,1940718035,1820587487,1704698154,1593112198,1485880197,1383039181,1284613438,1190613500,1101037876,1015870782,935082148,858631609,786462991,718509733,654691797,594918625,539088277,487088702,438798845,394088820,352821698,314853747,280035717,248214198,219232495,192931434,169151121,147731425,128513200,111339394,96056069,82512906,70564240,60069888,50895519,42913483,36002837,30050068,24949046,20601325,16916082,13810074,11207554,9039996,7245869,5770290,4564639,3586191,2797628,2166637,1665443,1270356,961336,721569,537068,396299,289834,210036,150778,107193,75449,52562,36232, + +// b2 +-25346783828,-25334493682,-25321849647,-25308841657,-25295459516,-25281692655,-25267530138,-25252960994,-25237973710,-25222556514,-25206697417,-25190383983,-25173603637,-25156343246,-25138589439,-25120328430,-25101546251,-25082228404,-25062359934,-25041925789,-25020910225,-24999297343,-24977070529,-24954213193,-24930707865,-24906536958,-24881682174,-24856125069,-24829846517,-24802826828,-24775046206,-24746483935,-24717119256,-24686930530,-24655895722,-24623992065,-24591196953,-24557486332,-24522836163,-24487221786,-24450617775,-24412998472,-24374336971,-24334606847,-24293780045,-24251828586,-24208723421,-24164435185,-24118933856,-24072188622,-24024168488,-23974841004,-23924174102,-23872134321,-23818687944,-23763800305,-23707436268,-23649560543,-23590136447,-23529126948,-23466494567,-23402201000,-23336207454,-23268474700,-23198962289,-23127630012,-23054436284,-22979340161,-22902298908,-22823269738,-22742209884,-22659075303,-22573822133,-22486405825,-22396781505,-22304904071,-22210727760,-22114207721,-22015297052,-21913949995,-21810120840,-21703762745,-21594829969,-21483276309,-21369055249,-21252121661,-21132430279,-21009934982,-20884592022,-20756357392,-20625187409,-20491039285,-20353872056,-20213643837,-20070315725,-19923849079,-19774206970,-19621353822,-19465254838,-19305879780,-19143196896,-18977178472,-18807799567,-18635034904,-18458865967,-18279274069,-18096244077,-17909765781,-17719828804,-17526430509,-17329569236,-17129247904,-16925475353,-16718263086,-16507628925,-16293592474,-16076183439,-15855432617,-15631378769,-15404066338,-15173543468,-14939868851,-14703105588,-14463322068,-14220595877,-13975010607,-13726658780,-13475637179,-13222053832,-12966021755,-12707665629,-12447114220,-12184506160,-11919987849,-11653714416,-11385850522,-11116564999,-10846039272,-10574461185,-10302023982,-10028933889,-9755398814,-9481639312,-9207878851,-8934349030,-8661288097,-8388938068,-8117550567,-7847376288,-7578673208,-7311701616,-7046727559,-6784013921,-6523826165,-6266432903,-6012100225,-5761089836,-5513666090,-5270084496,-5030599760,-4795458221,-4564898538,-4339156668,-4118451931,-3902998398,-3692996478,-3488636313,-3290091903,-3097523709,-2911077052,-2730881559,-2557047308,-2389669088,-2228820899,-2074559084,-1926920273,-1785920788,-1651557311,-1523806173,-1402623644,-1287947645,-1179694913,-1077764599,-982037991,-892378205,-808632415,-730633272,-658198267,-591133336,-529232706,-472280621,-420053727,-372321522,-328848822,-289397326,-253726827,-221597130,-192769800,-167009192,-144084190,-123769322,-105846359,-90104887,-76343302,-64370243,-54004256,-45075102,-37423569,-30901996,-25374131,-20715123,-16811341,-13559998,-10868810,-8655440,-6846967,-5379286,-4196442,-3249955,-2498165,-1905536,-1442005,-1082353,-805603,-594450,-434751,-315054,-226168,-160790,-113174,-78843,-54347,-37056,-24985,-16652,-10967,-7135,-4584,-2907,-1819,-1123,-683,-410,-242,-141,-81,-45,-25,-14,-7,-4,-2,-1,0,0,0, + +// b3 +16758590019,16746402641,16733867419,16720974639,16707714479,16694076766,16680050981,16665626598,16650792570,16635537622,16619850287,16603718684,16587130822,16570074189,16552536068,16534503367,16515962848,16496900789,16477303052,16457155451,16436443157,16415151234,16393264095,16370766224,16347641295,16323872925,16299444092,16274337693,16248536026,16222020905,16194774114,16166776617,16138009419,16108452749,16078086545,16046890124,16014843068,15981923651,15948110278,15913380869,15877712726,15841083057,15803468003,15764844318,15725187329,15684472606,15642674855,15599768657,15555728151,15510526917,15464138571,15416535548,15367690891,15317576546,15266164474,15213426002,15159332290,15103854655,15046963395,14988628809,14928821118,14867510122,14804665541,14740257081,14674253710,14606625068,14537339952,14466368251,14393678664,14319240378,14243023144,14164996097,14085129143,14003392174,13919755434,13834189642,13746665611,13657155745,13565631318,13472065467,13376432207,13278705377,13178860729,13076874519,12972723689,12866387449,12757845908,12647079477,12534071818,12418807494,12301272530,12181454967,12059345711,11934936122,11808221517,11679198778,11547867664,11414230514,11278291777,11140061318,10999549147,10856770267,10711743558,10564489138,10415034421,10263408192,10109643776,9953780159,9795857701,9635924710,9474031763,9310234660,9144595446,8977179684,8808059340,8637309060,8465012715,8291256095,8116132252,7939739535,7762179916,7583564113,7404006634,7223626305,7042548998,6860904977,6678830814,6496465692,6313956226,6131451595,5949108004,5767082941,5585538927,5404641655,5224560250,5045467372,4867535220,4690940713,4515860901,4342471931,4170953401,4001480715,3834231500,3669379075,3507095218,3347548763,3190903478,3037320974,2886954252,2739952010,2596455448,2456599770,2320509126,2188299472,2060078530,1935942718,1815976217,1700254282,1588837760,1481776947,1379108238,1280854737,1187028596,1097625498,1012629895,932012045,855729947,783727759,715937555,652279510,592662546,536983980,485131901,436984409,392411655,351276263,313434266,278736382,247028908,218154873,191955473,168270407,146939669,127804345,110707391,95494840,82016712,70127489,59687221,50561878,42623919,35752832,29835299,24765530,20445369,16784282,13699332,11115057,8963214,7182534,5718376,4522380,3552022,2770190,2144771,1648144,1256777,950760,713400,530811,391548,286257,207368,148808,105752,74405,51813,35701,24332,16398,10924,7191,4676,3003,1903,1190,734,447,268,158,92,53,30,16,9,5,3,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + +// b4 +-4155117982,-4151089493,-4146947044,-4142687514,-4138307750,-4133804491,-4129174368,-4124414014,-4119519901,-4114488432,-4109315954,-4103998687,-4098532825,-4092914399,-4087139380,-4081203631,-4075102975,-4068833088,-4062389525,-4055767832,-4048963365,-4041971455,-4034787237,-4027405884,-4019822321,-4012031476,-4004028081,-3995806868,-3987362389,-3978689063,-3969781324,-3960633360,-3951239402,-3941593452,-3931689450,-3921521163,-3911082475,-3900366880,-3889367951,-3878079140,-3866493738,-3854605048,-3842406070,-3829890050,-3817049818,-3803878335,-3790368337,-3776512573,-3762303712,-3747734300,-3732796962,-3717484012,-3701788027,-3685701309,-3669216242,-3652325087,-3635020140,-3617293834,-3599138372,-3580546052,-3561509251,-3542020319,-3522071692,-3501655915,-3480765421,-3459392982,-3437531235,-3415173296,-3392312050,-3368940680,-3345052701,-3320641593,-3295701241,-3270225696,-3244209296,-3217646707,-3190532816,-3162863193,-3134633261,-3105839225,-3076477772,-3046545752,-3016040825,-2984961035,-2953304872,-2921071751,-2888261609,-2854874719,-2820912593,-2786377265,-2751271471,-2715598811,-2679364003,-2642572166,-2605229857,-2567344359,-2528924064,-2489978382,-2450517598,-2410553823,-2370099455,-2329168575,-2287776601,-2245939530,-2203675639,-2161003782,-2117944271,-2074519162,-2030751027,-1986664761,-1942285970,-1897641754,-1852760945,-1807673321,-1762410346,-1717004121,-1671489082,-1625899998,-1580273333,-1534646660,-1489058172,-1443547929,-1398156513,-1352925094,-1307896048,-1263112201,-1218617229,-1174454664,-1130668987,-1087304361,-1044405610,-1002016765,-960181870,-918944459,-878347522,-838433445,-799243037,-760816606,-723192865,-686408655,-650499811,-615499487,-581439455,-548348716,-516254045,-485179684,-455146926,-426174680,-398278253,-371470217,-345759847,-321153456,-297653572,-275259552,-253967665,-233770692,-214657928,-196615866,-179627487,-163673048,-148729755,-134772069,-121772241,-109699751,-98522264,-88205451,-78713465,-70008971,-62053591,-54808137,-48232899,-42287807,-36932880,-32128317,-27834874,-24014034,-20628233,-17641071,-15017481,-12723891,-10728378,-9000716,-7512517,-6237265,-5150336,-4229022,-3452523,-2801890,-2260001,-1811469,-1442573,-1141162,-896549,-699407,-541660,-416361,-317589,-240334,-180392,-134267,-99075,-72459,-52509,-37695,-26798,-18862,-13140,-9058,-6176,-4164,-2775,-1828,-1189,-764,-485,-303,-187,-114,-68,-40,-23,-13,-8,-4,-2,-1,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 diff --git a/filterCoefficients_4stageLPinFloats.inc b/filterCoefficients_4stageLPinFloats.inc new file mode 100644 index 0000000..3502cbb --- /dev/null +++ b/filterCoefficients_4stageLPinFloats.inc @@ -0,0 +1,25 @@ +// value of x for implementation of four stage low pass filter +// in single precision float calculation with coefficients +// a0 = (1 - x)^4 +// b1 = 4x +// b2 = -6x^2 +// b3 = 4x^3 +// b4 = -x^4 +// x = EXP(-(14.445 * fc)) +// where fc is a value between 0.0 and 0.5 of the sampling rate (in this case 48KHz) +// + +// a0 +0.000000004613731727365660000000,0.000000005176230969328230000000,0.000000005807226140952210000000,0.000000006515048838524650000000,0.000000007309033784469370000000,0.000000008199653346037200000000,0.000000009198656401868580000000,0.000000010319197204301000000000,0.000000011576043086155800000000,0.000000012985747553178700000000,0.000000014566860505508300000000,0.000000016340190907999300000000,0.000000018329045066453400000000,0.000000020559576229388400000000,0.000000023061088831002400000000,0.000000025866440936143500000000,0.000000029012433980626000000000,0.000000032540341789532600000000,0.000000036496442894391300000000,0.000000040932543797034500000000,0.000000045906768675514200000000,0.000000051484195885369700000000,0.000000057737832333602400000000,0.000000064749357492340500000000,0.000000072610429362990600000000,0.000000081423638133443600000000,0.000000091304021339414800000000,0.000000102380331165032000000000,0.000000114796890171546000000000,0.000000128715420277157000000000,0.000000144316867145311000000000,0.000000161804139943715000000000,0.000000181404203016005000000000,0.000000203371475095039000000000,0.000000227990777406150000000000,0.000000255581226781474000000000,0.000000286499483895789000000000,0.000000321145721242199000000000,0.000000359967372437236000000000,0.000000403465340266089000000000,0.000000452200547927312000000000,0.000000506800318683209000000000,0.000000567967726558461000000000,0.000000636487788494692000000000,0.000000713240655118326000000000,0.000000799209798577538000000000,0.000000895496399069103000000000,0.000001003331603950610000000000,0.000001124092502013200000000000,0.000001259319671833220000000000,0.000001410734501348690000000000,0.000001580264444387730000000000,0.000001770060863504200000000000,0.000001982531475344610000000000,0.000002220365980485000000000000,0.000002486571810667770000000000,0.000002784508975628030000000000,0.000003117928794874210000000000,0.000003491026435221470000000000,0.000003908486382241310000000000,0.000004375539162796580000000000,0.000004898027085208320000000000,0.000005482472149134200000000000,0.000006136153317170690000000000,0.000006867201420418480000000000,0.000007684681501186200000000000,0.000008598717579921850000000000,0.000009620588238783330000000000,0.000010762890289939900000000000,0.000012039665318136300000000000,0.000013466559942057500000000000,0.000015061030189889800000000000,0.000016842519062503200000000000,0.000018832696705753500000000000,0.000021055703083055900000000000,0.000023538421536655200000000000,0.000026310797604647300000000000,0.000029406131013027100000000000,0.000032861543410688600000000000,0.000036718296288775300000000000,0.000041022279121982200000000000,0.000045824571588262600000000000,0.000051181914276245800000000000,0.000057157397330643100000000000,0.000063821151529730300000000000,0.000071251009054479400000000000,0.000079533421298609000000000000,0.000088764451498592700000000000,0.000099050561288766200000000000,0.000110509913742446000000000000,0.000123273580727125000000000000,0.000137486856384098000000000000,0.000153310638528679000000000000,0.000170923384528625000000000000,0.000190522465115459000000000000,0.000212326462103198000000000000,0.000236577155410040000000000000,0.000263541948221230000000000000,0.000293516598717711000000000000,0.000326827325550388000000000000,0.000363835112450333000000000000,0.000404938009049899000000000000,0.000450575008052283000000000000,0.000501230971259985000000000000,0.000557439031216422000000000000,0.000619787328152427000000000000,0.000688923168284303000000000000,0.000765558004895797000000000000,0.000850475611829806000000000000,0.000944535375695951000000000000,0.001048682332647230000000000000,0.001163953342688260000000000000,0.001291484420910980000000000000,0.001432521539796840000000000000,0.001588427922647640000000000000,0.001760697636941340000000000000,0.001950960126048560000000000000,0.002160999094162740000000000000,0.002392759322762610000000000000,0.002648361707691960000000000000,0.002930119982139650000000000000,0.003240547487756420000000000000,0.003582379857970010000000000000,0.003958591381161600000000000000,0.004372406516262540000000000000,0.004827322723475290000000000000,0.005327124180484900000000000000,0.005875910729101420000000000000,0.006478103938605880000000000000,0.007138481353571250000000000000,0.007862181370412810000000000000,0.008654744553847910000000000000,0.009522120519738140000000000000,0.010470695422754600000000000000,0.011507310414573300000000000000,0.012639278534611300000000000000,0.013874428341592400000000000000,0.015221087490177100000000000000,0.016688126580173800000000000000,0.018284984894894600000000000000,0.020021640737514800000000000000,0.021908690187039200000000000000,0.023957286281626800000000000000,0.026179209284143200000000000000,0.028586831909591500000000000000,0.031193123851377600000000000000,0.034011669977441800000000000000,0.037056593315000500000000000000,0.040342643303444900000000000000,0.043885077727601000000000000000,0.047699678565973200000000000000,0.051802651124936100000000000000,0.056210697556566900000000000000,0.060940868731794800000000000000,0.066010457942272800000000000000,0.071437004395611600000000000000,0.077238240024062700000000000000,0.083431806842929100000000000000,0.090035386976970300000000000000,0.097066356818964800000000000000,0.104541820759649000000000000000,0.112478432281249000000000000000,0.120892013350121000000000000000,0.129797843192465000000000000000,0.139210032988202000000000000000,0.149141615480298000000000000000,0.159604156590397000000000000000,0.170607790355494000000000000000,0.182160849726121000000000000000,0.194269687160368000000000000000,0.206938439412508000000000000000,0.220169049524868000000000000000,0.233960720424579000000000000000,0.248310098956965000000000000000,0.263210818016032000000000000000,0.278653468361157000000000000000,0.294625507645715000000000000000,0.311111065642452000000000000000,0.328090939455693000000000000000,0.345542529770487000000000000000,0.363439594667802000000000000000,0.381752747899152000000000000000,0.400449058025762000000000000000,0.419492260209973000000000000000,0.438843126313668000000000000000,0.458459416647719000000000000000,0.478295985438578000000000000000,0.498305503110738000000000000000,0.518438179828263000000000000000,0.538642504565039000000000000000,0.558865594131836000000000000000,0.579053306795471000000000000000,0.599151086777235000000000000000,0.619104122880539000000000000000,0.638857815771724000000000000000,0.658358458481038000000000000000,0.677553584366236000000000000000,0.696392305241026000000000000000,0.714826044930909000000000000000,0.732808788519859000000000000000,0.750297637857153000000000000000,0.767252840469215000000000000000,0.783638536854628000000000000000,0.799423073031810000000000000000,0.814578486172380000000000000000,0.829081814464901000000000000000,0.842914224718520000000000000000,0.856061784054115000000000000000,0.868514982056019000000000000000,0.880268985313666000000000000000,0.891323421471368000000000000000,0.901682153994239000000000000000,0.911353224775040000000000000000,0.920348419759477000000000000000,0.928683141579872000000000000000,0.936376034502292000000000000000,0.943448570973194000000000000000,0.949924731799648000000000000000,0.955830689950577000000000000000,0.961194276495881000000000000000,0.966044726527294000000000000000,0.970412260818434000000000000000,0.974327695231791000000000000000,0.977822074590333000000000000000,0.980926430451191000000000000000,0.983671429186012000000000000000,0.986087072622550000000000000000,0.988202518372260000000000000000,0.990045800750474000000000000000,0.991643749663706000000000000000,0.993021758976086000000000000000,0.994203739035142000000000000000,0.995212001250006000000000000000,0.996067230993009000000000000000,0.996788466633002000000000000000,0.997393090381519000000000000000,0.997896872599435000000000000000,0.998314006753347000000000000000,0.998657176451572000000000000000,0.998937635556803000000000000000,0.999165286302675000000000000000,0.999348785511623000000000000000,0.999495635960190000000000000000,0.999612290212276000000000000000,0.999704255031274000000000000000,0.999776190362342000000000000000,0.999832007214173000000000000000,0.999874959948381000000000000000,0.999907732553278000000000000000,0.999932519529119000000000000000,0.999951098146747000000000000000,0.999964894621099000000000000000,0.999975042376996000000000000000,0.999982433282298000000000000000,0.999987762049658000000000000000,0.999991564199853000000000000000, + +// b1 +3.967033482189860000000000000000,3.966071598170450000000000000000,3.965081773646280000000000000000,3.964063199371980000000000000000,3.963015054450190000000000000000,3.961936487332910000000000000000,3.960826615929470000000000000000,3.959684553935640000000000000000,3.958509370411140000000000000000,3.957300112551720000000000000000,3.956055808187760000000000000000,3.954775448051170000000000000000,3.953458009724340000000000000000,3.952102424459920000000000000000,3.950707602332880000000000000000,3.949272418128150000000000000000,3.947795729343890000000000000000,3.946276349034510000000000000000,3.944713050777200000000000000000,3.943104597370600000000000000000,3.941449693560520000000000000000,3.939747027816180000000000000000,3.937995228684510000000000000000,3.936192921959340000000000000000,3.934338659835870000000000000000,3.932430980453570000000000000000,3.930468360828530000000000000000,3.928449260971590000000000000000,3.926372081631310000000000000000,3.924235172967370000000000000000,3.922036870363820000000000000000,3.919775429873040000000000000000,3.917449097119120000000000000000,3.915056040487720000000000000000,3.912594389374030000000000000000,3.910062206420350000000000000000,3.907457558663380000000000000000,3.904778388655110000000000000000,3.902022630388580000000000000000,3.899188158146940000000000000000,3.896272774293780000000000000000,3.893274251050760000000000000000,3.890190249194550000000000000000,3.887018454753800000000000000000,3.883756410029400000000000000000,3.880401649119030000000000000000,3.876951605285490000000000000000,3.873403670395470000000000000000,3.869755166747000000000000000000,3.866003335392940000000000000000,3.862145383868520000000000000000,3.858178382752080000000000000000,3.854099412295960000000000000000,3.849905418554240000000000000000,3.845593303123310000000000000000,3.841159866718590000000000000000,3.836601845584080000000000000000,3.831915936201840000000000000000,3.827098693209370000000000000000,3.822146612218740000000000000000,3.817056120214990000000000000000,3.811823543184590000000000000000,3.806445131397120000000000000000,3.800917061719950000000000000000,3.795235371504450000000000000000,3.789396075666290000000000000000,3.783395032346430000000000000000,3.777228105532050000000000000000,3.770890963111110000000000000000,3.764379216964560000000000000000,3.757688426123140000000000000000,3.750813987170680000000000000000,3.743751251374920000000000000000,3.736495449566250000000000000000,3.729041719090060000000000000000,3.721385108283850000000000000000,3.713520536438890000000000000000,3.705442921802260000000000000000,3.697146929878400000000000000000,3.688627236020540000000000000000,3.679878430384790000000000000000,3.670894913435210000000000000000,3.661671079852530000000000000000,3.652201181323800000000000000000,3.642479334294510000000000000000,3.632499659230980000000000000000,3.622256145484940000000000000000,3.611742584042100000000000000000,3.600952837933170000000000000000,3.589880611355590000000000000000,3.578519492695920000000000000000,3.566862997369200000000000000000,3.554904642522170000000000000000,3.542637700956430000000000000000,3.530055534461910000000000000000,3.517151349251090000000000000000,3.503918315864400000000000000000,3.490349529646000000000000000000,3.476437951983300000000000000000,3.462176739363260000000000000000,3.447558693638350000000000000000,3.432576749704150000000000000000,3.417223855277330000000000000000,3.401492680632660000000000000000,3.385376254475610000000000000000,3.368867325818390000000000000000,3.351958693558690000000000000000,3.334643327074970000000000000000,3.316913885263290000000000000000,3.298763443578290000000000000000,3.280184856390620000000000000000,3.261171084089440000000000000000,3.241715315743660000000000000000,3.221810652468520000000000000000,3.201450449535530000000000000000,3.180627872213590000000000000000,3.159336697310650000000000000000,3.137570432290960000000000000000,3.115322981595590000000000000000,3.092588421998200000000000000000,3.069360798693930000000000000000,3.045634813127700000000000000000,3.021405208497460000000000000000,2.996666853466050000000000000000,2.971415147099320000000000000000,2.945645697006850000000000000000,2.919354631414780000000000000000,2.892538114099400000000000000000,2.865193096091830000000000000000,2.837316662279080000000000000000,2.808906770830920000000000000000,2.779961446041940000000000000000,2.750479430563100000000000000000,2.720459982303280000000000000000,2.689903011125050000000000000000,2.658809209925270000000000000000,2.627179468020070000000000000000,2.595015891996140000000000000000,2.562321137254010000000000000000,2.529098324043430000000000000000,2.495352016648940000000000000000,2.461086906269960000000000000000,2.426309232294310000000000000000,2.391025643059480000000000000000,2.355243928139770000000000000000,2.318972923520440000000000000000,2.282222221122640000000000000000,2.245003057665530000000000000000,2.207326994102820000000000000000,2.169207143073740000000000000000,2.130657609512810000000000000000,2.091694122432500000000000000000,2.052332869473070000000000000000,2.012591460511630000000000000000,1.972489193085750000000000000000,1.932046352227370000000000000000,1.891284046824350000000000000000,1.850225517467940000000000000000,1.808894443442060000000000000000,1.767316444140310000000000000000,1.725517989296560000000000000000,1.683526667273600000000000000000,1.641372303814570000000000000000,1.599084583169820000000000000000,1.556695328054890000000000000000,1.514237098915210000000000000000,1.471744034098560000000000000000,1.429250820418960000000000000000,1.386793365058360000000000000000,1.344408612255430000000000000000,1.302134566646490000000000000000,1.260009492639830000000000000000,1.218073004754590000000000000000,1.176364801186850000000000000000,1.134925462243710000000000000000,1.093795943788980000000000000000,1.053017361644420000000000000000,1.012631096731080000000000000000,0.972678462753104000000000000000,0.933200608287723000000000000000,0.894238863354069000000000000000,0.855833513351410000000000000000,0.818024653791738000000000000000,0.780851735938396000000000000000,0.744352948444269000000000000000,0.708565509855335000000000000000,0.673525678856731000000000000000,0.639267760605051000000000000000,0.605824958476150000000000000000,0.573228497932786000000000000000,0.541507527700213000000000000000,0.510689415442825000000000000000,0.480798944873432000000000000000,0.451858629176645000000000000000,0.423888556388324000000000000000,0.396905968441230000000000000000,0.370925338440070000000000000000,0.345958442667148000000000000000,0.322013902759242000000000000000,0.299097373660380000000000000000,0.277211307557855000000000000000,0.256355357369746000000000000000,0.236525847975935000000000000000,0.217715778308292000000000000000,0.199915750085903000000000000000,0.183112684517274000000000000000,0.167291083552773000000000000000,0.152432312506896000000000000000,0.138515286279969000000000000000,0.125516270439138000000000000000,0.113409175890776000000000000000,0.102165817437249000000000000000,0.091755953510471400000000000000,0.082147702989241400000000000000,0.073307600638999400000000000000,0.065200896215655700000000000000,0.057791871564358200000000000000,0.051044042901494300000000000000,0.044920350022800500000000000000,0.039383564427277500000000000000,0.034396402709336800000000000000,0.029921811013169600000000000000,0.025923222790015200000000000000,0.022364796271818500000000000000,0.019211533040953700000000000000,0.016429517313042500000000000000,0.013986110772290900000000000000,0.011850036464975500000000000000,0.009991573776262640000000000000,0.008382563807780720000000000000,0.006996576659065250000000000000,0.005808902474049970000000000000,0.004796619689822470000000000000,0.003938582350970370000000000000,0.003215408358781770000000000000,0.002609461992584920000000000000,0.002104788117744180000000000000,0.001687060261202450000000000000,0.001343500269242290000000000000,0.001062787937499430000000000000,0.000834975104727819000000000000,0.000651373578932398000000000000,0.000504459461542728000000000000,0.000387766170055980000000000000,0.000295777773793009000000000000,0.000223828424143332000000000000,0.000168003369955191000000000000,0.000125045915176920000000000000,0.000092270639375065300000000000,0.000067482178553169500000000000,0.000048902750050285600000000000,0.000035105841055312200000000000,0.000024957856588586900000000000,0.000017566833424837700000000000,0.000012238006505035000000000000,0.000008435826833623310000000000, + +// b2 +-5.901507993305770000000000000000,-5.898646470680350000000000000000,-5.895702551888220000000000000000,-5.892673893230720000000000000000,-5.889558120674580000000000000000,-5.886352773622450000000000000000,-5.883055305545730000000000000000,-5.879663162503670000000000000000,-5.876173663362290000000000000000,-5.872584067800710000000000000000,-5.868891584061040000000000000000,-5.865093316690630000000000000000,-5.861186337995070000000000000000,-5.857167590033230000000000000000,-5.853033959674050000000000000000,-5.848782237220410000000000000000,-5.844409170234680000000000000000,-5.839911383605940000000000000000,-5.835285394864500000000000000000,-5.830527699676940000000000000000,-5.825634632575610000000000000000,-5.820602491194920000000000000000,-5.815427407928240000000000000000,-5.810105519581040000000000000000,-5.804632758854660000000000000000,-5.799005031011630000000000000000,-5.793218075802780000000000000000,-5.787267598510590000000000000000,-5.781149146280180000000000000000,-5.774858134782850000000000000000,-5.768389954684960000000000000000,-5.761739782738650000000000000000,-5.754902785694780000000000000000,-5.747873925059770000000000000000,-5.740648070910420000000000000000,-5.733219921778790000000000000000,-5.725584214783350000000000000000,-5.717735349190510000000000000000,-5.709667728024240000000000000000,-5.701375609737500000000000000000,-5.692853074388610000000000000000,-5.684094147710580000000000000000,-5.675092565598130000000000000000,-5.665842175348720000000000000000,-5.656336444666660000000000000000,-5.646568859432130000000000000000,-5.636532656147150000000000000000,-5.626220997687420000000000000000,-5.615626893961910000000000000000,-5.604743170976010000000000000000,-5.593562612301350000000000000000,-5.582077662425780000000000000000,-5.570280854947530000000000000000,-5.558164399429990000000000000000,-5.545720444885060000000000000000,-5.532940920633590000000000000000,-5.519817645577190000000000000000,-5.506342403294110000000000000000,-5.492506652836820000000000000000,-5.478301771985700000000000000000,-5.463719034326520000000000000000,-5.448749521641130000000000000000,-5.433384201876310000000000000000,-5.417613941277680000000000000000,-5.401429321919460000000000000000,-5.384820981853170000000000000000,-5.367779239043870000000000000000,-5.350294560457970000000000000000,-5.332356995877380000000000000000,-5.313956583418030000000000000000,-5.295083365432430000000000000000,-5.275727087383200000000000000000,-5.255877537064230000000000000000,-5.235524341735970000000000000000,-5.214657053517820000000000000000,-5.193265171558810000000000000000,-5.171338040457530000000000000000,-5.148865217525420000000000000000,-5.125835782915990000000000000000,-5.102239082367200000000000000000,-5.078064473404210000000000000000,-5.053301049556690000000000000000,-5.027938161385650000000000000000,-5.001965050823600000000000000000,-4.975370887785960000000000000000,-4.948145165367430000000000000000,-4.920277343813770000000000000000,-4.891756685018680000000000000000,-4.862573002882100000000000000000,-4.832716051420050000000000000000,-4.802175659851740000000000000000,-4.770941865750600000000000000000,-4.739005131534640000000000000000,-4.706355705089200000000000000000,-4.672984528644430000000000000000,-4.638882605077030000000000000000,-4.604041336593770000000000000000,-4.568452439662530000000000000000,-4.532107812746190000000000000000,-4.495000415470490000000000000000,-4.457122854780520000000000000000,-4.418468678478560000000000000000,-4.379032078903670000000000000000,-4.338807171149100000000000000000,-4.297789644137740000000000000000,-4.255975147112520000000000000000,-4.213360156246380000000000000000,-4.169942294552100000000000000000,-4.125719145844650000000000000000,-4.080690096258190000000000000000,-4.034854759535390000000000000000,-3.988213814887900000000000000000,-3.940769320622640000000000000000,-3.892523955134850000000000000000,-3.843481867811710000000000000000,-3.793647623063240000000000000000,-3.743028137615170000000000000000,-3.691630581594940000000000000000,-3.639463979871610000000000000000,-3.586538680454010000000000000000,-3.532865892209650000000000000000,-3.478459280600780000000000000000,-3.423333537725850000000000000000,-3.367504586498300000000000000000,-3.310990491154230000000000000000,-3.253810714610610000000000000000,-3.195986798986100000000000000000,-3.137541278069140000000000000000,-3.078499304209600000000000000000,-3.018887190767440000000000000000,-2.958733967707420000000000000000,-2.898069615554840000000000000000,-2.836926411731510000000000000000,-2.775338443242590000000000000000,-2.713341828472350000000000000000,-2.650974905543790000000000000000,-2.588276983944840000000000000000,-2.525290304892190000000000000000,-2.462058603907010000000000000000,-2.398626874754720000000000000000,-2.335043132622730000000000000000,-2.271355785080030000000000000000,-2.207616184018730000000000000000,-2.143876359662990000000000000000,-2.080190235389710000000000000000,-2.016613282507850000000000000000,-1.953201849969740000000000000000,-1.890014523347840000000000000000,-1.827109672085620000000000000000,-1.764547361085810000000000000000,-1.702388193365570000000000000000,-1.640694113182000000000000000000,-1.579526327669830000000000000000,-1.518946645096620000000000000000,-1.459017606315030000000000000000,-1.399801165183160000000000000000,-1.341358254664600000000000000000,-1.283750424558560000000000000000,-1.227037165318340000000000000000,-1.171277780148280000000000000000,-1.116529624269770000000000000000,-1.062848264783000000000000000000,-1.010288639898580000000000000000,-0.958901814049270000000000000000,-0.908737629145466000000000000000,-0.859842746899179000000000000000,-0.812261438214263000000000000000,-0.766034215375601000000000000000,-0.721198439013713000000000000000,-0.677787943764967000000000000000,-0.635832911120868000000000000000,-0.595358970578429000000000000000,-0.556388191841953000000000000000,-0.518937804551764000000000000000,-0.483020926818412000000000000000,-0.448646087493456000000000000000,-0.415817086471718000000000000000,-0.384533151775046000000000000000,-0.354788771963903000000000000000,-0.326573765740716000000000000000,-0.299873679274791000000000000000,-0.274669125965782000000000000000,-0.250936625329160000000000000000,-0.228648537569252000000000000000,-0.207772991946629000000000000000,-0.188274405658706000000000000000,-0.170113815029783000000000000000,-0.153248726155874000000000000000,-0.137633955117236000000000000000,-0.123221591565854000000000000000,-0.109961400958499000000000000000,-0.097801379642000400000000000000,-0.086687859521777000000000000000,-0.076566082785523700000000000000,-0.067380565588866500000000000000,-0.059075380419101400000000000000,-0.051594602511330100000000000000,-0.044882716519754500000000000000,-0.038884857588839400000000000000,-0.033547214598951400000000000000,-0.028817290889225800000000000000,-0.024644275969563800000000000000,-0.020979178785275700000000000000,-0.017775060046644600000000000000,-0.014987365174653500000000000000,-0.012573845711671100000000000000,-0.010494864988597900000000000000,-0.008713353711074950000000000000,-0.007194931699958140000000000000,-0.005907875304356520000000000000,-0.004823115441084370000000000000,-0.003914195344733000000000000000,-0.003157183126730920000000000000,-0.002530591914903230000000000000,-0.002015251616792630000000000000,-0.001594183825246760000000000000,-0.001252462657091730000000000000,-0.000977060368398598000000000000,-0.000756689192314092000000000000,-0.000581649430124070000000000000,-0.000443667194753577000000000000,-0.000335743040365440000000000000,-0.000252005054932787000000000000,-0.000187569042104979000000000000,-0.000138406125668871000000000000,-0.000101223389677336000000000000,-0.000073354235450546400000000000,-0.000052658761582968300000000000,-0.000037436829947437200000000000,-0.000026350265996818200000000000,-0.000018357031854816200000000000,-0.000012653755482383900000000000,-0.000008627835168297240000000000,-0.000005817161600765750000000000,-0.000003877069092646370000000000,-0.000002553484459029480000000000,-0.000001661299882723900000000000,-0.000001067314621848180000000000,-0.000000676872365045288000000000,-0.000000423569325035356000000000,-0.000000261443784568212000000000,-0.000000159107827249201000000000,-0.000000095429755627492200000000,-0.000000056385975989956300000000,-0.000000032806684301230600000000,-0.000000018787186295432800000000,-0.000000010584424618612800000000,-0.000000005863680338412540000000,-0.000000003192701584006260000000,-0.000000001707691658355700000000,-0.000000000896804610930264000000,-0.000000000462157528575316000000,-0.000000000233585477061177000000,-0.000000000115722613715999000000,-0.000000000056163301206479300000,-0.000000000026686190387579600000, + +// b3 +3.901913300809180000000000000000,3.899075705835610000000000000000,3.896157121888640000000000000000,3.893155287675980000000000000000,3.890067916048790000000000000000,3.886892638521350000000000000000,3.883627006198430000000000000000,3.880268567818360000000000000000,3.876814751430460000000000000000,3.873262932079530000000000000000,3.869610439791490000000000000000,3.865854508229520000000000000000,3.861992345738910000000000000000,3.858021038839730000000000000000,3.853937626866130000000000000000,3.849739061515410000000000000000,3.845422260465120000000000000000,3.840984028930260000000000000000,3.836421075355270000000000000000,3.831730096282130000000000000000,3.826907639560120000000000000000,3.821950227464110000000000000000,3.816854230863750000000000000000,3.811616037001960000000000000000,3.806231844885270000000000000000,3.800697839959370000000000000000,3.795010059053790000000000000000,3.789164520068960000000000000000,3.783157101283530000000000000000,3.776983568568600000000000000000,3.770639680818450000000000000000,3.764121005616830000000000000000,3.757423120304720000000000000000,3.750541421711190000000000000000,3.743471238935830000000000000000,3.736207756207250000000000000000,3.728746219636490000000000000000,3.721081570594750000000000000000,3.713208781124990000000000000000,3.705122710439380000000000000000,3.696818073632500000000000000000,3.688289564304990000000000000000,3.679531626994390000000000000000,3.670538849550480000000000000000,3.661305487376170000000000000000,3.651825852334100000000000000000,3.642094054915630000000000000000,3.632104177149760000000000000000,3.621850197905420000000000000000,3.611325965502350000000000000000,3.600525337079870000000000000000,3.589441894669060000000000000000,3.578069361562790000000000000000,3.566401206430130000000000000000,3.554430900640670000000000000000,3.542151768210450000000000000000,3.529557094384830000000000000000,3.516640200894450000000000000000,3.503394172252590000000000000000,3.489812093084510000000000000000,3.475887029851860000000000000000,3.461611951251240000000000000000,3.446979807040350000000000000000,3.431983543869040000000000000000,3.416615936538340000000000000000,3.400869916133320000000000000000,3.384738217955150000000000000000,3.368213831106180000000000000000,3.351289467972720000000000000000,3.333957953745140000000000000000,3.316212246273770000000000000000,3.298045158642020000000000000000,3.279449684409590000000000000000,3.260418813164960000000000000000,3.240945617219200000000000000000,3.221023278801360000000000000000,3.200645002351120000000000000000,3.179804362598900000000000000000,3.158494671311460000000000000000,3.136709673984680000000000000000,3.114443320630580000000000000000,3.091689519812410000000000000000,3.068442626138790000000000000000,3.044697111259720000000000000000,3.020447606535140000000000000000,2.995689271170430000000000000000,2.970417474353290000000000000000,2.944627655009100000000000000000,2.918316009064250000000000000000,2.891478942196630000000000000000,2.864113201021560000000000000000,2.836216000590900000000000000000,2.807785223838150000000000000000,2.778818859160070000000000000000,2.749315816299360000000000000000,2.719275368910680000000000000000,2.688697461047960000000000000000,2.657582637331040000000000000000,2.625931933785150000000000000000,2.593747646978350000000000000000,2.561032107768800000000000000000,2.527788809173590000000000000000,2.494022147175720000000000000000,2.459736805890030000000000000000,2.424939167999180000000000000000,2.389635935433750000000000000000,2.353834867470640000000000000000,2.317545041135970000000000000000,2.280775853591450000000000000000,2.243538552351410000000000000000,2.205844913327270000000000000000,2.167707928379740000000000000000,2.129142043745860000000000000000,2.090162523940390000000000000000,2.050786125581240000000000000000,2.011030227878630000000000000000,1.970914359038990000000000000000,1.930458493292230000000000000000,1.889684296197230000000000000000,1.848614666370130000000000000000,1.807273346098530000000000000000,1.765686113507480000000000000000,1.723879630218150000000000000000,1.681881562209060000000000000000,1.639721216219580000000000000000,1.597428921727920000000000000000,1.555036477260100000000000000000,1.512576288562520000000000000000,1.470082492124140000000000000000,1.427589821317560000000000000000,1.385134645830140000000000000000,1.342753633198000000000000000000,1.300484623581450000000000000000,1.258366195364890000000000000000,1.216437725769890000000000000000,1.174739415690100000000000000000,1.133311358294800000000000000000,1.092194745516500000000000000000,1.051430800324840000000000000000,1.011060534824620000000000000000,0.971125764992068000000000000000,0.931667330356831000000000000000,0.892726588107833000000000000000,0.854343891917203000000000000000,0.816559236879542000000000000000,0.779411933224564000000000000000,0.742940110723131000000000000000,0.707181397324695000000000000000,0.672171416730157000000000000000,0.637944789993209000000000000000,0.604534393089851000000000000000,0.571971705542068000000000000000,0.540285633412479000000000000000,0.509503174482374000000000000000,0.479649410163040000000000000000,0.450746789172625000000000000000,0.422814911353885000000000000000,0.395871298929759000000000000000,0.369930118373542000000000000000,0.345003080252037000000000000000,0.321098658710001000000000000000,0.298222232837942000000000000000,0.276376632064672000000000000000,0.255560851269960000000000000000,0.235771270286404000000000000000,0.217000964431316000000000000000,0.199240154303359000000000000000,0.182475838465762000000000000000,0.166692201685778000000000000000,0.151870658146754000000000000000,0.137990002030325000000000000000,0.125026325742849000000000000000,0.112953572774483000000000000000,0.101743361213313000000000000000,0.091365458107128700000000000000,0.081787878449522600000000000000,0.072977101887186500000000000000,0.064898371201904000000000000000,0.057515899552651800000000000000,0.050793139473341500000000000000,0.044693116350748600000000000000,0.039178507180742700000000000000,0.034212057676425500000000000000,0.029756767913454400000000000000,0.025776073193760100000000000000,0.022234125039711900000000000000,0.019096003791807100000000000000,0.016327828330873700000000000000,0.013897014190634600000000000000,0.011772354641030300000000000000,0.009924154395914780000000000000,0.008324354899812490000000000000,0.006946571898567780000000000000,0.005766174201482040000000000000,0.004760308446015570000000000000,0.003907895179379590000000000000,0.003189624233032670000000000000,0.002587925784974220000000000000,0.002086910791736590000000000000,0.001672313963361250000000000000,0.001331413147946220000000000000,0.001052948695549360000000000000,0.000827019675337683000000000000,0.000644985172088643000000000000,0.000499368391783699000000000000,0.000383738440495019000000000000,0.000292616222613767000000000000,0.000221366109311616000000000000,0.000166101337364087000000000000,0.000123589079070386000000000000,0.000091164257899909300000000000,0.000066649494500620300000000000,0.000048281724700061200000000000,0.000034647052168741100000000000,0.000024622210118488700000000000,0.000017323702356431800000000000,0.000012063693502966700000000000,0.000008312185226981310000000000,0.000005665123896203200000000000,0.000003817904634230090000000000,0.000002543425916610960000000000,0.000001674339967133610000000000,0.000001088797197205440000000000,0.000000699157235596333000000000,0.000000443165642726319000000000,0.000000277175238864774000000000,0.000000170990077104675000000000,0.000000104001374159771000000000,0.000000062342141394869600000000,0.000000036813797678387300000000,0.000000021406063434187400000000,0.000000012250738587940600000000,0.000000006897407341466220000000,0.000000003818561668919760000000,0.000000002077726728011600000000,0.000000001110536774082280000000,0.000000000582780708861179000000,0.000000000300104014120066000000,0.000000000151563034113502000000,0.000000000075027394890391800000,0.000000000036383175233380000000,0.000000000017273105811911600000,0.000000000008023407189833140000,0.000000000003644095659082310000,0.000000000001617248008024670000,0.000000000000700851050432323000,0.000000000000296369834160607000,0.000000000000122204879036951000,0.000000000000049098769415006800,0.000000000000019206458900486200,0.000000000000007309368622044380,0.000000000000002704071456780160,0.000000000000000971632139611585,0.000000000000000338813313105965,0.000000000000000114554474251522,0.000000000000000037520013493121, + +// b4 +-0.967438794306997000000000000000,-0.966500838501938000000000000000,-0.965536349453924000000000000000,-0.964544600332301000000000000000,-0.963524857133442000000000000000,-0.962476360431465000000000000000,-0.961398325780827000000000000000,-0.960289969569520000000000000000,-0.959150470055350000000000000000,-0.957978989816296000000000000000,-0.956774678485071000000000000000,-0.955536655930253000000000000000,-0.954264035797225000000000000000,-0.952955893825992000000000000000,-0.951611292586048000000000000000,-0.950229268289584000000000000000,-0.948808848586757000000000000000,-0.947349026899173000000000000000,-0.945848767764415000000000000000,-0.944307034908335000000000000000,-0.942722746451790000000000000000,-0.941094815569569000000000000000,-0.939422109357859000000000000000,-0.937703504129613000000000000000,-0.935937818476906000000000000000,-0.934123870824948000000000000000,-0.932260435383559000000000000000,-0.930346284910294000000000000000,-0.928380151431556000000000000000,-0.926360735468545000000000000000,-0.924286740814177000000000000000,-0.922156814555366000000000000000,-0.919969613133265000000000000000,-0.917723740510612000000000000000,-0.915417785390211000000000000000,-0.913050296430034000000000000000,-0.910619850016006000000000000000,-0.908124931205075000000000000000,-0.905564043456707000000000000000,-0.902935662314158000000000000000,-0.900238225738219000000000000000,-0.897470174445492000000000000000,-0.894629878558533000000000000000,-0.891715765443343000000000000000,-0.888726165979564000000000000000,-0.885659441230796000000000000000,-0.882513899550369000000000000000,-0.879287853189413000000000000000,-0.875979594783008000000000000000,-0.872587389238952000000000000000,-0.869109519381542000000000000000,-0.865544195259802000000000000000,-0.861889688972084000000000000000,-0.858144208085859000000000000000,-0.854305979244894000000000000000,-0.850373200867268000000000000000,-0.846344078900702000000000000000,-0.842216851730967000000000000000,-0.837989703651575000000000000000,-0.833660841803934000000000000000,-0.829228491279497000000000000000,-0.824690870821789000000000000000,-0.820046219033309000000000000000,-0.815292800464620000000000000000,-0.810428853324758000000000000000,-0.805452694627948000000000000000,-0.800362609975290000000000000000,-0.795156996768504000000000000000,-0.789834198096736000000000000000,-0.784392626956994000000000000000,-0.778830773524423000000000000000,-0.773147119459689000000000000000,-0.767340241239344000000000000000,-0.761408753691942000000000000000,-0.755351338494531000000000000000,-0.749166753947938000000000000000,-0.742853809130087000000000000000,-0.736411473006753000000000000000,-0.729838679817278000000000000000,-0.723134545934313000000000000000,-0.716298299890278000000000000000,-0.709329208262521000000000000000,-0.702226726519947000000000000000,-0.694990399157244000000000000000,-0.687619874195223000000000000000,-0.680115016043031000000000000000,-0.672475809445753000000000000000,-0.664702318484025000000000000000,-0.656794894676608000000000000000,-0.648754012045916000000000000000,-0.640580307446458000000000000000,-0.632274619065884000000000000000,-0.623838045464213000000000000000,-0.615271778411825000000000000000,-0.606577344581951000000000000000,-0.597756439546841000000000000000,-0.588811017474003000000000000000,-0.579743269262737000000000000000,-0.570555589620974000000000000000,-0.561250798196664000000000000000,-0.551831781739079000000000000000,-0.542301818408226000000000000000,-0.532664498557427000000000000000,-0.522923546344856000000000000000,-0.513083217368266000000000000000,-0.503147901467763000000000000000,-0.493122327951237000000000000000,-0.483011631663735000000000000000,-0.472821068621919000000000000000,-0.462556435047212000000000000000,-0.452223692515149000000000000000,-0.441829150923964000000000000000,-0.431379523287794000000000000000,-0.420881742813852000000000000000,-0.410343135227705000000000000000,-0.399771174665926000000000000000,-0.389173878860525000000000000000,-0.378559343082417000000000000000,-0.367936057243970000000000000000,-0.357312769622021000000000000000,-0.346698372564952000000000000000,-0.336102193522157000000000000000,-0.325533680847738000000000000000,-0.315002420557974000000000000000,-0.304518278680937000000000000000,-0.294091226847634000000000000000,-0.283731433869262000000000000000,-0.273449035321881000000000000000,-0.263254387944972000000000000000,-0.253157774182770000000000000000,-0.243169630324048000000000000000,-0.233300208238949000000000000000,-0.223559762932773000000000000000,-0.213958429848338000000000000000,-0.204506218837158000000000000000,-0.195212998606191000000000000000,-0.186088270711628000000000000000,-0.177141420110625000000000000000,-0.168381460252015000000000000000,-0.159816969008212000000000000000,-0.151456289755794000000000000000,-0.143307141733793000000000000000,-0.135376922665040000000000000000,-0.127672384597829000000000000000,-0.120199761539186000000000000000,-0.112964698088530000000000000000,-0.105972151853478000000000000000,-0.099226524957382700000000000000,-0.092731382050800800000000000000,-0.086489649708746700000000000000,-0.080503487803068700000000000000,-0.074774365917502400000000000000,-0.069302872772281600000000000000,-0.064088858629174400000000000000,-0.059131454876034600000000000000,-0.054428980612448100000000000000,-0.049978943537690800000000000000,-0.045778198682063700000000000000,-0.041822783474235300000000000000,-0.038108101063030300000000000000,-0.034628844496444000000000000000,-0.031379067609784400000000000000,-0.028352309330781400000000000000,-0.025541463582971700000000000000,-0.022939002184025600000000000000,-0.020536931927642400000000000000,-0.018326906778052900000000000000,-0.016300233864614200000000000000,-0.014447977456550500000000000000,-0.012761013797587300000000000000,-0.011230096968456600000000000000,-0.009845897329116840000000000000,-0.008599106111698820000000000000,-0.007480456805361260000000000000,-0.006480811548458840000000000000,-0.005591203106199600000000000000,-0.004802884705606330000000000000,-0.004107381800390300000000000000,-0.003496529797545960000000000000,-0.002962511790835340000000000000,-0.002497895097827790000000000000,-0.002095642465522400000000000000,-0.001749144164766310000000000000,-0.001452226492571050000000000000,-0.001199156005068160000000000000,-0.000984645884059421000000000000,-0.000803853057332975000000000000,-0.000652365890788833000000000000,-0.000526197377811481000000000000,-0.000421765573000616000000000000,-0.000335875269465439000000000000,-0.000265697496107741000000000000,-0.000208744027457426000000000000,-0.000162843473142213000000000000,-0.000126115017196543000000000000,-0.000096941682546154300000000000,-0.000073944528008393100000000000,-0.000055957173394240000000000000,-0.000042000893047342300000000000,-0.000031261544648558200000000000,-0.000023067673727618300000000000,-0.000016870564946222700000000000,-0.000012225720625126800000000000,-0.000008776465546161670000000000,-0.000006239475413289330000000000,-0.000004391710999469700000000000,-0.000003059505309136040000000000,-0.000002108959247063990000000000,-0.000001437973393529520000000000,-0.000000969527516995158000000000,-0.000000646178959945180000000000,-0.000000425581255464707000000000,-0.000000276883480436512000000000,-0.000000177885984438156000000000,-0.000000112812196638481000000000,-0.000000070595057463288900000000,-0.000000043573964094702000000000,-0.000000026517971208200100000000,-0.000000015904959271248700000000,-0.000000009397668321212650000000,-0.000000005467793880569670000000,-0.000000003131205254273040000000,-0.000000001764070769768800000000,-0.000000000977281821004985000000,-0.000000000532118211740761000000,-0.000000000284615961604719000000,-0.000000000149467884959283000000,-0.000000000077026254762552700000,-0.000000000038931006569814800000,-0.000000000019287125502863200000,-0.000000000009360572736631610000,-0.000000000004447709105776710000,-0.000000000002067764991425190000,-0.000000000000939982474706208000,-0.000000000000417546243032049000,-0.000000000000181118968958474000,-0.000000000000076664369453846100,-0.000000000000031643347278081500,-0.000000000000012726561071166700,-0.000000000000004983638141969650,-0.000000000000001898690346926380,-0.000000000000000703202796998929,-0.000000000000000252967729420080,-0.000000000000000088316063564998,-0.000000000000000029896625967795,-0.000000000000000009804399136092,-0.000000000000000003111945680753,-0.000000000000000000955076308641,-0.000000000000000000283148427903,-0.000000000000000000081005855556,-0.000000000000000000022340514172,-0.000000000000000000005933043923,-0.000000000000000000001515615975,-0.000000000000000000000371992315,-0.000000000000000000000087619900,-0.000000000000000000000019782021 \ No newline at end of file diff --git a/filterCutoffFrequenciesMoogLadder.inc b/filterCutoffFrequenciesMoogLadder.inc new file mode 100644 index 0000000..a78632d --- /dev/null +++ b/filterCutoffFrequenciesMoogLadder.inc @@ -0,0 +1,3 @@ +// Cutoff frequencies for Moog Ladder type lowpass filter in 256 steps + +27.50,28.31,29.14,29.99,30.87,31.77,32.70,33.66,34.65,35.66,36.71,37.78,38.89,40.03,41.20,42.41,43.65,44.93,46.25,47.60,49.00,50.44,51.91,53.43,55.00,56.61,58.27,59.98,61.74,63.54,65.41,67.32,69.30,71.33,73.42,75.57,77.78,80.06,82.41,84.82,87.31,89.87,92.50,95.21,98.00,100.87,103.83,106.87,110.00,113.22,116.54,119.96,123.47,127.09,130.81,134.65,138.59,142.65,146.83,151.13,155.56,160.12,164.81,169.64,174.61,179.73,185.00,190.42,196.00,201.74,207.65,213.74,220.00,226.45,233.08,239.91,246.94,254.18,261.63,269.29,277.18,285.30,293.66,302.27,311.13,320.24,329.63,339.29,349.23,359.46,369.99,380.84,392.00,403.48,415.30,427.47,440.00,452.89,466.16,479.82,493.88,508.36,523.25,538.58,554.37,570.61,587.33,604.54,622.25,640.49,659.26,678.57,698.46,718.92,739.99,761.67,783.99,806.96,830.61,854.95,880.00,905.79,932.33,959.65,987.77,1016.71,1046.50,1077.17,1108.73,1141.22,1174.66,1209.08,1244.51,1280.97,1318.51,1357.15,1396.91,1437.85,1479.98,1523.34,1567.98,1613.93,1661.22,1709.90,1760.00,1811.57,1864.66,1919.29,1975.53,2033.42,2093.01,2154.33,2217.46,2282.44,2349.32,2418.16,2489.02,2561.95,2637.02,2714.29,2793.83,2875.69,2959.96,3046.69,3135.96,3227.86,3322.44,3419.79,3520.00,3623.14,3729.31,3838.59,3951.07,4066.84,4186.01,4308.67,4434.92,4564.88,4698.64,4836.32,4978.03,5123.90,5274.04,5428.58,5587.65,5751.38,5919.91,6093.38,6271.93,6455.71,6644.88,6839.59,7040.00,7246.29,7458.62,7677.18,7902.14,8133.69,8372.02,8617.34,8869.85,9129.75,9397.27,9672.64,9956.07,10247.80,10548.09,10857.17,11175.31,11502.77,11839.83,12186.76,12543.86,12911.42,13289.75,13679.17,14080.01,14492.58,14917.25,15354.35,15804.27,16267.37,16744.04,17234.68,17739.69,18259.51,18794.55,19345.28,19912.13,20495.60,21096.17,21714.34,22350.62,23005.54,23679.65,24373.52,25087.72,25822.84,26579.51,27358.35,28160.01,28985.16,29834.49,30708.71,31608.55,32534.75,33488.09,34469.36,35479.39,36519.02,37589.11,38690.55,39824.27,40991.21,42192.34,43428.68 \ No newline at end of file diff --git a/keywords.txt b/keywords.txt new file mode 100644 index 0000000..259a48b --- /dev/null +++ b/keywords.txt @@ -0,0 +1,91 @@ +####################################### +# Syntax Coloring Map For MMM Library +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +Music KEYWORD1 +MotorA KEYWORD1 +MotorB KEYWORD1 +MotionA KEYWORD1 +MotionB KEYWORD1 +Midi KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) +####################################### + +init KEYWORD2 +checkMidi KEYWORD2 +enableEnvelope KEYWORD2 +disableEnvelope KEYWORD2 +setEnvStage KEYWORD2 +setDetune KEYWORD2 +setDetune1 KEYWORD2 +setDetune2 KEYWORD2 +setDetune3 KEYWORD2 +setFrequency KEYWORD2 +setFrequency1 KEYWORD2 +setFrequency2 KEYWORD2 +setFrequency3 KEYWORD2 +setSemitone1 KEYWORD2 +setSemitone2 KEYWORD2 +setSemitone3 KEYWORD2 +setWaveform KEYWORD2 +setWaveform1 KEYWORD2 +setWaveform2 KEYWORD2 +setWaveform3 KEYWORD2 +setGain KEYWORD2 +setGain1 KEYWORD2 +setGain2 KEYWORD2 +setGain3 KEYWORD2 +getGain KEYWORD2 +getGain1 KEYWORD2 +getGain2 KEYWORD2 +getGain3 KEYWORD2 +noteOn KEYWORD2 +noteOff KEYWORD2 +getNoteFrequency KEYWORD2 +setAttack KEYWORD2 +setDecay KEYWORD2 +setSustain KEYWORD2 +setRelease KEYWORD2 +update_position KEYWORD2 +update_mass_spring_damper KEYWORD2 +torque KEYWORD2 +direction KEYWORD2 +stop KEYWORD2 +start KEYWORD2 +restart KEYWORD2 +setFM2 KEYWORD2 + + +####################################### +# Constants (LITERAL1) +####################################### + +NUM_OSCILLATORS LITERAL1 +BIT_DEPTH LITERAL1 +MIDI LITERAL1 +MIDI_CHANNEL LITERAL1 +FM LITERAL1 +CFO LITERAL1 + +SINE LITERAL1 +SQUARE LITERAL1 +PULSE LITERAL1 +TRIANGLE LITERAL1 +SAW LITERAL1 +FUZZ LITERAL1 +DIGI1 LITERAL1 +DIGI2 LITERAL1 +DIGI3 LITERAL1 +DIGI4 LITERAL1 +NOISE LITERAL1 +DIGI6 LITERAL1 +TAN1 LITERAL1 +TAN2 LITERAL1 +TAN3 LITERAL1 +TAN4 LITERAL1 \ No newline at end of file diff --git a/uCFO.h b/uCFO.h new file mode 100644 index 0000000..6996b39 --- /dev/null +++ b/uCFO.h @@ -0,0 +1,67 @@ +/* + M3T3.h - Motors, Music and Motion library for Teensy 3.1 + Copyright (c) 2013 Science Friction. + All right reserved. + + This library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your optionosc1modShape_ptr) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser Public License for more details. + + You should have received a copy of the GNU Lesser Public License + along with Foobar. If not, see . + + +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + author: Jakob Bak + + contact: j.bak@ciid.dk + */ + +#ifndef UCFO_h // include guard +#define UCFO_h + +#include +#include +#include "Sequencer.h" +#include "uSynth.h" + + +/////////////////////////////////////////////////////////////////////// +// THE BELOW FUNCTIONS ARE NEEDED FOR THE MUSIC PART TO RESPOND TO MIDI +/////////////////////////////////////////////////////////////////////// + +void OnNoteOn(byte channel, byte note, byte velocity) { + if(channel == MIDI_CHANNEL) { + Midi.noteOn(channel, note, velocity); + } + channel = channel - 1; + MIDI_SERIAL.write(byte(0x90 | (channel & 0x0F))); + MIDI_SERIAL.write(0x7F & note); + MIDI_SERIAL.write(0x7F & velocity); +} + +void OnNoteOff(byte channel, byte note, byte velocity) { + if(channel == MIDI_CHANNEL) { + Midi.noteOff(channel, note, velocity); + } + channel = channel - 1; + MIDI_SERIAL.write(byte(0x80 | (channel & 0x0F))); + MIDI_SERIAL.write(0x7F & note); + MIDI_SERIAL.write(0x7F & velocity); +} + +void OnControlChange(byte channel, byte control, byte value) { + if(channel == MIDI_CHANNEL) { + Midi.controller(channel, control, value); + } + channel = channel - 1; + MIDI_SERIAL.write(byte(0xB0 | (channel & 0x0F))); + MIDI_SERIAL.write(0x7F & control); + MIDI_SERIAL.write(0x7F & value); +} + +#endif // close guard UCFO_h diff --git a/uSynth.cpp b/uSynth.cpp new file mode 100644 index 0000000..02e6980 --- /dev/null +++ b/uSynth.cpp @@ -0,0 +1,2375 @@ +/* + Synth.cpp - Friction Music library + Copyright (c) 2013 Science Friction. + All right reserved. + + This library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your optionosc1modShape_ptr) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser Public License for more details. + + You should have received a copy of the GNU Lesser Public License + along with Foobar. If not, see . + + +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + author: Jakob Bak + + contact: j.bak@ciid.dk + */ + +#include "uSynth.h" + +IntervalTimer synthTimer; + +MMusic Music; + +MMidi Midi; + + + +const uint16_t sineTable[] = { +#include +}; + +const uint16_t waveTable[] = { +#include +}; + +// Table of MIDI note values to frequency in Hertz +const float hertzTable[] = { +#include +}; + +uint8_t sequencer[128]; +uint8_t instrument[128]; +uint8_t userPresets[MAX_PRESETS][PRESET_SIZE]; + +bool commandFlags[128]; + + +const uint8_t programPresets[] = { +#include +}; + + + +int64_t filterSamplesLP24dB[4]; +int64_t filterSamplesHP24dB[8]; +int64_t filterSamplesMoogLadder[4]; + +const int64_t filterCoefficient[] = { +#include +}; + +const float fcMoog[] = { +#include +}; + +float filterCoefficientsMoogLadderFloat[8][256]; +// T = 1 / samplerate +// [0] wd = 2 * PI() * fc +// [1] wa = (2/T) * tan(wd*T/2) +// [2] g = wa * (T/2) +// [3] gg = g * g +// [4] ggg = g * g * g +// [5] G = g * g * g * g +// [6] Gstage = g / (1.0 + g) +// [7] nothing yet + +const int64_t filterCoefficientsMoogLadder[] = { +#include +}; + + +// Used in the functions that set the envelope timing +const uint32_t envTimeTable[] = {1,5,9,14,19,26,34,42,53,65,79,95,113,134,157,182,211,243,278,317,359,405,456,511,570,633,702,776,854,939,1029,1124,1226,1333,1448,1568,1695,1829,1971,2119,2274,2438,2610,2789,2977,3172,3377,3590,3813,4044,4285,4535,4795,5065,5345,5635,5936,6247,6569,6902,7247,7602,7970,8349,8740,9143,9559,9986,10427,10880,11347,11827,12321,12828,13349,13883,14433,14996,15574,16167,16775,17398,18036,18690,19359,20045,20746,21464,22198,22949,23716,24501,25303,26122,26959,27813,28686,29577,30486,31413,32359,33325,34309,35312,36335,37378,38440,39522,40625,41748,42892,44056,45241,46448,47675,48925,50196,51489,52803,54141,55500,56883,58288,59716,61167,62642,64140,65662}; + +const float semitoneTable[] = {0.25,0.2648658,0.2806155,0.29730177,0.31498027,0.33370996,0.35355338,0.37457678,0.39685026,0.4204482,0.44544938,0.47193715,0.5,0.5297315,0.561231,0.59460354,0.62996054,0.6674199,0.70710677,0.74915355,0.7937005,0.8408964,0.8908987,0.9438743,1.0,1.0594631,1.122462,1.1892071,1.2599211,1.3348398,1.4142135,1.4983071,1.587401,1.6817929,1.7817974,1.8877486,2.0,2.1189263,2.244924,2.3784142,2.5198421,2.6696796,2.828427,2.9966142,3.174802,3.3635857,3.563595,3.7754972,4.0}; + +const extern uint32_t portamentoTimeTable[] = {1,5,9,13,17,21,26,30,35,39,44,49,54,59,64,69,74,79,85,90,96,101,107,113,119,125,132,138,144,151,158,165,172,179,187,194,202,210,218,226,234,243,252,261,270,279,289,299,309,320,330,341,353,364,376,388,401,414,427,440,455,469,484,500,516,532,549,566,584,602,622,642,663,684,706,729,753,778,804,831,859,888,919,951,984,1019,1056,1094,1134,1176,1221,1268,1317,1370,1425,1484,1547,1614,1684,1760,1841,1929,2023,2125,2234,2354,2484,2627,2785,2959,3152,3368,3611,3886,4201,4563,4987,5487,6087,6821,7739,8918,10491,12693,15996,21500,32509,65535}; + +void MMusic::generateFilterCoefficientsMoogLadder() { + + for(int i=0; i<256; i++) { + float T = 1.0f/float(SAMPLE_RATE); + float wd = 2.0f * PI * fcMoog[i]; + float wa = (2.0f/T) * tan(wd*T/2.0f); + // float g = tan(wd*T/2.0f); + float g = wa * (T/2.0f); + float gg = g * g; + float ggg = g * g * g; + float G = g * g * g * g; + float Gstage = g / (1.0 + g); + + filterCoefficientsMoogLadderFloat[0][i] = wd; + filterCoefficientsMoogLadderFloat[1][i] = wa; + filterCoefficientsMoogLadderFloat[2][i] = g; + filterCoefficientsMoogLadderFloat[3][i] = gg; + filterCoefficientsMoogLadderFloat[4][i] = ggg; + filterCoefficientsMoogLadderFloat[5][i] = G; + filterCoefficientsMoogLadderFloat[6][i] = Gstage; + filterCoefficientsMoogLadderFloat[7][i] = 0; + } + +} + +////////////////////////////////////////////////////////// +// +// SYNTH INTERRUPT +// +////////////////////////////////////////////////////////// + +void synth_isr(void) { + +// Music.output2T3DAC(); + Music.output2DAC(); + + Music.envelope1(); + Music.envelope2(); + if(Music.is12bit) Music.synthInterrupt12bitSineFM(); +// if(Music.is12bit) Music.synthInterrupt12bitSawFM(); + else Music.synthInterrupt8bitFM(); + + Music.amplifier(); + + if(Music.lowpass) Music.filterLP6dB(); + if(Music.highpass) Music.filterHP6dB(); + if(Music.lowpass24dB) Music.filterLP24dB(); + if(Music.highpass24dB) Music.filterHP24dB(); + if(Music.moogLadder) Music.filterMoogLadder(); + +// iSeq.iSeqUpdate(); + +} + + +void MMusic::set12bit(bool b) { + is12bit = b; +} + + + + +///////////////////////////////////////////////////////// +// +// 8 BIT OSCILLATOR - WAVETABLE - 16 WAVEFORMS +// +///////////////////////////////////////////////////////// + + + +void MMusic::synthInterrupt8bitFM () +{ + + dPhase1 = dPhase1 + (period1 - dPhase1) / portamento; + modulator1 = (fmAmount1 * fmOctaves1 * (*osc1modSource_ptr))>>10; + modulator1 = (modulator1 * (*osc1modShape_ptr))>>16; + modulator1 = (modulator1 * int64_t(dPhase1))>>16; + modulator1 = (modulator1>>((modulator1>>31)&zeroFM)); + accumulator1 = accumulator1 + dPhase1 + modulator1; + index1 = accumulator1 >> 24; + oscil1 = waveTable[index1 + waveForm1]; + oscil1 -= 128; + oscil1 <<= 8; + sample = (oscil1 * gain1); + + dPhase2 = dPhase2 + (period2 - dPhase2) / portamento; + modulator2 = (fmAmount2 * fmOctaves2 * (*osc2modSource_ptr))>>10; + modulator2 = (modulator2 * (*osc2modShape_ptr))>>16; + modulator2 = (modulator2 * int64_t(dPhase2))>>16; + modulator2 = (modulator2>>((modulator2>>31)&zeroFM)); + accumulator2 = accumulator2 + dPhase2 + modulator2; + index2 = accumulator2 >> 24; + oscil2 = waveTable[index2 + waveForm2]; + oscil2 -= 128; + oscil2 <<= 8; + sample += (oscil2 * gain2); + + dPhase3 = dPhase3 + (period3 - dPhase3) / portamento; + modulator3 = (fmAmount3 * fmOctaves3 * (*osc3modSource_ptr))>>10; + modulator3 = (modulator3 * (*osc3modShape_ptr))>>16; + modulator3 = (modulator3 * int64_t(dPhase3))>>16; + modulator3 = (modulator3>>((modulator3>>31)&zeroFM)); + accumulator3 = accumulator3 + dPhase3 + modulator3; + index3 = accumulator3 >> 24; + oscil3 = waveTable[index3 + waveForm3]; + oscil3 -= 128; + oscil3 <<= 8; + sample += (oscil3 * gain3); + + sample >>= 18; + +} + + + + + +///////////////////////////////////////////////////////// +// +// 12 BIT OSCILLATOR - SINETABLE +// +///////////////////////////////////////////////////////// + + +void MMusic::synthInterrupt12bitSineFM() +{ + + dPhase1 = dPhase1 + (period1 - dPhase1) / portamento; + modulator1 = (fmAmount1 * fmOctaves1 * (*osc1modSource_ptr))>>10; + modulator1 = (modulator1 * (*osc1modShape_ptr))>>16; + modulator1 = (modulator1 * int64_t(dPhase1))>>16; + modulator1 = (modulator1>>((modulator1>>31)&zeroFM)); + accumulator1 = accumulator1 + dPhase1 + modulator1; + index1 = accumulator1 >> 20; + oscil1 = sineTable[index1]; + index1 = accumulator1 >> 20; + oscil1 -= 32768; + sample = (oscil1 * gain1); + + dPhase2 = dPhase2 + (period2 - dPhase2) / portamento; + modulator2 = (fmAmount2 * fmOctaves2 * (*osc2modSource_ptr))>>10; + modulator2 = (modulator2 * (*osc2modShape_ptr))>>16; + modulator2 = (modulator2 * int64_t(dPhase2))>>16; + modulator2 = (modulator2>>((modulator2>>31)&zeroFM)); + accumulator2 = accumulator2 + dPhase2+ modulator2; + index2 = accumulator2 >> 20; + oscil2 = sineTable[index2]; + oscil2 -= 32768; + sample += (oscil2 * gain2); + + dPhase3 = dPhase3 + (period3 - dPhase3) / portamento; + modulator3 = (fmAmount3 * fmOctaves3 * (*osc3modSource_ptr))>>10; + modulator3 = (modulator3 * (*osc3modShape_ptr))>>16; + modulator3 = (modulator3 * int64_t(dPhase3))>>16; + modulator3 = (modulator3>>((modulator3>>31)&zeroFM)); + accumulator3 = accumulator3 + dPhase3 + modulator3; + index3 = accumulator3 >> 20; + oscil3 = sineTable[index3]; + oscil3 -= 32768; + sample += (oscil3 * gain3); + + sample >>= 18; + +} + + +void MMusic::synthInterrupt12bitSawFM() +{ + + dPhase1 = dPhase1 + (period1 - dPhase1) / portamento; + modulator1 = (fmAmount1 * fmOctaves1 * (*osc1modSource_ptr))>>10; + modulator1 = (modulator1 * (*osc1modShape_ptr))>>16; + modulator1 = (modulator1 * int64_t(dPhase1))>>16; + modulator1 = (modulator1>>((modulator1>>31)&zeroFM)); + accumulator1 = accumulator1 + dPhase1 + modulator1; + // index1 = accumulator1 >> 20; + // oscil1 = sineTable[index1]; + oscil1 = accumulator1 >> 16; + oscil1 -= 32768; + sample = (oscil1 * gain1); + + dPhase2 = dPhase2 + (period2 - dPhase2) / portamento; + modulator2 = (fmAmount2 * fmOctaves2 * (*osc2modSource_ptr))>>10; + modulator2 = (modulator2 * (*osc2modShape_ptr))>>16; + modulator2 = (modulator2 * int64_t(dPhase2))>>16; + modulator2 = (modulator2>>((modulator2>>31)&zeroFM)); + accumulator2 = accumulator2 + dPhase2+ modulator2; + // index2 = accumulator2 >> 20; + // oscil2 = sineTable[index2]; + oscil2 = accumulator2 >> 16; + oscil2 -= 32768; + sample += (oscil2 * gain2); + + dPhase3 = dPhase3 + (period3 - dPhase3) / portamento; + modulator3 = (fmAmount3 * fmOctaves3 * (*osc3modSource_ptr))>>10; + modulator3 = (modulator3 * (*osc3modShape_ptr))>>16; + modulator3 = (modulator3 * int64_t(dPhase3))>>16; + modulator3 = (modulator3>>((modulator3>>31)&zeroFM)); + accumulator3 = accumulator3 + dPhase3 + modulator3; + // index3 = accumulator3 >> 20; + // oscil3 = sineTable[index3]; + oscil3 = accumulator3 >> 16; + oscil3 -= 32768; + sample += (oscil3 * gain3); + + sample >>= 18; + +} + + + +///////////////////////////////////////////////////////// +// +// ENVELOPES +// +///////////////////////////////////////////////////////// + + +void MMusic::envelope1() { + + if(envelopeOn1) { + + // Attack + if(env1Stage == 1) { + env1 += 1; // to make sure the envelope increases when (MAX_ENV_GAIN-env1) is smaller than attack1 + env1 += (MAX_ENV_GAIN - env1)/attack1; + if(velPeak1 < env1) { + env1 = velPeak1; + env1Stage = 2; + } + } + // Decay + else if(env1Stage == 2) { + env1 += -1; // to make sure the envelope decreases when (velSustain1-env1) is smaller than decay1 + env1 += (velSustain1-env1)/decay1; + if(env1 < velSustain1 || MAX_ENV_GAIN < env1) { + env1 = velSustain1; + env1Stage = 3; + } + } + // Sustain + else if (env1Stage == 3) { + env1 = velSustain1; + } + + // Release + else if (env1Stage == 4) { + env1 += -1; // to make sure the envelope decreases when (0-env1) is smaller than release1 + env1 += (0 - env1) / release1; + if(env1 < 0 || MAX_ENV_GAIN < env1) { + env1 = 0; + env1Stage = 0; + } + } + + // No gain + else if (env1Stage == 0) { + env1 = 0; + } + + } else { + env1 = 65535; + } + +} + + + +void MMusic::envelope2() { + + if(envelopeOn2) { + + // Attack + if(env2Stage == 1) { + env2 += 1; // to make sure the envelope increases when (MAX_ENV_GAIN-env2) is smaller than attack1 + env2 += (MAX_ENV_GAIN-env2)/attack2; + if(velPeak2 < env2) { + env2 = velPeak2; + env2Stage = 2; + } + } + // Decay + else if(env2Stage == 2) { + env2 += -1; // to make sure the envelope decreases when (velSustain2-env2) is smaller than decay2 + env2 += (velSustain2-env2)/decay2; + if(env2 < velSustain2 || MAX_ENV_GAIN < env2) { + env2 = velSustain2; + env2Stage = 3; + } + } + // Sustain + else if (env2Stage == 3) { + env2 = velSustain2; + } + + // Release + else if (env2Stage == 4) { + env2 += -1; // to make sure the envelope decreases when (0-env2) is smaller than release2 + env2 += (0 - env2) / release2; + if(env2 < 0 || MAX_ENV_GAIN < env2) { + env2 = 0; + env2Stage = 0; + } + } + + // No gain + else if (env2Stage == 0) { + env2 = 0; + //accumulator1 = 0; + //accumulator2 = 0; + //accumulator3 = 0; + } + + } else { + env2 = 65535; + } + +} + + +void MMusic::amplifier() { + + sample = (env1 * sample) >> 16; + +} + + +///////////////////////////////////////////////////////// +// +// SEND SAMPLE TO DAC ON TEENSY 3.1 PIN A14 +// +///////////////////////////////////////////////////////// + + +void MMusic::output2T3DAC() { + sample += 32768; + analogWrite(A14, sample>>4); +} + +void MMusic::output2DAC() { + sample += 32768; + dacSPIA0 = sample >> 8; + dacSPIA0 >>= 4; + dacSPIA0 |= dacSetA; + dacSPIA1 = sample >> 4; + + digitalWriteFast(DAC_CS, LOW); + spi4teensy3::send(dacSPIA0); + spi4teensy3::send(dacSPIA1); + + // while(SPI.transfer(dacSPIB0)); + // while(SPI.transfer(dacSPIB1)); + digitalWriteFast(DAC_CS, HIGH); +} + + + + +///////////////////////////////////// +// +// INITIALIZING FUNCTION +// +///////////////////////////////////// + + +void MMusic::spi_setup() +{ + spi4teensy3::init(0,0,0); + pinMode(DAC_CS, OUTPUT); + Serial.println("SPI set up"); +} + + +void MMusic::getPreset(uint8_t p) +{ +// cli(); + if(p < MAX_PRESETS) { +// Serial.print("GETTING PRESET NUMBER : "); +// Serial.println(p); + for(uint8_t i=2; i<128; i++) { + instrument[i] = userPresets[p][i]; + Midi.controller(Midi.midiChannel, i, instrument[i]); +// Serial.println(userPresets[p][i]); + } + } else { + for(uint8_t i=2; i<128; i++) { + instrument[i] = programPresets[(p-MAX_PRESETS)*PRESET_SIZE + i]; + Midi.controller(Midi.midiChannel, i, instrument[i]); + // Serial.println(userPresets[p][i]); + } + + } + +// sei(); +} + +void MMusic::getRandomizedPreset(uint8_t p, uint8_t r) +{ + + Serial.print("randomize preset "); + Serial.print(p); + Serial.print(" by "); + Serial.print(r); + Serial.println("%"); + + // cli(); + + // load preset values + + if(p < MAX_PRESETS) { + for(uint8_t i=2; i<128; i++) { + instrument[i] = userPresets[p][i]; + } + } else { + for(uint8_t i=2; i<128; i++) { + instrument[i]=programPresets[(p-MAX_PRESETS)*PRESET_SIZE+i]; + } + + } + + // apply randomization + + for(uint8_t i=2; i<128; i++) { + + uint8_t presetValue = instrument[i]; + + int ran = 0; + + // randomization only affects the following settings. + // randomizing all paramaters will make a lot of unusable sounds. + + // 4: cutoff, 70: cutoff mod, 6: fm oct, 8: portamento + if (i==4||i==70||i==6||i==8) { + ran = random(float(r)/100*-127,float(r)/100*127); + } + + // 10: LFO1, 12: detune1, 13: gain1, 15: FM1 + // 20: LFO2, 22: detune2, 23: gain2, 25: FM2 + // 30: LFO3, 32: detune3, 33: gain3, 35: FM3 + if (i==10||i==12||i==13||i==15||i==20||i==22||i==23||i==25||i==30||i==32||i==33||i==35) { + ran = random(float(r)/100*-127,float(r)/100*127); + } + + // 114: attack1, 115: decay1, 116: sustain1, 117: release1 + // 124: attack2, 125: decay2, 126: sustain2, 127: release2 + if (i==114||i==115||i==116||i==117||i==124||i==125||i==126||i==127) { + ran = random(float(r)/100*-127,float(r)/100*127); + } + + uint8_t newVal = constrain(presetValue+ran,0,127); + + if (ran != 0) + { + /* + Serial.print(i); + Serial.print(": preset value "); + Serial.print(presetValue); + Serial.print(" randomized by "); + Serial.print(ran); + Serial.print(" yielding "); + Serial.println(newVal); + */ + } + + instrument[i] = newVal; + + Midi.controller(Midi.midiChannel, i, instrument[i]); + } + + // sei(); + +} + + +#if defined(USB_MIDI) + +void MMusic::sendInstrument() +{ +// Serial.print("SENDING PRESET NUMBER : "); +// Serial.print(p); +// Serial.println(" OVER MIDI"); + cli(); + for(uint8_t i=2; i<128; i++) { + usbMIDI.sendControlChange(i, instrument[i], Midi.midiChannel+1); + } + sei(); +} + +#else + +void MMusic::sendInstrument(){;} + +#endif + + +void MMusic::savePreset(uint8_t p) +{ + if(p < MAX_PRESETS) { + Serial.print("SAVING PRESET NUMBER : "); + Serial.println(p); + for(uint8_t i=0; i<128; i++) { + //Serial.print(i); + //Serial.print(" : "); + userPresets[p][i] = instrument[i]; + //Serial.println(userPresets[p][i]); + //insert code for saving instrument sequence here + cli(); + EEPROM.write(p * PRESET_SIZE + i, instrument[i]); + sei(); + } + } + else { + Serial.println("CAN NOT SAVE PRESET TO EEPROM - COPY/PASTE BELOW TO FILE"); + for(uint8_t i=0; i<128; i++) { + Serial.print(instrument[i]); + Serial.print(", "); + } + } + +} + + +void MMusic::loadAllPresets() +{ + for(uint8_t i=2; i<128; i++) { + for(uint8_t p=0; p>8); + +} + + +void MMusic::setResonance(uint32_t res) +{ + resonance = res; + k = res; +} + + +void MMusic::setCutoffModAmount(int32_t amount) { + if(amount >= 65536) cutoffModAmount = 65535; + else if(amount < -65536) cutoffModAmount = -65536; + else cutoffModAmount = amount; +// cutoffModAmount = amount; +} + +void MMusic::setCutoffModDirection(int32_t direction) { + if(direction >= 0) cutoffModDirection = 1; + else cutoffModDirection = -1; +} + + +void MMusic::filterLP6dB() { + + int64_t mod = (int64_t(cutoffModAmount) * (int64_t(*cutoffModSource_ptr)))>>16; + int64_t c = (mod + int64_t(cutoff)); + if(c > 65535) c = 65535; + else if(c < 0) c = 0; +// c = ((((c * 32768) >> 15) + 65536) >> 1); + + b1 = filterCoefficient[c>>8]; + a0 = BIT_32 - b1; + + sample = (a0 * sample + b1 * lastSampleOutLP) >> 32; + lastSampleOutLP = sample; + +} + + +void MMusic::filterLP24dB() { + + + int64_t mod = (int64_t(cutoffModAmount) * (int64_t(*cutoffModSource_ptr)))>>16; + int64_t c = (mod + int64_t(cutoff)); + if(c > 65535) c = 65535; + else if(c < 0) c = 0; + // c = ((((c * 32768) >> 15) + 65536) >> 1); + + int fc = c>>8; + // if(fc > 220) fc = 220; + + b1 = filterCoefficient[fc]; + a0 = BIT_32 - b1; + + // int64_t res = resonance - (c >> 1); + // k = resonance >> 12; + // x0 = sample + feedbackSample * k; + // x0 = sample + ((feedbackSample * resonance) >> 12); + // feedbackSample = + x0 = (sample << 12) + (feedbackSample * resonance); + x0 >>= 12; + // x0 += 32768; + if(x0 > 30735) { + x0 = (((x0 - 30735) * 4098) >> 16) + 30735; + } + else if(x0 < -30735) { + x0 = (((x0 + 30735) * 4098) >> 16) - 30735; + } + // x0 -= 32768; + // x0 = x0 / (4096 + resonance); + if(x0 > MAX_SAMPLE) x0 = MAX_SAMPLE; + else if(x0 < MIN_SAMPLE) x0 = MIN_SAMPLE; + + y1 = filterSamplesLP24dB[0]; + y2 = filterSamplesLP24dB[1]; + y3 = filterSamplesLP24dB[2]; + y4 = filterSamplesLP24dB[3]; + + y1 = (a0 * x0 + b1 * y1) >> 32; + y2 = (a0 * y1 + b1 * y2) >> 32; + y3 = (a0 * y2 + b1 * y3) >> 32; + y4 = (a0 * y3 + b1 * y4) >> 32; + + filterSamplesLP24dB[0] = y1; + filterSamplesLP24dB[1] = y2; + filterSamplesLP24dB[2] = y3; + filterSamplesLP24dB[3] = y4; + + sample = y4; + + // Feedback of LP output through HP + + a0 = (BIT_32 + b1) >> 1; + a1 = -a0; + + xNew = sample; + xOld = filterSamplesHP24dB[0]; + yOld = filterSamplesHP24dB[4]; + yNew = (a0 * xNew + a1 * xOld + b1 * yOld) >> 32; + x1 = xNew; + y1 = yNew; + + xNew = y1; + xOld = filterSamplesHP24dB[1]; + yOld = filterSamplesHP24dB[5]; + yNew = (a0 * xNew + a1 * xOld + b1 * yOld) >> 32; + x2 = xNew; + y2 = yNew; + + xNew = y2; + xOld = filterSamplesHP24dB[2]; + yOld = filterSamplesHP24dB[6]; + yNew = (a0 * xNew + a1 * xOld + b1 * yOld) >> 32; + x3 = xNew; + y3 = yNew; + + xNew = y3; + xOld = filterSamplesHP24dB[3]; + yOld = filterSamplesHP24dB[7]; + yNew = (a0 * xNew + a1 * xOld + b1 * yOld) >> 32; + x4 = xNew; + y4 = yNew; + + filterSamplesHP24dB[0] = x1; + filterSamplesHP24dB[1] = x2; + filterSamplesHP24dB[2] = x3; + filterSamplesHP24dB[3] = x4; + + filterSamplesHP24dB[4] = y1; + filterSamplesHP24dB[5] = y2; + filterSamplesHP24dB[6] = y3; + filterSamplesHP24dB[7] = y4; + + feedbackSample = y4; +} + + + +void MMusic::filterHP24dB() { + + int64_t mod = (int64_t(cutoffModAmount) * (int64_t(*cutoffModSource_ptr)))>>16; + int64_t c = (mod + int64_t(cutoff)); + if(c > 65535) c = 65535; + else if(c < 0) c = 0; + // c = ((((c * 32768) >> 15) + 65536) >> 1); + + + b1 = filterCoefficient[c>>8]; + a0 = (BIT_32 + b1) >> 1; + a1 = -a0; + + xNew = sample; + xOld = filterSamplesHP24dB[0]; + yOld = filterSamplesHP24dB[4]; + yNew = (a0 * xNew + a1 * xOld + b1 * yOld) >> 32; + x1 = xNew; + y1 = yNew; + + xNew = y1; + xOld = filterSamplesHP24dB[1]; + yOld = filterSamplesHP24dB[5]; + yNew = (a0 * xNew + a1 * xOld + b1 * yOld) >> 32; + x2 = xNew; + y2 = yNew; + + xNew = y2; + xOld = filterSamplesHP24dB[2]; + yOld = filterSamplesHP24dB[6]; + yNew = (a0 * xNew + a1 * xOld + b1 * yOld) >> 32; + x3 = xNew; + y3 = yNew; + + xNew = y3; + xOld = filterSamplesHP24dB[3]; + yOld = filterSamplesHP24dB[7]; + yNew = (a0 * xNew + a1 * xOld + b1 * yOld) >> 32; + x4 = xNew; + y4 = yNew; + + filterSamplesHP24dB[0] = x1; + filterSamplesHP24dB[1] = x2; + filterSamplesHP24dB[2] = x3; + filterSamplesHP24dB[3] = x4; + + filterSamplesHP24dB[4] = y1; + filterSamplesHP24dB[5] = y2; + filterSamplesHP24dB[6] = y3; + filterSamplesHP24dB[7] = y4; + + sample = y4; + +} + + +void MMusic::filterMoogLadder() { + + int64_t mod = (int64_t(cutoffModAmount) * (int64_t(*cutoffModSource_ptr)))>>16; + int64_t c = (mod + int64_t(cutoff)); + if(c > 65535) c = 65535; + else if(c < 0) c = 0; + + int fc = c>>8; + if(fc > 234) fc = 234; + x0 = sample; + u = x0; +// g = filterCoefficientsMoogLadder[fc]; +// gg = filterCoefficientsMoogLadder[256 + fc]; +// ggg = filterCoefficientsMoogLadder[512 + fc]; +// G = filterCoefficientsMoogLadder[768 + fc]; + Gstage = filterCoefficientsMoogLadder[1024 + fc]; + +// // u = (x0 - k * S) / (1 + k * G); // THIS IS THE ORIGINAL EQUATION + +// S = (ggg * z1) >> 16; +// S += (gg * z2) >> 16; +// S += (g * z3) >> 16; +// S += z4 >> 16; +// +// int64_t div = (281474976710656 + (k * G)); // 48bit +// int64_t sub = (k * S); +// u = x0 << 48; +// u = u - sub; +// u = (u / div); + +// S = (ggg * z1) >> 32; +// S += (gg * z2) >> 32; +// S += (g * z3) >> 32; +// S += z4 >> 32; +// +// int64_t div = (BIT_32 + ((k * G) >> 16)); // 32bit +// div = div >> 16; // 16bit +// int64_t sub = (k * S); // 32bit +// u = x0 << 16;// 32bit +// u = u - sub; +// u = (u / div); + +// g = filterCoefficientsMoogLadderFloat[2][fc]; +// gg = filterCoefficientsMoogLadderFloat[3][fc]; +// ggg = filterCoefficientsMoogLadderFloat[4][fc]; +// G = filterCoefficientsMoogLadderFloat[5][fc]; +// Gstage = filterCoefficientsMoogLadderFloat[6][fc]; +// float kfloat = 0.0f; +// float div = (1 + (kfloat * G)); +// u = int64_t(float(u) / div); // FIX // k << 16 + + v1 = ((u - z1) * Gstage) >> 32; + y1 = (v1 + z1); + z1 = y1 + v1; + + v2 = ((y1 - z2) * Gstage) >> 32; + y2 = (v2 + z2); + z2 = y2 + v2; + + v3 = ((y2 - z3) * Gstage) >> 32; + y3 = (v3 + z3); + z3 = y3 + v3; + + v4 = ((y3 - z4) * Gstage) >> 32; + y4 = (v4 + z4); + z4 = y4 + v4; + +// filterSamplesMoogLadder[0] = y1; +// filterSamplesMoogLadder[1] = y2; +// filterSamplesMoogLadder[2] = y3; +// filterSamplesMoogLadder[3] = y4; + + sample = y4; + + +} + +void MMusic::filterHP6dB() { + + sampleInHP = sample; + + int64_t mod = (int64_t(cutoffModAmount) * (int64_t(*cutoffModSource_ptr)))>>16; + int64_t c = (mod + int64_t(cutoff)); + if(c > 65535) c = 65535; + else if(c < 0) c = 0; + // c = ((((c * 32768) >> 15) + 65536) >> 1); + + b1 = filterCoefficient[c>>8]; + a0 = (BIT_32 + b1) >> 1; + a1 = -a0; + + sampleOutHP = (a0 * sampleInHP + a1 * lastSampleInHP + b1 * lastSampleOutHP) >> 32; + + lastSampleInHP = sampleInHP; + lastSampleOutHP = sampleOutHP; + sample = sampleOutHP; + +} + + + +void MMusic::setFilterType(uint8_t type) { + + switch (type) { + case LP6: + lowpass = true; + highpass = false; + lowpass24dB = false; + highpass24dB = false; + moogLadder = false; + break; + case HP6: + lowpass = false; + highpass = true; + lowpass24dB = false; + highpass24dB = false; + moogLadder = false; + break; + case BP6: + lowpass = true; + highpass = true; + lowpass24dB = false; + highpass24dB = false; + moogLadder = false; + break; + case THRU: + lowpass = false; + highpass = false; + lowpass24dB = false; + highpass24dB = false; + moogLadder = false; + break; + case LP24: + lowpass = false; + highpass = false; + lowpass24dB = true; + highpass24dB = false; + moogLadder = false; + break; + case HP24: + lowpass = false; + highpass = false; + lowpass24dB = false; + highpass24dB = true; + moogLadder = false; + break; + case BP24: + lowpass = false; + highpass = false; + lowpass24dB = true; + highpass24dB = true; + moogLadder = false; + break; + case MOOG: + lowpass = false; + highpass = false; + lowpass24dB = false; + highpass24dB = false; + moogLadder = true; + break; + default: + break; + } +} + + +void MMusic::setCutoffModShape(uint8_t shape) { + switch(shape) { + case 0: + cutoffModShape_ptr = &fullSignal; + break; + case 1: + cutoffModShape_ptr = &env1; + break; + case 2: + cutoffModShape_ptr = &env2; + break; + case 3: + cutoffModShape_ptr = &oscil1; + break; + case 4: + cutoffModShape_ptr = &oscil2; + break; + case 5: + cutoffModShape_ptr = &oscil3; + break; + default: + cutoffModShape_ptr = &fullSignal; + break; + } +} + + +void MMusic::setCutoffModSource(uint8_t source) { + switch(source) { + case 0: + cutoffModSource_ptr = &fullSignal; + break; + case 1: + cutoffModSource_ptr = &env1; + break; + case 2: + cutoffModSource_ptr = &env2; + break; + case 3: + cutoffModSource_ptr = &oscil1; + break; + case 4: + cutoffModSource_ptr = &oscil2; + break; + case 5: + cutoffModSource_ptr = &oscil3; + break; + default: + cutoffModSource_ptr = &fullSignal; + break; + } +} + + +void MMusic::setResonanceModShape(uint8_t shape) { + switch(shape) { + case 0: + resonanceModShape_ptr = &fullSignal; + break; + case 1: + resonanceModShape_ptr = &env1; + break; + case 2: + resonanceModShape_ptr = &env2; + break; + case 3: + resonanceModShape_ptr = &oscil1; + break; + case 4: + resonanceModShape_ptr = &oscil2; + break; + case 5: + resonanceModShape_ptr = &oscil3; + break; + default: + resonanceModShape_ptr = &fullSignal; + break; + } +} + + +void MMusic::setResonanceModSource(uint8_t source) { + switch(source) { + case 0: + resonanceModSource_ptr = &fullSignal; + break; + case 1: + resonanceModSource_ptr = &env1; + break; + case 2: + resonanceModSource_ptr = &env2; + break; + case 3: + resonanceModSource_ptr = &oscil1; + break; + case 4: + resonanceModSource_ptr = &oscil2; + break; + case 5: + resonanceModSource_ptr = &oscil3; + break; + default: + resonanceModSource_ptr = &fullSignal; + break; + } +} + + + + +///////////////////////////////////// +// +// FREQUENCY AND DETUNE FUNCTIONS +// +///////////////////////////////////// + +void MMusic::setFrequency(float freq) +{ + frequency = freq; + if(!osc1LFO) setFrequency1(freq); + if(!osc2LFO) setFrequency2(freq); + if(!osc3LFO) setFrequency3(freq); + // period1 = int32_t(((freq * semi1 * (1 + detune1 + bend)) * PERIOD_MAX) / SAMPLE_RATE); + // period2 = int32_t(((freq * semi2 * (1 + detune2 + bend)) * PERIOD_MAX) / SAMPLE_RATE); + // period3 = int32_t(((freq * semi3 * (1 + detune3 + bend)) * PERIOD_MAX) / SAMPLE_RATE); + // frequency1 = freq; + // frequency2 = freq; + // frequency3 = freq; +} + + +void inline MMusic::setFrequency1(float freq) +{ + frequency1 = freq; + period1 = int32_t(((frequency1 * semi1 * (1 + detune1 + bend)) * PERIOD_MAX) / SAMPLE_RATE); +} + + +void inline MMusic::setFrequency2(float freq) +{ + frequency2 = freq; + period2 = int32_t(((frequency2 * semi2 * (1 + detune2 + bend)) * PERIOD_MAX) / SAMPLE_RATE); +} + + +void inline MMusic::setFrequency3(float freq) +{ + frequency3 = freq; + period3 = int32_t(((frequency3 * semi3 * (1 + detune3 + bend)) * PERIOD_MAX) / SAMPLE_RATE); +} + + +void MMusic::setSemitone1(int8_t semi) +{ + if(-25 < semi && semi < 25){ + semi1 = semitoneTable[semi+24]; + } else if (semi < -24) { + semi1 = semitoneTable[0]; + } else { + semi1 = semitoneTable[48]; + } + setFrequency1(frequency1); + // period1 = int32_t(((frequency1 * semi1 * (1 + detune1 + bend)) * PERIOD_MAX) / SAMPLE_RATE); +} + + +void MMusic::setSemitone2(int8_t semi) +{ + if(-25 < semi && semi < 25){ + semi2 = semitoneTable[semi+24]; + } else if (semi < -24) { + semi2 = semitoneTable[0]; + } else { + semi2 = semitoneTable[48]; + } + setFrequency2(frequency2); +// period2 = int32_t(((frequency2 * semi2 * (1 + detune2 + bend)) * PERIOD_MAX) / SAMPLE_RATE); +} + + +void MMusic::setSemitone3(int8_t semi) +{ + if(-25 < semi && semi < 25){ + semi3 = semitoneTable[semi+24]; + } else if (semi < -24) { + semi3 = semitoneTable[0]; + } else { + semi3 = semitoneTable[48]; + } + setFrequency3(frequency3); +// period3 = int32_t(((frequency3 * semi3 * (1 + detune3 + bend)) * PERIOD_MAX) / SAMPLE_RATE); +} + + +void MMusic::setDetune(float detune) +{ + detune1 = 0.0; + detune2 = detune*0.123456789; + detune3 = -detune; + setFrequency2(frequency2); + setFrequency3(frequency3); +// period2 = int32_t(((frequency2 * semi2 * (1 + detune2 + bend)) * PERIOD_MAX) / SAMPLE_RATE); +// period3 = int32_t(((frequency3 * semi3 * (1 + detune3 + bend)) * PERIOD_MAX) / SAMPLE_RATE); +} + + +void MMusic::setDetune1(float detune) +{ + detune1 = detune; + setFrequency1(frequency1); +// period1 = int32_t(((frequency1 * semi1 * (1 + detune1 + bend)) * PERIOD_MAX) / SAMPLE_RATE); +} + + +void MMusic::setDetune2(float detune) +{ + detune2 = detune; + setFrequency2(frequency2); +// period2 = int32_t(((frequency2 * semi2 * (1 + detune2 + bend)) * PERIOD_MAX) / SAMPLE_RATE); +} + + +void MMusic::setDetune3(float detune) +{ + detune3 = detune; + setFrequency3(frequency3); +// period3 = int32_t(((frequency3 * semi3 * (1 + detune3 + bend)) * PERIOD_MAX) / SAMPLE_RATE); +} + + +void MMusic::pitchBend(float b) +{ + bend = b; + setFrequency1(frequency1); + setFrequency2(frequency2); + setFrequency3(frequency3); +// period1 = int32_t(((frequency1 * semi1 * (1 + detune1 + bend)) * PERIOD_MAX) / SAMPLE_RATE); +// period2 = int32_t(((frequency2 * semi2 * (1 + detune2 + bend)) * PERIOD_MAX) / SAMPLE_RATE); +// period3 = int32_t(((frequency3 * semi3 * (1 + detune3 + bend)) * PERIOD_MAX) / SAMPLE_RATE); +} + + +void MMusic::setOsc1LFO(bool lfo) { + osc1LFO = lfo; +} + + +void MMusic::setOsc2LFO(bool lfo) { + osc2LFO = lfo; +} + + +void MMusic::setOsc3LFO(bool lfo) { + osc3LFO = lfo; +} + + +void MMusic::setFM1(uint8_t fm) { + fmAmount1 = fm; +} + + +void MMusic::setFM2(uint8_t fm) { + fmAmount2 = fm; +// fmAmount2 = (fm * fmOctaves2); +} + + +void MMusic::setFM3(uint8_t fm) { + fmAmount3 = fm; +// fmAmount3 = (fm * fmOctaves3); +} + + +void MMusic::setFMoctaves(uint8_t octs) { +// fmAmount1 = (fmAmount1 * octs); +// fmAmount2 = (fmAmount2 * octs); +// fmAmount3 = (fmAmount3 * octs); + fmOctaves1 = octs; + fmOctaves2 = octs; + fmOctaves3 = octs; +} + + +void MMusic::setFM1octaves(uint8_t octs) { + if(octs < 1) octs = 1; + fmOctaves1 = octs; +} + + +void MMusic::setFM2octaves(uint8_t octs) { + if(octs < 1) octs = 1; + fmOctaves2 = octs; +} + + +void MMusic::setFM3octaves(uint8_t octs) { + if(octs < 1) octs = 1; + fmOctaves3 = octs; +} + + +void MMusic::setFM1Source(uint8_t source) { + switch(source) { + case 0: + osc1modSource_ptr = &fullSignal; + break; + case 1: + osc1modSource_ptr = &oscil1; + break; + case 2: + osc1modSource_ptr = &oscil2; + break; + case 3: + osc1modSource_ptr = &oscil3; + break; + default: + osc1modSource_ptr = &fullSignal; + break; + } +} + + +void MMusic::setFM2Source(uint8_t source) { + switch(source) { + case 0: + osc2modSource_ptr = &fullSignal; + break; + case 1: + osc2modSource_ptr = &oscil1; + break; + case 2: + osc2modSource_ptr = &oscil2; + break; + case 3: + osc2modSource_ptr = &oscil3; + break; + default: + osc1modSource_ptr = &fullSignal; + break; + } +} + + +void MMusic::setFM3Source(uint8_t source) { + switch(source) { + case 0: + osc3modSource_ptr = &fullSignal; + break; + case 1: + osc3modSource_ptr = &oscil1; + break; + case 2: + osc3modSource_ptr = &oscil2; + break; + case 3: + osc3modSource_ptr = &oscil3; + break; + default: + osc1modSource_ptr = &fullSignal; + break; + } +} + + +void MMusic::setFM1Shape(uint8_t shape) { + switch(shape) { + case 0: + osc1modShape_ptr = &fullSignal; + break; + case 1: + osc1modShape_ptr = &env1; + break; + case 2: + osc1modShape_ptr = &env2; + break; + case 3: + osc1modShape_ptr = &oscil1; + break; + case 4: + osc1modShape_ptr = &oscil2; + break; + case 5: + osc1modShape_ptr = &oscil3; + break; + default: + osc1modShape_ptr = &fullSignal; + break; + } +} + + +void MMusic::setFM2Shape(uint8_t shape) { + switch(shape) { + case 0: + osc2modShape_ptr = &fullSignal; + break; + case 1: + osc2modShape_ptr = &env1; + break; + case 2: + osc2modShape_ptr = &env2; + break; + case 3: + osc2modShape_ptr = &oscil1; + break; + case 4: + osc2modShape_ptr = &oscil2; + break; + case 5: + osc2modShape_ptr = &oscil3; + break; + default: + osc2modShape_ptr = &fullSignal; + break; + } +} + + +void MMusic::setFM3Shape(uint8_t shape) { + switch(shape) { + case 0: + osc3modShape_ptr = &fullSignal; + break; + case 1: + osc3modShape_ptr = &env1; + break; + case 2: + osc3modShape_ptr = &env2; + break; + case 3: + osc3modShape_ptr = &oscil1; + break; + case 4: + osc3modShape_ptr = &oscil2; + break; + case 5: + osc3modShape_ptr = &oscil3; + break; + default: + osc3modShape_ptr = &fullSignal; + break; + } +} + + +void MMusic::fmToZeroHertz(bool zero) { + if(!zero) zeroFM = 1; + else zeroFM = 0; +} + +void MMusic::setPortamento(int32_t port) { + if(port == 0) port = 1; + portamento = port; +// portamento = envTimeTable[uint8_t(port)]; +} + + + +///////////////////////////////////// +// +// WAVEFORM FUNCTIONS +// +///////////////////////////////////// + + +void MMusic::setWaveform(uint16_t waveForm) +{ + waveForm1 = waveForm * 256; + waveForm2 = waveForm * 256; + waveForm3 = waveForm * 256; +} + + +void MMusic::setWaveform1(uint16_t waveForm) +{ + waveForm1 = waveForm * 256; +} + + +void MMusic::setWaveform2(uint16_t waveForm) +{ + waveForm2 = waveForm * 256; +} + + +void MMusic::setWaveform3(uint16_t waveForm) +{ + waveForm3 = waveForm * 256; +} + + + + +///////////////////////////////////// +// +// GAIN FUNCTIONS +// +///////////////////////////////////// + + +void MMusic::setGain(float value) +{ + gain = uint16_t(value * 65535); + gain1 = gain; + gain2 = gain; + gain3 = gain; +} + + +void MMusic::setGain1(float value) +{ + gain1 = uint16_t(value * 65535); +} + + +void MMusic::setGain2(float value) +{ + gain2 = uint16_t(value * 65535); +} + + +void MMusic::setGain3(float value) +{ + gain3 = uint16_t(value * 65535); +} + + +float MMusic::getGain() +{ + return float(gain)/65535.0; +} + + +float MMusic::getGain1() +{ + return float(gain1)/65535.0; +} + + +float MMusic::getGain2() +{ + return float(gain2)/65535.0; +} + + +float MMusic::getGain3() +{ + return float(gain3)/65535.0; +} + + + + +///////////////////////////////////// +// +// NOTE_ON/OFF FUNCTIONS +// +///////////////////////////////////// + + +void MMusic::noteOn(uint8_t note, uint8_t vel) +{ + env1Stage = 1; + env2Stage = 1; + setEnv1VelSustain(vel); + setEnv2VelSustain(vel); + setEnv1VelPeak(vel); + setEnv2VelPeak(vel); + notePlayed = note; + velocityPlayed = vel; + frequency16bit = hertzTable[notePlayed]; + setFrequency(frequency16bit); + //setFrequency1(frequency16bit); + //setFrequency2(frequency16bit); + //setFrequency3(frequency16bit); +} + + +void MMusic::noteOn(uint8_t note) +{ + int vel = 127; + env1Stage = 1; + env2Stage = 1; + setEnv1VelSustain(vel); + setEnv2VelSustain(vel); + setEnv1VelPeak(vel); + setEnv2VelPeak(vel); + notePlayed = note; + velocityPlayed = vel; + frequency16bit = hertzTable[notePlayed]; + setFrequency(frequency16bit); + //setFrequency1(frequency16bit); + //setFrequency2(frequency16bit); + //setFrequency3(frequency16bit); +} + + +void MMusic::noteOff(uint8_t note) +{ + if(notePlayed = note) { + env1Stage = 4; + env2Stage = 4; + } +} + + +void MMusic::noteOff() +{ + env1Stage = 4; + env2Stage = 4; +} + + +float MMusic::getNoteFrequency(uint8_t note) +{ + return hertzTable[note]; +} + + + + +///////////////////////////////////// +// +// ENVELOPE FUNCTIONS +// +///////////////////////////////////// + + +// ENVELOPE 1 + +void MMusic::enableEnvelope1() +{ + envelopeOn1 = true; +} + + +void MMusic::disableEnvelope1() +{ + envelopeOn1 = false; +} + + +void MMusic::setEnv1Stage(uint8_t stage) +{ + env1Stage = stage; +} + + +void MMusic::setEnv1Attack(uint8_t att) +{ + if(att>127) att = 127; + attack1 = envTimeTable[att]; +} + + +void MMusic::setEnv1Decay(uint8_t dec) +{ + if(dec>127) dec = 127; + decay1 = envTimeTable[dec]; +} + + +void MMusic::setEnv1Sustain(uint8_t sus) +{ + sustain1 = ((sus * MAX_ENV_GAIN)/128); +} + + +void MMusic::setEnv1Release(uint8_t rel) +{ + if(rel>127) rel = 127; + release1 = envTimeTable[rel]; +} + + +void MMusic::setEnv1VelSustain(uint8_t vel) +{ + velSustain1 = vel * (sustain1 / 128); +} + + +void MMusic::setEnv1VelPeak(uint8_t vel) +{ + velPeak1 = vel * (MAX_ENV_GAIN / 128); +} + + +// ENVELOPE 2 + +void MMusic::enableEnvelope2() +{ + envelopeOn2 = true; +} + + +void MMusic::disableEnvelope2() +{ + envelopeOn2 = false; +} + + +void MMusic::setEnv2Stage(uint8_t stage) +{ + env2Stage = stage; +} + + +void MMusic::setEnv2Attack(uint8_t att) +{ + if(att>127) att = 127; + attack2 = envTimeTable[att]; +} + + +void MMusic::setEnv2Decay(uint8_t dec) +{ + if(dec>127) dec = 127; + decay2 = envTimeTable[dec]; +} + + +void MMusic::setEnv2Sustain(uint8_t sus) +{ + sustain2 = ((sus * MAX_ENV_GAIN)/128); +} + + +void MMusic::setEnv2Release(uint8_t rel) +{ + if(rel>127) rel = 127; + release2 = envTimeTable[rel]; +} + + +void MMusic::setEnv2VelSustain(uint8_t vel) +{ + velSustain2 = vel * (sustain2 / 128); +} + + +void MMusic::setEnv2VelPeak(uint8_t vel) +{ + velPeak2 = vel * (MAX_ENV_GAIN / 128); +} + + +void MMusic::setCommandFlag(uint8_t flag) +{ + commandFlags[flag] = 1; +// switch(flag) { +// case SEQ_STEP_FORWARD: +// commandFlags[SEQ_STEP_FORWARD] = 1; +// break; +// default: +// break; +// +// } +} + + +void MMusic::clearCommandFlag(uint8_t flag) +{ + commandFlags[flag] = 0; +// switch(flag) { +// case SEQ_STEP_FORWARD: +// commandFlags[SEQ_STEP_FORWARD] = 0; +// break; +// default: +// break; +// +// } +} + + +bool MMusic::checkCommandFlag(uint8_t flag) +{ + return commandFlags[flag]; +// switch(flag) { +// case SEQ_STEP_FORWARD: +// return commandFlags[SEQ_STEP_FORWARD]; +// break; +// default: +// break; +// +// } +} + + + +///////////////////////////////////// +// +// MIDI specific functions +// +///////////////////////////////////// + +bool midiRead = false; + +void MMidi::init() +{ + pinMode(0, INPUT); + Serial.begin(9600); + MIDI_SERIAL.begin(31250); + + midiBufferIndex = 0; + midiChannel = 1; + Serial.println("MIDI intialised on channel 1. Use Midi.setChannel(channel) to set to other channel"); +} + +void MMidi::setChannel(uint8_t channel) +{ + if(channel < 1 || channel > 16) { + Serial.println("MIDI channel must be set to a number between 1 and 16"); + } + else midiChannel = channel - 1; +} + + +void MMidi::checkSerialMidi() +{ + //while(Serial.available() > 32) Serial.read(); +// while(MIDI_SERIAL.available() > 0) { + while(MIDI_SERIAL.available()) { + + data = MIDI_SERIAL.read(); + + if(data & 0x80 && (data & 0x0F) == midiChannel) { // bitmask with 10000000 to see if byte is over 127 (data&0x80) + midiBufferIndex = 0; // and check if the midi channel corresponds to the midiChannel + midiRead = true; // the device is set to listen to. + } else if(data & 0x80) { // Else if the byte is over 127 (but not on the device's + midiRead = false; // midiChannel, don't read this or any following bytes. + } + + if(midiRead) { + midiBuffer[midiBufferIndex] = data; + midiBufferIndex++; + if (midiBufferIndex > 2) { + midiRead = false; + midiHandler(); + Serial.println("MIDI RECEIVED"); + Serial.println(midiBuffer[0], HEX); + Serial.println(midiBuffer[1], HEX); + Serial.println(midiBuffer[2], HEX); + } + } + } +} + + +void MMidi::sendNoteOff(uint8_t note) { + + MIDI_SERIAL.write(0x80 | midiChannel); + MIDI_SERIAL.write(byte(note)); + MIDI_SERIAL.write(0x00); + +} + + +void MMidi::sendNoteOn(uint8_t note, uint8_t vel) { + + MIDI_SERIAL.write(0x90 | midiChannel); + MIDI_SERIAL.write(byte(note)); + MIDI_SERIAL.write(byte(vel)); + +} + +void MMidi::sendController(uint8_t number, uint8_t value) { + + MIDI_SERIAL.write(0xB0 | midiChannel); + MIDI_SERIAL.write(byte(number)); + MIDI_SERIAL.write(byte(value)); + +} + +void MMidi::sendStep() { + MIDI_SERIAL.write(0xB0 | midiChannel); + MIDI_SERIAL.write(byte(CFO_COMMAND)); + MIDI_SERIAL.write(byte(SEQ_STEP_FORWARD)); + +} + + +void MMidi::midiHandler() { + + if(MIDI_THROUGH) { + MIDI_SERIAL.write(midiBuffer[0]); + MIDI_SERIAL.write(midiBuffer[1]); + MIDI_SERIAL.write(midiBuffer[2]); + } +// uint8_t midiChannel = (midiBuffer[0] & 0x0F); + + if((midiBuffer[0] & 0x0F) == midiChannel) { + switch(midiBuffer[0] & 0xF0) { // bit mask with &0xF0 ? + case 0x80: + noteOff (midiBuffer[0] & 0x0F, // midi channel 0-15 + midiBuffer[1] & 0x7F, // note value 0-127 + midiBuffer[2] & 0x7F); // note velocity 0-127 + break; + + case 0x90: + noteOn (midiBuffer[0] & 0x0F, // midi channel 0-15 + midiBuffer[1] & 0x7F, // note value 0-127 + midiBuffer[2] & 0x7F); // note velocity 0-127 + break; + + case 0xA0: + aftertouch (midiBuffer[0] & 0x0F, // midi channel 0-15 + midiBuffer[1] & 0x7F, // note value 0-127 + midiBuffer[2] & 0x7F);// note velocity 0-127 + break; + + case 0xB0: + controller (midiBuffer[0] & 0x0F, // midi channel 0-15 + midiBuffer[1] & 0x7F, // controller number 0-127 + midiBuffer[2] & 0x7F);// controller value 0-127 + break; + + case 0xC0: + programChange (midiBuffer[0] & 0x0F, // midi channel 0-15 + midiBuffer[1] & 0x7F); // program number 0-127 + break; + + case 0xD0: + channelPressure (midiBuffer[0] & 0x0F, // midi channel 0-15 + midiBuffer[1] & 0x7F); // pressure amount 0-127 + break; + + case 0xE0: + pitchWheel (midiBuffer[0] & 0x0F, // midi channel 0-15 + midiBuffer[1] & 0x7F, // higher bits 0-6 + midiBuffer[2] & 0x7F);// lower bits 7-13 + break; + + default: + break; + } + } + else Serial.println("Skipped MIDI message on other channel"); +} + + +void MMidi::noteOff(uint8_t channel, uint8_t note, uint8_t vel) { +// Serial.print("NoteOff received on channel: "); +// Serial.println(channel, HEX); + + Music.noteOff(note); +} + + +void MMidi::noteOn(uint8_t channel, uint8_t note, uint8_t vel) { +// Serial.print("NoteOn received on channel: "); +// Serial.println(channel, HEX); + Music.noteOn(note, vel); +} + + +void MMidi::aftertouch(uint8_t channel, uint8_t note, uint8_t pressure) { + // Write code here for Aftertouch +} + + +void MMidi::controller(uint8_t channel, uint8_t number, uint8_t value) { + + if(value >= 128) value = 127; + instrument[number] = value; +// Serial.print(number); +// Serial.print(" : "); +// Serial.println(instrument[number]); + + switch(number) { + case IS_12_BIT: + if(value) Music.set12bit(true); + else Music.set12bit(false); +// Music.set12bit(value/64); + break; + case PORTAMENTO: + Music.setPortamento(portamentoTimeTable[value]); + break; + case CUTOFF: + Music.setCutoff(value * 512); + break; + case RESONANCE: + Music.setResonance(value * 512); + break; + case FILTER_TYPE: + Music.setFilterType(value); + break; + case CUTOFF_MOD_AMOUNT: + Music.setCutoffModAmount((value-64) * 1024); + // if(value > 63) Music.setCutoffModAmount((value-64) * 512); + // if(value < 64) Music.setCutoffModAmount(() * 512); + break; + // case CUTOFF_MOD_DIRECTION: + // Music.setCutoffModDirection(value); + // break; + case CUTOFF_SOURCE: + Music.setCutoffModSource(value); + break; + case CUTOFF_SHAPE: + Music.setCutoffModShape(value); + break; + case ZERO_HZ_FM: + if(value) Music.fmToZeroHertz(true); + else Music.fmToZeroHertz(false); + break; + case FM_OCTAVES: + Music.setFMoctaves(value+1); + break; + case LFO1: + if(value) { + Music.setOsc1LFO(true); + Music.setFrequency1(Music.getNoteFrequency(value)/1024.0); + } else { + Music.setOsc1LFO(false); + } +// if(Music.osc1LFO) Music.setFrequency1(Music.getNoteFrequency(value)/1024.0); +// else Music.setFrequency1(Music.getNoteFrequency(value)); + break; + case LFO2: + if(value) { + Music.setOsc2LFO(true); + Music.setFrequency2(Music.getNoteFrequency(value)/1024.0); + } else { + Music.setOsc2LFO(false); + } + // if(Music.osc2LFO) Music.setFrequency2(Music.getNoteFrequency(value)/1024.0); +// else Music.setFrequency2(Music.getNoteFrequency(value)); + break; + case LFO3: + if(value) { + Music.setOsc3LFO(true); + Music.setFrequency3(Music.getNoteFrequency(value)/1024.0); + } else { + Music.setOsc3LFO(false); + } + // if(Music.osc3LFO) Music.setFrequency3(Music.getNoteFrequency(value)/1024.0); +// else Music.setFrequency3(Music.getNoteFrequency(value)); + break; + case DETUNE1: + Music.setDetune1(map(value,0,127,-100,100)*0.0005946); + break; + case DETUNE2: + Music.setDetune2(map(value,0,127,-100,100)*0.0005946); + //Music.setDetune2((value-64.0)*0.0005946); + //Music.setDetune2(value/5120.0); + break; + case DETUNE3: + Music.setDetune3(map(value,0,127,-100,100)*0.0005946); + //Music.setDetune3((value-64.0)*0.0005946); + //Music.setDetune3(value/5120.0); + break; + case SEMITONE1: +// if(15 < value && value < 113) { +// int8_t val = (((value-16)/2)-24); +// Music.setSemitone1(val); +// } else if (value < 16) { +// Music.setSemitone1(-24); +// } else { +// Music.setSemitone1(24); +// } + if(40 <= value && value <= 88) { + Music.setSemitone1(value-64); + } else if (value < 40) { + Music.setSemitone1(-24); + } else { + Music.setSemitone1(24); + } + break; + case SEMITONE2: +// if(15 < value && value < 113) { +// int8_t val = (((value-16)/2)-24); +// Music.setSemitone2(val); +// } else if (value < 16) { +// Music.setSemitone2(-24); +// } else { +// Music.setSemitone2(24); +// } + if(40 <= value && value <= 88) { + Music.setSemitone2(value-64); + } else if (value < 40) { + Music.setSemitone2(-24); + } else { + Music.setSemitone2(24); + } + break; + case SEMITONE3: +// if(15 < value && value < 113) { +// int8_t val = (((value-16)/2)-24); +// Music.setSemitone3(val); +// } else if (value < 16) { +// Music.setSemitone3(-24); +// } else { +// Music.setSemitone3(24); +// } + if(40 <= value && value <= 88) { + Music.setSemitone3(value-64); + } else if (value < 40) { + Music.setSemitone3(-24); + } else { + Music.setSemitone3(24); + } + break; + case GAIN1: + Music.setGain1(value / 127.0); + break; + case GAIN2: + Music.setGain2(value / 127.0); + break; + case GAIN3: + Music.setGain3(value / 127.0); + break; + case WAVEFORM1: + Music.setWaveform1(value); + break; + case WAVEFORM2: + Music.setWaveform2(value); + break; + case WAVEFORM3: + Music.setWaveform3(value); + break; + case FM1: + Music.setFM1(value); + break; + case FM2: + Music.setFM2(value); + break; + case FM3: + Music.setFM3(value); + break; +// case FM1_OCTAVES: +// Music.setFM1octaves(value+1); +// break; +// case FM2_OCTAVES: +// Music.setFM2octaves(value+1); +// break; +// case FM3_OCTAVES: +// Music.setFM3octaves(value+1); +// break; + case FM1_SOURCE: + Music.setFM1Source(value); + break; + case FM2_SOURCE: + Music.setFM2Source(value); + break; + case FM3_SOURCE: + Music.setFM3Source(value); + break; + case FM1_SHAPE: + Music.setFM1Shape(value); + break; + case FM2_SHAPE: + Music.setFM2Shape(value); + break; + case FM3_SHAPE: + Music.setFM3Shape(value); + break; + case ENV1_ENABLE: + if(value) Music.enableEnvelope1(); + else Music.disableEnvelope1(); + break; + case ENV1_ATTACK: + Music.setEnv1Attack(value); + break; + case ENV1_DECAY: + Music.setEnv1Decay(value); + break; + case ENV1_SUSTAIN: + Music.setEnv1Sustain(value); + break; + case ENV1_RELEASE: + Music.setEnv1Release(value); + break; + case ENV2_ENABLE: + if(value) Music.enableEnvelope2(); + else Music.disableEnvelope2(); + break; + case ENV2_ATTACK: + Music.setEnv2Attack(value); + break; + case ENV2_DECAY: + Music.setEnv2Decay(value); + break; + case ENV2_SUSTAIN: + Music.setEnv2Sustain(value); + break; + case ENV2_RELEASE: + Music.setEnv2Release(value); + break; + case PRESET_SAVE: + Music.savePreset(value); + break; + case PRESET_RECALL: + Music.getPreset(value); + Music.sendInstrument(); + break; + case CFO_COMMAND: + Music.setCommandFlag(value); + break; + default: + break; + } +} + + +void MMidi::programChange(uint8_t channel, uint8_t number) { + Music.getPreset(number); +} + + +void MMidi::channelPressure(uint8_t channel, uint8_t pressure) { + // Write code here for Channel Pressure +} + + +void MMidi::pitchWheel(uint8_t channel, uint8_t highBits, uint8_t lowBits) { + // Write code here for Pitch Wheel +} + diff --git a/uSynth.h b/uSynth.h new file mode 100644 index 0000000..4cfd9a9 --- /dev/null +++ b/uSynth.h @@ -0,0 +1,683 @@ +/* + Synth.h - Friction Music library + Copyright (c) 2013 Science Friction. + All right reserved. + + This library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your optionosc1modShape_ptr) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser Public License for more details. + + You should have received a copy of the GNU Lesser Public License + along with Foobar. If not, see . + + +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + author: Jakob Bak + + contact: j.bak@ciid.dk + */ + + +#include +#include +#include "MCP4251.h" +#include +#include + +#ifndef Synth_h // include guard +#define Synth_h + +// Useful bit constants +#define BIT_8 256 +#define BIT_12 4096 +#define BIT_16 65536 +#define BIT_20 1048576 +#define BIT_24 16777216 +#define BIT_28 268435456 +#define BIT_32 4294967296 +#define MAX_SAMPLE 32767 +#define MIN_SAMPLE -32768 + +// Constants for bitvalues within the TCTRL1 register +#define TIE 2 +#define TEN 1 +#define TIF 1 + +// Constants for bitvalues for DAC output A and B +#define DAC_A 0 +#define DAC_B 1 +// Constants for positions for control bits in dacSettings +#define DAC_AB 7 +#define DAC_BUF 6 +#define DAC_GA 5 +#define DAC_SHDN 4 + +// Output pin for cutoff filter on Monotron +#define CUTOFF_PIN 3 + +// Multiplexer Pins (CD4052) +#define MUX_A 8 +#define MUX_B 7 + + +#if defined __MK20DX128__ +#define LP6 0 +#define HP6 1 +#define BP6 2 +#define LP24 4 +#define HP24 5 +#define BP24 6 +#define MOOG 3 +#define THRU 7 + +#else +#define LP6 4 +#define HP6 5 +#define BP6 2 +#define LP24 0 +#define HP24 1 +#define BP24 6 +#define MOOG 3 +#define THRU 7 +#endif + +// SPI pins +#define MCP4251_CS 9 // Digital 9 +#define DAC_CS 10 // Digital 10 + +#define SAMPLE_RATE 48000 +#define CPU_FREQ 96 // in MHz +#define PERIOD_MAX BIT_32 + +// Specify highest and lowest pitch in Hz +#define LOW_PITCH 55 +#define HIGH_PITCH 1000 + +// Shortnames for waveforms +#define SINE 0 +#define SQUARE 1 +#define PULSE 2 +#define TRIANGLE 3 +#define SAW 4 +#define FUZZ 5 +#define DIGI1 6 +#define DIGI2 7 +#define DIGI3 8 +#define DIGI4 9 +#define NOISE 10 +#define DIGI6 11 +#define TAN1 12 +#define TAN2 13 +#define TAN3 14 +#define TAN4 15 + +#define WAVEFORM_TRIANGLE 0 +#define WAVEFORM_SAW 1 +#define WAVEFORM_SQUARE 2 +#define WAVEFORM_ALTERNATE 3 + +// Maximum possible value for amplification envelope in audio code +#define MAX_ENV_GAIN 65535 +#define MIN_ENV_GAIN -65535 + +// MIDI specific constants + +#define MIDI_SERIAL Serial1 +#define MIDI_THROUGH true + +#ifndef MIDI_CHANNEL + #define MIDI_CHANNEL 1 +#elif (MIDI_CHANNEL > 0)&&(MIDI_CHANNEL < 17) +#else + #error MIDI_CHANNEL should be between 1 - 16 +#endif + +// parameters for modulation +#define MOD_FULL 0 +#define MOD_ENV1 1 +#define MOD_ENV2 2 +//#define MOD_ENV0 9 +#define MOD_OSC1 3 +#define MOD_OSC2 4 +#define MOD_OSC3 5 + +// parameters for presets || the two parameters below should multiply to 2048. +#define MAX_PRESETS 16 +#define PRESET_SIZE 128 + +#define BANK_U 0 +#define BANK_A 16 +#define BANK_B 32 +#define BANK_C 48 + +//synth functions and parameters as MIDI controller numbers +#define PRESET_SAVE 0 +#define PRESET_RECALL 1 + +#define IS_12_BIT 3 +#define CUTOFF 4 +#define ZERO_HZ_FM 5 +#define FM_OCTAVES 6 +#define RESONANCE 7 +#define PORTAMENTO 8 +#define FILTER_TYPE 9 + +#define LFO1 10 +#define SEMITONE1 11 +#define DETUNE1 12 +#define GAIN1 13 +#define WAVEFORM1 14 +#define FM1 15 +#define FM1_OCTAVES 16 +#define FM1_SOURCE 17 +#define FM1_SHAPE 18 +#define FREQUENCY1 19 + +#define LFO2 20 +#define SEMITONE2 21 +#define DETUNE2 22 +#define GAIN2 23 +#define WAVEFORM2 24 +#define FM2 25 +#define FM2_OCTAVES 26 +#define FM2_SOURCE 27 +#define FM2_SHAPE 28 +#define FREQUENCY2 29 + +#define LFO3 30 +#define SEMITONE3 31 +#define DETUNE3 32 +#define GAIN3 33 +#define WAVEFORM3 34 +#define FM3 35 +#define FM3_OCTAVES 36 +#define FM3_SOURCE 37 +#define FM3_SHAPE 38 +#define FREQUENCY3 39 + +#define CUTOFF_MOD_AMOUNT 70 +#define CUTOFF_MOD_DIRECTION 71 +#define CUTOFF_SOURCE 72 +#define CUTOFF_SHAPE 73 +#define RESONANCE_MOD_AMOUNT 74 +#define RESONANCE_MOD_DIRECTION 75 +#define RESONANCE_SOURCE 76 +#define RESONANCE_SHAPE 77 + +#define SEQ_WRITE_POSITION 80 +#define SEQ_WRITE_VALUE 81 +#define SEQ_START 82 +#define SEQ_STOP 83 +#define SEQ_PAUSE 84 +#define SEQ_JUMP_POSITION 85 +#define SEQ_BPM 86 +#define SEQ_SYNC 87 +#define SEQ_ON 88 + +#define CFO_COMMAND 90 +#define SEQ_STEP_FORWARD 91 + + +#define ENV0_VELOCITY 102 +#define ENV0_ENABLE 103 +#define ENV0_ATTACK 104 +#define ENV0_DECAY 105 +#define ENV0_SUSTAIN 106 +#define ENV0_RELEASE 107 + +#define ENV1_VELOCITY 112 +#define ENV1_ENABLE 113 +#define ENV1_ATTACK 114 +#define ENV1_DECAY 115 +#define ENV1_SUSTAIN 116 +#define ENV1_RELEASE 117 + +#define ENV2_VELOCITY 122 +#define ENV2_ENABLE 123 +#define ENV2_ATTACK 124 +#define ENV2_DECAY 125 +#define ENV2_SUSTAIN 126 +#define ENV2_RELEASE 127 + + +//int iSeq0,iSeq1; +// +//int iSeq_indx0 = 0; +//int iSeq_indx1 = 0; +//#define ISEQ_NBR_STEPS 32 +//const int iSeq_nbr_notes = 32; +//const int iSeq_nbr_steps = 32; +// +//int iSeq_notes[ISEQ_NBR_STEPS]; +//int iSeq_velocity[ISEQ_NBR_STEPS]; +//int iSeq_midi_numbers[ISEQ_NBR_STEPS]; +//int iSeq_midi_values[ISEQ_NBR_STEPS]; + + +// MMusic class for handling sound engine + +class MMusic { +public: + + // INITIALIZER + void init(); + void spi_setup(); + void set12bit(bool b); + bool is12bit; + + // PRESETS + void getPreset(uint8_t p); + void getRandomizedPreset(uint8_t p, uint8_t r); + void savePreset(uint8_t p); + void sendInstrument(); + void loadAllPresets(); + + // AUDIO INTERRUPT SERVICE ROUTINE + void synthInterrupt8bit(); + void synthInterrupt8bitFM(); + void synthInterrupt12bitSine(); + void synthInterrupt12bitSineFM(); + void synthInterrupt12bitSawFM(); + void phaseDistortionOscillator(); + + void envelope1(); + void envelope2(); + void envelopeRC(); + void amplifier(); + void sendToDAC(); // sending both sound and cutoff + void output2DAC(); // sending only sound + void output2T3DAC(); // sending sample to Teensy3.1 DAC on pin 14 + + // FILTER FUNCTIONS + void filter(); + void filterLP6dB(); + void filterHP6dB(); + void filterLP24dB(); + void filterHP24dB(); + void filterMoogLadder(); + void setCutoff(uint16_t c); +// void setResonance(uint8_t res); + void setResonance(uint32_t res); + void setFilterType(uint8_t type); + void setCutoffModAmount(int32_t amount); + void setCutoffModDirection(int32_t direction); + void setCutoffModSource(uint8_t source); + void setResonanceModSource(uint8_t source); + void setCutoffModShape(uint8_t shape); + void setResonanceModShape(uint8_t shape); + + void generateFilterCoefficientsMoogLadder(); + + bool lowpass; + bool highpass; + bool lowpass24dB; + bool highpass24dB; + bool moogLadder; + + + + // FREQUENCY AND DETUNE FUNCTIONS + void setFrequency(float frequency); + void setFrequency1(float frequency1); + void setFrequency2(float frequency2); + void setFrequency3(float frequency3); + void setSemitone1(int8_t semi); + void setSemitone2(int8_t semi); + void setSemitone3(int8_t semi); + void setDetune(float detune); + void setDetune1(float detune); + void setDetune2(float detune); + void setDetune3(float detune); + void setOsc1LFO(bool lfo); + void setOsc2LFO(bool lfo); + void setOsc3LFO(bool lfo); + void setFM1(uint8_t fm); + void setFM2(uint8_t fm); + void setFM3(uint8_t fm); + void setFMoctaves(uint8_t octs); // THIS SHOULD PROBABLY BE CALLED SOMETHING ELSE + void setFM1octaves(uint8_t octs); + void setFM2octaves(uint8_t octs); + void setFM3octaves(uint8_t octs); + void setFM1Source(uint8_t source); + void setFM2Source(uint8_t source); + void setFM3Source(uint8_t source); + void setFM1Shape(uint8_t shape); + void setFM2Shape(uint8_t shape); + void setFM3Shape(uint8_t shape); + void fmToZeroHertz(bool); // THIS SHOULD PROBABLY BE CALLED SOMETHING ELSE + void pitchBend(float b); // NOT IMPLEMENTED + void setPortamento(int32_t port); + + // WAVEFORM FUNCTIONS + void setWaveform(uint16_t waveForm); // JUST FOR 8bit WAVEFORMS + void setWaveform1(uint16_t waveForm); // + void setWaveform2(uint16_t waveForm); // + void setWaveform3(uint16_t waveForm); // + void setPhaseDistortion(uint16_t pd); + void setPhaseDistortion1(uint16_t pd); + void setPhaseDistortion2(uint16_t pd); + void setPhaseDistortion3(uint16_t pd); + void setWaveformPosition(uint32_t wp); + void setWaveformPosition1(uint32_t wp); + void setWaveformPosition2(uint32_t wp); + void setWaveformPosition3(uint32_t wp); + + int64_t vectorOscillator(int64_t phase, uint32_t wp, uint16_t pd); + + // GAIN FUNCTIONS + void setGain(float value); // 0.0 - 1.0 + void setGain1(float value); // 0.0 - 1.0 + void setGain2(float value); // 0.0 - 1.0 + void setGain3(float value); // 0.0 - 1.0 + float getGain(); // 0.0 - 1.0 + float getGain1(); // 0.0 - 1.0 + float getGain2(); // 0.0 - 1.0 + float getGain3(); // 0.0 - 1.0 + + // NOTE FUNCTIONS + void noteOn(uint8_t note, uint8_t vel); // 0 - 127 + void noteOn(uint8_t note); // 0 - 127 + void noteOff(uint8_t note); // 0 - 127 + void noteOff(); + float getNoteFrequency(uint8_t note); // 0 - 127 + + // ENVELOPE FUNCTIONS + void enableEnvelope1(); + void disableEnvelope1(); + void setEnv1Stage(uint8_t stage1); // 0 - 4 + void setEnv1Attack(uint8_t att); // 0 - 127 + void setEnv1Decay(uint8_t dec); // 0 - 127 + void setEnv1Sustain(uint8_t sus); // 0 - 127 + void setEnv1Release(uint8_t rel); // 0 - 127 + void setEnv1VelSustain(uint8_t vel); // 0 - 127 + void setEnv1VelPeak(uint8_t vel); // 0 - 127 + + void enableEnvelope2(); + void disableEnvelope2(); + void setEnv2Stage(uint8_t stage); // 0 - 4 + void setEnv2Attack(uint8_t att); // 0 - 127 + void setEnv2Decay(uint8_t dec); // 0 - 127 + void setEnv2Sustain(uint8_t sus); // 0 - 127 + void setEnv2Release(uint8_t rel); // 0 - 127 + void setEnv2VelSustain(uint8_t vel); // 0 - 127 + void setEnv2VelPeak(uint8_t vel); // 0 - 127 + + + void setCommandFlag(uint8_t flag); + void clearCommandFlag(uint8_t flag); + bool checkCommandFlag(uint8_t flag); + + bool osc1LFO; + bool osc2LFO; + bool osc3LFO; + + int32_t oscil1; + int32_t oscil2; + int32_t oscil3; + int32_t lastOscil1; + int32_t lastOscil2; + int32_t lastOscil3; + int64_t integralOfOscil1; + int64_t integralOfOscil2; + int64_t integralOfOscil3; + int64_t derivativeOfOscil1; + int64_t derivativeOfOscil2; + int64_t derivativeOfOscil3; + + // NOTE VARIABLE + uint8_t notePlayed; + uint8_t velocityPlayed; + + + +private: + // TIMER VARIABLES + uint32_t sampleRate; + + // WAVEFORM VARIABLES + uint16_t waveForm1; + uint16_t waveForm2; + uint16_t waveForm3; + uint16_t waveForm; + uint16_t waveform; + int64_t waveformVector[5]; + uint16_t phaseDistortion1; + uint16_t phaseDistortion2; + uint16_t phaseDistortion3; + uint32_t waveformPosition1; + uint32_t waveformPosition2; + uint32_t waveformPosition3; +// int16_t waveformVector[8]; + bool sine; + bool saw; + bool square; + + + + // FREQUENCY VARIABLES + uint16_t frequency16bit; + float frequency; + float frequency1; + float frequency2; + float frequency3; + float semi1; + float semi2; + float semi3; + float detune1; + float detune2; + float detune3; + float bend; + + // OSCILLATOR VARIABLES + int32_t period1; + int32_t period2; + int32_t period3; + int32_t portamento; + volatile int32_t dPhase1; + volatile int32_t dPhase2; + volatile int32_t dPhase3; + uint32_t accumulator1; + uint32_t accumulator2; + uint32_t accumulator3; + int32_t vectorAccumulator1; + int32_t vectorAccumulator2; + int32_t vectorAccumulator3; + int32_t index1; + int32_t index2; + int32_t index3; + int32_t fraction1; + int32_t fraction2; + int32_t fraction3; + int64_t modulator1; + int64_t modulator2; + int64_t modulator3; + int32_t fullSignal; + int32_t invertSignal; + int32_t noSignal; + int32_t *osc1modSource_ptr; + int32_t *osc2modSource_ptr; + int32_t *osc3modSource_ptr; + int32_t *amp_modSource_ptr; + int32_t *osc1modShape_ptr; + int32_t *osc2modShape_ptr; + int32_t *osc3modShape_ptr; + int32_t *amp_modShape_ptr; + int32_t zeroFM; + int32_t fmAmount1; + int32_t fmAmount2; + int32_t fmAmount3; + int32_t fmOctaves1; + int32_t fmOctaves2; + int32_t fmOctaves3; + + + int32_t gain; + int32_t gain1; + int32_t gain2; + int32_t gain3; + + // FILTER VARIABLES + + int64_t a0; + int64_t a1; + int64_t a2; + int64_t a3; + int64_t a4; + + int64_t b0; + int64_t b1; + int64_t b2; + int64_t b3; + int64_t b4; + + int64_t x0; + int64_t x1; + int64_t x2; + int64_t x3; + int64_t x4; + + int64_t y0; + int64_t y1; + int64_t y2; + int64_t y3; + int64_t y4; + + int64_t xNew; + int64_t xOld; + int64_t yNew; + int64_t yOld; + int64_t feedbackSample; + + volatile int64_t u; + int64_t g; + int64_t gg; + int64_t ggg; + int64_t G; + int64_t Gstage; + volatile int64_t S; + + volatile int64_t k; + int64_t v1; + int64_t v2; + int64_t v3; + int64_t v4; + int64_t z1; + int64_t z2; + int64_t z3; + int64_t z4; + + uint16_t cutoff; + uint32_t resonance; + + int32_t cutoffModAmount; + int32_t cutoffModDirection; + int32_t *cutoffModSource_ptr; + int32_t *resonanceModSource_ptr; + int32_t *cutoffModShape_ptr; + int32_t *resonanceModShape_ptr; + + + int64_t lastSampleOutLP; + int64_t lastSampleInLP; + int64_t sampleOutLP; + int64_t sampleInLP; + int64_t lastSampleOutHP; + int64_t lastSampleInHP; + int64_t sampleOutHP; + int64_t sampleInHP; + + + // ENVELOPE VARIABLES + bool envelopeOn1; + int32_t env1; + int32_t env1Stage; + int32_t attack1; + int32_t decay1; + int32_t sustain1; + int32_t release1; + int32_t velSustain1; + int32_t velPeak1; + int32_t envTarget; + + bool envelopeOn2; + int32_t env2; + int32_t env2Stage; + int32_t attack2; + int32_t decay2; + int32_t sustain2; + int32_t release2; + int32_t velSustain2; + int32_t velPeak2; + + + + // final sample that goes to the DAC + volatile int64_t sample; + + + // the two bytes that go to the DAC over SPI for VCF and VCA + volatile uint8_t dacSPIA0; + volatile uint8_t dacSPIA1; + volatile uint8_t dacSPIB0; + volatile uint8_t dacSPIB1; + volatile uint8_t dacSetA; + volatile uint8_t dacSetB; + +}; + + +extern MMusic Music; + + +// MMidi class for handling MIDI implementation + +class MMidi { +public: + void init(); + void checkSerialMidi(); + void setChannel(uint8_t channel); + + void midiHandler(); + void noteOff(uint8_t channel, uint8_t note, uint8_t vel); + void noteOn(uint8_t channel, uint8_t note, uint8_t vel); + void aftertouch(uint8_t channel, uint8_t note, uint8_t pressure); + void controller(uint8_t channel, uint8_t number, uint8_t value); + void programChange(uint8_t channel, uint8_t number); + void channelPressure(uint8_t channel, uint8_t pressure); + void pitchWheel(uint8_t channel, uint8_t highBits, uint8_t lowBits); + void pitchChange(uint8_t channel, int pitch); // extra pitchWheel function for USB MIDI interfacing + + void sendNoteOff(uint8_t note); + void sendNoteOn(uint8_t note, uint8_t vel); + void sendController(uint8_t number, uint8_t value); + + void sendStep(); + + void iSeqNote(); + void iSeqController(); + + uint8_t midiChannel; + uint16_t frequency; + uint8_t notePlayed; + uint8_t velocityPlayed; + +private: + + // MIDI + uint8_t data; + uint8_t midiBuffer[3]; + + int midiBufferIndex; +}; + + +extern MMidi Midi; + + +#endif // Close guard Synth_h + +