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

Method startOnCOMThread

driver_wasapi_windows.go:195–315  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

193}
194
195func (c *wasapiContext) startOnCOMThread() (ferr error) {
196 if c.enumerator == nil {
197 e, err := _CoCreateInstance(&uuidMMDeviceEnumerator, nil, uint32(_CLSCTX_ALL), &uuidIMMDeviceEnumerator)
198 if err != nil {
199 return err
200 }
201 c.enumerator = (*_IMMDeviceEnumerator)(e)
202 defer func() {
203 if ferr != nil {
204 c.enumerator.Release()
205 c.enumerator = nil
206 }
207 }()
208 }
209
210 device, err := c.enumerator.GetDefaultAudioEndPoint(eRender, eConsole)
211 if err != nil {
212 if errors.Is(err, _E_NOTFOUND) {
213 return errDeviceNotFound
214 }
215 return err
216 }
217 defer device.Release()
218
219 id, err := device.GetId()
220 if err != nil {
221 return err
222 }
223 c.currentDeviceID = id
224
225 if c.client != nil {
226 c.client.Release()
227 c.client = nil
228 }
229
230 client, err := device.Activate(&uuidIAudioClient2, uint32(_CLSCTX_ALL), nil)
231 if err != nil {
232 return err
233 }
234 c.client = (*_IAudioClient2)(client)
235
236 if err := c.client.SetClientProperties(&_AudioClientProperties{
237 cbSize: uint32(unsafe.Sizeof(_AudioClientProperties{})),
238 bIsOffload: 0, // false
239 eCategory: _AudioCategory_Other, // In the example, AudioCategory_ForegroundOnlyMedia was used, but this value is deprecated.
240 }); err != nil {
241 return err
242 }
243
244 // Check the format is supported by WASAPI.
245 // Stereo with 48000 [Hz] is likely supported, but mono and/or other sample rates are unlikely supported.
246 // Fallback to WinMM in this case anyway.
247 const bitsPerSample = 32
248 nBlockAlign := c.channelCount * bitsPerSample / 8
249 var channelMask uint32
250 switch c.channelCount {
251 case 1:
252 channelMask = _SPEAKER_FRONT_CENTER

Callers 1

startMethod · 0.95

Calls 12

_CoCreateInstanceFunction · 0.85
_REFERENCE_TIMETypeAlias · 0.85
GetIdMethod · 0.80
ActivateMethod · 0.80
SetClientPropertiesMethod · 0.80
InitializeMethod · 0.80
GetBufferSizeMethod · 0.80
GetServiceMethod · 0.80
SetEventHandleMethod · 0.80
StartMethod · 0.80
ReleaseMethod · 0.45

Tested by

no test coverage detected