Do entire for-loops run during a single sample?


    Jan 12 2021 | 7:21 am
    I'm having two problems: 1. I don't know if what I'm trying is possible in gen~. 2. I'm not sure of the correct codebox syntax.
    I want to use a for-loop to update all the values of buffer 'u' every sample based on some simple arithmetic and values in two other buffers. Then copy buffer 'u1' over 'u2', and copy 'u' over 'u1'. It's a lot of peeking a poking, which has to be done in a for-loop, so I need to get the codebox syntax right. I've come this far by making some assumptions looking at example patches and stuff posted on this forum, but I can't find official genexpr syntax documentation.
    I'm looking for something like: poke( buffer name, value to insert, buffer index, ... ) ; variable = peek( buffer name, buffer index, ... );
    I have the codebox compiling without errors now, but it isn't working as I expect (I get no sound at all), and I can't tell if it's because of problem 1, problem 2, or something else. If this works as I intend, the input can be any audio signal and the output will be an excited string.
    Any help is greatly appreciated!

    • Jan 12 2021 | 6:13 pm
      Do entire for-loops run during a single sample?
      yes, they can, this much i know.... i'm not quickly finding your problem yet though(definitely not problem1), but at the very least, letting you know the all-at-once in-a for-loop is possible, and bumping this thread for others to find and add more help :)
    • Jan 12 2021 | 6:49 pm
      Thanks, Raja! Good to know it's possible at least. I was afraid it would only do one iteration per sample, or it wouldn't do the whole loop every sample, or something like that.
      It occurred to me that I should probably include a patch that runs the gen~, though there's not much to it as of right now. Perhaps that's where I'm doing something wrong.
    • Jan 12 2021 | 11:42 pm
      ah, that helps more... first off, instead of this: u2 = u1; u1 = u;
      you'll want to do this(you have to specifically write each sample to duplicate a buffer): for (n=0; n<=N; n+=1) { poke(u2,peek(u1,n),n); //u2 = u1; poke(u1,peek(u,n),n); //u1 = u; } then, beyond that, i feel like the algorithm is missing something... if you go through your code, you'll notice the 'u1' and 'u2' buffers starting off at 0, cause every write operation into buffer 'u', to also be filled with 0.
      and also the 'input' section near the bottom: // input pluck = peek(u,li) + d0*input; poke(u, pluck, li);
      ....seems like if you only write to the index of 'li' every time, you're not going to be writing much to the other buffers beyond that when 'shifting state', so maybe somewhere along the way, you need to think more specifically about how every single sample of buffer 'u' gets filled with something other than the initial '0's at some point(and also, one last thing is that you don't need to intialize buffer~s with '0's, they start like that, but there's no harm... it's what needs to be done programming lower-level in C/C++/etc.). Hope it helps! 🍻
    • Jan 13 2021 | 3:04 am
      That did it! Thanks so much! You were right, the state update should have been at the very end.