()
| 371 | } |
| 372 | |
| 373 | func (c *wasapiContext) writeOnRenderThread() error { |
| 374 | c.m.Lock() |
| 375 | defer c.m.Unlock() |
| 376 | |
| 377 | paddingFrames, err := c.client.GetCurrentPadding() |
| 378 | if err != nil { |
| 379 | return err |
| 380 | } |
| 381 | |
| 382 | frames := c.bufferFrames - paddingFrames |
| 383 | if frames <= 0 { |
| 384 | return nil |
| 385 | } |
| 386 | |
| 387 | // Get the destination buffer. |
| 388 | dstBuf, err := c.renderClient.GetBuffer(frames) |
| 389 | if err != nil { |
| 390 | return err |
| 391 | } |
| 392 | |
| 393 | // Calculate the buffer size. |
| 394 | if buflen := int(frames) * c.channelCount; cap(c.buf) < buflen { |
| 395 | c.buf = make([]float32, buflen) |
| 396 | } else { |
| 397 | c.buf = c.buf[:buflen] |
| 398 | } |
| 399 | |
| 400 | // Read the buffer from the players. |
| 401 | c.mux.ReadFloat32s(c.buf) |
| 402 | |
| 403 | // Copy the read buf to the destination buffer. |
| 404 | copy(unsafe.Slice((*float32)(unsafe.Pointer(dstBuf)), len(c.buf)), c.buf) |
| 405 | |
| 406 | // Release the buffer. |
| 407 | if err := c.renderClient.ReleaseBuffer(frames, 0); err != nil { |
| 408 | return err |
| 409 | } |
| 410 | |
| 411 | c.buf = c.buf[:0] |
| 412 | return nil |
| 413 | } |
| 414 | |
| 415 | func (c *wasapiContext) Suspend() error { |
| 416 | c.suspendedCond.L.Lock() |
no test coverage detected