Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

nekobee_voice.h 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be
  16. * useful, but WITHOUT ANY WARRANTY; without even the implied
  17. * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  18. * PURPOSE. See the GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public
  21. * License along with this program; if not, write to the Free
  22. * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  23. * MA 02111-1307, USA.
  24. */
  25. #ifndef _XSYNTH_VOICE_H
  26. #define _XSYNTH_VOICE_H
  27. #include <string.h>
  28. #include "nekobee_types.h"
  29. /* maximum size of a rendering burst */
  30. #define XSYNTH_NUGGET_SIZE 64
  31. /* minBLEP constants */
  32. /* minBLEP table oversampling factor (must be a power of two): */
  33. #define MINBLEP_PHASES 64
  34. /* MINBLEP_PHASES minus one: */
  35. #define MINBLEP_PHASE_MASK 63
  36. /* length in samples of (truncated) step discontinuity delta: */
  37. #define STEP_DD_PULSE_LENGTH 72
  38. /* length in samples of (truncated) slope discontinuity delta: */
  39. #define SLOPE_DD_PULSE_LENGTH 71
  40. /* the longer of the two above: */
  41. #define LONGEST_DD_PULSE_LENGTH STEP_DD_PULSE_LENGTH
  42. /* MINBLEP_BUFFER_LENGTH must be at least XSYNTH_NUGGET_SIZE plus
  43. * LONGEST_DD_PULSE_LENGTH, and not less than twice LONGEST_DD_PULSE_LENGTH: */
  44. #define MINBLEP_BUFFER_LENGTH 512
  45. /* delay between start of DD pulse and the discontinuity, in samples: */
  46. #define DD_SAMPLE_DELAY 4
  47. struct _nekobee_patch_t
  48. {
  49. float tuning;
  50. unsigned char waveform;
  51. float cutoff;
  52. float resonance;
  53. float envmod;
  54. float decay;
  55. float accent;
  56. float volume;
  57. };
  58. enum nekobee_voice_status
  59. {
  60. XSYNTH_VOICE_OFF, /* silent: is not processed by render loop */
  61. XSYNTH_VOICE_ON, /* has not received a note off event */
  62. XSYNTH_VOICE_SUSTAINED, /* has received note off, but sustain controller is on */
  63. XSYNTH_VOICE_RELEASED /* had note off, not sustained, in final decay phase of envelopes */
  64. };
  65. struct blosc
  66. {
  67. int last_waveform, /* persistent */
  68. waveform, /* comes from LADSPA port each cycle */
  69. bp_high; /* persistent */
  70. float pos, /* persistent */
  71. pw; /* comes from LADSPA port each cycle */
  72. };
  73. /*
  74. * nekobee_voice_t
  75. */
  76. struct _nekobee_voice_t
  77. {
  78. unsigned int note_id;
  79. unsigned char status;
  80. unsigned char key;
  81. unsigned char velocity;
  82. unsigned char rvelocity; /* the note-off velocity */
  83. /* translated controller values */
  84. float pressure; /* filter resonance multiplier, off = 1.0, full on = 0.0 */
  85. /* persistent voice state */
  86. float prev_pitch,
  87. target_pitch,
  88. lfo_pos;
  89. struct blosc osc1;
  90. float vca_eg,
  91. vcf_eg,
  92. accent_slug,
  93. delay1,
  94. delay2,
  95. delay3,
  96. delay4,
  97. c5;
  98. unsigned char vca_eg_phase,
  99. vcf_eg_phase;
  100. int osc_index; /* shared index into osc_audio */
  101. float osc_audio[MINBLEP_BUFFER_LENGTH];
  102. float freqcut_buf[XSYNTH_NUGGET_SIZE];
  103. float vca_buf[XSYNTH_NUGGET_SIZE];
  104. };
  105. #define _PLAYING(voice) ((voice)->status != XSYNTH_VOICE_OFF)
  106. #define _ON(voice) ((voice)->status == XSYNTH_VOICE_ON)
  107. #define _SUSTAINED(voice) ((voice)->status == XSYNTH_VOICE_SUSTAINED)
  108. #define _RELEASED(voice) ((voice)->status == XSYNTH_VOICE_RELEASED)
  109. #define _AVAILABLE(voice) ((voice)->status == XSYNTH_VOICE_OFF)
  110. extern float nekobee_pitch[128];
  111. typedef struct { float value, delta; } float_value_delta;
  112. extern float_value_delta step_dd_table[];
  113. extern float slope_dd_table[];
  114. /* nekobee_voice.c */
  115. nekobee_voice_t *nekobee_voice_new();
  116. void nekobee_voice_note_on(nekobee_synth_t *synth,
  117. nekobee_voice_t *voice,
  118. unsigned char key,
  119. unsigned char velocity);
  120. void nekobee_voice_remove_held_key(nekobee_synth_t *synth,
  121. unsigned char key);
  122. void nekobee_voice_note_off(nekobee_synth_t *synth,
  123. nekobee_voice_t *voice,
  124. unsigned char key,
  125. unsigned char rvelocity);
  126. void nekobee_voice_release_note(nekobee_synth_t *synth,
  127. nekobee_voice_t *voice);
  128. void nekobee_voice_set_ports(nekobee_synth_t *synth,
  129. nekobee_patch_t *patch);
  130. void nekobee_voice_update_pressure_mod(nekobee_synth_t *synth,
  131. nekobee_voice_t *voice);
  132. /* nekobee_voice_render.c */
  133. void nekobee_init_tables(void);
  134. void nekobee_voice_render(nekobee_synth_t *synth, nekobee_voice_t *voice,
  135. float *out, unsigned long sample_count,
  136. int do_control_update);
  137. /* inline functions */
  138. /*
  139. * nekobee_voice_off
  140. *
  141. * Purpose: Turns off a voice immediately, meaning that it is not processed
  142. * anymore by the render loop.
  143. */
  144. static inline void
  145. nekobee_voice_off(nekobee_voice_t* voice)
  146. {
  147. voice->status = XSYNTH_VOICE_OFF;
  148. /* silence the oscillator buffer for the next use */
  149. memset(voice->osc_audio, 0, MINBLEP_BUFFER_LENGTH * sizeof(float));
  150. /* -FIX- decrement active voice count? */
  151. }
  152. /*
  153. * nekobee_voice_start_voice
  154. */
  155. static inline void
  156. nekobee_voice_start_voice(nekobee_voice_t *voice)
  157. {
  158. voice->status = XSYNTH_VOICE_ON;
  159. /* -FIX- increment active voice count? */
  160. }
  161. #endif /* _XSYNTH_VOICE_H */