PokittoLib is the library needed for programming the Pokitto DIY game console (www.pokitto.com)
Fork of PokittoLib by
Synth_wavefuncs.cpp
00001 /**************************************************************************/ 00002 /*! 00003 @file Synth_wavefuncs.cpp 00004 @author Jonne Valola 00005 00006 @section LICENSE 00007 00008 Software License Agreement (BSD License) 00009 00010 Copyright (c) 2016, Jonne Valola 00011 All rights reserved. 00012 00013 Redistribution and use in source and binary forms, with or without 00014 modification, are permitted provided that the following conditions are met: 00015 1. Redistributions of source code must retain the above copyright 00016 notice, this list of conditions and the following disclaimer. 00017 2. Redistributions in binary form must reproduce the above copyright 00018 notice, this list of conditions and the following disclaimer in the 00019 documentation and/or other materials provided with the distribution. 00020 3. Neither the name of the copyright holders nor the 00021 names of its contributors may be used to endorse or promote products 00022 derived from this software without specific prior written permission. 00023 00024 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY 00025 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00026 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00027 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY 00028 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00029 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00030 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00031 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00032 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00033 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00034 */ 00035 /**************************************************************************/ 00036 00037 #include "Synth.h " 00038 00039 uint16_t noiseval, noiseval2; 00040 00041 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); 00042 void noADSR(OSC* o); void attackFunc(OSC* o); void decayFunc(OSC* o); void releaseFunc(OSC* o); 00043 void mix1 (); void mix2(); void mix3(); void updateEnvelopes(); 00044 00045 waveFunction Farr [] = {waveoff, sqwave, sawwave, triwave, noise, tonenoise}; 00046 envFunction Earr [] = {noADSR, attackFunc, decayFunc, releaseFunc}; 00047 mixFunction Marr [] = {updateEnvelopes,mix3,mix2,mix1 }; // counts down 00048 mixFunction HWMarr [] = {updateEnvelopes,mix3,mix2,mix1 }; // counts down 00049 00050 /** SOUND FUNCTIONS **/ 00051 00052 void waveoff(OSC* o){ 00053 o->output = 0; 00054 } 00055 00056 void sqwave(OSC* o){ 00057 // square. If bit 16 set, its 2nd half of cycle and then output. if not, silence. 00058 if (o->count & 0x8000) o->output = 0; 00059 else o->output = 0xFFFF; 00060 } 00061 00062 void sawwave(OSC* o){ 00063 // saw is just twice the count, so it happens 2 times in a cycle. 00064 o->output = o->count << 1; // simple, eh ? 00065 } 00066 00067 void triwave(OSC* o){ 00068 // exploit the fact that above 0x7FFF bit 16 will be set (ie. when on second side of cycle) 00069 if (o->count & 0x8000) o->output = (~o->count) << 1; // counts down because complement goes other way 00070 else o->output = o->count << 1; // count up on first side of cycle 00071 } 00072 00073 void noise(OSC* o){ 00074 // Standard libc random gives 10-12 fps 00075 // Xorshift16 gives 32-39 fps 00076 // Xorshift8 gives 00077 00078 if (o->count > 0x8000) { 00079 o->output = noiseval2; 00080 //noiseval = random(0,0xFFFF); 00081 noiseval = xorshift16(); 00082 //noiseval = xorshift8()*256; 00083 } 00084 else { 00085 o->output = noiseval; 00086 //noiseval2 = random(0,0xFFFF); 00087 noiseval2 = xorshift16(); 00088 //noiseval2 = xorshift8()*256; 00089 } 00090 } 00091 00092 void tonenoise(OSC* o){ 00093 // square. If bit 16 set, its 2nd half of cycle and then output. if not, silence. 00094 if (o->count & 0x8000) o->output = (xorshift16()>>6); //was 0 00095 else o->output = (xorshift16()>>1) + 0x4000;//random(0,0xFFFF); 00096 } 00097 00098 void sample(OSC* o) { 00099 00100 /*if (o->samplepos > o->samplelength ) o->samplepos = 0; 00101 00102 if (o->count > o->wcycle) { 00103 o->count=0; 00104 if (o->output) o->output = 0; 00105 //else o->output = o->output=pgm_read_byte((uint32_t)(sfxBike) + o->inccount); 00106 }*/ 00107 } 00108
Generated on Tue Jul 12 2022 18:08:13 by 1.7.2