zynaddsubfx

ZynAddSubFX open source synthesizer
Log | Files | Refs | Submodules | LICENSE

PADnoteParameters.h (7838B)


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