HISE Logo Forum
    • Categories
    • Register
    • Login

    Force mono node?

    Scheduled Pinned Locked Moved C++ Development
    3 Posts 2 Posters 140 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.
    • OrvillainO
      Orvillain
      last edited by Orvillain

      Sometimes you know that you definitely want a node to only process in mono.

      So if I do:

      static constexpr int getFixChannelAmount() { return 1; };
      

      And then later on:

      template <typename T> void process(T& data)
      		template <typename T> void process(T& data)
      		{
      			auto& fd = data.template as<ProcessData<getFixChannelAmount()>>();
      			auto block = fd.toAudioBlock();
      			auto* left = block.getChannelPointer(0);
                  auto* right = block.getChannelPointer(1);
      			numSamples = data.getNumSamples();
      			
      			// change "effect" object to StereoAudioEffect
      			// and switch to this if stereo
      			//effect.process(left, right, numSamples);
      
      			// change "effect" object to MonoAudioEffect
      			// and switch to this if mono
      			//effect.process(left, numSamples);
      			
      		}
      

      I would have two separate effect processor classes; MonoAudioEffect and StereoAudioEffect. Essentially wrappers around some child DSP objects.

      Is this a legal approach to effectively switching between mono versus stereo processing? Should I be copying the left channel to the right channel to make things consistent with the rest of scriptnode?

      Musician - Instrument Designer - Sonic Architect - Creative Product Owner
      Crafting sound at every level. From strings to signal paths, samples to systems.

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

        Not sure I understand, where do you do the switch? And why do you want to switch if you know that a node is only processing a single channel?

        If you're node is known to be mono, then just process the first channel in the implementation, or if you want to force a generic node to only process the first channel, you can use the wrap::fix template to force mono processing.

        // instead of this member declaration
        MyClass obj;
        
        // use
        wrap::fix<1, MyClass> obj;
        

        Your code is probably throwing an assertion at auto* right = block.getChannelPointer(1); if you have created the audio block from a single channel process data object.

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

          @Christoph-Hart said in Force mono node?:

          Not sure I understand, where do you do the switch? And why do you want to switch if you know that a node is only processing a single channel?

          If you're node is known to be mono, then just process the first channel in the implementation, or if you want to force a generic node to only process the first channel, you can use the wrap::fix template to force mono processing.

          // instead of this member declaration
          MyClass obj;
          
          // use
          wrap::fix<1, MyClass> obj;
          

          Your code is probably throwing an assertion at auto* right = block.getChannelPointer(1); if you have created the audio block from a single channel process data object.

          I was thinking in situations where I want to do a tubescreamer emulation, for example. I don't want true stereo processing.

          But maybe I'm overthinking it, and I just do a stereo node... collapse the channels... process the result... write the result back to output left and output right, with some gain compensation?

          Musician - Instrument Designer - Sonic Architect - Creative Product Owner
          Crafting sound at every level. From strings to signal paths, samples to systems.

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

          14

          Online

          1.9k

          Users

          12.5k

          Topics

          108.9k

          Posts