Wednesday, 5 December 2012

Compression 101

I have recently put up a video introducing the basics of audio compression (dynamic range compression) for voice:



The patch used in this video is this one (remember AGPL):



2 SetSwapLimit
"temp/input.wav" ReadFile ^signal
?signal !orig

[Low peak cut]
(?signal,150,3)ButterworthLowPass  !lower
(?signal,150,3)ButterworthHighPass !upper
(>lower,60,2)ButterworthHighPass   !lower
(?lower Normalise,100,100)Follow           !shape
(?shape,(1,?shape MaxValue)/)NumericVolume !shape
(0.1,>shape dbs+48)DirectMix               !shape
(
    >lower,
    >shape 
)Divide !lower

(
    >lower,
    >upper 
)Mix  Normalise !signal

[ De-ess ]
(?signal,4000,5)ButterworthLowPass  !lower
(?signal,4000,5)ButterworthHighPass !upper
(?upper Normalise,100,100)Follow           !shape
(?shape,(1,?shape MaxValue)/)NumericVolume !shape
(0.1,>shape dbs+48)DirectMix               !shape
(
    >upper,
    >shape 
)Divide !upper

(
    >lower,
    >upper dbs+3
)Mix  Normalise !signal

{
    (
        (?signal Reverse,1,50)Follow Reverse,
        (?signal        ,1,50)Follow,
    )Mix !shape    
    (?shape,(2,?shape MaxValue)/)NumericVolume   !shape
    (0.04,>shape)DirectMix Clip                  !shape
    (>signal,?shape)Multiply Normalise           !signal
    
    (
        (?signal Normalise,25,25)Follow,
        (?signal Normalise Reverse,25,25)Follow Reverse,
    )Mix !shape
    (?shape,(1,?shape MaxValue)/)NumericVolume !shape
    (0.3,>shape dbs+24)DirectMix               !shape
    (
        >signal,
        >shape 
    )Divide Normalise !signal 
}!envelope-compress

{
    (?signal,50,10)Granulate !grains
    Bunch !output
    (
        >grains,
        {
            ^grain ^time
            (                
                (?time,(?time,?grain length)+,?signal)Cut !sample
                (?grain Rectify MaxValue !v,?gate-point)Gt,
                {
                    (                    
                        (?v,?slam-point)Gt,
                        {
                            (>grain,(?slam-point,?v)/)NumericVolume !grain
                        },
                        {
                            [ Do nothing ]
                        }
                    )Choose Invoke
                }
                ,
                {
                    (>grain,(1,(?gate-point,?v)/)/)NumericVolume !grain
                }
            )Choose Invoke
            ((>grain swapout,>time),>output)AddEnd !output
        }
    )InvokeAll
    >output MixAt Normalise !signal
    
}!compress
{
    0.02 !gate-point
    0.50 !slam-point
    [ Do in pairs to avoid running out of memory ]
    (
        (
            ?compress,
        )DoAll Mix Swapout,
        (
            ?compress,
        )DoAll Mix Swapout,
        (
            ?compress,
        )DoAll Mix Swapout,
        (
            ?compress,
        )DoAll Mix Swapout,
    )Mix Normalise !signal
}!granular-compress

?envelope-compress Invoke

[ Reverb ]
(15 Silence,?signal)Concatenate !note-left
?signal                         !note-right

(>note-left ,1000,0.25)RBJLowPass !note-left
(>note-right,1000,0.25)RBJLowPass !note-right
(
    1,2,
    {    
        !outer
        (
            1,4,
            {
                !t
                {((30,(?t,(24,?outer)*)*)+ Prime Silence,?note-left )Concatenate} Do !nlTask
                {((45,(?t,(15,?outer)*)*)+ Prime Silence,?note-right)Concatenate} Do !nrTask
            
                {((>nlTask Done, -15)Volume,(700,(?t,3)*)-,1)ButterworthLowPass}  Do  !nlTask
                {((>nrTask Done, -15)Volume,(700,(?t,3)*)-,1)ButterworthLowPass}  Do  !nrTask
            
                {(>nlTask Done, ?note-left )Mix Normalise}                        Do !nlTask 
                {(>nrTask Done, ?note-right)Mix Normalise}                        Do !nrTask
                
                ?nlTask Done !note-left
                ?nrTask Done !note-right
            }
        )Repeat
    }
)Repeat
(
    >note-left dbs-12,
    ?signal
)Mix Normalise !left
(
    >note-right dbs-12,
    >signal
)Mix Normalise !right

(>left ,3000,2,6)RBJPeaking  Normalise   !left
(>right,3000,2,6)RBJPeaking  Normalise   !right
(>left, 150,2,12)RBJPeaking  Normalise  !left
(>right,150,2,12)RBJPeaking  Normalise  !right
>left  !signal ?granular-compress Invoke
>signal dbs+6 WaveLimit !left
>right !signal ?granular-compress Invoke
>signal dbs+6 WaveLimit !right

(
    (
        >left,
        >right
    ),"temp/step-1.wav"
)WriteFile32

No comments:

Post a Comment