This is a part of the Kinetiszer project.

Dependencies:   inc

Dependents:   kinetisizer

Committer:
Clemo
Date:
Tue Oct 28 20:09:12 2014 +0000
Revision:
1:8ae4ab73ca6a
Parent:
0:cb80470434eb
First publication (untested)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Clemo 0:cb80470434eb 1 /*
Clemo 0:cb80470434eb 2 Copyright 2013 Paul Soulsby www.soulsbysynths.com
Clemo 0:cb80470434eb 3 This file is part of Atmegatron.
Clemo 0:cb80470434eb 4
Clemo 0:cb80470434eb 5 Atmegatron is free software: you can redistribute it and/or modify
Clemo 0:cb80470434eb 6 it under the terms of the GNU General Public License as published by
Clemo 0:cb80470434eb 7 the Free Software Foundation, either version 3 of the License, or
Clemo 0:cb80470434eb 8 (at your option) any later version.
Clemo 0:cb80470434eb 9
Clemo 0:cb80470434eb 10 Atmegatron is distributed in the hope that it will be useful,
Clemo 0:cb80470434eb 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
Clemo 0:cb80470434eb 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Clemo 0:cb80470434eb 13 GNU General Public License for more details.
Clemo 0:cb80470434eb 14
Clemo 0:cb80470434eb 15 You should have received a copy of the GNU General Public License
Clemo 0:cb80470434eb 16 along with Atmegatron. If not, see <http://www.gnu.org/licenses/>.
Clemo 0:cb80470434eb 17 */
Clemo 0:cb80470434eb 18
Clemo 0:cb80470434eb 19 //*******THIS IS THE WAVE CRUSHER***************
Clemo 0:cb80470434eb 20
Clemo 0:cb80470434eb 21 #include "atmegatron.h"
Clemo 0:cb80470434eb 22
Clemo 0:cb80470434eb 23 //local vars
Clemo 0:cb80470434eb 24 byte sampshft = 8;
Clemo 0:cb80470434eb 25 byte samphold = 32;
Clemo 0:cb80470434eb 26
Clemo 0:cb80470434eb 27 //local lets and gets
Clemo 0:cb80470434eb 28 byte bitcrush_type = 0; //0=off
Clemo 0:cb80470434eb 29 boolean bitcrush_prefilt = false;
Clemo 0:cb80470434eb 30
Clemo 0:cb80470434eb 31 //lets and gets
Clemo 0:cb80470434eb 32 //set the bitcrush parameters
Clemo 0:cb80470434eb 33 void BitCrush_Let_Type(byte newtype)
Clemo 0:cb80470434eb 34 {
Clemo 0:cb80470434eb 35 if (newtype!=bitcrush_type){
Clemo 0:cb80470434eb 36 bitcrush_type = newtype;
Clemo 0:cb80470434eb 37 switch (bitcrush_type){
Clemo 0:cb80470434eb 38 case 0: //Bit crush off
Clemo 0:cb80470434eb 39 break;
Clemo 0:cb80470434eb 40 case 1:
Clemo 0:cb80470434eb 41 sampshft = 5; //sampshft decreases bit depth
Clemo 0:cb80470434eb 42 samphold = 1; //sampshft decrease sample frequency
Clemo 0:cb80470434eb 43 break;
Clemo 0:cb80470434eb 44 case 2:
Clemo 0:cb80470434eb 45 sampshft = 6;
Clemo 0:cb80470434eb 46 samphold = 1;
Clemo 0:cb80470434eb 47 break;
Clemo 0:cb80470434eb 48 case 3:
Clemo 0:cb80470434eb 49 sampshft = 7;
Clemo 0:cb80470434eb 50 samphold = 1;
Clemo 0:cb80470434eb 51 break;
Clemo 0:cb80470434eb 52 case 4:
Clemo 0:cb80470434eb 53 sampshft = 4;
Clemo 0:cb80470434eb 54 samphold = 2;
Clemo 0:cb80470434eb 55 break;
Clemo 0:cb80470434eb 56 case 5:
Clemo 0:cb80470434eb 57 sampshft = 5;
Clemo 0:cb80470434eb 58 samphold = 2;
Clemo 0:cb80470434eb 59 break;
Clemo 0:cb80470434eb 60 case 6:
Clemo 0:cb80470434eb 61 sampshft = 6;
Clemo 0:cb80470434eb 62 samphold = 2;
Clemo 0:cb80470434eb 63 break;
Clemo 0:cb80470434eb 64 case 7:
Clemo 0:cb80470434eb 65 sampshft = 7;
Clemo 0:cb80470434eb 66 samphold = 2;
Clemo 0:cb80470434eb 67 break;
Clemo 0:cb80470434eb 68 case 8:
Clemo 0:cb80470434eb 69 sampshft = 4;
Clemo 0:cb80470434eb 70 samphold = 4;
Clemo 0:cb80470434eb 71 break;
Clemo 0:cb80470434eb 72 case 9:
Clemo 0:cb80470434eb 73 sampshft = 5;
Clemo 0:cb80470434eb 74 samphold = 4;
Clemo 0:cb80470434eb 75 break;
Clemo 0:cb80470434eb 76 case 10:
Clemo 0:cb80470434eb 77 sampshft = 6;
Clemo 0:cb80470434eb 78 samphold = 4;
Clemo 0:cb80470434eb 79 break;
Clemo 0:cb80470434eb 80 case 11:
Clemo 0:cb80470434eb 81 sampshft = 7;
Clemo 0:cb80470434eb 82 samphold = 4;
Clemo 0:cb80470434eb 83 break;
Clemo 0:cb80470434eb 84 case 12:
Clemo 0:cb80470434eb 85 sampshft = 4;
Clemo 0:cb80470434eb 86 samphold = 8;
Clemo 0:cb80470434eb 87 break;
Clemo 0:cb80470434eb 88 case 13:
Clemo 0:cb80470434eb 89 sampshft = 5;
Clemo 0:cb80470434eb 90 samphold = 8;
Clemo 0:cb80470434eb 91 break;
Clemo 0:cb80470434eb 92 case 14:
Clemo 0:cb80470434eb 93 sampshft = 6;
Clemo 0:cb80470434eb 94 samphold = 8;
Clemo 0:cb80470434eb 95 break;
Clemo 0:cb80470434eb 96 case 15:
Clemo 0:cb80470434eb 97 sampshft = 7;
Clemo 0:cb80470434eb 98 samphold = 8;
Clemo 0:cb80470434eb 99 break;
Clemo 0:cb80470434eb 100 }
Clemo 0:cb80470434eb 101 }
Clemo 0:cb80470434eb 102 }
Clemo 0:cb80470434eb 103
Clemo 0:cb80470434eb 104
Clemo 0:cb80470434eb 105 byte BitCrush_Get_Type(void)
Clemo 0:cb80470434eb 106 {
Clemo 0:cb80470434eb 107 return bitcrush_type;
Clemo 0:cb80470434eb 108 }
Clemo 0:cb80470434eb 109
Clemo 0:cb80470434eb 110
Clemo 0:cb80470434eb 111 //set pre-filter mode. this processes the bitcrush before the filter (rather than before distortion)
Clemo 0:cb80470434eb 112 void BitCrush_Let_PreFilt(boolean newprefilt)
Clemo 0:cb80470434eb 113 {
Clemo 0:cb80470434eb 114 bitcrush_prefilt = newprefilt;
Clemo 0:cb80470434eb 115 }
Clemo 0:cb80470434eb 116
Clemo 0:cb80470434eb 117
Clemo 0:cb80470434eb 118 boolean BitCrush_Get_PreFilt(void)
Clemo 0:cb80470434eb 119 {
Clemo 0:cb80470434eb 120 return bitcrush_prefilt;
Clemo 0:cb80470434eb 121 }
Clemo 0:cb80470434eb 122
Clemo 0:cb80470434eb 123 //process the wavetable
Clemo 0:cb80470434eb 124 void BitCrush_Process(void)
Clemo 0:cb80470434eb 125 {
Clemo 0:cb80470434eb 126 byte i;
Clemo 0:cb80470434eb 127 sample_t samp = 0;
Clemo 0:cb80470434eb 128 for (i=0;i<WAVE_LEN;i++){ //cycle through wavetable
Clemo 0:cb80470434eb 129 if (i % samphold == 0){ //every samphold samples
Clemo 0:cb80470434eb 130 samp = Wave_Get_Process(i); //get the wavetable sample
Clemo 0:cb80470434eb 131 samp = samp >> sampshft; //shift sampshft bits, to reduce bit rate
Clemo 0:cb80470434eb 132 samp = samp << sampshft; //shift back again to restore amplitude
Clemo 0:cb80470434eb 133 }
Clemo 0:cb80470434eb 134 Wave_Let_Process(i, samp); //write back to wavetable
Clemo 0:cb80470434eb 135 }
Clemo 0:cb80470434eb 136 }