func BenchmarkSong(b *testing.B) { s := song.New(song.Tempo(1.0)) s.AddAfter(note.Note{Note: note.E, Octave: 4}, note.Full) ks := Song{ Song: s, SamplingRate: 44100, } b.ResetTimer() b.ReportAllocs() for i := 0; i < b.N; i++ { ks.Sound(FakeWriter{}) } }
func New(r io.Reader) Hasher { buf := make([]byte, 16) r.Read(buf) speed := song.Slow + song.Tempo(float64(buf[0])/256) scl := scaleMap[int(buf[1])%len(scaleMap)] var sum int for i := 1; i < len(buf); i++ { sum += int(buf[i]) } nt := note.Note{Note: note.C, Octave: 1}.AddHalfSteps(sum % 36) s := song.New(speed) s.Scale = scl.New(nt, buf[2]%2 == 0) return Hasher{ Song: &s, r: r, } }