~ubuntu-branches/ubuntu/vivid/aeolus/vivid

« back to all changes in this revision

Viewing changes to rankwave.h

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2010-04-19 19:12:51 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20100419191251-hgarjfcdfl7c0ryl
Tags: 0.8.4-3
debian/patches/01-makefile.patch: Drop -march=native flag, it isn't valid
for Debian packages as the results are unpredictable, thanks to
Bastian Blank for reporting this (Closes: #578278).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
    Copyright (C) 2003-2008 Fons Adriaensen <fons@kokkinizita.net>
3
 
    
4
 
    This program is free software; you can redistribute it and/or modify
5
 
    it under the terms of the GNU General Public License as published by
6
 
    the Free Software Foundation; either version 2 of the License, or
7
 
    (at your option) any later version.
8
 
 
9
 
    This program is distributed in the hope that it will be useful,
10
 
    but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
    GNU General Public License for more details.
13
 
 
14
 
    You should have received a copy of the GNU General Public License
15
 
    along with this program; if not, write to the Free Software
16
 
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
 
*/
18
 
 
19
 
 
20
 
#ifndef __RANKWAVE_H
21
 
#define __RANKWAVE_H
22
 
 
23
 
 
24
 
#include "addsynth.h"
25
 
#include "rngen.h"
26
 
 
27
 
 
28
 
#define PERIOD 64
29
 
 
30
 
 
31
 
class Pipewave
32
 
{
33
 
private:
34
 
 
35
 
    Pipewave (void) :
36
 
        _p0 (0), _p1 (0), _p2 (0), _l1 (0), _k_s (0),  _k_r (0), _m_r (0),
37
 
        _link (0), _sbit (0), _sdel (0), 
38
 
        _p_p (0), _y_p (0), _z_p (0), _p_r (0), _y_r (0), _g_r (0), _i_r (0)
39
 
    {}     
40
 
 
41
 
    ~Pipewave (void) { delete[] _p0; }
42
 
 
43
 
    friend class Rankwave;   
44
 
 
45
 
    void genwave (Addsynth *D, int n, float fsamp, float fpipe);
46
 
    void save (FILE *F);
47
 
    void load (FILE *F);
48
 
    void play (void);
49
 
 
50
 
    static void looplen (float f, float fsamp, int lmax, int *aa, int *bb);
51
 
    static void attgain (int n, float p);
52
 
 
53
 
    float     *_p0;    // attack start
54
 
    float     *_p1;    // loop start
55
 
    float     *_p2;    // loop end
56
 
    int32_t    _l0;    // attack length
57
 
    int32_t    _l1;    // loop length
58
 
    int16_t    _k_s;   // sample step
59
 
    int16_t    _k_r;   // release lenght
60
 
    float      _m_r;   // release multiplier
61
 
    float      _d_r;   // release detune
62
 
    float      _d_p;   // instability
63
 
 
64
 
    Pipewave  *_link;  // link to next in active chain
65
 
    uint32_t   _sbit;  // on state bit  
66
 
    uint32_t   _sdel;  // delayed state
67
 
    float     *_out;   // audio output buffer
68
 
    float     *_p_p;   // play pointer   
69
 
    float      _y_p;   // play interpolation            
70
 
    float      _z_p;   // play interpolation speed
71
 
    float     *_p_r;   // release pointer
72
 
    float      _y_r;   // release interpolation
73
 
    float      _g_r;   // release gain  
74
 
    int16_t    _i_r;   // release count
75
 
 
76
 
 
77
 
    static void initstatic (float fsamp);
78
 
 
79
 
    static   Rngen   _rgen;
80
 
    static   float  *_arg;
81
 
    static   float  *_att; 
82
 
};
83
 
 
84
 
 
85
 
class Rankwave
86
 
{
87
 
public:
88
 
 
89
 
    Rankwave (int n0, int n1);
90
 
    ~Rankwave (void);
91
 
 
92
 
    void note_on (int n)
93
 
    {
94
 
        if ((n < _n0) || (n > _n1)) return;
95
 
        Pipewave *P = _pipes + (n - _n0);
96
 
        P->_sbit = _sbit;   
97
 
        if (! (P->_sdel || P->_p_p || P->_p_r))
98
 
        {
99
 
            P->_sdel |= _sbit;
100
 
            P->_link = _list;
101
 
            _list = P;
102
 
        }
103
 
    }
104
 
 
105
 
    void note_off (int n)
106
 
    {
107
 
        if ((n < _n0) || (n > _n1)) return;
108
 
        Pipewave *P = _pipes + (n - _n0);
109
 
        P->_sdel >>= 4;
110
 
        P->_sbit = 0;     
111
 
    }
112
 
 
113
 
    void all_off (void)
114
 
    {
115
 
        Pipewave *P;
116
 
        for (P = _list; P; P = P->_link) P->_sbit = 0;
117
 
    }        
118
 
 
119
 
    int  n0 (void) const { return _n0; }
120
 
    int  n1 (void) const { return _n1; }
121
 
    void play (int shift);
122
 
    void set_param (float *out, int del, int pan);
123
 
    void gen_waves (Addsynth *D, float fsamp, float fbase, float *scale);
124
 
    int  save (const char *path, Addsynth *D, float fsamp, float fbase, float *scale);
125
 
    int  load (const char *path, Addsynth *D, float fsamp, float fbase, float *scale);
126
 
    bool modif (void) const { return _modif; }
127
 
 
128
 
    int  _cmask;  // used by division logic 
129
 
    int  _nmask;  // used by division logic
130
 
 
131
 
private:
132
 
 
133
 
    Rankwave (const Rankwave&);
134
 
    Rankwave& operator=(const Rankwave&);
135
 
 
136
 
    int         _n0;
137
 
    int         _n1;
138
 
    uint32_t    _sbit;
139
 
    Pipewave   *_list;
140
 
    Pipewave   *_pipes;
141
 
    bool        _modif;
142
 
};
143
 
 
144
 
 
145
 
#endif
146