func NewContext(sampleRate int) (*Context, error) {
	theContextLock.Lock()
	defer theContextLock.Unlock()
	if theContext != nil {
		panic("audio: context is already created")
	}

	c := &Context{
		sampleRate: sampleRate,
		c:          newContext(sampleRate),
		players:    map[*playerImpl]struct{}{},
		inited:     make(chan struct{}),
	}
	theContext = c

	h := getHook()
	h.OnSuspendAudio(func() {
		c.m.Lock()
		c.suspended = true
		c.m.Unlock()
	})
	h.OnResumeAudio(func() {
		c.m.Lock()
		c.suspended = false
		c.m.Unlock()
	})

	h.AppendHookOnBeforeUpdate(func() error {
		c.initedOnce.Do(func() {
			close(c.inited)
		})

		var err error
		theContextLock.Lock()
		if theContext != nil {
			theContext.m.Lock()
			err = theContext.err
			theContext.m.Unlock()
		}
		theContextLock.Unlock()
		return err
	})

	return c, nil
}
func NewContext(sampleRate int) (*Context, error) {
	theContextLock.Lock()
	defer theContextLock.Unlock()
	if theContext != nil {
		panic("audio: context is already created")
	}

	c := &Context{
		sampleRate: sampleRate,
		c:          newContext(sampleRate),
		players:    map[*playerImpl]struct{}{},
		inited:     make(chan struct{}),
	}
	theContext = c

	h := getHook()
	h.OnSuspendAudio(func() {
		c.m.Lock()
		c.suspended = true
		c.m.Unlock()
	})
	h.OnResumeAudio(func() {
		c.m.Lock()
		c.suspended = false
		c.m.Unlock()
	})

	h.AppendHookOnBeforeUpdate(func() error {
		c.initedOnce.Do(func() {
			close(c.inited)
		})

		var err error
		theContextLock.Lock()
		if theContext != nil {
			theContext.m.Lock()
			err = theContext.err
			theContext.m.Unlock()
		}
		theContextLock.Unlock()
		return err
	})

	return c, nil
}
func NewContext ( sampleRate int ) ( * Context , error ) { theContextLock . Lock ( ) defer theContextLock . Unlock ( ) if theContext != nil { panic ( " " ) } c := & Context { sampleRate : sampleRate , c : newContext ( sampleRate ) , players : map [ * playerImpl ] struct { } { } , inited : make ( chan struct { } ) , } theContext = c h := getHook ( ) h . OnSuspendAudio ( func ( ) { c . m . Lock ( ) c . suspended = true c . m . Unlock ( ) } ) h . OnResumeAudio ( func ( ) { c . m . Lock ( ) c . suspended = false c . m . Unlock ( ) } ) h . AppendHookOnBeforeUpdate ( func ( ) error { c . initedOnce . Do ( func ( ) { close ( c . inited ) } ) var err error theContextLock . Lock ( ) if theContext != nil { theContext . m . Lock ( ) err = theContext . err theContext . m . Unlock ( ) } theContextLock . Unlock ( ) return err } ) return c , nil }
// NewContext creates a new audio context with the given sample rate.
//
// The sample rate is also used for decoding MP3 with audio/mp3 package
// 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.
//
// NewContext panics when an audio context is already created.
NewContext creates a new audio context with the given sample rate . The sample rate is also used for decoding MP3 with audio / mp3 package 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 . NewContext panics when an audio context is already created .