Feature/mixer - #1
Conversation
… case block because now it work faster
| } | ||
|
|
||
| //Compare two voices to one | ||
| func (m *Mixer) Compare(chanVoice1, chanVoice2 chan float64, joinedVoices chan<- float64) { |
There was a problem hiding this comment.
Perhaps Mix would be a better name. Audio streams are joined here, not compared.
| } | ||
| } | ||
|
|
||
| func (m *Mixer) waitAnotherChan(ch chan float64, voice *VoiceBit) { |
There was a problem hiding this comment.
Why not use a float64 pointer directly? It doesn't look like this new type is needed.
| return m.audioCompressor.Compress(bitVoice1 + bitVoice2) | ||
| } | ||
|
|
||
| func (m *Mixer) setRecivedVoice1(volume float64) { |
There was a problem hiding this comment.
No need for a private setter that is used only once.
| ) | ||
|
|
||
| func TestOneChanelInput(t *testing.T) { | ||
| ch1, ch2, exit2, output := chanelInitializer() |
There was a problem hiding this comment.
It's easier to use Ginkgo's BeforeEach callbacks for setup IMO
| @@ -0,0 +1,183 @@ | |||
| package mixer | |||
There was a problem hiding this comment.
Should be mixer_test. Don't include tests in the same package.
|
|
||
| m := new(Mixer) | ||
| compressor := new(compressor.MockCompressorImpl) | ||
| m.audioCompressor = compressor |
There was a problem hiding this comment.
Mixer does not allow this private field to be set by other packages. Tests shouldn't do it either.
This is another reason why it's better to put tests in a separate _test package.
| m.setRecivedVoice1(bitChanVoice1) | ||
| m.waitAnotherChan(chanVoice2, &m.voice2) | ||
| } else { | ||
| chanVoice1 = nil |
|
|
||
| buffer1 := getBufferFromFile("../samples/Telephone prompt poss.wav", t) | ||
|
|
||
| go saveChanToFile(output, exit2, buffer1, t) |
There was a problem hiding this comment.
This looks more like an example than a test since we have to check the file manually.
Maybe it should use a real compressor and be in ./examples.
Here should be a simple test with bare values like in Compressor.
| threshold float64 | ||
| attack int | ||
| release int | ||
| compretionRatio float64 |
| releaseTimer int | ||
|
|
||
| isInitialize bool | ||
| thresholHasBeenExceeded bool |
| ) | ||
|
|
||
| //Mixer compare voice streams | ||
| type Mixer struct { |
There was a problem hiding this comment.
There should be an initialization func:
func NewMixer(compressor compressor.Compressor) *Mixer {
return &Mixer{audioCompressor: compressor}
}
| package compressor | ||
|
|
||
| //Compressor interface for sound compressor's | ||
| type Compressor interface { |
There was a problem hiding this comment.
In Go interfaces are usually defined in user packages. So Mixer should define what it accepts as a Compressor.
| } | ||
|
|
||
| //NewDynamicRangeCompressor creates new DynamicRangeCompressor to process sounds | ||
| func NewDynamicRangeCompressor(threshold, compretionRatio float64, attack, release int) *DynamicRangeCompressor { |
There was a problem hiding this comment.
It's convenient to use a struct instead of obscure parameter lists:
compressor.NewDynamicRangeCompressor(compressor.Options{
Threshold: 0.8,
CompressionRatio: 0.8,
Attack: 200,
Release: 1000,
})
| compressedSound := notCompressedSound | ||
|
|
||
| if notCompressedSound > d.threshold { | ||
| d.releaseTimer = d.release |
There was a problem hiding this comment.
Can attackTimer be set here as well?
| d.thresholHasBeenExceeded = true | ||
| } | ||
|
|
||
| if d.attackTimer == 0 && d.releaseTimer == 0 && d.thresholHasBeenExceeded { |
There was a problem hiding this comment.
Looks like it's possible to do this without thresholHasBeenExceeded:
decrease attackTimer until it's zero,
then if attackTimer == 0 decrease releaseTimer (and apply compressFunction) until it's zero
add voice mixer and voice compressor