# Dolby Surround encoder sink
#
# start with pipewire -c filter-chain/sink-dolby-surround.conf
#
context.properties = {
    log.level = 0
}

context.spa-libs = {
    audio.convert.* = audioconvert/libspa-audioconvert
    support.*       = support/libspa-support
}

context.modules = [
    { name = libpipewire-module-rt
        args = {
            #rt.prio      = 88
            #rt.time.soft = -1
            #rt.time.hard = -1
        }
        flags = [ ifexists nofail ]
    }
    { name = libpipewire-module-protocol-native }
    { name = libpipewire-module-client-node }
    { name = libpipewire-module-adapter }

    { name = libpipewire-module-filter-chain
        args = {
            node.description = "Dolby Surround Sink"
            media.name       = "Dolby Surround Sink"
            filter.graph = {
                nodes = [
                    {
                        type  = builtin
                        name  = mixer
                        label = mixer
                        control = { "Gain 1" = 0.5 "Gain 2" = 0.5 }
                    }
                    {
                        type   = ladspa
                        name   = enc
                        plugin = surround_encoder_1401
                        label  = surroundEncoder
                    }
                ]
                links = [
                    { output = "mixer:Out" input = "enc:S" }
                ]
                inputs  = [ "enc:L" "enc:R" "enc:C" null "mixer:In 1" "mixer:In 2" ]
                outputs = [ "enc:Lt" "enc:Rt" ]
            }
            capture.props = {
                node.name      = "effect_input.dolby_surround"
                media.class    = Audio/Sink
                audio.channels = 6
                audio.position = [ FL FR FC LFE SL SR ]
            }
            playback.props = {
                node.name      = "effect_output.dolby_surround"
                node.passive   = true
                audio.channels = 2
                audio.position = [ FL FR ]
            }
        }
    }
]
