audio: Add comments (#199)

This commit is contained in:
Hajime Hoshi 2016-04-19 02:00:16 +09:00
parent b0178e8425
commit 5ae624b891
3 changed files with 11 additions and 2 deletions

View File

@ -39,12 +39,14 @@ func (s *Stream) Close() error {
return s.decoded.Close() return s.decoded.Close()
} }
// TODO: Should be int? // Size returns the size of decoded stream in bytes.
func (s *Stream) Size() int64 { func (s *Stream) Size() int64 {
return s.decoded.Size() return s.decoded.Size()
} }
// TODO: src should be ReadCloser? // Decode decodes Ogg/Vorbis data to playable stream.
//
// The sample rate must be same as that of audio context.
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

@ -14,6 +14,7 @@
// +build !js // +build !js
// Package vorbis provides Ogg/Vorbis decoder.
package vorbis package vorbis
import ( import (

View File

@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
// Package vorbis provides WAV (RIFF) decoder.
package wav package wav
import ( import (
@ -43,10 +44,15 @@ func (s *Stream) Close() error {
return s.src.Close() return s.src.Close()
} }
// Size returns the size of decoded stream in bytes.
func (s *Stream) Size() int64 { func (s *Stream) Size() int64 {
return s.dataSize return s.dataSize
} }
// Decode decodes WAV (RIFF) data to playable stream.
//
// The format must be 2 channels, 16bit little endian PCM.
// The sample rate must be same as that of audio context.
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)