HISE Logo Forum
    • Categories
    • Register
    • Login

    What does this snex error mean? (no instruction found for type Negation)

    Scheduled Pinned Locked Moved ScriptNode
    3 Posts 2 Posters 243 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • griffinboyG
      griffinboy
      last edited by griffinboy

      I've been seeing this error a lot!

      09069b51-bc7c-4d8e-a4c1-ad0032405d58-image.png

      Unfortunately it does not point to any particular line and I cannot figure out what it means!
      I've had to abandon a lot of my scripts because I eventually run into this error, and it unfortunately happens when my algorithm becomes longer and more developed.

      It would be nice just to understand what it means thanks!

      There might be other errors in my code but if you want to see it, here it is 😅

      template <int NV> struct Spring1
      {
      	SNEX_NODE(Spring1);
      	
      	// Note about snex syntax and api. Do not delete empty inliners, variables are declared like (float name = 0.0f;), math functions are used like Math.sin(x)
      	
      	// Start
      	
         // External Variables
             float mix = 0.0f;
         
             // Internal Variables
             static const int NUM_CHANNELS = 2;
             double nyquistFreq = 0.0f;
             double sr = 0.0f; // Sample rate, initialized here and set properly in the prepare function
         
             // Modal parameters using span
             static const int numModes = 2031; // Number of modes in the audio range
             span<float, numModes> frequencies; // Resonance frequencies
             span<float, numModes> damping; // Damping factors
             span<float, numModes> modalAmplitudes; // Modal amplitudes
             span<span<float, 2>, numModes> modalStatesL; // State variables for each mode (left channel)
             span<span<float, 2>, numModes> modalStatesR; // State variables for each mode (right channel)
         
             // Function to calculate resonance frequency
             float calculateResonanceFrequency(int mode, float L, float T, float mu)
             {
                 return (float)(mode + 1) * ((float)1 / (2 * L)) * Math.sqrt(T / mu);
             }
         
             // Function to calculate damping factor
             float calculateDampingFactor(int mode, float frequency)
             {
                 float sigma0 = 3.0f; // Example value from paper
                 float sigma2 = 3e-9f; // Example value from paper
                 return sigma0 + sigma2 * frequency * frequency;
             }
         
             // Function to calculate modal amplitude
             float calculateModalAmplitude(int mode)
             {
                 return 1.0f / (mode + 1); // Example: inversely proportional to mode number
             }
         
             // Initialize the processing specs here
             void prepare(PrepareSpecs ps)
             {
                 sr = ps.sampleRate;
                 nyquistFreq = sr / 2.0;
         
                 // Physical properties of the spring
                 float L = 1.0f; // Length of the spring in meters
                 float T = 100.0f; // Tension in Newtons
                 float mu = 0.01f; // Linear mass density in kg/m
         
                 // Initialize modal parameters
                 for (int i = 0; i < numModes; ++i)
                 {
                     frequencies[i] = calculateResonanceFrequency(i, L, T, mu); // Assign resonance frequencies
                     damping[i] = calculateDampingFactor(i, frequencies[i]); // Assign damping factors
                     modalAmplitudes[i] = calculateModalAmplitude(i); // Assign modal amplitudes
                     modalStatesL[i][0] = 0.0f;
                     modalStatesL[i][1] = 0.0f;
                     modalStatesR[i][0] = 0.0f;
                     modalStatesR[i][1] = 0.0f;
                 }
             }
         
             // Process a block of samples for the left channel
             void processBlockL(span<float, 1024> block)
             {
                 for (auto& input : block)
                 {
                     float output = 0.0f;
         
                     // Update each mode
                     for (int i = 0; i < numModes; ++i)
                     {
                         float freq = frequencies[i];
                         float damp = damping[i];
                         float amp = modalAmplitudes[i];
         
                         // Modal update equations
                         float y = modalStatesL[i][0];
                         float yPrev = modalStatesL[i][1];
                         float yNext = (2.0f * Math.exp(-damp) * Math.cos(2.0f * Math.PI * freq / sr)) * y - Math.exp(-2.0f * damp) * yPrev + amp * input;
         
                         modalStatesL[i][1] = y;
                         modalStatesL[i][0] = yNext;
         
                         output += yNext;
                     }
         
                     // Apply mix
                     input = mix * output + (1.0f - mix) * input;
                 }
             }
         
             // Process a block of samples for the right channel
             void processBlockR(span<float, 1024> block)
             {
                 for (auto& input : block)
                 {
                     float output = 0.0f;
         
                     // Update each mode
                     for (int i = 0; i < numModes; ++i)
                     {
                         float freq = frequencies[i];
                         float damp = damping[i];
                         float amp = modalAmplitudes[i];
         
                         // Modal update equations
                         float y = modalStatesR[i][0];
                         float yPrev = modalStatesR[i][1];
                         float yNext = (2.0f * Math.exp(-damp) * Math.cos(2.0f * Math.PI * freq / sr)) * y - Math.exp(-2.0f * damp) * yPrev + amp * input;
         
                         modalStatesR[i][1] = y;
                         modalStatesR[i][0] = yNext;
         
                         output += yNext;
                     }
         
                     // Apply mix
                     input = mix * output + (1.0f - mix) * input;
                 }
             }
         
             // Process audio samples in blocks (frames)
             template <int C> void processFrame(span<float, C> data)
             {
                 if (C > 0)
                 {
                     span<float, 1024> leftChannel = data[0];
                     processBlockL(leftChannel); // Process the left channel
                 }
                 if (C > 1)
                 {
                     span<float, 1024> rightChannel = data[1];
                     processBlockR(rightChannel); // Process the right channel
                 }
             }
         
             // Set external variables
             template <int P> void setParameter(double v)
             {
                 if (P == 0)
                     mix = (float)(v);
             }
      	    
      	// End
      	
      	// Inliners. Do not delete. Snex won't run without these, they are needed even if empty.
      	// reset Is run every time the software is restarted. You can initialise variable values in here but not declare them
      	void reset(){}
      	// Process the signal as a sample here
      	template <typename T> void process(T& data) {}
      	// Process the MIDI events here
      	void handleHiseEvent(HiseEvent& e){}
      	// Use this function to setup the external data
      	void setExternalData(const ExternalData& d, int index){}
      };
      
      
      Christoph HartC 1 Reply Last reply Reply Quote 0
      • Christoph HartC
        Christoph Hart @griffinboy
        last edited by

        @griffinboy probably this line:

        float yNext = (2.0f * Math.exp(-damp) * Math.cos(2.0f * Math.PI * freq / sr)) * y - Math.exp(-2.0f * damp) * yPrev + amp * input;

        What happens if you change it to Math.exp(-1.0f * damp)?

        I remember stumbling over this too and the SNEX parser chokes at directly negating floating point values

        griffinboyG 1 Reply Last reply Reply Quote 1
        • griffinboyG
          griffinboy @Christoph Hart
          last edited by griffinboy

          @Christoph-Hart

          Yeah that worked! Thanks!

          Edit:
          For those who want to know the solution: avoid using the negative of a variable.

          For example, instead of using (-Variable) use (-1.0f * Variable) instead.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post

          34

          Online

          1.7k

          Users

          11.9k

          Topics

          103.5k

          Posts