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 // Very simple clipping distortion
Clemo 0:cb80470434eb 20
Clemo 0:cb80470434eb 21 #include "atmegatron.h"
Clemo 0:cb80470434eb 22
Clemo 0:cb80470434eb 23 //lets and gets
Clemo 0:cb80470434eb 24 byte dist_amt;
Clemo 0:cb80470434eb 25
Clemo 0:cb80470434eb 26
Clemo 0:cb80470434eb 27 void Distortion_Let_Amt(byte newamt)
Clemo 0:cb80470434eb 28 {
Clemo 0:cb80470434eb 29 dist_amt = newamt;
Clemo 0:cb80470434eb 30 }
Clemo 0:cb80470434eb 31
Clemo 0:cb80470434eb 32
Clemo 0:cb80470434eb 33 byte Distortion_Get_Amt(void)
Clemo 0:cb80470434eb 34 {
Clemo 0:cb80470434eb 35 return dist_amt;
Clemo 0:cb80470434eb 36 }
Clemo 0:cb80470434eb 37
Clemo 0:cb80470434eb 38
Clemo 0:cb80470434eb 39 //process the wavetable
Clemo 0:cb80470434eb 40 void Distortion_Process(void)
Clemo 0:cb80470434eb 41 {
Clemo 0:cb80470434eb 42 byte i;
Clemo 0:cb80470434eb 43 int s;
Clemo 0:cb80470434eb 44 for (i=0; i<WAVE_LEN; i++) //cycle through wavetable
Clemo 0:cb80470434eb 45 {
Clemo 0:cb80470434eb 46 s = (int)Wave_Get_Process(i); //get wavetable sample
Clemo 0:cb80470434eb 47 s = s << dist_amt; //shift by dist_amt bits (0-7)
Clemo 0:cb80470434eb 48 if (s > 127) //clip sample if necessary
Clemo 0:cb80470434eb 49 {
Clemo 0:cb80470434eb 50 s = 127;
Clemo 0:cb80470434eb 51 }
Clemo 0:cb80470434eb 52 else if (s < -128)
Clemo 0:cb80470434eb 53 {
Clemo 0:cb80470434eb 54 s = -128;
Clemo 0:cb80470434eb 55 }
Clemo 0:cb80470434eb 56 Wave_Let_Process(i, (sample_t)s); //write back to wavetable
Clemo 0:cb80470434eb 57 }
Clemo 0:cb80470434eb 58 }
Clemo 0:cb80470434eb 59