Files
icecast-ripper/vendor/github.com/tcolgate/mp3/silence.go
Dmitry Andreev b5f23a50b7
Some checks failed
CodeQL / Analyze (go) (push) Has been cancelled
Docker / build (push) Has been cancelled
golangci-lint / lint (push) Has been cancelled
Integrate MP3 duration extraction and silence handling (#6)
* feat: integrate MP3 duration extraction and silence handling

- Added a new dependency on github.com/tcolgate/mp3 for MP3 frame decoding.
- Implemented actual MP3 duration retrieval in the scanRecordings function, falling back to an estimation if retrieval fails.
- Introduced a silent frame asset for generating silence in audio streams.
- Created a silence reader to provide a continuous stream of silent frames.
- Added necessary documentation and licensing for the new MP3 package.
- Updated .gitignore to exclude MP3 files except for the internal data directory.

* feat: update README and improve application configuration and logging

* refactor: remove unused GenerateFileHash function and improve resource cleanup in MP3 and recorder modules
2025-04-13 15:56:22 +03:00

52 lines
911 B
Go

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}
}