func mixLogarithmicRangeCompression(i sample.Value) sample.Value { if i < -1 { return sample.Value(-math.Log(-float64(i)-0.85)/14 - 0.75) } else if i > 1 { return sample.Value(math.Log(float64(i)-0.85)/14 + 0.75) } else { return sample.Value(i / 1.61803398875) } }
// volume (0 to 1), and pan (-1 to +1) // TODO: ensure implicit panning of source channels! e.g. 2 channels is full left, full right. func volume(channel float64, volume float64, pan float64) sample.Value { if pan == 0 { return sample.Value(volume) } else if pan < 0 { return sample.Value(math.Max(0, 1+pan*channel/masterChannelsFloat)) } else { // pan > 0 return sample.Value(math.Max(0, 1-pan*channel/masterChannelsFloat)) } }
func TestMixer_mixVolume(t *testing.T) { masterChannelsFloat = 1 assert.Equal(t, sample.Value(0), volume(0, 0, 0)) assert.Equal(t, sample.Value(1), volume(0, 1, .5)) masterChannelsFloat = 2 assert.Equal(t, sample.Value(1), volume(0, 1, -.5)) assert.Equal(t, sample.Value(.75), volume(1, 1, .5)) assert.Equal(t, sample.Value(.5), volume(0, .5, 0)) assert.Equal(t, sample.Value(.5), volume(1, .5, 1)) masterChannelsFloat = 3 assert.Equal(t, sample.Value(1), volume(0, 1, 0)) assert.Equal(t, sample.Value(0.6666666666666667), volume(1, 1, -1)) assert.Equal(t, sample.Value(0.6666666666666667), volume(2, .5, -.5)) assert.Equal(t, sample.Value(0.6666666666666667), volume(1, .5, 1)) masterChannelsFloat = 4 assert.Equal(t, sample.Value(1), volume(0, 1, -1)) assert.Equal(t, sample.Value(1), volume(1, 1, 0)) assert.Equal(t, sample.Value(.75), volume(2, .5, .5)) assert.Equal(t, sample.Value(.625), volume(3, .5, -.5)) }