[sharing unfinished thing] a compressor in gen~


    Mar 30 2016 | 10:23 pm
    I'm trying to replicate a guitar heavy amplifier kind of sound in max. i may have gotten lost along the way and thought i need a compressor for that. so here is an attempt at making a compressor with gen~. I'm not sure what i'm doing.
    There is a buffer of 50 samples that is rewritten each sample and averaged, so it's a circular running buffer, to get the average sound level. Then this level is compared to a threshold and the sound that will be louder than this threshold will be attenuated, according to a ceiling : a maximum ceiling level must be set in dB wherein it will be the new maximum amplitude of the compressed sound. Then there is an automatic makeup gain which will add as much as the ceil level to the sound, so that the new maximum is like the previous maximum.
    I am not sure i got the maths right. It seems to work, but, well, sometimes it doesn't seem right, so i don't know, can someone advise ? !

    • Apr 02 2016 | 6:16 am
      hm, *please* help ?
    • Apr 03 2016 | 1:47 am
      Hey, not as much time and energy these days to help like I used to but until others arrive, I can bump this thread and advise two things: 1) To help visualize the 'action' of the compressor, create an output for just the gain reduction(but i'm confused as it looks like the outlet2 of 'gate 2' in gen~ is going to both the dry output and the compressor instead of just one or the other as your comments say it should.... (i wonder if that's the best practice... did you learn that from somewhere specific where i could take a look to understand better how you're trying to achieve this style of compressor?)) 2) 'Averaging' is ok, but I prefer RMS(Root Mean Square) whenever you're going for an 'average of digital signal samples'. The algorithm is easy as the name implies: 'Root' - take the vector of samples, calculate the 'square-root' of every sample, then... 'Mean' - sum all of those square-roots together and divide by the number of samples in the vector('mean' is the same as 'average'), then... 'Square' - square the result(or put another way, 'to the power of 2' aka 'pow 2'; this also removes any need for 'abs' since squaring turns everything positive)
      So your gen~ code for RMS might be something like this to replace the avg stuff you had: summm = 0.; for (i=0; i summm = summm + sqrt(peek(lvl, i, 0, channels=1)); } sumavg = pow(summm/lvlsize, 2); out1 = sumavg;
      I could be wrong, perhaps I've misunderstood your intent, in which case, feel free to completely ignore me, but just in case it helps or at the very least encourages others to jump in and help, thought i'd do what i could :)
    • Apr 03 2016 | 2:32 am
      (^i meant to add for my advice #1 there: creating a visual for the action of the compressor is a quick way to help yourself and others debug where your compressor doesn't perform to expectations over different types of audio)
    • Apr 03 2016 | 12:15 pm
      @raja: RMS is the other way around. It's the square root of the mean of squares (see wikipedia).
    • Apr 03 2016 | 4:05 pm
      hey, thanks, 1) probably the design is confusing ; this compressor's aim is to boost instead of reducing the final level ; by reducing difference between peak levels and lower levels ; that's why in each case i add the original input * ceil level (because logically, nothing should exceed ceil level) to get back to a level as close as 1 as possible. I'm not really sure how to visualize efficiently... tho indeed if i seek other people's advice i should care more about making things clear :) 2) it seems better indeed !! and tried the square root of the mean of squares as AK suggested...
      i think there are several things i didn't get right. Plus i mistook the wet and dry level...
    • Apr 03 2016 | 5:24 pm
      @AK oops, i'm an idiot, thanks for lettin me know(haven't done this stuff in awhile :)
      @Vichug glad it got further, will take a look again later, hope others with more knowledge will help soon in the meantime. Best of luck!
    • Apr 04 2016 | 9:26 am
      The running average or rms can also be implemented without a buffer, which makes it cheaper especially with larger buffer sizes.
    • Apr 04 2016 | 11:38 am
      thanks a lot, that gets better every time!