MCPcopy
hub / github.com/ebitengine/oto / NewContext

Function NewContext

context.go:83–105  ·  view source on GitHub ↗

NewContext creates a new context with given options. A context creates and holds ready-to-use Player objects. NewContext returns a context, a channel that is closed when the context is ready, and an error if it exists. Creating multiple contexts is NOT supported.

(options *NewContextOptions)

Source from the content-addressed store, hash-verified

81//
82// Creating multiple contexts is NOT supported.
83func NewContext(options *NewContextOptions) (*Context, chan struct{}, error) {
84 contextCreationMutex.Lock()
85 defer contextCreationMutex.Unlock()
86
87 if contextCreated {
88 return nil, nil, fmt.Errorf("oto: context is already created")
89 }
90 contextCreated = true
91
92 var bufferSizeInBytes int
93 if options.BufferSize != 0 {
94 // The underying driver always uses 32bit floats.
95 bytesPerSample := options.ChannelCount * 4
96 bytesPerSecond := options.SampleRate * bytesPerSample
97 bufferSizeInBytes = int(int64(options.BufferSize) * int64(bytesPerSecond) / int64(time.Second))
98 bufferSizeInBytes = bufferSizeInBytes / bytesPerSample * bytesPerSample
99 }
100 ctx, ready, err := newContext(options.SampleRate, options.ChannelCount, mux.Format(options.Format), bufferSizeInBytes)
101 if err != nil {
102 return nil, nil, err
103 }
104 return &Context{context: ctx}, ready, nil
105}
106
107// NewPlayer creates a new, ready-to-use Player belonging to the Context.
108// It is safe to create multiple players.

Callers

nothing calls this directly

Calls 2

FormatTypeAlias · 0.92
newContextFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…