~ubuntu-branches/debian/stretch/synthv1/stretch

« back to all changes in this revision

Viewing changes to src/synthv1_fx.h

  • Committer: Package Import Robot
  • Author(s): Jaromír Mikeš
  • Date: 2014-03-11 15:08:33 UTC
  • mfrom: (1.1.8)
  • Revision ID: package-import@ubuntu.com-20140311150833-hdd95xtc6ks4lwv5
Tags: 0.4.0-1
* Imported Upstream version 0.4.0
* Two patches removed - applied upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// synthv1_fx.h
2
2
//
3
3
/****************************************************************************
4
 
   Copyright (C) 2012-2013, rncbc aka Rui Nuno Capela. All rights reserved.
 
4
   Copyright (C) 2012-2014, rncbc aka Rui Nuno Capela. All rights reserved.
5
5
 
6
6
   This program is free software; you can redistribute it and/or
7
7
   modify it under the terms of the GNU General Public License
22
22
#ifndef __synthv1_fx_h
23
23
#define __synthv1_fx_h
24
24
 
 
25
#include <stdint.h>
 
26
#include <math.h>
 
27
 
25
28
 
26
29
//-------------------------------------------------------------------------
27
30
// synthv1_fx
28
31
//
29
32
// -- borrowed, stirred and refactored from Highlife --
30
 
// Copyright (C) 2007 arguru, discodsp.com
 
33
//    Copyright (C) 2007 arguru, discodsp.com
31
34
//
32
35
 
33
36
//-------------------------------------------------------------------------
281
284
{
282
285
public:
283
286
 
284
 
        static const uint32_t MAX_SIZE = 4096;  //= (1 << 12);
285
 
        static const uint32_t MAX_MASK = MAX_SIZE - 1;
286
 
 
287
287
        synthv1_fx_flanger()
288
288
                { reset(); }
289
289
 
340
340
                        in[i] += wet * output(in[i], delay, feedb);
341
341
        }
342
342
 
 
343
        static const uint32_t MAX_SIZE = (1 << 12);     //= 4096;
 
344
        static const uint32_t MAX_MASK = MAX_SIZE - 1;
 
345
 
343
346
private:
344
347
 
345
348
        float m_buffer[MAX_SIZE];
399
402
                }
400
403
        }
401
404
 
 
405
protected:
 
406
 
402
407
        float pseudo_sinf(float x) const
403
408
        {
404
409
                x *= x;
405
410
                x -= 1.0f;
406
 
                x *= x;
407
 
                return x;
 
411
                return x * x;
408
412
        }
409
413
 
410
414
private:
425
429
{
426
430
public:
427
431
 
428
 
        static const uint32_t MAX_SIZE = 65536; //= (1 << 16);
429
 
        static const uint32_t MAX_MASK = MAX_SIZE - 1;
430
 
 
431
432
        synthv1_fx_delay(uint32_t iSampleRate = 44100)
432
433
                : m_srate(iSampleRate) { reset(); }
433
434
 
459
460
                // set integer delay
460
461
                uint32_t ndelay = uint32_t(delay_time);
461
462
                // clamp
462
 
                if (ndelay < 256)
463
 
                        ndelay = 256;
 
463
                if (ndelay < MIN_SIZE)
 
464
                        ndelay = MIN_SIZE;
 
465
                else
464
466
                if (ndelay > MAX_SIZE)
465
467
                        ndelay = MAX_SIZE;
466
468
                // delay process
472
474
                }
473
475
        }
474
476
 
 
477
        static const uint32_t MIN_SIZE = (1 <<  8);     //= 256;
 
478
        static const uint32_t MAX_SIZE = (1 << 16);     //= 65536;
 
479
        static const uint32_t MAX_MASK = MAX_SIZE - 1;
 
480
 
475
481
private:
476
482
 
477
483
        float m_srate;
517
523
{
518
524
public:
519
525
 
520
 
        static const uint16_t MAX_TAPS = 6;
521
 
 
522
526
        synthv1_fx_phaser(uint32_t iSampleRate = 44100)
523
527
                : m_srate(float(iSampleRate)) { reset(); }
524
528
 
563
567
                        // positive wrap phase
564
568
                        if (m_lfo_phase >= 2.0f * M_PI)
565
569
                                m_lfo_phase -= 2.0f * M_PI;
566
 
                        // anti-denormalizer noise
567
 
                        const float ad = 1E-14f * float(::rand());
568
570
                        // get input
569
 
                        m_out = in[i] + ad + m_out * feedb;
 
571
                        m_out = denormal(in[i] + m_out * feedb);
570
572
                        // update filter coeffs and calculate output
571
573
                        for (uint16_t n = 0; n < MAX_TAPS; ++n)
572
574
                                m_out = m_taps[n].output(m_out, delay);
575
577
                }
576
578
        }
577
579
 
 
580
        static const uint16_t MAX_TAPS = 6;
 
581
 
 
582
protected:
 
583
 
 
584
        static float denormal(float v)
 
585
        {
 
586
                union { float f; unsigned int w; } u;
 
587
                u.f = v;
 
588
                return (u.w & 0x7f800000) ? v : 0.0f;
 
589
        }
 
590
 
578
591
private:
579
592
 
580
593
        float m_srate;