# How to limit the volume level in Csound?

**URL:** <https://forum.cabbageaudio.com/t/how-to-limit-the-volume-level-in-csound/611>\
**Category:** Tutorial Requests\
**Created:** [10 July 2017 09:59 UTC](https://forum.cabbageaudio.com/t/how-to-limit-the-volume-level-in-csound/611 "2017-07-10T09:59:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karamel1](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/karamel1/32/1680_2.png) [@Karamel1](https://forum.cabbageaudio.com/u/Karamel1)\
**Post date:** [10 July 2017 09:59 UTC](https://forum.cabbageaudio.com/t/how-to-limit-the-volume-level-in-csound/611/1 "2017-07-10T09:59:59Z")

</div>

Hello,  
In order to protect my ears, I wish to implement a sound level limiter.  
Using ASIO4all, there is no way to limit to level of the sound output… and it is really too much loud.  
So, I’d like to add a vumeter ranging from volume 0 (no sound) to a maximum ( lower than the 0dbfs of Csound) which would be the “maximum acceptable volume for my ears”.

I tried using aOut gain aOut, kFactor and aOut = aOut\*kFactor I don’t find these solution satisfactory as these do not limit the level of the output.

Thank you for your help.

---

<div class="post-metadata">

**Author:** ![rorywalsh](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/rorywalsh/32/165_2.png) [@rorywalsh](https://forum.cabbageaudio.com/u/rorywalsh)\
**Post date:** [10 July 2017 14:54 UTC](https://forum.cabbageaudio.com/t/how-to-limit-the-volume-level-in-csound/611/2 "2017-07-10T14:54:25Z")

</div>

It’s not something I’ve ever really had to do but have you looked at the various [limiters](http://csound.github.io/docs/manual/SigmodSiglimit.html) that ship with Csound? There are also some compressors that might be of help.

---

<div class="post-metadata">

**Author:** ![Karamel1](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/karamel1/32/1680_2.png) [@Karamel1](https://forum.cabbageaudio.com/u/Karamel1)\
**Post date:** [10 July 2017 16:23 UTC](https://forum.cabbageaudio.com/t/how-to-limit-the-volume-level-in-csound/611/3 "2017-07-10T16:23:54Z")

</div>

Thank you Rory.  
The example given in the limiters… almost killed my ears. It is so loud and noisy (the “wrap” is so loud and distorded !!)  
Maybe I should better formulate my question : is there a way to know how many db the sound output is and then to tell csound not to go over a % of that lvl ? (like it is implemented in reaper for instance) ?  
Sorry if I do not use the right vocabulary…

---

<div class="post-metadata">

**Author:** ![rorywalsh](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/rorywalsh/32/165_2.png) [@rorywalsh](https://forum.cabbageaudio.com/u/rorywalsh)\
**Post date:** [10 July 2017 17:44 UTC](https://forum.cabbageaudio.com/t/how-to-limit-the-volume-level-in-csound/611/4 "2017-07-10T17:44:57Z")

</div>

Ok, you could perhaps send all signals to a single instrument and do all your mixing and outputting there. You could test to see if the signal gets above a particular level using the rms opcode. If it is, you can mute the output? This is a crude example, but might give you some ideas.

```
<Cabbage>
form caption("Untitled") size(400, 300), colour(58, 110, 182), pluginID("def1")
keyboard bounds(18, 32, 348, 80) mouseoeverkeycolour(255, 255, 0, 128) 
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d --midi-key-cps=4 --midi-velocity-amp=5
</CsOptions>
<CsInstruments>
; Initialize the global variables. 
sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1

;instrument will be triggered by keyboard widget
instr 1
    kAmp line 1, 5, 10
    kEnv madsr .1, .2, .6, .4
    aOut vco2 p5*kAmp, p4
    chnset aOut*kEnv, "LeftSignal"
    chnset aOut*kEnv, "RightSignal"
endin

instr LIMIT
    aL chnget "LeftSignal"
    aR chnget "RightSignal"
    kRmsL rms aL
    kRmsR rms aR
    if kRmsL < 1 && kRmsR < 1 then
        outs aL, aR
    endif
endin

</CsInstruments>
<CsScore>
;causes Csound to run for about 7000 years...
f0 z
i"LIMIT" 0 z
</CsScore>
</CsoundSynthesizer>
```

---

<div class="post-metadata">

**Author:** ![Karamel1](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/karamel1/32/1680_2.png) [@Karamel1](https://forum.cabbageaudio.com/u/Karamel1)\
**Post date:** [10 July 2017 20:34 UTC](https://forum.cabbageaudio.com/t/how-to-limit-the-volume-level-in-csound/611/5 "2017-07-10T20:34:08Z")

</div>

Thank you a lot !  
This is also interesting to combine with the vumeter widget.  
Somehow, I found out that it is possible to reduce the volume thanks to windows mixer even with asio4all.  
Now, I can survive my experiments 🙂

---

<div class="post-metadata">

**Author:** ![rorywalsh](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/rorywalsh/32/165_2.png) [@rorywalsh](https://forum.cabbageaudio.com/u/rorywalsh)\
**Post date:** [11 July 2017 10:02 UTC](https://forum.cabbageaudio.com/t/how-to-limit-the-volume-level-in-csound/611/6 "2017-07-11T10:02:18Z")

</div>

That’s good to know.
