1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
2 /*****************************************************************************
4 * Copyright (C) 2006,2007,2008,2009 Nedko Arnaudov <nedko@arnaudov.name>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License
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 for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *****************************************************************************/
29 * Transform the velocity according the scaling parameter (velocity sensing)
32 VelF(REALTYPE velocity
,unsigned char scaling
)
36 x
= (64.0 - scaling
) / 64.0; /* 0 .. 127 -> 1 .. -1 */
38 x
= pow(VELOCITY_MAX_SCALE
, x
);
40 if (scaling
== 127 || velocity
> 0.99)
46 return pow(velocity
, x
);
51 zyn_velocity_scale(float velocity
, float scaling
)
55 x
= pow(VELOCITY_MAX_SCALE
, scaling
);
57 if (scaling
< -0.99 || velocity
> 0.99)
63 return pow(velocity
, x
);
68 * Get the detune in cents
73 unsigned short int coarsedetune
,
74 unsigned short int finedetune
)
81 int octave
= coarsedetune
/ 1024;
87 octdet
= octave
* 1200.0;
89 // Coarse and fine detune
90 int cdetune
= coarsedetune
% 1024;
96 int fdetune
= finedetune
- 8192;
100 case ZYN_DETUNE_TYPE_L35CENTS
:
101 cdet
= fabs(cdetune
* 50.0);
102 findet
= fabs(fdetune
/ 8192.0) * 35.0; // almost like "Paul's Sound Designer 2"
103 case ZYN_DETUNE_TYPE_L10CENTS
:
104 cdet
= fabs(cdetune
* 10.0);
105 findet
= fabs(fdetune
/ 8192.0) * 10.0;
107 case ZYN_DETUNE_TYPE_E100CENTS
:
108 cdet
= fabs(cdetune
* 100);
109 findet
= pow(10, fabs(fdetune
/ 8192.0) * 3.0) / 10.0 - 0.1;
111 case ZYN_DETUNE_TYPE_E1200CENTS
:
112 cdet
= fabs(cdetune
* 701.95500087); // perfect fifth
113 findet
= (pow(2, fabs(fdetune
/ 8192.0) * 12.0) - 1.0) / 4095 * 1200;
120 if (finedetune
< 8192)
130 return octdet
+ cdet
+ findet
;
135 zyn_sample_type
* buffer
,
147 zyn_sample_type
* buffer1
,
148 zyn_sample_type
* buffer2
,
161 zyn_sample_type
* buffer_mix_1
,
162 zyn_sample_type
* buffer_mix_2
,
163 zyn_sample_type
* buffer1
,
164 zyn_sample_type
* buffer2
,
170 buffer_mix_1
[size
] += buffer1
[size
];
171 buffer_mix_2
[size
] += buffer2
[size
];
177 zyn_sample_type
* buffer1
,
178 zyn_sample_type
* buffer2
,
181 zyn_sample_type fade
;
185 fade
= 1.0 - (zyn_sample_type
)size
/ (zyn_sample_type
)SOUND_BUFFER_SIZE
;
187 buffer1
[size
] *= fade
;
188 buffer2
[size
] *= fade
;
194 zyn_sample_type
* buffer_dest
,
195 zyn_sample_type
* buffer_src
,
201 buffer_dest
[size
] = buffer_src
[size
];
207 zyn_sample_type
* buffer
,
214 buffer
[size
] *= multiplyer
;
221 return rand() / (RAND_MAX
+ 1.0);