|
|
|
@ -39,6 +39,14 @@ func supressorState(ctx *ntcontext) int {
|
|
|
|
|
c := ctx.paClient
|
|
|
|
|
var inpLoaded, outLoaded, inputInc, outputInc bool
|
|
|
|
|
if ctx.config.FilterInput {
|
|
|
|
|
if ctx.serverInfo.servertype == servertype_pipewire {
|
|
|
|
|
_, ladspasource, err := findModule(c, "module-ladspa-source", "source_name='NoiseTorch Microphone'")
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Printf("Couldn't fetch module list to check for module-ladspa-source: %v\n", err)
|
|
|
|
|
}
|
|
|
|
|
inpLoaded = ladspasource
|
|
|
|
|
inputInc = false
|
|
|
|
|
} else {
|
|
|
|
|
_, nullsink, err := findModule(c, "module-null-sink", "sink_name=nui_mic_denoised_out")
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Printf("Couldn't fetch module list to check for module-null-sink: %v\n", err)
|
|
|
|
@ -61,11 +69,20 @@ func supressorState(ctx *ntcontext) int {
|
|
|
|
|
} else if nullsink || ladspasink || loopback || remap {
|
|
|
|
|
inputInc = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
inpLoaded = true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ctx.config.FilterOutput {
|
|
|
|
|
if ctx.serverInfo.servertype == servertype_pipewire {
|
|
|
|
|
_, ladspasink, err := findModule(c, "module-ladspa-sink", "sink_name='NoiseTorch Headphones'")
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Printf("Couldn't fetch module list to check for module-ladspa-sink: %v\n", err)
|
|
|
|
|
}
|
|
|
|
|
outLoaded = ladspasink
|
|
|
|
|
outputInc = false
|
|
|
|
|
} else {
|
|
|
|
|
_, out, err := findModule(c, "module-null-sink", "sink_name=nui_out_out_sink")
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Printf("Couldn't fetch module list to check for output module-ladspa-sink: %v\n", err)
|
|
|
|
@ -89,6 +106,7 @@ func supressorState(ctx *ntcontext) int {
|
|
|
|
|
|
|
|
|
|
outLoaded = out && lad && loop && outin && loop2
|
|
|
|
|
outputInc = out || lad || loop || outin || loop2
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
outLoaded = true
|
|
|
|
|
}
|
|
|
|
@ -105,11 +123,8 @@ func supressorState(ctx *ntcontext) int {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func loadSupressor(ctx *ntcontext, inp *device, out *device) error {
|
|
|
|
|
|
|
|
|
|
if ctx.serverInfo.servertype == servertype_pulse {
|
|
|
|
|
log.Printf("Querying pulse rlimit\n")
|
|
|
|
|
|
|
|
|
|
c := ctx.paClient
|
|
|
|
|
|
|
|
|
|
pid, err := getPulsePid()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
@ -130,9 +145,70 @@ func loadSupressor(ctx *ntcontext, inp *device, out *device) error {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
log.Printf("Rlimit: %+v\n", newLim)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if inp.checked {
|
|
|
|
|
log.Printf("Loading supressor\n")
|
|
|
|
|
var err error
|
|
|
|
|
if ctx.serverInfo.servertype == servertype_pipewire {
|
|
|
|
|
err = loadPipeWireInput(ctx, inp)
|
|
|
|
|
} else {
|
|
|
|
|
err = loadPulseInput(ctx, inp)
|
|
|
|
|
}
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Printf("Error loading input: %v\n", err)
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if out.checked {
|
|
|
|
|
var err error
|
|
|
|
|
if ctx.serverInfo.servertype == servertype_pipewire {
|
|
|
|
|
err = loadPipeWireOutput(ctx, out)
|
|
|
|
|
} else {
|
|
|
|
|
err = loadPulseOutput(ctx, out)
|
|
|
|
|
}
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Printf("Error loading output: %v\n", err)
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func loadPipeWireInput(ctx *ntcontext, inp *device) error {
|
|
|
|
|
c := ctx.paClient
|
|
|
|
|
log.Printf("Loading supressor for pipewire\n")
|
|
|
|
|
idx, err := c.LoadModule("module-ladspa-source",
|
|
|
|
|
fmt.Sprintf("source_name='NoiseTorch Microphone' master=%s "+
|
|
|
|
|
"rate=48000 channels=1 "+
|
|
|
|
|
"label=noisetorch plugin=%s control=%d", inp.ID, ctx.librnnoise, ctx.config.Threshold))
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
log.Printf("Loaded ladspa source as idx: %d\n", idx)
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func loadPipeWireOutput(ctx *ntcontext, out *device) error {
|
|
|
|
|
c := ctx.paClient
|
|
|
|
|
log.Printf("Loading supressor for pipewire\n")
|
|
|
|
|
idx, err := c.LoadModule("module-ladspa-sink",
|
|
|
|
|
fmt.Sprintf("sink_name='NoiseTorch Headphones' master=%s "+
|
|
|
|
|
"rate=48000 channels=1 "+
|
|
|
|
|
"label=noisetorch plugin=%s control=%d", out.ID, ctx.librnnoise, ctx.config.Threshold))
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
log.Printf("Loaded ladspa source as idx: %d\n", idx)
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func loadPulseInput(ctx *ntcontext, inp *device) error {
|
|
|
|
|
c := ctx.paClient
|
|
|
|
|
log.Printf("Loading supressor for pulse\n")
|
|
|
|
|
idx, err := c.LoadModule("module-null-sink", "sink_name=nui_mic_denoised_out rate=48000")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
@ -169,10 +245,11 @@ func loadSupressor(ctx *ntcontext, inp *device, out *device) error {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
log.Printf("Loaded remap source as idx: %d\n", idx)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if out.checked {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func loadPulseOutput(ctx *ntcontext, out *device) error {
|
|
|
|
|
c := ctx.paClient
|
|
|
|
|
_, err := c.LoadModule("module-null-sink", `sink_name=nui_out_out_sink`)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
@ -201,14 +278,45 @@ func loadSupressor(ctx *ntcontext, inp *device, out *device) error {
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func unloadSupressor(ctx *ntcontext) error {
|
|
|
|
|
if ctx.serverInfo.servertype == servertype_pipewire {
|
|
|
|
|
return unloadSupressorPipeWire(ctx)
|
|
|
|
|
} else {
|
|
|
|
|
return unloadSupressorPulse(ctx)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func unloadSupressorPipeWire(ctx *ntcontext) error {
|
|
|
|
|
log.Printf("Unloading modules for pipewire\n")
|
|
|
|
|
|
|
|
|
|
log.Printf("Searching for module-ladspa-source\n")
|
|
|
|
|
c := ctx.paClient
|
|
|
|
|
m, found, err := findModule(c, "module-ladspa-source", "source_name='NoiseTorch Microphone'")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if found {
|
|
|
|
|
log.Printf("Found module-ladspa-source at id [%d], sending unload command\n", m.Index)
|
|
|
|
|
c.UnloadModule(m.Index)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.Printf("Searching for module-ladspa-sink\n")
|
|
|
|
|
m, found, err = findModule(c, "module-ladspa-sink", "sink_name='NoiseTorch Headphones'")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if found {
|
|
|
|
|
log.Printf("Found module-ladspa-sink at id [%d], sending unload command\n", m.Index)
|
|
|
|
|
c.UnloadModule(m.Index)
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func unloadSupressor(ctx *ntcontext) error {
|
|
|
|
|
log.Printf("Unloading pulseaudio modules\n")
|
|
|
|
|
func unloadSupressorPulse(ctx *ntcontext) error {
|
|
|
|
|
log.Printf("Unloading modules for pulseaudio\n")
|
|
|
|
|
|
|
|
|
|
if pid, err := getPulsePid(); err == nil {
|
|
|
|
|
if lim, err := getRlimit(pid); err == nil {
|
|
|
|
@ -318,6 +426,7 @@ func unloadSupressor(ctx *ntcontext) error {
|
|
|
|
|
// Finds a module by exactly matching the module name, and checking if the second string is a substring of the argument
|
|
|
|
|
func findModule(c *pulseaudio.Client, name string, argMatch string) (module pulseaudio.Module, found bool, err error) {
|
|
|
|
|
lst, err := c.ModuleList()
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
return pulseaudio.Module{}, false, err
|
|
|
|
|
}
|
|
|
|
|