Skip to content

Commit

Permalink
audio/mp3: add (*Stream).SampleRate
Browse files Browse the repository at this point in the history
  • Loading branch information
hajimehoshi committed May 18, 2024
1 parent d2c58da commit ac83181
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions audio/mp3/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
type Stream struct {
orig *mp3.Decoder
resampling *convert.Resampling
sampleRate int
}

// Read is implementation of io.Reader's Read.
Expand All @@ -57,6 +58,11 @@ func (s *Stream) Length() int64 {
return s.orig.Length()
}

// SampleRate returns the sample rate of the decoded stream.
func (s *Stream) SampleRate() int {
return s.sampleRate
}

// DecodeWithoutResampling decodes an MP3 source and returns a decoded stream.
//
// DecodeWithoutResampling returns error when decoding fails or IO error happens.
Expand All @@ -73,6 +79,7 @@ func DecodeWithoutResampling(src io.Reader) (*Stream, error) {
s := &Stream{
orig: d,
resampling: nil,
sampleRate: d.SampleRate(),
}
return s, nil
}
Expand Down Expand Up @@ -103,6 +110,7 @@ func DecodeWithSampleRate(sampleRate int, src io.Reader) (*Stream, error) {
s := &Stream{
orig: d,
resampling: r,
sampleRate: sampleRate,
}
return s, nil
}
Expand Down

0 comments on commit ac83181

Please sign in to comment.