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

Method readAndWrite

driver_unix.go:214–239  ·  view source on GitHub ↗
(buf32 []float32)

Source from the content-addressed store, hash-verified

212}
213
214func (c *context) readAndWrite(buf32 []float32) bool {
215 c.cond.L.Lock()
216 defer c.cond.L.Unlock()
217
218 for c.suspended && c.err.Load() == nil {
219 c.cond.Wait()
220 }
221 if c.err.Load() != nil {
222 return false
223 }
224
225 c.mux.ReadFloat32s(buf32)
226
227 for len(buf32) > 0 {
228 n := C.snd_pcm_writei(c.handle, unsafe.Pointer(&buf32[0]), C.snd_pcm_uframes_t(len(buf32)/c.channelCount))
229 if n < 0 {
230 n = C.long(C.snd_pcm_recover(c.handle, C.int(n), 1))
231 }
232 if n < 0 {
233 c.err.TryStore(alsaError("snd_pcm_writei or snd_pcm_recover", C.int(n)))
234 return false
235 }
236 buf32 = buf32[int(n)*c.channelCount:]
237 }
238 return true
239}
240
241func (c *context) Suspend() error {
242 <-c.ready

Callers 1

newContextFunction · 0.95

Calls 4

alsaErrorFunction · 0.85
LoadMethod · 0.80
ReadFloat32sMethod · 0.80
TryStoreMethod · 0.80

Tested by

no test coverage detected