audio: Add comments

This commit is contained in:
Hajime Hoshi 2017-09-26 00:38:50 +09:00
parent d9f6699b7f
commit fe2380f1ab
2 changed files with 8 additions and 1 deletions

View File

@ -194,7 +194,13 @@ var (
theContextLock sync.Mutex theContextLock sync.Mutex
) )
// NewContext creates a new audio context with the given sample rate (e.g. 44100). // NewContext creates a new audio context with the given sample rate.
//
// The sample rate is also used for decoding MP3 or other formats as the target sample rate.
//
// sampleRate should be 44100 or 48000.
// Other values might not work.
// For example, 22050 causes error on Safari when decoding MP3.
// //
// Error returned by NewContext is always nil as of 1.5.0-alpha. // Error returned by NewContext is always nil as of 1.5.0-alpha.
// //

View File

@ -108,6 +108,7 @@ func Decode(context *audio.Context, src audio.ReadSeekCloser) (*Stream, error) {
if klass == js.Undefined { if klass == js.Undefined {
return nil, errors.New("audio/mp3: OfflineAudioContext is not available") return nil, errors.New("audio/mp3: OfflineAudioContext is not available")
} }
// This might causes 'Syntax' error when the sample rate is not so usual like 22050 on Safari.
// TODO: 1 is a correct second argument? // TODO: 1 is a correct second argument?
oc := klass.New(2, 1, context.SampleRate()) oc := klass.New(2, 1, context.SampleRate())
oc.Call("decodeAudioData", js.NewArrayBuffer(b), func(buf *js.Object) { oc.Call("decodeAudioData", js.NewArrayBuffer(b), func(buf *js.Object) {