PokittoLib is the library needed for programming the Pokitto DIY game console (www.pokitto.com)

Dependents:   YATTT sd_map_test cPong SnowDemo ... more

PokittoLib

Library for programming Pokitto hardware

How to Use

  1. Import this library to online compiler (see button "import" on the right hand side
  2. DO NOT import mbed-src anymore, a better version is now included inside PokittoLib
  3. Change My_settings.h according to your project
  4. Start coding!
Committer:
Pokitto
Date:
Fri Jan 05 02:19:51 2018 +0000
Revision:
28:958b71c4b92a
Parent:
17:10609a82d462
Sound level stored in EEPROM, sound output improved

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Pokitto 6:72f87b7c7400 1 /**************************************************************************/
Pokitto 6:72f87b7c7400 2 /*!
Pokitto 6:72f87b7c7400 3 @file Synth_mixfuncs.cpp
Pokitto 6:72f87b7c7400 4 @author Jonne Valola
Pokitto 6:72f87b7c7400 5
Pokitto 6:72f87b7c7400 6 @section LICENSE
Pokitto 6:72f87b7c7400 7
Pokitto 6:72f87b7c7400 8 Software License Agreement (BSD License)
Pokitto 6:72f87b7c7400 9
Pokitto 6:72f87b7c7400 10 Copyright (c) 2016, Jonne Valola
Pokitto 6:72f87b7c7400 11 All rights reserved.
Pokitto 6:72f87b7c7400 12
Pokitto 6:72f87b7c7400 13 Redistribution and use in source and binary forms, with or without
Pokitto 6:72f87b7c7400 14 modification, are permitted provided that the following conditions are met:
Pokitto 6:72f87b7c7400 15 1. Redistributions of source code must retain the above copyright
Pokitto 6:72f87b7c7400 16 notice, this list of conditions and the following disclaimer.
Pokitto 6:72f87b7c7400 17 2. Redistributions in binary form must reproduce the above copyright
Pokitto 6:72f87b7c7400 18 notice, this list of conditions and the following disclaimer in the
Pokitto 6:72f87b7c7400 19 documentation and/or other materials provided with the distribution.
Pokitto 6:72f87b7c7400 20 3. Neither the name of the copyright holders nor the
Pokitto 6:72f87b7c7400 21 names of its contributors may be used to endorse or promote products
Pokitto 6:72f87b7c7400 22 derived from this software without specific prior written permission.
Pokitto 6:72f87b7c7400 23
Pokitto 6:72f87b7c7400 24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
Pokitto 6:72f87b7c7400 25 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
Pokitto 6:72f87b7c7400 26 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Pokitto 6:72f87b7c7400 27 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
Pokitto 6:72f87b7c7400 28 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
Pokitto 6:72f87b7c7400 29 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
Pokitto 6:72f87b7c7400 30 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
Pokitto 6:72f87b7c7400 31 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Pokitto 6:72f87b7c7400 32 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
Pokitto 6:72f87b7c7400 33 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Pokitto 6:72f87b7c7400 34 */
Pokitto 6:72f87b7c7400 35 /**************************************************************************/
Pokitto 6:72f87b7c7400 36
Pokitto 6:72f87b7c7400 37 #include "PokittoGlobs.h"
Pokitto 6:72f87b7c7400 38 #include "Synth.h"
Pokitto 6:72f87b7c7400 39
Pokitto 6:72f87b7c7400 40 /** MIXING FUNCTIONS **/
Pokitto 6:72f87b7c7400 41
Pokitto 6:72f87b7c7400 42 char voltick=0; // i need to make volume changes even slower
Pokitto 6:72f87b7c7400 43 uint16_t arptick=0; // i need to make volume changes even slower
Pokitto 6:72f87b7c7400 44 int8_t bendtick = 0; // ditto for bend.
Pokitto 6:72f87b7c7400 45
Pokitto 6:72f87b7c7400 46
Pokitto 6:72f87b7c7400 47 void mix1(){
Pokitto 6:72f87b7c7400 48 // Track 1
Pokitto 6:72f87b7c7400 49 if (osc1.on) {
Pokitto 6:72f87b7c7400 50 Farr[osc1.wave](&osc1);
Pokitto 6:72f87b7c7400 51 #if PROJ_ARDUBOY > 0
Pokitto 6:72f87b7c7400 52 if (osc1.duration) {
Pokitto 6:72f87b7c7400 53 /**this is special for osc1 and is only used to emulate arduino Tone(); */
Pokitto 6:72f87b7c7400 54 osc1.duration--;
Pokitto 6:72f87b7c7400 55 } else osc1.on = 0;
Pokitto 6:72f87b7c7400 56 #endif
Pokitto 6:72f87b7c7400 57
Pokitto 6:72f87b7c7400 58 #ifdef POK_SIM
Pokitto 6:72f87b7c7400 59 soundbyte = (((osc1.output>>8) * (osc1.adsrvol >>8 )) >> 8) >> osc1.echodiv; // To output, shift back to 8-bit
Pokitto 6:72f87b7c7400 60 if (osc1.overdrive) soundbyte *= OVERDRIVE;
Pokitto 6:72f87b7c7400 61 if (osc1.kick ) soundbyte >>= 2;
Pokitto 6:72f87b7c7400 62 osc1.output = soundbyte;
Pokitto 6:72f87b7c7400 63 #else
Pokitto 6:72f87b7c7400 64 //OCR2B = osc1.output>>8;
Pokitto 17:10609a82d462 65 #if POK_ENABLE_SOUND > 0
Pokitto 6:72f87b7c7400 66 soundbyte = (((osc1.output>>8) * (osc1.adsrvol >>8 )) >> 8) >> osc1.echodiv; // To output, shift back to 8-bit
Pokitto 6:72f87b7c7400 67 if (osc1.overdrive) soundbyte *= OVERDRIVE;
Pokitto 6:72f87b7c7400 68 if (osc1.kick ) soundbyte >>= 2;
Pokitto 6:72f87b7c7400 69 osc1.output = soundbyte;
Pokitto 6:72f87b7c7400 70 #endif
Pokitto 6:72f87b7c7400 71 #endif
Pokitto 6:72f87b7c7400 72 }
Pokitto 6:72f87b7c7400 73 }
Pokitto 6:72f87b7c7400 74
Pokitto 6:72f87b7c7400 75 void mix2(){
Pokitto 6:72f87b7c7400 76 // Track 2
Pokitto 6:72f87b7c7400 77 if (osc2.on) {
Pokitto 6:72f87b7c7400 78 Farr[osc2.wave](&osc2);
Pokitto 6:72f87b7c7400 79 #ifdef POK_SIM
Pokitto 6:72f87b7c7400 80 soundbyte = (((osc2.output>>8) * (osc2.adsrvol >>8 )) >> 8) >> osc2.echodiv;
Pokitto 6:72f87b7c7400 81 if (osc2.overdrive) soundbyte *= OVERDRIVE;
Pokitto 6:72f87b7c7400 82 if (osc2.kick ) soundbyte >>= 2;
Pokitto 6:72f87b7c7400 83 osc2.output = soundbyte;
Pokitto 6:72f87b7c7400 84 #else
Pokitto 6:72f87b7c7400 85 //OCR2B = osc2.output>>8;
Pokitto 17:10609a82d462 86 #if POK_ENABLE_SOUND > 0
Pokitto 6:72f87b7c7400 87 soundbyte = (((osc2.output>>8) * (osc2.adsrvol >>8 )) >> 8) >> osc2.echodiv;
Pokitto 6:72f87b7c7400 88 if (osc2.overdrive) soundbyte *= OVERDRIVE;
Pokitto 6:72f87b7c7400 89 if (osc2.kick ) soundbyte >>= 2;
Pokitto 6:72f87b7c7400 90 osc2.output = soundbyte;
Pokitto 6:72f87b7c7400 91 #endif
Pokitto 6:72f87b7c7400 92 #endif
Pokitto 6:72f87b7c7400 93 }
Pokitto 6:72f87b7c7400 94 }
Pokitto 6:72f87b7c7400 95
Pokitto 6:72f87b7c7400 96 void mix3(){
Pokitto 6:72f87b7c7400 97 // Track 3
Pokitto 6:72f87b7c7400 98 if (osc3.on) {
Pokitto 6:72f87b7c7400 99 Farr[osc3.wave](&osc3);
Pokitto 6:72f87b7c7400 100 #ifdef POK_SIM
Pokitto 6:72f87b7c7400 101 soundbyte = (((osc3.output>>8) * (osc3.adsrvol >>8 )) >> 8) >> osc3.echodiv;
Pokitto 6:72f87b7c7400 102 if (osc3.overdrive) soundbyte *= OVERDRIVE;
Pokitto 6:72f87b7c7400 103 if (osc3.kick ) soundbyte >>= 2;
Pokitto 6:72f87b7c7400 104 osc3.output = soundbyte;
Pokitto 6:72f87b7c7400 105 #else
Pokitto 6:72f87b7c7400 106 //OCR2B = osc3.output>>8;
Pokitto 17:10609a82d462 107 #if POK_ENABLE_SOUND > 0
Pokitto 6:72f87b7c7400 108 soundbyte = (((osc3.output>>8) * (osc3.adsrvol >>8 )) >> 8) >> osc3.echodiv;
Pokitto 6:72f87b7c7400 109 if (osc3.overdrive) soundbyte *= OVERDRIVE;
Pokitto 6:72f87b7c7400 110 if (osc3.kick ) soundbyte >>= 2;
Pokitto 6:72f87b7c7400 111 osc3.output = soundbyte;
Pokitto 6:72f87b7c7400 112 #endif
Pokitto 6:72f87b7c7400 113 #endif
Pokitto 6:72f87b7c7400 114 }
Pokitto 6:72f87b7c7400 115 }
Pokitto 6:72f87b7c7400 116
Pokitto 6:72f87b7c7400 117 void updateEnvelopes(){
Pokitto 6:72f87b7c7400 118 //calculate volume envelopes, I do this to save cpu power
Pokitto 6:72f87b7c7400 119 if (arptick) --arptick;
Pokitto 6:72f87b7c7400 120 else {
Pokitto 6:72f87b7c7400 121 if (osc1.arpmode && osc1.on) {
Pokitto 6:72f87b7c7400 122 osc1.cinc = cincs[osc1.tonic+arptable[osc1.arpmode][osc1.arpstep]];
Pokitto 6:72f87b7c7400 123 osc1.arpstep++;
Pokitto 6:72f87b7c7400 124 if (osc1.arpstep==ARPSTEPMAX) osc1.arpstep = 0;
Pokitto 6:72f87b7c7400 125 arptick = ARPTICK << (3-osc1.arpspeed);
Pokitto 6:72f87b7c7400 126 }
Pokitto 6:72f87b7c7400 127 if (osc2.arpmode && osc2.on) {
Pokitto 6:72f87b7c7400 128 osc2.cinc = cincs[osc2.tonic+arptable[osc2.arpmode][osc2.arpstep]];
Pokitto 6:72f87b7c7400 129 osc2.arpstep++;
Pokitto 6:72f87b7c7400 130 if (osc2.arpstep==ARPSTEPMAX) osc2.arpstep = 0;
Pokitto 6:72f87b7c7400 131 arptick = ARPTICK << (3-osc2.arpspeed);
Pokitto 6:72f87b7c7400 132 }
Pokitto 6:72f87b7c7400 133 if (osc3.arpmode && osc3.on) {
Pokitto 6:72f87b7c7400 134 osc3.cinc = cincs[osc3.tonic+arptable[osc3.arpmode][osc3.arpstep]];
Pokitto 6:72f87b7c7400 135 osc3.arpstep++;
Pokitto 6:72f87b7c7400 136 if (osc3.arpstep==ARPSTEPMAX) osc3.arpstep = 0;
Pokitto 6:72f87b7c7400 137 arptick = ARPTICK << (3-osc3.arpspeed);
Pokitto 6:72f87b7c7400 138 }
Pokitto 6:72f87b7c7400 139
Pokitto 6:72f87b7c7400 140 }
Pokitto 6:72f87b7c7400 141
Pokitto 6:72f87b7c7400 142 if (voltick) --voltick;
Pokitto 6:72f87b7c7400 143 else {
Pokitto 6:72f87b7c7400 144 bendtick = !bendtick;
Pokitto 6:72f87b7c7400 145 if (osc1.on) Earr[osc1.adsrphase](&osc1);
Pokitto 6:72f87b7c7400 146 if (bendtick) osc1.pitchbend += osc1.bendrate; //slow bend to every second beat
Pokitto 6:72f87b7c7400 147 if (osc1.bendrate > 0 && osc1.pitchbend > osc1.maxbend) {
Pokitto 6:72f87b7c7400 148 osc1.pitchbend = osc1.maxbend;
Pokitto 6:72f87b7c7400 149 osc1.bendrate = 0; // STOP BENDING !
Pokitto 6:72f87b7c7400 150 }
Pokitto 6:72f87b7c7400 151 else if (osc1.bendrate < 0 && osc1.pitchbend < osc1.maxbend) {
Pokitto 6:72f87b7c7400 152 osc1.pitchbend = osc1.maxbend;
Pokitto 6:72f87b7c7400 153 osc1.bendrate = 0; // STOP BENDING !
Pokitto 6:72f87b7c7400 154 }
Pokitto 6:72f87b7c7400 155
Pokitto 6:72f87b7c7400 156 if (osc2.on) Earr[osc2.adsrphase](&osc2);
Pokitto 6:72f87b7c7400 157 if (bendtick) osc2.pitchbend += osc2.bendrate;
Pokitto 6:72f87b7c7400 158 if (osc2.bendrate > 0 && osc2.pitchbend > osc2.maxbend) osc2.pitchbend = osc2.maxbend;
Pokitto 6:72f87b7c7400 159 else if (osc2.bendrate < 0 && osc2.pitchbend < osc2.maxbend) osc2.pitchbend = osc2.maxbend;
Pokitto 6:72f87b7c7400 160
Pokitto 6:72f87b7c7400 161 if (osc3.on) Earr[osc3.adsrphase](&osc3);
Pokitto 6:72f87b7c7400 162 if (bendtick) osc3.pitchbend += osc3.bendrate;
Pokitto 6:72f87b7c7400 163 if (osc3.bendrate > 0 && osc3.pitchbend > osc3.maxbend) osc3.pitchbend = osc3.maxbend;
Pokitto 6:72f87b7c7400 164 else if (osc3.bendrate < 0 && osc3.pitchbend < osc3.maxbend) osc3.pitchbend = osc3.maxbend;
Pokitto 6:72f87b7c7400 165
Pokitto 6:72f87b7c7400 166 voltick = VOLTICK;
Pokitto 6:72f87b7c7400 167 }
Pokitto 6:72f87b7c7400 168 tick = 4;
Pokitto 6:72f87b7c7400 169 }
Pokitto 6:72f87b7c7400 170