Learning to program MSP external / dsp process on single sample instead of vector


    Dec 07 2018 | 2:30 pm
    I just recently made the jump to programming MSP externals (with Windows and Visual Code). I'm trying to understand how to specify in the perform routine that the dsp process is applied at a single sample level instead of the vector (for single sample feedback for example). Is there any example where I could find this ? Maybe in one of the max sdk package source codes ? Thanks a lot!!

    • Dec 07 2018 | 7:35 pm
      if you look at the example in the SDK called plussz~, it has the basics:
      while (sampleframes--) *out++ = *in1++ + *in2++;
      *in1++ is grabbing the 'next' sample within the vector(same as saying *in1 = *in1 + 1, which in literal words means, "the memory-address to which 'in1' is pointing to should be incremented by 1 and assigned back to 'in1' thus telling 'in1' to point to the next consecutive address space in a vector of memory addresses") if you want recursive history, you could do something like this, of course this is just a snippet of an example, a real perform method would have more to this including initialized variables above/before this code:
      outhistory = x->outhistory //<-between vectors, we need to recall the sample history stored in the object's struct from the previous vector(the single sample at end of while-loop from the previous vector) while (sampleframes--) //counts down the number of samples within the vector { input1 = *in1++; input2 = *in2++; //write input samples to internal variables output = input1 + input2 + outhistory ; //combine inputs plus running history... //....and write to variable named 'output' outhistory = output; //keep a running history of the 'output' variable } x->outhistory = outhistory; //<-between vectors, we need to store the sample history(the single sample at the end of while-loop needs to be written to the object struct because the 'while' loop will no longer be in effect and therefore not keep a running tally of the history between loops), the next time the loop begins, it can pull this history from the object's internal memory/struct
      Warning: Don't actually use the above code as a real MSP object(it will accumulate inputs very quickly and if you're sending anything through the inputs besides complete silence(0.) it can blow up pretty quickly).
      i probably confused more than helped here, but was trying to explain it from many different angles, hope it makes sense(essentially, all the audio examples in the SDK already show you what you need).
    • Dec 08 2018 | 5:47 pm
      Great, thanks a lot for your reply! There's a lot to read in the documentation so I really needed a bit of direction here
      It does make sense, I get the general idea with the increment of 1 in your examples