[Csnd] rms useage question
Date | 2013-12-19 15:53 |
From | Jacques Leplat |
Subject | [Csnd] rms useage question |
Hello CSounders, I’ve been banging my head with the rms opcode. And wonder if someone could point me in the right direction. The csd uses an “output instrument” to do the one and only actual “outs” in the csd. ;-- Output Instrument instr outInstr kfactorL = sin((gkPan/100) * $M_PI_2) * (gkVolume / 100) kfactorR = cos((gkPan/100) * $M_PI_2) * (gkVolume / 100) gaoutL = gaoutL * kfactorL gaoutR = gaoutR * kfactorR outs gaoutL,gaoutR kvl rms gaoutL kvr rms gaoutR if gklevelL < kvl then gklevelL = kvl endif if gklevelR < kvr then gklevelR = kvr endif printk2 gklevelL printk2 gklevelR gaoutL = 0 gaoutR = 0 endin When run, The printk2’s output lots of very small values (below 1.0), and yet the console also reports output values, which are much higher, 1.19064 being the highest. And yet they are all below 1.0. I have looked at the shapes.csd example, it does something like “gklevel = gklevel + ks”. Were I to add the k rate levels in the output instrument, I do not know when to stop adding. This leads me to believe that I am missing a fundamental point here, I was expecting at least one of the printk2’s to be of the same magnitude as that reported by the console (i.e.: up to 1.19064). Could someone please give me an idea where I should look? new alloc for instr 1: new alloc for instr 1: new alloc for instr 1: new alloc for instr outInstr: i2 0.00000 i2 0.00000 i2 0.00129 i2 0.00129 i2 0.00348 i2 0.00348 i2 0.00865 i2 0.00865 i2 0.01284 i2 0.01284 i2 0.02594 i2 0.02594 i2 0.04014 i2 0.04014 i2 0.04670 i2 0.04670 i2 0.06009 i2 0.06009 i2 0.07767 i2 0.07767 i2 0.09349 i2 0.09349 i2 0.10157 i2 0.10157 i2 0.10702 i2 0.10702 i2 0.12628 i2 0.12628 i2 0.13595 i2 0.13595 i2 0.14677 i2 0.14677 i2 0.16026 i2 0.16026 i2 0.17295 i2 0.17295 i2 0.18748 i2 0.18748 i2 0.20885 i2 0.20885 i2 0.24224 i2 0.24224 i2 0.25734 i2 0.25734 i2 0.30191 i2 0.30191 i2 0.31421 i2 0.31421 i2 0.34097 i2 0.34097 i2 0.34517 i2 0.34517 i2 0.35635 i2 0.35635 WARNING: Buffer overrun in real-time audio input i2 0.36647 i2 0.36647 i2 0.38649 i2 0.38649 i2 0.38656 i2 0.38656 i2 0.39982 i2 0.39982 i2 0.40219 i2 0.40219 i2 0.41401 i2 0.41401 B 0.000 .. 0.183 T 0.183 TT 0.183 M: 1.19064 1.19064 number of samples out of range: 6 6 WARNING: Buffer overrun in real-time audio input B 0.183 .. 0.344 T 0.344 TT 0.344 M: 0.83548 0.83548 B 0.344 .. 0.510 T 0.510 TT 0.510 M: 0.60467 0.60467 B 0.510 .. 0.759 T 0.759 TT 0.759 M: 0.52492 0.52492 WARNING: Buffer overrun in real-time audio input B 0.759 .. 1.006 T 1.006 TT 1.006 M: 0.52469 0.52469 B 1.006 .. 1.171 T 1.171 TT 1.171 M: 1.11965 1.11965 number of samples out of range: 1 1 B 1.171 .. 1.331 T 1.331 TT 1.331 M: 0.71890 0.71890 B 1.331 .. 2.000 T 2.000 TT 2.000 M: 0.55596 0.55596 Score finished in csoundPerformKsmps(). inactive allocs returned to freespace end of score. overall amps: 1.19064 1.19064 overall samples out of range: 7 7 0 errors in performance Elapsed time at end of performance: real: 3.324s, CPU: 0.406s closing device 87 2048 sample blks of 64-bit floats written to dac |
Date | 2013-12-19 16:45 |
From | Victor Lazzarini |
Subject | Re: [Csnd] rms useage question |
If your signal is a pure sine then the reported rms should be around 0.707*amp. Here’s a printout of a sine wave with amp = 1, every 0.1 secs i 1 time 0.00227: 0.25806 i 1 time 0.10204: 0.71042 i 1 time 0.20181: 0.70922 i 1 time 0.30159: 0.70452 i 1 time 0.40136: 0.70336 i 1 time 0.50113: 0.70735 i 1 time 0.60091: 0.71098 i 1 time 0.70068: 0.70929 i 1 time 0.80045: 0.70458 i 1 time 0.90023: 0.70333 i 1 time 1.00000: 0.70728 once it settles down, it’s around 0.707. So the rms relation to peak amp will depend on the waveform shape. A spiky signal will have a lower rms relatively to its peak amp than a “fuller” signal such as the sinewave. A pulse wave will for instance get these values i 1 time 0.00227: 0.03676 i 1 time 0.10204: 0.09732 i 1 time 0.20181: 0.09803 i 1 time 0.30159: 0.09869 i 1 time 0.40136: 0.09943 i 1 time 0.50113: 0.10011 i 1 time 0.60091: 0.10070 i 1 time 0.70068: 0.10157 i 1 time 0.80045: 0.10214 i 1 time 0.90023: 0.10284 i 1 time 1.00000: 0.09737 The key thing here is that you are measuring an average of the amplitude over a (short) timespan, which is different from measuring the max positive (or absolute) amplitude of the signal. Victor On 19 Dec 2013, at 15:53, Jacques Leplat |
Date | 2013-12-19 17:12 |
From | Jacques Leplat |
Subject | Re: [Csnd] rms useage question |
Thanks Victor, After reading your reply it seemed worthwhile to try out max_k instead of rms. The result compared to rms is enlightening (to me anyway). All the best, Jacques On 19 Dec 2013, at 16:45, Victor Lazzarini wrote: > If your signal is a pure sine then the reported rms should be around 0.707*amp. Here’s a printout of > a sine wave with amp = 1, every 0.1 secs > > i 1 time 0.00227: 0.25806 > i 1 time 0.10204: 0.71042 > i 1 time 0.20181: 0.70922 > i 1 time 0.30159: 0.70452 > i 1 time 0.40136: 0.70336 > i 1 time 0.50113: 0.70735 > i 1 time 0.60091: 0.71098 > i 1 time 0.70068: 0.70929 > i 1 time 0.80045: 0.70458 > i 1 time 0.90023: 0.70333 > i 1 time 1.00000: 0.70728 > > once it settles down, it’s around 0.707. > > So the rms relation to peak amp will depend on the waveform shape. A spiky signal will have a lower rms > relatively to its peak amp than a “fuller” signal such as the sinewave. A pulse wave will for instance get > these values > > i 1 time 0.00227: 0.03676 > i 1 time 0.10204: 0.09732 > i 1 time 0.20181: 0.09803 > i 1 time 0.30159: 0.09869 > i 1 time 0.40136: 0.09943 > i 1 time 0.50113: 0.10011 > i 1 time 0.60091: 0.10070 > i 1 time 0.70068: 0.10157 > i 1 time 0.80045: 0.10214 > i 1 time 0.90023: 0.10284 > i 1 time 1.00000: 0.09737 > > The key thing here is that you are measuring an average of the amplitude over a (short) timespan, which > is different from measuring the max positive (or absolute) amplitude of the signal. > > Victor > |