HISE Logo Forum
    • Categories
    • Register
    • Login

    render audio in background?

    Scheduled Pinned Locked Moved Scripting
    11 Posts 3 Posters 823 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.
    • ulrikU
      ulrik
      last edited by

      Is it possible to set a function to push buffers through modules silently in the background?

      Lets say I have an audio buffer, can I let it through different effects, nodes silently in the background, and then store the processed buffer and write to an audio file?

      Hise Develop branch
      MacOs 15.3.1, Xcode 16.2
      http://musikboden.se

      HISEnbergH Christoph HartC 2 Replies Last reply Reply Quote 0
      • HISEnbergH
        HISEnberg @ulrik
        last edited by

        @ulrik I haven't tried pushing audio to a separate thread, my understanding is pretty limited but it should, hypothetically, be possible.

        The BackgroundTask API is certainly what you would want to use for this. I may be working on this exact topic in a few weeks so let me know if you make any progress with it!

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

          @ulrik There are multiple ways to achieve this, the most fun one is this here:

          • a scriptnode network with a split container that provides a "silent processing chain" by adding a clear node at the start and the end
          • two audio file slots, the first is connected to a file player and a file analyzer.
          • the second is connected to a recorder node
          • the file analyser sends the length of the loaded file of the first slot to the length parameter of the recorder note and starts the playback and recording
          • you can add whatever DSP processing you want between the file player and the recorder.
          • once the file player is done, the recorder will save the incoming audio into a new buffer
          • we can then register the content callback of the second slot to flush the recording. pick and save a file, clear out the first audio file slot.
          HiseSnippet 2001.3oc4Y0saaibEdnrGmXkra1TrK1a45qjaSIjbb7lfEoV9GoV05eTkz5cw1KLFSNxZfI4vRNxxZCBvdQun.8pdYtoMOB8191r8MHuAsmYFRQRIYYKA6Esn1.wjyYNy7Mme9NmgoYH2lFEwCQFE6LLfhLdLt8PeQu85QX9nF6iL9X7gjHAMzTOztCCHQQTGjgwR+Z4.FqtLR8yG1dWhKw2llNDBcBmYSOf4wDoi1r5ui45Vm3P6v7xL6Mq1vl6uG2k2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zczLR3jg0Yz7dtWFiIxheL9MMNpSsVGsyAuclss7W9twyOJb+W4Ogn6Nrekqsz+s6HLYo+2+t28OmwQXRt945v7q9au6uFV81cXxe0O0EPlmqljny+2cyjbknt9W1kyuvin9LJKz2b8mjO5iGwNjeZb+RRexCUi.TG9Jm7p3CkuaNku4rGygcpsc9kZBE2XQU74KphatnJ9hEUwsVTE+xEUwWdyJJ+u3LNeW1uGjL0rllC2nlO4LWcpL5+fcNTD0
          
          ulrikU 2 Replies Last reply Reply Quote 5
          • ulrikU
            ulrik @Christoph Hart
            last edited by

            @Christoph-Hart that sounds great, I will study your example, thanks!

            Hise Develop branch
            MacOs 15.3.1, Xcode 16.2
            http://musikboden.se

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

              @Christoph-Hart This works great!
              If I set a stretch node instead of the "file player" node, I am able to pitch shift the original audio, nice!
              If I change the time ratio on the stretch player, I am also getting a time stretched result, however I need to change the "recording length" dependent on the time ratio.
              Now the file analyser provides me with the original length of the audio file, is there a way to modify the recording length related to the time ratio set in the stretch player?

              Hise Develop branch
              MacOs 15.3.1, Xcode 16.2
              http://musikboden.se

              ulrikU 1 Reply Last reply Reply Quote 0
              • ulrikU
                ulrik @ulrik
                last edited by ulrik

                @ulrik never mind, I found out, I need to scale the length coming from the file analyzer with the time ratio value, and set it to the recorder.
                Using a pma node will fix that I guess

                Hise Develop branch
                MacOs 15.3.1, Xcode 16.2
                http://musikboden.se

                ulrikU 1 Reply Last reply Reply Quote 0
                • ulrikU
                  ulrik @ulrik
                  last edited by

                  @ulrik said in render audio in background?:

                  @ulrik I need to scale the length coming from the file analyzer ...

                  That was harder than I thought.
                  I set it up like this:
                  Skärmavbild 2025-09-23 kl. 10.23.17.png

                  Using the min max node to invert the TimeRatio value and feed that into the pma Multiply.
                  That is working if I can find the exact Skew value on the min max node.
                  As it is now I have set the skew to 0.65, and it's close.

                  Is it possible to find the exact skew value considering the TimeRatio range 0.5 => 2.0

                  Hise Develop branch
                  MacOs 15.3.1, Xcode 16.2
                  http://musikboden.se

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

                    @ulrik Right click on the stretch player's time ratio parameter and you'll see this:

                    0a57b0b2-68dd-4e00-b454-60744725df81-image.png

                    Here it is as a number so you don't have to do it yourself:

                    0.6309297680854797
                    
                    ulrikU 1 Reply Last reply Reply Quote 1
                    • ulrikU
                      ulrik @Christoph Hart
                      last edited by

                      @Christoph-Hart perfect, thanks!

                      One more question, when I render the buffer through the stretch node, there is latency baked into the resulting file (there is a small part at the beginning which is silent), is there a way to find out how many samples that is?
                      I'm thinking of adding the silent length to the resulting buffer and then trim the start, is that a proper way to get rid of it?

                      Hise Develop branch
                      MacOs 15.3.1, Xcode 16.2
                      http://musikboden.se

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

                        @ulrik yeah there are tools in the Buffer API:

                        Link Preview Image
                        HISE | Scripting | Buffer

                        A buffer of floating point data

                        favicon

                        (docs.hise.dev)

                        • getNextZeroCrossing() should give you the first non-zero value (haven't checked that though), otherwise it's trivially to implement this with a loop
                        • trim() can be used to create a buffer from a sub range of an existing buffer, this is the most efficient way.
                        ulrikU 1 Reply Last reply Reply Quote 1
                        • ulrikU
                          ulrik @Christoph Hart
                          last edited by

                          @Christoph-Hart thanks a lot!

                          Hise Develop branch
                          MacOs 15.3.1, Xcode 16.2
                          http://musikboden.se

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

                          20

                          Online

                          2.0k

                          Users

                          12.6k

                          Topics

                          109.6k

                          Posts