1 /* 2 Rakarrack Audio FX software 3 ShelfBoost.C - Tone Booster 4 Modified for rakarrack by Josep Andreu 5 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of version 2 of the GNU General Public License 8 as published by the Free Software Foundation. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License (version 2) for more details. 14 15 You should have received a copy of the GNU General Public License (version 2) 16 along with this program; if not, write to the Free Software Foundation, 17 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 19 */ 20 21 #include <stdio.h> 22 #include <stdlib.h> 23 #include <math.h> 24 #include "ShelfBoost.h" 25 26 27 28 ShelfBoost::ShelfBoost (float * efxoutl_, float * efxoutr_, double sample_rate, uint32_t intermediate_bufsize) 29 { 30 efxoutl = efxoutl_; 31 efxoutr = efxoutr_; 32 33 34 //default values 35 Ppreset = 0; 36 Pvolume = 50; 37 Pstereo = 0; 38 39 interpbuf = new float[intermediate_bufsize]; 40 RB1l = new AnalogFilter(7,3200.0f,0.5f,0,sample_rate, interpbuf); 41 RB1r = new AnalogFilter(7,3200.0f,0.5f,0,sample_rate, interpbuf); 42 43 44 cleanup (); 45 46 setpreset (Ppreset); 47 }; 48 49 ShelfBoost::~ShelfBoost () 50 { 51 delete RB1l; 52 delete RB1r; 53 delete[] interpbuf; 54 }; 55 56 /* 57 * Cleanup the effect 58 */ 59 void 60 ShelfBoost::cleanup () 61 { 62 63 RB1l->cleanup(); 64 RB1r->cleanup(); 65 66 }; 67 68 69 /* 70 * Effect output 71 */ 72 void 73 ShelfBoost::out (float * smpsl, float * smpsr, uint32_t period) 74 { 75 unsigned int i; 76 77 78 RB1l->filterout(smpsl,period); 79 if(Pstereo) RB1r->filterout(smpsr,period); 80 81 82 for(i=0; i<period; i++) { 83 smpsl[i]*=outvolume*u_gain; 84 if(Pstereo) smpsr[i]*=outvolume*u_gain; 85 } 86 87 if(!Pstereo) memcpy(smpsr,smpsl,sizeof(float)*period); 88 89 90 91 92 }; 93 94 95 /* 96 * Parameter control 97 */ 98 void 99 ShelfBoost::setvolume (int value) 100 { 101 Pvolume = value; 102 outvolume = (float)Pvolume / 127.0f; 103 104 }; 105 106 void 107 ShelfBoost::setpreset (int npreset) 108 { 109 const int PRESET_SIZE = 5; 110 const int NUM_PRESETS = 4; 111 int pdata[PRESET_SIZE]; 112 int presets[NUM_PRESETS][PRESET_SIZE] = { 113 //Trebble 114 {127, 64, 16000, 1, 24}, 115 //Mid 116 {127, 64, 4400, 1, 24}, 117 //Bass 118 {127, 64, 220, 1, 24}, 119 //Distortion 1 120 {6, 40, 12600, 1, 127} 121 122 }; 123 124 if(npreset>NUM_PRESETS-1) { 125 Fpre->ReadPreset(34,npreset-NUM_PRESETS+1,pdata); 126 for (int n = 0; n < PRESET_SIZE; n++) 127 changepar (n, pdata[n]); 128 } else { 129 for (int n = 0; n < PRESET_SIZE; n++) 130 changepar (n, presets[npreset][n]); 131 } 132 Ppreset = npreset; 133 cleanup (); 134 135 }; 136 137 138 void 139 ShelfBoost::changepar (int npar, int value) 140 { 141 switch (npar) { 142 case 0: 143 setvolume (value); 144 break; 145 case 1: 146 Pq1 = value; 147 q1 = powf (30.0f, ((float)value - 64.0f) / 64.0f); 148 RB1l->setq(q1); 149 RB1r->setq(q1); 150 break; 151 case 2: 152 Pfreq1 = value; 153 freq1 = (float) value; 154 RB1l->setfreq(freq1); 155 RB1r->setfreq(freq1); 156 break; 157 case 3: 158 Pstereo = value; 159 break; 160 case 4: 161 Plevel = value; 162 gain = .375f * (float)value; 163 u_gain = 1.0f / gain; 164 RB1l->setgain(gain); 165 RB1r->setgain(gain); 166 break; 167 168 }; 169 }; 170 171 int 172 ShelfBoost::getpar (int npar) 173 { 174 switch (npar) { 175 case 0: 176 return (Pvolume); 177 break; 178 case 1: 179 return (Pq1); 180 break; 181 case 2: 182 return (Pfreq1); 183 break; 184 case 3: 185 return (Pstereo); 186 break; 187 case 4: 188 return (Plevel); 189 break; 190 191 }; 192 return (0); //in case of bogus parameter number 193 }; 194 195