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

Function newContext

driver_windows.go:41–74  ·  view source on GitHub ↗
(sampleRate int, channelCount int, format mux.Format, bufferSizeInBytes int)

Source from the content-addressed store, hash-verified

39}
40
41func newContext(sampleRate int, channelCount int, format mux.Format, bufferSizeInBytes int) (*context, chan struct{}, error) {
42 ctx := &context{
43 sampleRate: sampleRate,
44 channelCount: channelCount,
45 mux: mux.New(sampleRate, channelCount, format),
46 ready: make(chan struct{}),
47 }
48
49 // Initializing drivers might take some time. Do this asynchronously.
50 go func() {
51 defer close(ctx.ready)
52
53 xc, err0 := newWASAPIContext(sampleRate, channelCount, ctx.mux, bufferSizeInBytes)
54 if err0 == nil {
55 ctx.wasapiContext = xc
56 return
57 }
58
59 wc, err1 := newWinMMContext(sampleRate, channelCount, ctx.mux, bufferSizeInBytes)
60 if err1 == nil {
61 ctx.winmmContext = wc
62 return
63 }
64
65 if errors.Is(err0, errDeviceNotFound) && errors.Is(err1, errDeviceNotFound) {
66 ctx.nullContext = newNullContext(sampleRate, channelCount, ctx.mux)
67 return
68 }
69
70 ctx.err.TryStore(fmt.Errorf("oto: initialization failed: WASAPI: %v, WinMM: %v", err0, err1))
71 }()
72
73 return ctx, ctx.ready, nil
74}
75
76func (c *context) Suspend() error {
77 <-c.ready

Callers

nothing calls this directly

Calls 5

NewFunction · 0.92
newWASAPIContextFunction · 0.85
newWinMMContextFunction · 0.85
newNullContextFunction · 0.85
TryStoreMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…