From 0f361e2afcf77cc637540c44ee44fc5ecf874a7a Mon Sep 17 00:00:00 2001 From: Kian Kasad Date: Sat, 20 Aug 2022 17:27:02 -0700 Subject: [PATCH] Fix naming of audio devices under PipeWire Under PulseAudio, the user-friendly name for each audio device was stored under its `device.description` property. Under PipeWire, `device.description` is the name of the sound card, not the source/sink. This results in all source devices showing their sound card's name in NoiseTorch. Since I have multiple sources on the same sound card, it meant all my microphones had the same name, making NoiseTorch unusable. This commit changes the assignment of device names. When running under PipeWire, the `pulseaudio.Source.Description` field holds the correct device name, while the `pulseaudio.Source.PropList["device.description"]` field that was being used previously is the sound card's description. The NoiseTorch context must now be passed to the `getSources` and `getSinks` functions so they can check whether the program is running under PulseAudio or PipeWire. --- cli.go | 8 ++++---- main.go | 20 ++++++++++++++------ 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/cli.go b/cli.go index 89915e9..c018b5e 100644 --- a/cli.go +++ b/cli.go @@ -88,13 +88,13 @@ func doCLI(opt CLIOpts, config *config, librnnoise string) { if opt.list { fmt.Println("Sources:") - sources := getSources(paClient) + sources := getSources(&ctx, paClient) for i := range sources { fmt.Printf("\tDevice Name: %s\n\tDevice ID: %s\n\n", sources[i].Name, sources[i].ID) } fmt.Println("Sinks:") - sinks := getSinks(paClient) + sinks := getSinks(&ctx, paClient) for i := range sinks { fmt.Printf("\tDevice Name: %s\n\tDevice ID: %s\n\n", sinks[i].Name, sinks[i].ID) } @@ -121,7 +121,7 @@ func doCLI(opt CLIOpts, config *config, librnnoise string) { } if opt.loadInput { - sources := getSources(paClient) + sources := getSources(&ctx, paClient) if opt.sinkName == "" { defaultSource, err := getDefaultSourceID(paClient) @@ -147,7 +147,7 @@ func doCLI(opt CLIOpts, config *config, librnnoise string) { } if opt.loadOutput { - sinks := getSinks(paClient) + sinks := getSinks(&ctx, paClient) if opt.sinkName == "" { defaultSink, err := getDefaultSinkID(paClient) diff --git a/main.go b/main.go index 522111b..2914893 100644 --- a/main.go +++ b/main.go @@ -123,7 +123,7 @@ func removeLib(file string) { log.Printf("Deleted temp librnnoise: %s\n", file) } -func getSources(client *pulseaudio.Client) []device { +func getSources(ctx *ntcontext, client *pulseaudio.Client) []device { sources, err := client.Sources() if err != nil { log.Printf("Couldn't fetch sources from pulseaudio\n") @@ -138,7 +138,11 @@ func getSources(client *pulseaudio.Client) []device { var inp device inp.ID = sources[i].Name - inp.Name = sources[i].PropList["device.description"] + if ctx.serverInfo.servertype == servertype_pulse { + inp.Name = sources[i].PropList["device.description"] + } else { + inp.Name = sources[i].Description + } inp.isMonitor = (sources[i].MonitorSourceIndex != 0xffffffff) inp.rate = sources[i].SampleSpec.Rate @@ -151,7 +155,7 @@ func getSources(client *pulseaudio.Client) []device { return outputs } -func getSinks(client *pulseaudio.Client) []device { +func getSinks(ctx *ntcontext, client *pulseaudio.Client) []device { sources, err := client.Sinks() if err != nil { log.Printf("Couldn't fetch sources from pulseaudio\n") @@ -168,7 +172,11 @@ func getSinks(client *pulseaudio.Client) []device { var inp device inp.ID = sources[i].Name - inp.Name = sources[i].PropList["device.description"] + if ctx.serverInfo.servertype == servertype_pulse { + inp.Name = sources[i].PropList["device.description"] + } else { + inp.Name = sources[i].Description + } inp.rate = sources[i].SampleSpec.Rate // PA_SINK_DYNAMIC_LATENCY = 0x0080U @@ -207,8 +215,8 @@ func paConnectionWatchdog(ctx *ntcontext) { ctx.paClient = paClient go updateNoiseSupressorLoaded(ctx) - ctx.inputList = preselectDevice(ctx, getSources(ctx.paClient), ctx.config.LastUsedInput, getDefaultSourceID) - ctx.outputList = preselectDevice(ctx, getSinks(paClient), ctx.config.LastUsedOutput, getDefaultSinkID) + ctx.inputList = preselectDevice(ctx, getSources(ctx, paClient), ctx.config.LastUsedInput, getDefaultSourceID) + ctx.outputList = preselectDevice(ctx, getSinks(ctx, paClient), ctx.config.LastUsedOutput, getDefaultSinkID) resetUI(ctx) (*ctx.masterWindow).Changed()