HISE Logo Forum
    • Categories
    • Register
    • Login

    SNEX channel in processFrame

    Scheduled Pinned Locked Moved General Questions
    8 Posts 3 Posters 452 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.
    • ustkU
      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 :)

      Can't help pressing F5 in the forum...

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

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

        ustkU 2 Replies Last reply Reply Quote 1
        • ustkU
          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);
          	}
          }
          

          Can't help pressing F5 in the forum...

          1 Reply Last reply Reply Quote 0
          • ustkU
            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;
            	}
            

            Can't help pressing F5 in the forum...

            Dan KorneffD 1 Reply Last reply Reply Quote 0
            • Dan KorneffD
              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 HartC 1 Reply Last reply Reply Quote 1
              • Christoph HartC
                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;
                }
                
                ustkU Dan KorneffD 2 Replies Last reply Reply Quote 1
                • ustkU
                  ustk @Christoph Hart
                  last edited by

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

                  Can't help pressing F5 in the forum...

                  1 Reply Last reply Reply Quote 0
                  • Dan KorneffD
                    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

                    42

                    Online

                    1.7k

                    Users

                    11.7k

                    Topics

                    101.8k

                    Posts