HISE Logo Forum
    • Categories
    • Register
    • Login

    SNEX - reading external files

    Scheduled Pinned Locked Moved ScriptNode
    4 Posts 2 Posters 187 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

      What is the best way to get a text file into SNEX?
      I have a BIG dataset that I need to feed into a snex node for some physical modelling.
      50 x 50 array (there are 50 chunks of data, and each one of those chunks contains 50 numbers).

      7cc743bb-5d64-4dab-9e9a-89289ec0bf2e-image.png

      My first guess is maybe external data?
      I thought it was worth making a post just in case there is a better way!
      I really don't want to have to punch it in like this

      105957c2-eafe-489b-9ff1-af9e859e9284-image.png

      Thank you

      ustkU 1 Reply Last reply Reply Quote 0
      • ustkU
        ustk @griffinboy
        last edited by ustk

        @griffinboy From interface you could create an array of audio buffers that contain the data, so in the end it's a matrix of NxN

        From this I write a real audioFile, but I think it should stay internal to get passed to the externalData object of a SNEX node, I just don't know how...

        So I think the procedure is to take the reference of an audioFile slot from the SNEX node into the interface script, xrite the array of buffers into it, then read it from the SNEX ExternalData. But all my attempts failed...

        There's a externalData example in the Snippet Browser you could check.

        const var ScriptFX1 = Synth.getAudioSampleProcessor("Script FX1");
        
        const var dataSetFile = FileSystem.getFolder(FileSystem.Downloads).getChildFile("dataSet.txt");
        const var dataSetAudioFile = FileSystem.getFolder(FileSystem.Downloads).getChildFile("dataSet.wav");
        
        // Maybe a lead to what should be done next to pass to the externalData?
        //const var refAudioFile = Engine.createAndRegisterAudioFile(0);
        //const var audioFile = ScriptFX1.getAudioFile(0);
        
        // the array of buffers that'll hold the data
        reg dataAsBufferArray = importDataFile(dataSetFile);
        
        
        inline function importDataFile(df)
        {
        	if (!df.isFile())
        		return {};
        	
        	local asText = df.loadAsString();
        	local buffer = Buffer.create();
        	local temp = asText.split("\n"); // split each line
        	
        	for (line in temp)
        		line = line.split("\t"); // if TAB has been used, otherwise -> split(" ") for spaces
        	
        	local arrayOfBuffers = [];
        	
        	// now we have all strings in a 2D array, we need to parse them
        	for (i=0; i<temp.length; i++)
        	{
        		local newBuffer = Buffer.create(temp.length);
        		
        		for (j=0; j<temp[i].length; j++)
        			newBuffer[j] = parseFloat(temp[i][j]);
        		
        		arrayOfBuffers.push(newBuffer);
        	}
        	
        	// here I write to a real file but I think it should stay internal...;
        	// ... just couldn't get it to work with the externalData thing so I choose a real file in the waiting
        	dataSetAudioFile.writeAudioFile(arrayOfBuffers, 44100.0, 16);
        	
        	return arrayOfBuffers;
        }
        

        If your matrix is always square (50x50) you can also simply write only one buffer as opposed to an array. This might be easier to handle later in the externalData SNEX object. But if you are at this point, it's already looking good!

        	ExternalData data;
        
        	void setExternalData(const ExternalData& ed, int index)
        	{
        		data = ed;
        
        		ed.referBlockTo(sample[0], 0);
        	}
        

        Screenshot 2024-07-07 at 14.00.25.png

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

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

          @ustk
          mmm.
          Really interesting thank you.

          I'll try this method out!

          I could always format the data and paste it directly into a snex array 😅
          But I'm trying not to do that becuase that would box me in a bit. I'd have to edit the data instead of just editing the text file.

          I might make a feature request for an easier way.
          Most people probably don't care about this functionality, but it's very useful for physical modelling / analog emulation.

          ustkU 1 Reply Last reply Reply Quote 0
          • ustkU
            ustk @griffinboy
            last edited by ustk

            @griffinboy Well, I care about this too 😀
            This is definitely doable already, it is just a matter of taking the right path...
            I don't think SNEX is made for direct communication with the outside world anyway, so to me ExternalData is the way, until the master of the castle pops in at least... @Christoph-Hart ?

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

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

            7

            Online

            1.7k

            Users

            11.9k

            Topics

            103.5k

            Posts