| @@ -123,6 +123,16 @@ float t808Hihat_tick(t808Hihat* const hihat) { · 122 unmodified lines |
| 123 | float sample = 0.0f; | 123 | float sample = 0.0f; |
| 124 | float gainScale = 0.1666f; | 124 | float gainScale = 0.1666f; |
| 125 | | 125 | |
| | 126 | |
| | 127 | float myNoise = tNoise_tick(&hihat->n); |
| | 128 | |
| | 129 | tSquare_setFreq(&hihat->p[0], ((2.0f + hihat->stretch) * hihat->freq)); |
| | 130 | tSquare_setFreq(&hihat->p[1], ((3.00f + hihat->stretch) * hihat->freq)); |
| | 131 | tSquare_setFreq(&hihat->p[2], ((4.16f + hihat->stretch) * hihat->freq)); |
| | 132 | tSquare_setFreq(&hihat->p[3], ((5.43f + hihat->stretch) * hihat->freq)); |
| | 133 | tSquare_setFreq(&hihat->p[4], ((6.79f + hihat->stretch) * hihat->freq)); |
| | 134 | tSquare_setFreq(&hihat->p[5], ((8.21f + hihat->stretch) * hihat->freq)); |
| | 135 | |
| 126 | for (int i = 0; i < 6; i++) | 136 | for (int i = 0; i < 6; i++) |
| 127 | { | 137 | { |
| 128 | sample += tSquare_tick(&hihat->p[i]); | 138 | sample += tSquare_tick(&hihat->p[i]); |
| @@ -130,22 +140,23 @@ float t808Hihat_tick(t808Hihat* const hihat) { · 1 unmodified line |
| 130 | | 140 | |
| 131 | sample *= gainScale; | 141 | sample *= gainScale; |
| 132 | | 142 | |
| 133 | sample = (hihat->oscNoiseMix * sample) + ((1.0f-hihat->oscNoiseMix) * (0.8f * tNoise_tick(&hihat->n))); | 143 | sample = (hihat->oscNoiseMix * sample) + ((1.0f-hihat->oscNoiseMix) * myNoise); |
| 134 | | 144 | |
| 135 | sample = tSVF_tick(&hihat->bandpassOsc, sample); | 145 | sample = tSVF_tick(&hihat->bandpassOsc, sample); |
| 136 | | 146 | |
| 137 | sample *= tEnvelope_tick(&hihat->envGain); | 147 | float myGain = tEnvelope_tick(&hihat->envGain); |
| 138 | | 148 | sample *= (myGain*myGain);//square the output gain envelope |
| 139 | sample = 0.85f * LEAF_clip(0.0f, tHighpass_tick(&hihat->highpass, sample), 1.0f); | 149 | sample = tHighpass_tick(&hihat->highpass, sample); |
| 140 | | 150 | sample += ((0.5f * tEnvelope_tick(&hihat->envStick)) * tSVF_tick(&hihat->bandpassStick, tNoise_tick(&hihat->stick))); |
| 141 | sample += 0.15f * tEnvelope_tick(&hihat->envStick) * tSVF_tick(&hihat->bandpassStick, tNoise_tick(&hihat->stick)); | 151 | sample = tanhf(sample * 2.0f); |
| 142 | | 152 | |
| 143 | return sample; | 153 | return sample; |
| 144 | } | 154 | } |
| 145 | | 155 | |
| 146 | void t808Hihat_setDecay(t808Hihat* const hihat, float decay) | 156 | void t808Hihat_setDecay(t808Hihat* const hihat, float decay) |
| 147 | { | 157 | { |
| 148 | tEnvelope_setDecay(&hihat->envGain,decay); | 158 | tEnvelope_setDecay(&hihat->envGain,decay); |
| | 159 | tEnvelope_setDecay(&hihat->noiseFMGain,decay); |
| 149 | } | 160 | } |
| 150 | | 161 | |
| 151 | void t808Hihat_setHighpassFreq(t808Hihat* const hihat, float freq) | 162 | void t808Hihat_setHighpassFreq(t808Hihat* const hihat, float freq) |
| @@ -153,21 +164,35 @@ void t808Hihat_setHighpassFreq(t808Hihat* const hihat, float freq) · 1 unmodified line |
| 153 | tHighpass_setFreq(&hihat->highpass,freq); | 164 | tHighpass_setFreq(&hihat->highpass,freq); |
| 154 | } | 165 | } |
| 155 | | 166 | |
| | 167 | void t808Hihat_setStretch(t808Hihat* const hihat, float stretch) |
| | 168 | { |
| | 169 | hihat->stretch = stretch; |
| | 170 | } |
| | 171 | |
| | 172 | void t808Hihat_setFM(t808Hihat* const hihat, float FM_amount) |
| | 173 | { |
| | 174 | hihat->FM_amount = FM_amount; |
| | 175 | } |
| | 176 | |
| 156 | void t808Hihat_setOscBandpassFreq(t808Hihat* const hihat, float freq) | 177 | void t808Hihat_setOscBandpassFreq(t808Hihat* const hihat, float freq) |
| 157 | { | 178 | { |
| 158 | tSVF_setFreq(&hihat->bandpassOsc,freq); | 179 | tSVF_setFreq(&hihat->bandpassOsc,freq); |
| 159 | } | 180 | } |
| 160 | | 181 | |
| | 182 | void t808Hihat_setOscBandpassQ(t808Hihat* const hihat, float Q) |
| | 183 | { |
| | 184 | tSVF_setQ(&hihat->bandpassOsc,Q); |
| | 185 | } |
| | 186 | |
| | 187 | void t808Hihat_setStickBandPassFreq(t808Hihat* const hihat, float freq) |
| | 188 | { |
| | 189 | tSVF_setFreq(&hihat->bandpassStick,freq); |
| | 190 | } |
| | 191 | |
| 161 | | 192 | |
| 162 | void t808Hihat_setOscFreq(t808Hihat* const hihat, float freq) | 193 | void t808Hihat_setOscFreq(t808Hihat* const hihat, float freq) |
| 163 | { | 194 | { |
| 164 | tSquare_setFreq(&hihat->p[0], 2.0f * freq); | 195 | hihat->freq = freq; |
| 165 | tSquare_setFreq(&hihat->p[1], 3.00f * freq); | | |
| 166 | tSquare_setFreq(&hihat->p[2], 4.16f * freq); | | |
| 167 | tSquare_setFreq(&hihat->p[3], 5.43f * freq); | | |
| 168 | tSquare_setFreq(&hihat->p[4], 6.79f * freq); | | |
| 169 | tSquare_setFreq(&hihat->p[5], 8.21f * freq); | | |
| 170 | | | |
| 171 | } | 196 | } |
| 172 | | 197 | |
| 173 | void t808Hihat_init(t808Hihat* const hihat) | 198 | void t808Hihat_init(t808Hihat* const hihat) |
| @@ -184,19 +209,22 @@ void t808Hihat_init(t808Hihat* const hihat) · 10 unmodified lines |
| 184 | tSVF_init(&hihat->bandpassStick, SVFTypeBandpass,2500.0,1.5f); | 209 | tSVF_init(&hihat->bandpassStick, SVFTypeBandpass,2500.0,1.5f); |
| 185 | tSVF_init(&hihat->bandpassOsc, SVFTypeBandpass,3500,0.5f); | 210 | tSVF_init(&hihat->bandpassOsc, SVFTypeBandpass,3500,0.5f); |
| 186 | | 211 | |
| 187 | tEnvelope_init(&hihat->envGain, 5.0f, 50.0f, OFALSE); | 212 | tEnvelope_init(&hihat->envGain, 0.0f, 50.0f, OFALSE); |
| 188 | tEnvelope_init(&hihat->envStick, 5.0f, 15.0f, OFALSE); | 213 | tEnvelope_init(&hihat->noiseFMGain, 0.0f, 500.0f, OFALSE); |
| 189 | | 214 | tEnvelope_init(&hihat->envStick, 0.0f, 4.0f, OFALSE); |
| | 215 | |
| 190 | tHighpass_init(&hihat->highpass, 7000.0f); | 216 | tHighpass_init(&hihat->highpass, 7000.0f); |
| 191 | | 217 | |
| 192 | float freq = 40.0f; | 218 | hihat->freq = 40.0f; |
| | 219 | hihat->stretch = 0.0f; |
| | 220 | hihat->FM_amount = 1000.0f; |
| 193 | | 221 | |
| 194 | tSquare_setFreq(&hihat->p[0], 2.0f * freq); | 222 | tSquare_setFreq(&hihat->p[0], 2.0f * hihat->freq); |
| 195 | tSquare_setFreq(&hihat->p[1], 3.00f * freq); | 223 | tSquare_setFreq(&hihat->p[1], 3.00f * hihat->freq); |
| 196 | tSquare_setFreq(&hihat->p[2], 4.16f * freq); | 224 | tSquare_setFreq(&hihat->p[2], 4.16f * hihat->freq); |
| 197 | tSquare_setFreq(&hihat->p[3], 5.43f * freq); | 225 | tSquare_setFreq(&hihat->p[3], 5.43f * hihat->freq); |
| 198 | tSquare_setFreq(&hihat->p[4], 6.79f * freq); | 226 | tSquare_setFreq(&hihat->p[4], 6.79f * hihat->freq); |
| 199 | tSquare_setFreq(&hihat->p[5], 8.21f * freq); | 227 | tSquare_setFreq(&hihat->p[5], 8.21f * hihat->freq); |
| 200 | } | 228 | } |
| 201 | | 229 | |
| 202 | void t808Snare_on(t808Snare* const snare, float vel) | 230 | void t808Snare_on(t808Snare* const snare, float vel) |
| @@ -262,19 +290,19 @@ float t808Snare_tick(t808Snare* const snare) · 59 unmodified lines |
| 262 | { | 290 | { |
| 263 | for (int i = 0; i < 2; i++) | 291 | for (int i = 0; i < 2; i++) |
| 264 | { | 292 | { |
| 265 | tTriangle_setFreq(&snare->tone[i], snare->tone1Freq + (50.0f * tEnvelope_tick(&snare->toneEnvOsc[i]))); | 293 | tTriangle_setFreq(&snare->tone[i], snare->tone1Freq + (20.0f * tEnvelope_tick(&snare->toneEnvOsc[i]))); |
| 266 | tone[i] = tTriangle_tick(&snare->tone[i]); | 294 | tone[i] = tTriangle_tick(&snare->tone[i]); |
| 267 | | 295 | |
| 268 | tSVF_setFreq(&snare->toneLowpass[i], 2000 + (500 * tEnvelope_tick(&snare->toneEnvFilter[i]))); | 296 | tSVF_setFreq(&snare->toneLowpass[i], 2000.0f + (500.0f * tEnvelope_tick(&snare->toneEnvFilter[i]))); |
| 269 | tone[i] = tSVF_tick(&snare->toneLowpass[i], tone[i]) * tEnvelope_tick(&snare->toneEnvGain[i]); | 297 | tone[i] = tSVF_tick(&snare->toneLowpass[i], tone[i]) * tEnvelope_tick(&snare->toneEnvGain[i]); |
| 270 | } | 298 | } |
| 271 | | 299 | |
| 272 | float noise = tNoise_tick(&snare->noiseOsc); | 300 | float noise = tNoise_tick(&snare->noiseOsc); |
| 273 | tSVF_setFreq(&snare->noiseLowpass, snare->noiseFilterFreq +(500 * tEnvelope_tick(&snare->noiseEnvFilter))); | 301 | tSVF_setFreq(&snare->noiseLowpass, snare->noiseFilterFreq + (1000.0f * tEnvelope_tick(&snare->noiseEnvFilter))); |
| 274 | noise = tSVF_tick(&snare->noiseLowpass, noise) * tEnvelope_tick(&snare->noiseEnvGain); | 302 | noise = tSVF_tick(&snare->noiseLowpass, noise) * tEnvelope_tick(&snare->noiseEnvGain); |
| 275 | | 303 | |
| 276 | float sample = (snare->toneNoiseMix)*(tone[0] * snare->toneGain[0] + tone[1] * snare->toneGain[1]) + (1.0f-snare->toneNoiseMix) * (noise * snare->noiseGain); | 304 | float sample = (snare->toneNoiseMix)*(tone[0] * snare->toneGain[0] + tone[1] * snare->toneGain[1]) + (1.0f-snare->toneNoiseMix) * (noise * snare->noiseGain); |
| 277 | | 305 | sample = tanhf(sample * 2.0f); |
| 278 | return sample; | 306 | return sample; |
| 279 | } | 307 | } |
| 280 | | 308 | |
| @@ -284,21 +312,24 @@ void t808Snare_init(t808Snare* const snare) · 3 unmodified lines |
| 284 | for (int i = 0; i < 2; i++) | 312 | for (int i = 0; i < 2; i++) |
| 285 | { | 313 | { |
| 286 | tTriangle_init(&snare->tone[i]); | 314 | tTriangle_init(&snare->tone[i]); |
| | 315 | |
| 287 | tTriangle_setFreq(&snare->tone[i], ratio[i] * 400.0f); | 316 | tTriangle_setFreq(&snare->tone[i], ratio[i] * 400.0f); |
| 288 | tSVF_init(&snare->toneLowpass[i], SVFTypeLowpass, 2000, 1.0f); | 317 | tSVF_init(&snare->toneLowpass[i], SVFTypeLowpass, 4000, 1.0f); |
| 289 | tEnvelope_init(&snare->toneEnvOsc[i], 3.0f, 20.0f, OFALSE); | 318 | tEnvelope_init(&snare->toneEnvOsc[i], 0.0f, 50.0f, OFALSE); |
| 290 | tEnvelope_init(&snare->toneEnvGain[i], 10.0f, 200.0f, OFALSE); | 319 | tEnvelope_init(&snare->toneEnvGain[i], 1.0f, 150.0f, OFALSE); |
| 291 | tEnvelope_init(&snare->toneEnvFilter[i], 3.0f, 200.0f, OFALSE); | 320 | tEnvelope_init(&snare->toneEnvFilter[i], 1.0f, 2000.0f, OFALSE); |
| 292 | | 321 | |
| 293 | snare->toneGain[i] = 0.5f; | 322 | snare->toneGain[i] = 0.5f; |
| 294 | } | 323 | } |
| 295 | | 324 | |
| 296 | | 325 | snare->tone1Freq = ratio[0] * 100.0f; |
| | 326 | snare->tone2Freq = ratio[1] * 100.0f; |
| | 327 | snare->noiseFilterFreq = 3000.0f; |
| 297 | tNoise_init(&snare->noiseOsc, WhiteNoise); | 328 | tNoise_init(&snare->noiseOsc, WhiteNoise); |
| 298 | tSVF_init(&snare->noiseLowpass, SVFTypeLowpass, 2000, 3.0f); | 329 | tSVF_init(&snare->noiseLowpass, SVFTypeLowpass, 12000.0f, 0.8f); |
| 299 | tEnvelope_init(&snare->noiseEnvGain, 10.0f, 125.0f, OFALSE); | 330 | tEnvelope_init(&snare->noiseEnvGain, 0.0f, 100.0f, OFALSE); |
| 300 | tEnvelope_init(&snare->noiseEnvFilter, 3.0f, 100.0f, OFALSE); | 331 | tEnvelope_init(&snare->noiseEnvFilter, 0.0f, 1000.0f, OFALSE); |
| 301 | snare->noiseGain = 0.3f; | 332 | snare->noiseGain = 1.0f; |
| 302 | } | 333 | } |
| 303 | | 334 | |
| 304 | void t808Snare_free (t808Snare* const snare) | 335 | void t808Snare_free (t808Snare* const snare) |
| @@ -320,3 +351,68 @@ void t808Snare_free (t808Snare* const snare) · 15 unmodified lines |
| 320 | } | 351 | } |
| 321 | | 352 | |
| 322 | | 353 | |
| | 354 | void t808Kick_init (t808Kick* const kick) |
| | 355 | { |
| | 356 | tCycle_init(&kick->tone); |
| | 357 | kick->toneInitialFreq = 40.0f; |
| | 358 | kick->sighAmountInHz = 7.0f; |
| | 359 | kick->chirpRatioMinusOne = 3.3f; |
| | 360 | tCycle_setFreq(&kick->tone, 50.0f); |
| | 361 | tSVF_init(&kick->toneLowpass, SVFTypeLowpass, 2000.0f, 0.5f); |
| | 362 | tEnvelope_init(&kick->toneEnvOscChirp, 0.0f, 20.0f, OFALSE); |
| | 363 | tEnvelope_init(&kick->toneEnvOscSigh, 0.0f, 2500.0f, OFALSE); |
| | 364 | tEnvelope_init(&kick->toneEnvGain, 0.0f, 800.0f, OFALSE); |
| | 365 | tNoise_init(&kick->noiseOsc, PinkNoise); |
| | 366 | tEnvelope_init(&kick->noiseEnvGain, 0.0f, 1.0f, OFALSE); |
| | 367 | kick->noiseGain = 0.3f; |
| | 368 | } |
| | 369 | |
| | 370 | |
| | 371 | void t808Kick_free (t808Kick* const kick) |
| | 372 | { |
| | 373 | tCycle_free(&kick->tone); |
| | 374 | tSVF_free(&kick->toneLowpass); |
| | 375 | tEnvelope_free(&kick->toneEnvOscChirp); |
| | 376 | tEnvelope_free(&kick->toneEnvOscSigh); |
| | 377 | tEnvelope_free(&kick->toneEnvGain); |
| | 378 | tNoise_free(&kick->noiseOsc); |
| | 379 | tEnvelope_free(&kick->noiseEnvGain); |
| | 380 | } |
| | 381 | |
| | 382 | float t808Kick_tick (t808Kick* const kick) |
| | 383 | { |
| | 384 | tCycle_setFreq(&kick->tone, (kick->toneInitialFreq * (1.0f + (kick->chirpRatioMinusOne * tEnvelope_tick(&kick->toneEnvOscChirp)))) + (kick->sighAmountInHz * tEnvelope_tick(&kick->toneEnvOscSigh))); |
| | 385 | float sample = tCycle_tick(&kick->tone) * tEnvelope_tick(&kick->toneEnvGain); |
| | 386 | sample+= tNoise_tick(&kick->noiseOsc) * tEnvelope_tick(&kick->noiseEnvGain); |
| | 387 | //add distortion here |
| | 388 | sample = tSVF_tick(&kick->toneLowpass, sample); |
| | 389 | return sample; |
| | 390 | } |
| | 391 | |
| | 392 | void t808Kick_on (t808Kick* const kick, float vel) |
| | 393 | { |
| | 394 | tEnvelope_on(&kick->toneEnvOscChirp, vel); |
| | 395 | tEnvelope_on(&kick->toneEnvOscSigh, vel); |
| | 396 | tEnvelope_on(&kick->toneEnvGain, vel); |
| | 397 | tEnvelope_on(&kick->noiseEnvGain, vel); |
| | 398 | |
| | 399 | } |
| | 400 | void t808Kick_setToneFreq (t808Kick* const kick, float freq) |
| | 401 | { |
| | 402 | kick->toneInitialFreq = freq; |
| | 403 | |
| | 404 | } |
| | 405 | |
| | 406 | void t808Kick_setToneDecay (t808Kick* const kick, float decay) |
| | 407 | { |
| | 408 | tEnvelope_setDecay(&kick->toneEnvGain,decay); |
| | 409 | tEnvelope_setDecay(&kick->toneEnvGain,decay * 3.0f); |
| | 410 | } |
| | 411 | void t808Kick_setNoiseDecay (t808Kick* const kick, float decay); |
| | 412 | void t808Kick_setSighAmount (t808Kick* const kick, float sigh); |
| | 413 | void t808Kick_setChirpAmount (t808Kick* const kick, float chirp); |
| | 414 | void t808Kick_setToneNoiseMix (t808Kick* const kick, float toneNoiseMix); |
| | 415 | void t808Kick_setNoiseFilterFreq (t808Kick* const kick, float noiseFilterFreq); |
| | 416 | void t808Kick_setNoiseFilterQ (t808Kick* const kick, float noiseFilterQ); |
| | 417 | |
| | 418 | |