audio: Fix wrong comments

This commit is contained in:
Hajime Hoshi 2017-10-01 18:07:18 +09:00
parent 626b772b25
commit bc2469a275
4 changed files with 19 additions and 10 deletions

View File

@ -33,7 +33,7 @@ func NewInfiniteLoop(stream ReadSeekCloser, size int64) *InfiniteLoop {
} }
} }
// Read is implementation of ReadSeekCloser. // Read is implementation of ReadSeekCloser's Read.
func (i *InfiniteLoop) Read(b []byte) (int, error) { func (i *InfiniteLoop) Read(b []byte) (int, error) {
n, err := i.stream.Read(b) n, err := i.stream.Read(b)
if err == io.EOF { if err == io.EOF {
@ -45,7 +45,7 @@ func (i *InfiniteLoop) Read(b []byte) (int, error) {
return n, err return n, err
} }
// Seek is implementation of ReadSeekCloser. // Seek is implementation of ReadSeekCloser's Seek.
func (i *InfiniteLoop) Seek(offset int64, whence int) (int64, error) { func (i *InfiniteLoop) Seek(offset int64, whence int) (int64, error) {
next := int64(0) next := int64(0)
switch whence { switch whence {
@ -68,7 +68,7 @@ func (i *InfiniteLoop) Seek(offset int64, whence int) (int64, error) {
return pos, nil return pos, nil
} }
// Close is implementation of ReadSeekCloser. // Close is implementation of ReadSeekCloser's Close.
func (l *InfiniteLoop) Close() error { func (l *InfiniteLoop) Close() error {
return l.stream.Close() return l.stream.Close()
} }

View File

@ -15,6 +15,9 @@
// +build !js // +build !js
// Package mp3 provides MP3 decoder. // Package mp3 provides MP3 decoder.
//
// On desktops and mobiles, a pure Go decoder is used.
// On browsers, a native decoder on the browser is used.
package mp3 package mp3
import ( import (
@ -24,6 +27,7 @@ import (
"github.com/hajimehoshi/ebiten/audio/internal/convert" "github.com/hajimehoshi/ebiten/audio/internal/convert"
) )
// Stream is a decoded stream.
type Stream struct { type Stream struct {
inner audio.ReadSeekCloser inner audio.ReadSeekCloser
size int64 size int64
@ -39,7 +43,7 @@ func (s *Stream) Seek(offset int64, whence int) (int64, error) {
return s.inner.Seek(offset, whence) return s.inner.Seek(offset, whence)
} }
// Read is implementation of io.Closer's Close. // Close is implementation of io.Closer's Close.
func (s *Stream) Close() error { func (s *Stream) Close() error {
return s.inner.Close() return s.inner.Close()
} }
@ -49,6 +53,11 @@ func (s *Stream) Size() int64 {
return s.size return s.size
} }
// Decode decodes MP3 source and returns a decoded stream.
//
// Decode returns error when decoding fails or IO error happens.
//
// Decode automatically resamples the stream to fit with the audio context if necessary.
func Decode(context *audio.Context, src audio.ReadSeekCloser) (*Stream, error) { func Decode(context *audio.Context, src audio.ReadSeekCloser) (*Stream, error) {
d, err := mp3.NewDecoder(src) d, err := mp3.NewDecoder(src)
if err != nil { if err != nil {

View File

@ -43,7 +43,7 @@ func (s *Stream) Seek(offset int64, whence int) (int64, error) {
return s.decoded.Seek(offset, whence) return s.decoded.Seek(offset, whence)
} }
// Read is implementation of io.Closer's Close. // Close is implementation of io.Closer's Close.
func (s *Stream) Close() error { func (s *Stream) Close() error {
return s.decoded.Close() return s.decoded.Close()
} }
@ -170,9 +170,9 @@ func decode(in audio.ReadSeekCloser) (*decoded, int, int, error) {
// Decode decodes Ogg/Vorbis data to playable stream. // Decode decodes Ogg/Vorbis data to playable stream.
// //
// Decode returns error when the source format is wrong. // Decode returns error when decoding fails or IO error happens.
// //
// Sample rate is automatically adjusted to fit with the audio context. // Decode automatically resamples the stream to fit with the audio context if necessary.
func Decode(context *audio.Context, src audio.ReadSeekCloser) (*Stream, error) { func Decode(context *audio.Context, src audio.ReadSeekCloser) (*Stream, error) {
decoded, channelNum, sampleRate, err := decode(src) decoded, channelNum, sampleRate, err := decode(src)
if err != nil { if err != nil {

View File

@ -98,7 +98,7 @@ func (s *stream) Seek(offset int64, whence int) (int64, error) {
return n - s.headerSize, nil return n - s.headerSize, nil
} }
// Read is implementation of io.Closer's Close. // Close is implementation of io.Closer's Close.
func (s *stream) Close() error { func (s *stream) Close() error {
return s.src.Close() return s.src.Close()
} }
@ -113,9 +113,9 @@ func (s *stream) Size() int64 {
// The format must be 1 or 2 channels, 8bit or 16bit little endian PCM. // The format must be 1 or 2 channels, 8bit or 16bit little endian PCM.
// The format is converted into 2 channels and 16bit. // The format is converted into 2 channels and 16bit.
// //
// Decode returns error when the source format is wrong. // Decode returns error when decoding fails or IO error happens.
// //
// Sample rate is automatically adjusted to fit with the audio context. // Decode automatically resamples the stream to fit with the audio context if necessary.
func Decode(context *audio.Context, src audio.ReadSeekCloser) (*Stream, error) { func Decode(context *audio.Context, src audio.ReadSeekCloser) (*Stream, error) {
buf := make([]byte, 12) buf := make([]byte, 12)
n, err := io.ReadFull(src, buf) n, err := io.ReadFull(src, buf)