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 #include "atmegatron.h"
Clemo 0:cb80470434eb 20
Clemo 0:cb80470434eb 21 //lets and gets
Clemo 0:cb80470434eb 22 byte amp_lfoamt = 0;
Clemo 0:cb80470434eb 23
Clemo 0:cb80470434eb 24 //process wavetable
Clemo 0:cb80470434eb 25 void Amplitude_Process(void)
Clemo 0:cb80470434eb 26 {
Clemo 0:cb80470434eb 27 byte i;
Clemo 0:cb80470434eb 28 int samp;
Clemo 0:cb80470434eb 29 for (i=0; i<WAVE_LEN; i++)
Clemo 0:cb80470434eb 30 {
Clemo 0:cb80470434eb 31 samp = (int)Wave_Get_Process(i); //get wavetable sample
Clemo 0:cb80470434eb 32 samp = (samp * (int)Aenv_Get_Level()) >> 8; //multiply sample by current amp env level (0-255) and / 255
Clemo 0:cb80470434eb 33 if (amp_lfoamt>0)
Clemo 0:cb80470434eb 34 {
Clemo 0:cb80470434eb 35 samp = (samp * Amplitude_Get_LFOGain()) >> 8; //multiply sample by current amp lfo level (0-255) and / 255
Clemo 0:cb80470434eb 36 }
Clemo 0:cb80470434eb 37 Wave_Let_Process(i,(sample_t)samp); //write back to wavetable
Clemo 0:cb80470434eb 38 }
Clemo 0:cb80470434eb 39 }
Clemo 0:cb80470434eb 40
Clemo 0:cb80470434eb 41 //lets and gets
Clemo 0:cb80470434eb 42 void Amplitude_Let_LFOAmt(byte newamt) //amp lfo amount (0-255)
Clemo 0:cb80470434eb 43 {
Clemo 0:cb80470434eb 44 amp_lfoamt = newamt;
Clemo 0:cb80470434eb 45 }
Clemo 0:cb80470434eb 46
Clemo 0:cb80470434eb 47
Clemo 0:cb80470434eb 48 byte Amplitude_Get_LFOAmt(void)
Clemo 0:cb80470434eb 49 {
Clemo 0:cb80470434eb 50 return amp_lfoamt;
Clemo 0:cb80470434eb 51 }
Clemo 0:cb80470434eb 52
Clemo 0:cb80470434eb 53 //calculate current amp LFO level
Clemo 0:cb80470434eb 54 byte Amplitude_Get_LFOGain(void)
Clemo 0:cb80470434eb 55 {
Clemo 0:cb80470434eb 56 int lfo_gain = 0; //255 = unity,
Clemo 0:cb80470434eb 57 lfo_gain = 253 - (amp_lfoamt * (127 - (int)LFO_Get_Level()) >> 8); //253 - (lfo amount * inverse current LFO level (-127to127)) / 256 (253, not 255, coz LFO range is (-127to127)
Clemo 0:cb80470434eb 58 return (byte)lfo_gain;
Clemo 0:cb80470434eb 59 }