LMMS
Loading...
Searching...
No Matches
nekobee_synth.c
Go to the documentation of this file.
1/* nekobee DSSI software synthesizer plugin
2 *
3 * Copyright (C) 2004 Sean Bolton and others.
4 *
5 * Portions of this file may have come from Steve Brookes'
6 * nekobee, copyright (C) 1999 S. J. Brookes.
7 * Portions of this file may have come from Peter Hanappe's
8 * Fluidsynth, copyright (C) 2003 Peter Hanappe and others.
9 * Portions of this file may have come from Chris Cannam and Steve
10 * Harris's public domain DSSI example code.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2 of
15 * the License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be
18 * useful, but WITHOUT ANY WARRANTY; without even the implied
19 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public
23 * License along with this program; if not, write to the Free
24 * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 * MA 02111-1307, USA.
26 */
27
28#include <stdlib.h>
29#include <stdio.h>
30#include <string.h>
31#include <math.h>
32#include <pthread.h>
33
34#include "nekobee.h"
35#include "nekobee_synth.h"
36#include "nekobee_voice.h"
37
38/*
39 * nekobee_synth_all_voices_off
40 *
41 * stop processing all notes immediately
42 */
43void
45{
46 int i;
47 nekobee_voice_t *voice;
48
49 for (i = 0; i < synth->voices; i++) {
50 //voice = synth->voice[i];
51 voice = synth->voice;
52 if (_PLAYING(voice)) {
53 nekobee_voice_off(voice);
54 }
55 }
56 for (i = 0; i < 8; i++) synth->held_keys[i] = -1;
57}
58
59/*
60 * nekobee_synth_note_off
61 *
62 * handle a note off message
63 */
64void
65nekobee_synth_note_off(nekobee_synth_t *synth, unsigned char key, unsigned char rvelocity)
66{
67 int i, count = 0;
68 nekobee_voice_t *voice;
69
70 for (i = 0; i < synth->voices; i++) {
71 voice = synth->voice;
72 if (_PLAYING(voice)) {
73 XDB_MESSAGE(XDB_NOTE, " nekobee_synth_note_off: key %d rvel %d voice %d note id %d\n", key, rvelocity, i, voice->note_id);
74 nekobee_voice_note_off(synth, voice, key, 64);
75 count++;
76 }
77 }
78
79 if (!count)
81
82 return;
83 (void)rvelocity;
84}
85
86/*
87 * nekobee_synth_all_notes_off
88 *
89 * put all notes into the released state
90 */
91void
93{
94 int i;
95 nekobee_voice_t *voice;
96
97 /* reset the sustain controller */
98 synth->cc[MIDI_CTL_SUSTAIN] = 0;
99 for (i = 0; i < synth->voices; i++) {
100 //voice = synth->voice[i];
101 voice = synth->voice;
102 if (_ON(voice) || _SUSTAINED(voice)) {
104 }
105 }
106}
107
108/*
109 * nekobee_synth_note_on
110 */
111void
112nekobee_synth_note_on(nekobee_synth_t *synth, unsigned char key, unsigned char velocity)
113{
114 nekobee_voice_t* voice;
115
116 voice = synth->voice;
117 if (_PLAYING(synth->voice)) {
118 XDB_MESSAGE(XDB_NOTE, " nekobee_synth_note_on: retriggering mono voice on new key %d\n", key);
119 }
120
121 voice->note_id = synth->note_id++;
122
123 nekobee_voice_note_on(synth, voice, key, velocity);
124}
125
126/*
127 * nekobee_synth_update_volume
128 */
129void
131{
132 synth->cc_volume = (float)(synth->cc[MIDI_CTL_MSB_MAIN_VOLUME] * 128 +
133 synth->cc[MIDI_CTL_LSB_MAIN_VOLUME]) / 16256.0f;
134 if (synth->cc_volume > 1.0f)
135 synth->cc_volume = 1.0f;
136 /* don't need to check if any playing voices need updating, because it's global */
137}
138
139/*
140 * nekobee_synth_control_change
141 */
142void
144{
145 synth->cc[param] = value;
146
147 switch (param) {
148
152 break;
153
156 break;
157
160 break;
161
164 break;
165
166 /* what others should we respond to? */
167
168 /* these we ignore (let the host handle):
169 * BANK_SELECT_MSB
170 * BANK_SELECT_LSB
171 * DATA_ENTRY_MSB
172 * NRPN_MSB
173 * NRPN_LSB
174 * RPN_MSB
175 * RPN_LSB
176 * -FIX- no! we need RPN (0, 0) Pitch Bend Sensitivity!
177 */
178 }
179}
180
181/*
182 * nekobee_synth_init_controls
183 */
184void
186{
187 int i;
188
189 for (i = 0; i < 128; i++) {
190 synth->cc[i] = 0;
191 }
192
193 synth->cc[7] = 127; /* full volume */
195}
196
197/*
198 * nekobee_synth_render_voices
199 */
200void
201nekobee_synth_render_voices(nekobee_synth_t *synth, float *out, unsigned long sample_count,
202 int do_control_update)
203{
204 unsigned long i;
205 float res, wow;
206
207 /* clear the buffer */
208 for (i = 0; i < sample_count; i++)
209 out[i] = 0.0f;
210
211 // we can do anything that must be updated all the time here
212 // this is called even when a voice isn't playing
213
214 // approximate a log scale
215 res = 1-synth->resonance;
216 wow = res*res;
217 wow = wow/10.0f;
218
219 // as the resonance is increased, "wow" slows down the accent attack
220 if ((synth->voice->velocity>90) && (synth->vcf_accent < synth->voice->vcf_eg)) {
221 synth->vcf_accent=(0.985-wow)*synth->vcf_accent+(0.015+wow)*synth->voice->vcf_eg;
222 } else {
223 synth->vcf_accent=(0.985-wow)*synth->vcf_accent; // or just decay
224 }
225
226 if (synth->voice->velocity>90) {
227 synth->vca_accent=0.95*synth->vca_accent+0.05; // ramp up accent on with a time constant
228 } else {
229 synth->vca_accent=0.95*synth->vca_accent; // accent off with time constant
230 }
231#if defined(XSYNTH_DEBUG) && (XSYNTH_DEBUG & XDB_AUDIO)
232 out[0] += 0.10f; /* add a 'buzz' to output so there's something audible even when quiescent */
233#endif /* defined(XSYNTH_DEBUG) && (XSYNTH_DEBUG & XDB_AUDIO) */
234 if (_PLAYING(synth->voice)) {
235 nekobee_voice_render(synth, synth->voice, out, sample_count, do_control_update);
236 }
237}
SYNTH_T * synth
Definition LocalZynAddSubFx.cpp:47
register unsigned i
Definition inflate.c:1575
static PuglViewHint int value
Definition pugl.h:1708
float out
Definition lilv_test.c:1461
#define XDB_MESSAGE(type, fmt...)
Definition nekobee.h:66
#define XDB_NOTE
Definition nekobee.h:32
void nekobee_synth_note_off(nekobee_synth_t *synth, unsigned char key, unsigned char rvelocity)
Definition nekobee_synth.c:65
void nekobee_synth_all_notes_off(nekobee_synth_t *synth)
Definition nekobee_synth.c:92
void nekobee_synth_control_change(nekobee_synth_t *synth, unsigned int param, signed int value)
Definition nekobee_synth.c:143
void nekobee_synth_update_volume(nekobee_synth_t *synth)
Definition nekobee_synth.c:130
void nekobee_synth_render_voices(nekobee_synth_t *synth, float *out, unsigned long sample_count, int do_control_update)
Definition nekobee_synth.c:201
void nekobee_synth_init_controls(nekobee_synth_t *synth)
Definition nekobee_synth.c:185
void nekobee_synth_all_voices_off(nekobee_synth_t *synth)
Definition nekobee_synth.c:44
void nekobee_synth_note_on(nekobee_synth_t *synth, unsigned char key, unsigned char velocity)
Definition nekobee_synth.c:112
#define MIDI_CTL_ALL_NOTES_OFF
Definition nekobee_synth.h:128
#define MIDI_CTL_LSB_MAIN_VOLUME
Definition nekobee_synth.h:113
#define MIDI_CTL_RESET_CONTROLLERS
Definition nekobee_synth.h:127
#define MIDI_CTL_MSB_MAIN_VOLUME
Definition nekobee_synth.h:109
#define MIDI_CTL_ALL_SOUNDS_OFF
Definition nekobee_synth.h:126
#define MIDI_CTL_SUSTAIN
Definition nekobee_synth.h:115
struct _nekobee_synth_t nekobee_synth_t
Definition nekobee_types.h:26
struct _nekobee_voice_t nekobee_voice_t
Definition nekobee_types.h:27
void nekobee_voice_release_note(nekobee_synth_t *synth, nekobee_voice_t *voice)
Definition nekobee_voice.c:244
void nekobee_voice_note_on(nekobee_synth_t *synth, nekobee_voice_t *voice, unsigned char key, unsigned char velocity)
Definition nekobee_voice.c:56
void nekobee_voice_note_off(nekobee_synth_t *synth, nekobee_voice_t *voice, unsigned char key, unsigned char rvelocity)
Definition nekobee_voice.c:182
void nekobee_voice_remove_held_key(nekobee_synth_t *synth, unsigned char key)
Definition nekobee_voice.c:160
void nekobee_voice_render(nekobee_synth_t *synth, nekobee_voice_t *voice, float *out, unsigned long sample_count, int do_control_update)
Definition nekobee_voice_render.c:273
static void nekobee_voice_off(nekobee_voice_t *voice)
Definition nekobee_voice.h:165
#define _PLAYING(voice)
Definition nekobee_voice.h:118
#define _ON(voice)
Definition nekobee_voice.h:119
#define _SUSTAINED(voice)
Definition nekobee_voice.h:120
unsigned int note_id
Definition nekobee_voice.h:87
ZCONST char * key
Definition crypt.c:587
#define void
Definition unzip.h:396
_WDL_CSTRING_PREFIX void INT_PTR count
Definition wdlcstring.h:263