Skip to content

Commit

Permalink
Added input and output channels
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony Lee authored and Tony Lee committed Sep 11, 2021
1 parent 22cebd7 commit a9c5521
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 19 deletions.
19 changes: 7 additions & 12 deletions cmd/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,15 @@ func updateServiceConfigs(config client.AgentConfig, remoteName string, isServer
jackTripExtraOpts = fmt.Sprintf("%s -f \"%s\"", jackTripExtraOpts, strings.TrimSpace(jackTripEffects))
}

// check if loopback
//hubpatch := 2
//if config.LoopBack {
// hubpatch = 4
//}

// check if stereo
channels := 1
if config.Stereo {
channels = 2
receiveChannels := config.OutputChannels // audio signals from the audio server to the user, hence receiveChannels
if receiveChannels == 0 {
receiveChannels = 2 // default output channels is stereo
}

receiveChannels := config.ReceiveChannels // output channels
sendChannels := config.SendChannels // input channels
sendChannels := config.InputChannels // audio signals to the audio server from user's input, hence sendChannels
if sendChannels == 0 {
sendChannels = 1 // default input channels is mono
}

jackTripConfig = fmt.Sprintf(JackTripDeviceConfigTemplate, receiveChannels, sendChannels, config.Host, config.Port, config.DevicePort, remoteName, strings.TrimSpace(jackTripExtraOpts))
}
Expand Down
10 changes: 10 additions & 0 deletions pkg/client/devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ type DeviceConfig struct {
// 1: high quality Jamulus (medium)
// 2: JackTrip (high)
Quality int `json:"quality" db:"quality"`

// Input Channel Count
// 1: mono
// 2: stereo
InputChannels int `json:"inputChannels" db:"input_channels"`

// Outputs Channel Count
// 1: mono
// 2: stereo
OutputChannels int `json:"outputChannels" db:"outputs_channels"`
}

// ALSAConfig defines configuration for a device's ALSA sound card
Expand Down
5 changes: 3 additions & 2 deletions pkg/client/devices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestAgentConfig(t *testing.T) {
var target AgentConfig

// Parse JSON into AgentConfig struct
raw = `{"period": 3, "queueBuffer": 128, "devicePort": 8000, "reverb": 42, "limiter": true, "compressor": 0, "quality": 2, "captureBoost": true, "playbackBoost": 0, "captureVolume": 100, "playbackVolume": 0, "type": "JackTrip+Jamulus", "mixBranch": "main", "mixCode": "echo hi", "serverHost": "a.b.com", "serverPort": 8000, "sampleRate": 96000, "stereo": true, "loopback": false, "enabled": true}`
raw = `{"period": 3, "queueBuffer": 128, "devicePort": 8000, "reverb": 42, "limiter": true, "compressor": 0, "quality": 2, "captureBoost": true, "playbackBoost": 0, "captureVolume": 100, "playbackVolume": 0, "type": "JackTrip+Jamulus", "mixBranch": "main", "mixCode": "echo hi", "serverHost": "a.b.com", "serverPort": 8000, "sampleRate": 96000, "inputChannels": 2, "outputChannels": 2, "loopback": false, "enabled": true}`
target = AgentConfig{}
json.Unmarshal([]byte(raw), &target)
assert.Equal(3, target.Period)
Expand All @@ -96,7 +96,8 @@ func TestAgentConfig(t *testing.T) {
assert.Equal("a.b.com", target.Host)
assert.Equal(8000, target.Port)
assert.Equal(96000, target.SampleRate)
assert.Equal(true, bool(target.Stereo))
assert.Equal(2, target.InputChannels)
assert.Equal(2, target.OutputChannels)
assert.Equal(false, bool(target.LoopBack))
assert.Equal(true, bool(target.Enabled))
}
Expand Down
3 changes: 0 additions & 3 deletions pkg/client/servers.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ type ServerConfig struct {
// sample rate frequency (48000 or 96000)
SampleRate int `json:"sampleRate" db:"sample_rate"`

// true if stereo, false if mono
Stereo types.BitBool `json:"stereo" db:"stereo"`

// true if client's audio should loop back to them
LoopBack types.BitBool `json:"loopback" db:"loopback"`

Expand Down
3 changes: 1 addition & 2 deletions pkg/client/servers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestServerConfig(t *testing.T) {
var target ServerConfig

// Parse JSON into ServerConfig struct
raw = `{"type": "JackTrip+Jamulus", "mixBranch": "main", "mixCode": "echo hi", "serverHost": "a.b.com", "serverPort": 8000, "sampleRate": 96000, "stereo": true, "loopback": false, "enabled": true}`
raw = `{"type": "JackTrip+Jamulus", "mixBranch": "main", "mixCode": "echo hi", "serverHost": "a.b.com", "serverPort": 8000, "sampleRate": 96000, "loopback": false, "enabled": true}`
target = ServerConfig{}
json.Unmarshal([]byte(raw), &target)
assert.Equal(JackTripJamulus, target.Type)
Expand All @@ -42,7 +42,6 @@ func TestServerConfig(t *testing.T) {
assert.Equal("a.b.com", target.Host)
assert.Equal(8000, target.Port)
assert.Equal(96000, target.SampleRate)
assert.Equal(true, bool(target.Stereo))
assert.Equal(false, bool(target.LoopBack))
assert.Equal(true, bool(target.Enabled))
}

0 comments on commit a9c5521

Please sign in to comment.