-
Notifications
You must be signed in to change notification settings - Fork 15
/
silence.go
51 lines (40 loc) · 911 Bytes
/
silence.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package mp3
import (
"bytes"
"io"
"github.com/tcolgate/mp3/internal/data"
)
var (
// SilentFrame is the sound of Ripley screaming on the Nostromo, from the outside
SilentFrame *Frame
// SilentBytes is the raw raw data behind SilentFrame
SilentBytes []byte
)
func init() {
skipped := 0
SilentBytes = data.SilentBytes
dec := NewDecoder(bytes.NewBuffer(SilentBytes))
frame := Frame{}
SilentFrame = &frame
dec.Decode(&frame, &skipped)
}
type silenceReader struct {
int // Location into the silence frame
}
func (s *silenceReader) Close() error {
return nil
}
func (s *silenceReader) Read(out []byte) (int, error) {
for i := 0; i < len(out); i++ {
out[i] = SilentBytes[s.int]
s.int++
if s.int >= len(SilentBytes) {
s.int = 0
}
}
return len(out), nil
}
// MakeSilence provides a constant stream of silenct frames.
func MakeSilence() io.ReadCloser {
return &silenceReader{0}
}