✨ 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 {
|
||||
UUID string
|
||||
Output *Port
|
||||
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 {
|
||||
if ch == 0 {
|
||||
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
|
||||
var outputBuffers []JackOutputBuffers = []JackOutputBuffers{}
|
||||
for _, out := range portConfig.Output {
|
||||
outputBuffer := JackOutputBuffers{out.UUID, [][]jack.AudioSample{}}
|
||||
outputBuffer := JackOutputBuffers{&out, [][]jack.AudioSample{}}
|
||||
for _, port := range out.object {
|
||||
buffer := port.GetBuffer(nframes)
|
||||
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
|
||||
for _, in := range portConfig.Input {
|
||||
if in.State.Mute {
|
||||
// Input is muted
|
||||
continue
|
||||
}
|
||||
|
||||
@ -166,8 +173,13 @@ func processJackCb(nframes uint32) int {
|
||||
|
||||
// For every route that exists for the input
|
||||
for _, route := range in.Route {
|
||||
if route.Mute {
|
||||
// Route is muted
|
||||
continue
|
||||
}
|
||||
|
||||
for _, out := range outputBuffers {
|
||||
if out.UUID != route.ToUUID {
|
||||
if out.Output.UUID != route.ToUUID {
|
||||
continue
|
||||
}
|
||||
|
||||
@ -176,6 +188,11 @@ func processJackCb(nframes uint32) int {
|
||||
continue
|
||||
}
|
||||
|
||||
if out.Output.State.Mute {
|
||||
// Output is muted
|
||||
continue
|
||||
}
|
||||
|
||||
routeVolume := in.State.Volume * route.Volume * calcBalanceFactor(ch, in.State.Balance)
|
||||
|
||||
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
|
||||
}
|
||||
|
Reference in New Issue
Block a user