Forum

    • Register
    • Login
    • Search
    • Categories

    SNEX channel in processFrame

    General Questions
    3
    8
    218
    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.
    • ustk
      ustk last edited by ustk

      How do we get access to the channels in a framex_block processing context?

      // Process the signal as frame here
      template <int C> void processFrame(span<float, C>& data)
      {
      	for(auto& s: data)
      	{
      		// process channels independently?
      	}
      }
      

      My guess is that the processFrame function is called once per channel so it is impossible, so we would need 2 nodes inside a multi... But I prefer to ask 🙂

      I can't help pressing F5 in the forum...

      Christoph Hart 1 Reply Last reply Reply Quote 0
      • Christoph Hart
        Christoph Hart @ustk last edited by

        @ustk What's wrong with data[0] = independentProcessing(data[0]) ?

        ustk 2 Replies Last reply Reply Quote 1
        • ustk
          ustk @Christoph Hart last edited by

          @Christoph-Hart said in SNEX channel in processFrame:

          @ustk What's wrong with data[0] = independentProcessing(data[0]) ?

          Just me I guess... 😬
          I wonder how I couldn't see this, the presence of the span is obvious though...

          I was trying with the iterative way like in the block processing:

          for(auto ch: data)
          {
          	for(auto& s: data.toChannelData(ch))
          	{
          		s = getNew(s);
          	}
          }
          

          I can't help pressing F5 in the forum...

          1 Reply Last reply Reply Quote 0
          • ustk
            ustk @Christoph Hart last edited by ustk

            @Christoph-Hart Hmmm... Why do I get an out of bound error on data[1] knowing everything is in a 2 channels node?

            	template <int C> void processFrame(span<float, C>& data)
            	{
            		mono = (data[0] + data[1]) / 2.0f;
            	}
            

            I can't help pressing F5 in the forum...

            Dan Korneff 1 Reply Last reply Reply Quote 0
            • Dan Korneff
              Dan Korneff @ustk last edited by

              @ustk @Christoph-Hart I'm getting the same error

              		inputL = data[0];
              		inputR = data[1];
              

              constant index out of bounds (for the line containing data[1])

              Also tried to upload a photo but get the error

              Imgur is temporarily over capacity. Please try again later.
              

              ![Screenshot 2023-05-15 121621.jpg](Imgur is temporarily over capacity. Please try again later.)

              Dan Korneff - Producer / Mixer / Audio Nerd

              Christoph Hart 1 Reply Last reply Reply Quote 1
              • Christoph Hart
                Christoph Hart @Dan Korneff last edited by

                Yes that is expected behaviour (but it's definitely unintentional and maybe I'll change that during the current SNEX compiler rewrite).

                When you define a process function with a templated channel count, the SNEX compiler will create functions for all channels up to the max channel amount. So if you're using it in a stereo DSP network, the snex compiler will expand this function

                template <int C> void processFrame(span<float, C>& data);
                

                to

                void processFrame(span<float, 1>& data);
                void processFrame(span<float, 2>& data);
                

                The rationale behind this is that the node can be used with different channel configs (so if you drag it into a multi container, it will get processed with less channels) and thus it would require a recompilation.

                Now the compile error with the constant out of bound index is caused if you try to access data[1] in the first method, which only has a single element. What I'm usually doing here is to remove the template function and use overloading to specify the behaviour for each channel count individually (in this case it's good because if you already assume that there are two channels with data[1], you can as well just type out the actual channel number). If you never expect the function to be called in a mono context (which again should be the case if you assume that there is a data[1] element, you can leave it just empty:

                void processFrame(span<float, 1>& data)
                {
                    // nothing to see here, move along...
                }
                
                void processFrame(span<float, 2>& data)
                {
                    // Now you can use data[1] as much as you want...
                    data[1] = data[1] + data[1];
                    data[1] *= data[1] > 0.5f ? data[1] * 2.0f : data[1] - 0.5f;
                    data[1] = 0.0f;
                }
                
                ustk Dan Korneff 2 Replies Last reply Reply Quote 1
                • ustk
                  ustk @Christoph Hart last edited by

                  @Christoph-Hart suddenly it all makes sense! Thanks for the clarification 🙂

                  I can't help pressing F5 in the forum...

                  1 Reply Last reply Reply Quote 0
                  • Dan Korneff
                    Dan Korneff @Christoph Hart last edited by

                    @Christoph-Hart said in SNEX channel in processFrame:

                    If you never expect the function to be called in a mono context (which again should be the case if you assume that there is a data[1] element, you can leave it just empty:

                    How does this work with the "Support Mono FX" option? Fill both functions and just exclude data[1] in the first?

                    Dan Korneff - Producer / Mixer / Audio Nerd

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

                    6
                    Online

                    1.1k
                    Users

                    7.0k
                    Topics

                    64.6k
                    Posts