mirror of
https://github.com/faiface/beep.git
synced 2025-12-23 23:38:45 -05:00
fix goreportcard problems
This commit is contained in:
@@ -2,7 +2,7 @@ package beep
|
||||
|
||||
// Take returns a Streamer which streams at most num samples from s.
|
||||
//
|
||||
// The returned Streamer propagates s's errors throught Err.
|
||||
// The returned Streamer propagates s's errors through Err.
|
||||
func Take(num int, s Streamer) Streamer {
|
||||
return &take{
|
||||
s: s,
|
||||
@@ -94,7 +94,7 @@ func Seq(s ...Streamer) Streamer {
|
||||
})
|
||||
}
|
||||
|
||||
// Mix takes zero or more Streamers and returns a Streamer which streames them mixed together.
|
||||
// Mix takes zero or more Streamers and returns a Streamer which streams them mixed together.
|
||||
//
|
||||
// Mix does not propagate errors from the Streamers.
|
||||
func Mix(s ...Streamer) Streamer {
|
||||
|
||||
@@ -5,7 +5,7 @@ import "github.com/faiface/beep"
|
||||
// Mono converts the wrapped Streamer to a mono buffer
|
||||
// by downmixing the left and right channels together.
|
||||
//
|
||||
// The returned Streamer propagates s's errors throught Err.
|
||||
// The returned Streamer propagates s's errors through Err.
|
||||
func Mono(s beep.Streamer) beep.Streamer {
|
||||
return &mono{s}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import "github.com/faiface/beep"
|
||||
|
||||
// Swap swaps the left and right channel of the wrapped Streamer.
|
||||
//
|
||||
// The returned Streamer propagates s's errors throught Err.
|
||||
// The returned Streamer propagates s's errors through Err.
|
||||
func Swap(s beep.Streamer) beep.Streamer {
|
||||
return &swap{s}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
// StreamSeekCloser when you want to release the resources.
|
||||
func Decode(rc io.ReadCloser) (s beep.StreamSeekCloser, format beep.Format, err error) {
|
||||
d := decoder{rc: rc}
|
||||
defer func() { // hacky way to always close rc if an error occured
|
||||
defer func() { // hacky way to always close rc if an error occurred
|
||||
if err != nil {
|
||||
d.rc.Close()
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ type Streamer interface {
|
||||
// this case is valid. Only this case may occur in the following calls.
|
||||
Stream(samples [][2]float64) (n int, ok bool)
|
||||
|
||||
// Err returns an error which occured during streaming. If no error occured, nil is
|
||||
// Err returns an error which occurred during streaming. If no error occurred, nil is
|
||||
// returned.
|
||||
//
|
||||
// When an error occurs, Streamer must become drained and Stream must return 0, false
|
||||
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
// StreamSeekCloser when you want to release the resources.
|
||||
func Decode(rc io.ReadCloser) (s beep.StreamSeekCloser, format beep.Format, err error) {
|
||||
d := decoder{rc: rc}
|
||||
defer func() { // hacky way to always close rsc if an error occured
|
||||
defer func() { // hacky way to always close rsc if an error occurred
|
||||
if err != nil {
|
||||
d.rc.Close()
|
||||
}
|
||||
@@ -29,7 +29,7 @@ func Decode(rc io.ReadCloser) (s beep.StreamSeekCloser, format beep.Format, err
|
||||
return nil, beep.Format{}, errors.Wrap(err, "wav")
|
||||
}
|
||||
if string(d.h.RiffMark[:]) != "RIFF" {
|
||||
return nil, beep.Format{}, errors.New(fmt.Sprintf("wav: missing RIFF at the beginning > %s", string(d.h.RiffMark[:])))
|
||||
return nil, beep.Format{}, fmt.Errorf("wav: missing RIFF at the beginning > %s", string(d.h.RiffMark[:]))
|
||||
}
|
||||
|
||||
// READ Total file size
|
||||
@@ -45,7 +45,7 @@ func Decode(rc io.ReadCloser) (s beep.StreamSeekCloser, format beep.Format, err
|
||||
|
||||
// check each formtypes
|
||||
ft := [4]byte{0, 0, 0, 0}
|
||||
var fs int32 = 0
|
||||
var fs int32
|
||||
d.hsz = 4 + 4 + 4 // add size of (RiffMark + FileSize + WaveMark)
|
||||
for string(ft[:]) != "data" {
|
||||
if err = binary.Read(rc, binary.LittleEndian, ft[:]); err != nil {
|
||||
@@ -69,13 +69,12 @@ func Decode(rc io.ReadCloser) (s beep.StreamSeekCloser, format beep.Format, err
|
||||
}
|
||||
if err := binary.Read(rc, binary.LittleEndian, &fmtchunk); err != nil {
|
||||
return nil, beep.Format{}, errors.New("wav: missing format chunk body")
|
||||
} else {
|
||||
d.h.NumChans = fmtchunk.NumChans
|
||||
d.h.SampleRate = fmtchunk.SampleRate
|
||||
d.h.ByteRate = fmtchunk.ByteRate
|
||||
d.h.BytesPerFrame = fmtchunk.BytesPerFrame
|
||||
d.h.BitsPerSample = fmtchunk.BitsPerSample
|
||||
}
|
||||
d.h.NumChans = fmtchunk.NumChans
|
||||
d.h.SampleRate = fmtchunk.SampleRate
|
||||
d.h.ByteRate = fmtchunk.ByteRate
|
||||
d.h.BytesPerFrame = fmtchunk.BytesPerFrame
|
||||
d.h.BitsPerSample = fmtchunk.BitsPerSample
|
||||
|
||||
// SubFormat is represented by GUID. Plain PCM is KSDATAFORMAT_SUBTYPE_PCM GUID.
|
||||
// See https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/content/ksmedia/ns-ksmedia-waveformatextensible
|
||||
@@ -84,12 +83,10 @@ func Decode(rc io.ReadCloser) (s beep.StreamSeekCloser, format beep.Format, err
|
||||
[8]byte{0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71},
|
||||
}
|
||||
if fmtchunk.SubFormat != pcmguid {
|
||||
return nil, beep.Format{}, errors.New(
|
||||
fmt.Sprintf(
|
||||
"wav: unsupported sub format type - %08x-%04x-%04x-%s",
|
||||
fmtchunk.SubFormat.Data1, fmtchunk.SubFormat.Data2, fmtchunk.SubFormat.Data3,
|
||||
hex.EncodeToString(fmtchunk.SubFormat.Data4[:]),
|
||||
),
|
||||
return nil, beep.Format{}, fmt.Errorf(
|
||||
"wav: unsupported sub format type - %08x-%04x-%04x-%s",
|
||||
fmtchunk.SubFormat.Data1, fmtchunk.SubFormat.Data2, fmtchunk.SubFormat.Data3,
|
||||
hex.EncodeToString(fmtchunk.SubFormat.Data4[:]),
|
||||
)
|
||||
}
|
||||
} else {
|
||||
@@ -97,13 +94,13 @@ func Decode(rc io.ReadCloser) (s beep.StreamSeekCloser, format beep.Format, err
|
||||
fmtchunk := formatchunk{0, 0, 0, 0, 0}
|
||||
if err := binary.Read(rc, binary.LittleEndian, &fmtchunk); err != nil {
|
||||
return nil, beep.Format{}, errors.New("wav: missing format chunk body")
|
||||
} else {
|
||||
d.h.NumChans = fmtchunk.NumChans
|
||||
d.h.SampleRate = fmtchunk.SampleRate
|
||||
d.h.ByteRate = fmtchunk.ByteRate
|
||||
d.h.BytesPerFrame = fmtchunk.BytesPerFrame
|
||||
d.h.BitsPerSample = fmtchunk.BitsPerSample
|
||||
}
|
||||
d.h.NumChans = fmtchunk.NumChans
|
||||
d.h.SampleRate = fmtchunk.SampleRate
|
||||
d.h.ByteRate = fmtchunk.ByteRate
|
||||
d.h.BytesPerFrame = fmtchunk.BytesPerFrame
|
||||
d.h.BitsPerSample = fmtchunk.BitsPerSample
|
||||
|
||||
// it would be skipping cbSize (WAVEFORMATEX's last member).
|
||||
if d.h.FormatSize > 16 {
|
||||
trash := make([]byte, d.h.FormatSize-16)
|
||||
@@ -137,7 +134,7 @@ func Decode(rc io.ReadCloser) (s beep.StreamSeekCloser, format beep.Format, err
|
||||
return nil, beep.Format{}, errors.New("wav: missing data chunk marker")
|
||||
}
|
||||
if d.h.FormatType != 1 && d.h.FormatType != -2 {
|
||||
return nil, beep.Format{}, errors.New(fmt.Sprintf("wav: unsupported format type - %d", d.h.FormatType))
|
||||
return nil, beep.Format{}, fmt.Errorf("wav: unsupported format type - %d", d.h.FormatType)
|
||||
}
|
||||
if d.h.NumChans <= 0 {
|
||||
return nil, beep.Format{}, errors.New("wav: invalid number of channels (less than 1)")
|
||||
|
||||
Reference in New Issue
Block a user