✨ Respect mute, volume and balance of routes and outputs
This commit is contained in:
31
routing.go
31
routing.go
@ -113,7 +113,7 @@ func startRouting() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type JackOutputBuffers struct {
|
type JackOutputBuffers struct {
|
||||||
UUID string
|
Output *Port
|
||||||
Buffers [][]jack.AudioSample
|
Buffers [][]jack.AudioSample
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,6 +123,12 @@ func addToBuffer(src *[]jack.AudioSample, dst *[]jack.AudioSample, volume float3
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func multiplyBuffer(dst *[]jack.AudioSample, factor float32) {
|
||||||
|
for i, _ := range *dst {
|
||||||
|
(*dst)[i] *= jack.AudioSample(factor)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func calcBalanceFactor(ch uint8, balance float32) float32 {
|
func calcBalanceFactor(ch uint8, balance float32) float32 {
|
||||||
if ch == 0 {
|
if ch == 0 {
|
||||||
return max(0, min(1, 1-balance))
|
return max(0, min(1, 1-balance))
|
||||||
@ -139,7 +145,7 @@ func processJackCb(nframes uint32) int {
|
|||||||
// Get memory addresses to write to for all outputs
|
// Get memory addresses to write to for all outputs
|
||||||
var outputBuffers []JackOutputBuffers = []JackOutputBuffers{}
|
var outputBuffers []JackOutputBuffers = []JackOutputBuffers{}
|
||||||
for _, out := range portConfig.Output {
|
for _, out := range portConfig.Output {
|
||||||
outputBuffer := JackOutputBuffers{out.UUID, [][]jack.AudioSample{}}
|
outputBuffer := JackOutputBuffers{&out, [][]jack.AudioSample{}}
|
||||||
for _, port := range out.object {
|
for _, port := range out.object {
|
||||||
buffer := port.GetBuffer(nframes)
|
buffer := port.GetBuffer(nframes)
|
||||||
for i := range buffer {
|
for i := range buffer {
|
||||||
@ -153,6 +159,7 @@ func processJackCb(nframes uint32) int {
|
|||||||
// Write audio data from every input to all outputs it routes to
|
// Write audio data from every input to all outputs it routes to
|
||||||
for _, in := range portConfig.Input {
|
for _, in := range portConfig.Input {
|
||||||
if in.State.Mute {
|
if in.State.Mute {
|
||||||
|
// Input is muted
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,8 +173,13 @@ func processJackCb(nframes uint32) int {
|
|||||||
|
|
||||||
// For every route that exists for the input
|
// For every route that exists for the input
|
||||||
for _, route := range in.Route {
|
for _, route := range in.Route {
|
||||||
|
if route.Mute {
|
||||||
|
// Route is muted
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
for _, out := range outputBuffers {
|
for _, out := range outputBuffers {
|
||||||
if out.UUID != route.ToUUID {
|
if out.Output.UUID != route.ToUUID {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,6 +188,11 @@ func processJackCb(nframes uint32) int {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if out.Output.State.Mute {
|
||||||
|
// Output is muted
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
routeVolume := in.State.Volume * route.Volume * calcBalanceFactor(ch, in.State.Balance)
|
routeVolume := in.State.Volume * route.Volume * calcBalanceFactor(ch, in.State.Balance)
|
||||||
|
|
||||||
if in.Properties.Channels < uint8(len(out.Buffers)) {
|
if in.Properties.Channels < uint8(len(out.Buffers)) {
|
||||||
@ -193,6 +210,14 @@ func processJackCb(nframes uint32) int {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Apply output volume and balance
|
||||||
|
// (mute state is already checked above)
|
||||||
|
for _, out := range outputBuffers {
|
||||||
|
for ch, buf := range out.Buffers {
|
||||||
|
multiplyBuffer(&buf, out.Output.State.Volume*calcBalanceFactor(uint8(ch), out.Output.State.Balance))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user