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.

216 lines
7.4KB

  1. /*
  2. ZynAddSubFX - a software synthesizer
  3. PADnoteParameters.h - Parameters for PADnote (PADsynth)
  4. Copyright (C) 2002-2005 Nasca Octavian Paul
  5. Author: Nasca Octavian Paul
  6. This program is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU General Public License
  8. as published by the Free Software Foundation; either version 2
  9. of the License, or (at your option) any later version.
  10. */
  11. #ifndef PAD_NOTE_PARAMETERS_H
  12. #define PAD_NOTE_PARAMETERS_H
  13. #include "../globals.h"
  14. #include "Presets.h"
  15. #include <string>
  16. #include <functional>
  17. namespace zyncarla {
  18. /**
  19. * Parameters for PAD synthesis
  20. *
  21. * @note unlike most other parameter objects significant portions of this
  22. * object are `owned' by the non-realtime context. The realtime context only
  23. * needs the samples generated by the PADsynth algorithm and modulators (ie
  24. * envelopes/filters/LFOs) for amplitude, frequency, and filters.
  25. * The ownership will be unclear for the time being, but it should be made more
  26. * explicit with time.
  27. */
  28. class PADnoteParameters:public Presets
  29. {
  30. public:
  31. PADnoteParameters(const SYNTH_T &synth_, FFTwrapper *fft_,
  32. const AbsTime *time_ = nullptr);
  33. ~PADnoteParameters();
  34. void defaults();
  35. void add2XML(XMLwrapper& xml);
  36. void getfromXML(XMLwrapper& xml);
  37. void paste(PADnoteParameters &p);
  38. void pasteRT(PADnoteParameters &p);
  39. //returns a value between 0.0f-1.0f that represents the estimation perceived bandwidth
  40. float getprofile(float *smp, int size);
  41. //parameters
  42. //the mode: 0 - bandwidth, 1 - discrete (bandwidth=0), 2 - continous
  43. //the harmonic profile is used only on mode 0
  44. unsigned char Pmode;
  45. //Harmonic profile (the frequency distribution of a single harmonic)
  46. struct {
  47. struct { //base function
  48. unsigned char type;
  49. unsigned char par1;
  50. } base;
  51. unsigned char freqmult; //frequency multiplier of the distribution
  52. struct { //the modulator of the distribution
  53. unsigned char par1;
  54. unsigned char freq;
  55. } modulator;
  56. unsigned char width; //the width of the resulting function after the modulation
  57. struct { //the amplitude multiplier of the harmonic profile
  58. unsigned char mode;
  59. unsigned char type;
  60. unsigned char par1;
  61. unsigned char par2;
  62. } amp;
  63. bool autoscale; //if the scale of the harmonic profile is computed automaticaly
  64. unsigned char onehalf; //what part of the base function is used to make the distribution
  65. } Php;
  66. unsigned int Pbandwidth; //the values are from 0 to 1000
  67. unsigned char Pbwscale; //how the bandwidth is increased according to the harmonic's frequency
  68. struct { //where are positioned the harmonics (on integer multimplier or different places)
  69. unsigned char type;
  70. unsigned char par1, par2, par3; //0..255
  71. } Phrpos;
  72. struct { //quality of the samples (how many samples, the length of them,etc.)
  73. unsigned char samplesize;
  74. unsigned char basenote, oct, smpoct;
  75. } Pquality;
  76. //frequency parameters
  77. //If the base frequency is fixed to 440 Hz
  78. unsigned char Pfixedfreq;
  79. /* Equal temperate (this is used only if the Pfixedfreq is enabled)
  80. If this parameter is 0, the frequency is fixed (to 440 Hz);
  81. if this parameter is 64, 1 MIDI halftone -> 1 frequency halftone */
  82. unsigned char PfixedfreqET;
  83. unsigned char PBendAdjust;
  84. unsigned char POffsetHz;
  85. unsigned short int PDetune; //fine detune
  86. unsigned short int PCoarseDetune; //coarse detune+octave
  87. unsigned char PDetuneType; //detune type
  88. EnvelopeParams *FreqEnvelope; //Frequency Envelope
  89. LFOParams *FreqLfo; //Frequency LFO
  90. //Amplitude parameters
  91. unsigned char PStereo;
  92. /* Panning - 0 - random
  93. 1 - left
  94. 64 - center
  95. 127 - right */
  96. unsigned char PPanning;
  97. unsigned char PVolume;
  98. unsigned char PAmpVelocityScaleFunction;
  99. EnvelopeParams *AmpEnvelope;
  100. LFOParams *AmpLfo;
  101. /* Adjustment factor for anti-pop fadein */
  102. unsigned char Fadein_adjustment;
  103. unsigned char PPunchStrength, PPunchTime, PPunchStretch,
  104. PPunchVelocitySensing;
  105. //Filter Parameters
  106. FilterParams *GlobalFilter;
  107. // filter velocity sensing
  108. unsigned char PFilterVelocityScale;
  109. // filter velocity sensing
  110. unsigned char PFilterVelocityScaleFunction;
  111. EnvelopeParams *FilterEnvelope;
  112. LFOParams *FilterLfo;
  113. float setPbandwidth(int Pbandwidth); //!< Return the BandWidth in cents
  114. //! Get the n-th overtone position relatively to N harmonic
  115. float getNhr(int n) const;
  116. void applyparameters(void);
  117. //! Compute the #sample array from the other parameters.
  118. //! For the function's parameters, see sampleGenerator()
  119. void applyparameters(std::function<bool()> do_abort,
  120. unsigned max_threads = 0);
  121. void export2wav(std::string basefilename);
  122. OscilGen *oscilgen;
  123. Resonance *resonance;
  124. struct Sample {
  125. int size;
  126. float basefreq;
  127. float *smp;
  128. };
  129. //! RT sample data
  130. Sample sample[PAD_MAX_SAMPLES];
  131. typedef std::function<void(int,PADnoteParameters::Sample&)> callback;
  132. //! PAD synth main function
  133. //! Generate spectrum and run IFFTs on it
  134. //! @param cb A callback that will be executed for each sample buffer
  135. //! Note that this function can be executed by multiple
  136. //! threads at the same time, so make sure you use mutexes
  137. //! etc where required
  138. //! @param do_abort Function that decides whether the calculation should
  139. //! be aborted (probably because of interruptions by the
  140. //! user)
  141. //! @param max_threads Maximum number of threads for computation, or
  142. //! zero if no maximum shall be set
  143. int sampleGenerator(PADnoteParameters::callback cb,
  144. std::function<bool()> do_abort,
  145. unsigned max_threads = 0);
  146. const AbsTime *time;
  147. int64_t last_update_timestamp;
  148. static const rtosc::MergePorts ports;
  149. static const rtosc::Ports &non_realtime_ports;
  150. static const rtosc::Ports &realtime_ports;
  151. private:
  152. void generatespectrum_bandwidthMode(float *spectrum,
  153. int size,
  154. float basefreq,
  155. const float *profile,
  156. int profilesize,
  157. float bwadjust) const;
  158. void generatespectrum_otherModes(float *spectrum,
  159. int size,
  160. float basefreq) const;
  161. void deletesamples();
  162. void deletesample(int n);
  163. public:
  164. const SYNTH_T &synth;
  165. };
  166. }
  167. #endif