PokittoLib with changes to lcd refresh etc.

Dependents:   Pokittris

Fork of Pokitto by Pokitto Community Team

This is a fork by user @Spinal, and is used in Pokittris for testing. Do not import this to your own program.

Committer:
spinal
Date:
Sun Oct 15 18:03:02 2017 +0000
Revision:
11:02ad9c807a21
Parent:
0:e8b8f36b4505
fixed 4color refreshRegion code

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Pokitto 0:e8b8f36b4505 1 /**************************************************************************/
Pokitto 0:e8b8f36b4505 2 /*!
Pokitto 0:e8b8f36b4505 3 @file Synth_wavefuncs.cpp
Pokitto 0:e8b8f36b4505 4 @author Jonne Valola
Pokitto 0:e8b8f36b4505 5
Pokitto 0:e8b8f36b4505 6 @section LICENSE
Pokitto 0:e8b8f36b4505 7
Pokitto 0:e8b8f36b4505 8 Software License Agreement (BSD License)
Pokitto 0:e8b8f36b4505 9
Pokitto 0:e8b8f36b4505 10 Copyright (c) 2016, Jonne Valola
Pokitto 0:e8b8f36b4505 11 All rights reserved.
Pokitto 0:e8b8f36b4505 12
Pokitto 0:e8b8f36b4505 13 Redistribution and use in source and binary forms, with or without
Pokitto 0:e8b8f36b4505 14 modification, are permitted provided that the following conditions are met:
Pokitto 0:e8b8f36b4505 15 1. Redistributions of source code must retain the above copyright
Pokitto 0:e8b8f36b4505 16 notice, this list of conditions and the following disclaimer.
Pokitto 0:e8b8f36b4505 17 2. Redistributions in binary form must reproduce the above copyright
Pokitto 0:e8b8f36b4505 18 notice, this list of conditions and the following disclaimer in the
Pokitto 0:e8b8f36b4505 19 documentation and/or other materials provided with the distribution.
Pokitto 0:e8b8f36b4505 20 3. Neither the name of the copyright holders nor the
Pokitto 0:e8b8f36b4505 21 names of its contributors may be used to endorse or promote products
Pokitto 0:e8b8f36b4505 22 derived from this software without specific prior written permission.
Pokitto 0:e8b8f36b4505 23
Pokitto 0:e8b8f36b4505 24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
Pokitto 0:e8b8f36b4505 25 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
Pokitto 0:e8b8f36b4505 26 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Pokitto 0:e8b8f36b4505 27 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
Pokitto 0:e8b8f36b4505 28 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
Pokitto 0:e8b8f36b4505 29 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
Pokitto 0:e8b8f36b4505 30 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
Pokitto 0:e8b8f36b4505 31 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Pokitto 0:e8b8f36b4505 32 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
Pokitto 0:e8b8f36b4505 33 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Pokitto 0:e8b8f36b4505 34 */
Pokitto 0:e8b8f36b4505 35 /**************************************************************************/
Pokitto 0:e8b8f36b4505 36
Pokitto 0:e8b8f36b4505 37 #include "Synth.h"
Pokitto 0:e8b8f36b4505 38
Pokitto 0:e8b8f36b4505 39 uint16_t noiseval, noiseval2;
Pokitto 0:e8b8f36b4505 40
Pokitto 0:e8b8f36b4505 41 void waveoff(OSC* o); void sqwave(OSC* o); void sawwave(OSC* o); void triwave(OSC* o); void noise(OSC* o); void tonenoise(OSC* o); void sample(OSC* o);
Pokitto 0:e8b8f36b4505 42 void noADSR(OSC* o); void attackFunc(OSC* o); void decayFunc(OSC* o); void releaseFunc(OSC* o);
Pokitto 0:e8b8f36b4505 43 void mix1(); void mix2(); void mix3(); void updateEnvelopes();
Pokitto 0:e8b8f36b4505 44
Pokitto 0:e8b8f36b4505 45 waveFunction Farr [] = {waveoff, sqwave, sawwave, triwave, noise, tonenoise};
Pokitto 0:e8b8f36b4505 46 envFunction Earr [] = {noADSR, attackFunc, decayFunc, releaseFunc};
Pokitto 0:e8b8f36b4505 47 mixFunction Marr [] = {updateEnvelopes,mix3,mix2,mix1}; // counts down
Pokitto 0:e8b8f36b4505 48 mixFunction HWMarr [] = {updateEnvelopes,mix3,mix2,mix1}; // counts down
Pokitto 0:e8b8f36b4505 49
Pokitto 0:e8b8f36b4505 50 /** SOUND FUNCTIONS **/
Pokitto 0:e8b8f36b4505 51
Pokitto 0:e8b8f36b4505 52 void waveoff(OSC* o){
Pokitto 0:e8b8f36b4505 53 o->output = 0;
Pokitto 0:e8b8f36b4505 54 }
Pokitto 0:e8b8f36b4505 55
Pokitto 0:e8b8f36b4505 56 void sqwave(OSC* o){
Pokitto 0:e8b8f36b4505 57 // square. If bit 16 set, its 2nd half of cycle and then output. if not, silence.
Pokitto 0:e8b8f36b4505 58 if (o->count & 0x8000) o->output = 0;
Pokitto 0:e8b8f36b4505 59 else o->output = 0xFFFF;
Pokitto 0:e8b8f36b4505 60 }
Pokitto 0:e8b8f36b4505 61
Pokitto 0:e8b8f36b4505 62 void sawwave(OSC* o){
Pokitto 0:e8b8f36b4505 63 // saw is just twice the count, so it happens 2 times in a cycle.
Pokitto 0:e8b8f36b4505 64 o->output = o->count << 1; // simple, eh ?
Pokitto 0:e8b8f36b4505 65 }
Pokitto 0:e8b8f36b4505 66
Pokitto 0:e8b8f36b4505 67 void triwave(OSC* o){
Pokitto 0:e8b8f36b4505 68 // exploit the fact that above 0x7FFF bit 16 will be set (ie. when on second side of cycle)
Pokitto 0:e8b8f36b4505 69 if (o->count & 0x8000) o->output = (~o->count) << 1; // counts down because complement goes other way
Pokitto 0:e8b8f36b4505 70 else o->output = o->count << 1; // count up on first side of cycle
Pokitto 0:e8b8f36b4505 71 }
Pokitto 0:e8b8f36b4505 72
Pokitto 0:e8b8f36b4505 73 void noise(OSC* o){
Pokitto 0:e8b8f36b4505 74 // Standard libc random gives 10-12 fps
Pokitto 0:e8b8f36b4505 75 // Xorshift16 gives 32-39 fps
Pokitto 0:e8b8f36b4505 76 // Xorshift8 gives
Pokitto 0:e8b8f36b4505 77
Pokitto 0:e8b8f36b4505 78 if (o->count > 0x8000) {
Pokitto 0:e8b8f36b4505 79 o->output = noiseval2;
Pokitto 0:e8b8f36b4505 80 //noiseval = random(0,0xFFFF);
Pokitto 0:e8b8f36b4505 81 noiseval = xorshift16();
Pokitto 0:e8b8f36b4505 82 //noiseval = xorshift8()*256;
Pokitto 0:e8b8f36b4505 83 }
Pokitto 0:e8b8f36b4505 84 else {
Pokitto 0:e8b8f36b4505 85 o->output = noiseval;
Pokitto 0:e8b8f36b4505 86 //noiseval2 = random(0,0xFFFF);
Pokitto 0:e8b8f36b4505 87 noiseval2 = xorshift16();
Pokitto 0:e8b8f36b4505 88 //noiseval2 = xorshift8()*256;
Pokitto 0:e8b8f36b4505 89 }
Pokitto 0:e8b8f36b4505 90 }
Pokitto 0:e8b8f36b4505 91
Pokitto 0:e8b8f36b4505 92 void tonenoise(OSC* o){
Pokitto 0:e8b8f36b4505 93 // square. If bit 16 set, its 2nd half of cycle and then output. if not, silence.
Pokitto 0:e8b8f36b4505 94 if (o->count & 0x8000) o->output = (xorshift16()>>6); //was 0
Pokitto 0:e8b8f36b4505 95 else o->output = (xorshift16()>>1) + 0x4000;//random(0,0xFFFF);
Pokitto 0:e8b8f36b4505 96 }
Pokitto 0:e8b8f36b4505 97
Pokitto 0:e8b8f36b4505 98 void sample(OSC* o) {
Pokitto 0:e8b8f36b4505 99
Pokitto 0:e8b8f36b4505 100 /*if (o->samplepos > o->samplelength ) o->samplepos = 0;
Pokitto 0:e8b8f36b4505 101
Pokitto 0:e8b8f36b4505 102 if (o->count > o->wcycle) {
Pokitto 0:e8b8f36b4505 103 o->count=0;
Pokitto 0:e8b8f36b4505 104 if (o->output) o->output = 0;
Pokitto 0:e8b8f36b4505 105 //else o->output = o->output=pgm_read_byte((uint32_t)(sfxBike) + o->inccount);
Pokitto 0:e8b8f36b4505 106 }*/
Pokitto 0:e8b8f36b4505 107 }
Pokitto 0:e8b8f36b4505 108