Browse Source

audio: do not change final background level.

Instead, change level of individual reversed sounds when making
background to the appropriate values.

This speeds up makeBackgroundSound ~3%.

Before and after.
captcha.BenchmarkNewAudio      50  30436940 ns/op
captcha.BenchmarkNewAudio      50  29435780 ns/op

Also, level up white noise a bit.
Dmitry Chestnykh 14 years ago
parent
commit
436e363f84
1 changed files with 2 additions and 3 deletions
  1. 2 3
      audio.go

+ 2 - 3
audio.go

@@ -196,15 +196,14 @@ func reversedSound(a []byte) []byte {
 }
 
 func makeBackgroundSound(length int) []byte {
-	b := makeWhiteNoise(length, 8)
+	b := makeWhiteNoise(length, 4)
 	for i := 0; i < length/(sampleRate/10); i++ {
 		snd := reverseDigitSounds[rand.Intn(10)]
 		snd = changeSpeed(snd, rndf(0.8, 1.4))
 		place := rand.Intn(len(b) - len(snd))
-		setSoundLevel(snd, rndf(0.5, 1.2))
+		setSoundLevel(snd, rndf(0.2, 0.3))
 		mixSound(b[place:], snd)
 	}
-	setSoundLevel(b, rndf(0.2, 0.3))
 	return b
 }