| 181 | } |
| 182 | |
| 183 | func (c *context) appendBuffer(buf32 []float32) { |
| 184 | c.cond.L.Lock() |
| 185 | defer c.cond.L.Unlock() |
| 186 | |
| 187 | if c.err.Load() != nil { |
| 188 | return |
| 189 | } |
| 190 | |
| 191 | if c.toPause { |
| 192 | if err := c.pause(); err != nil { |
| 193 | c.err.TryStore(err) |
| 194 | } |
| 195 | c.toPause = false |
| 196 | return |
| 197 | } |
| 198 | |
| 199 | if c.toResume { |
| 200 | if err := c.resume(); err != nil { |
| 201 | c.err.TryStore(err) |
| 202 | } |
| 203 | c.toResume = false |
| 204 | return |
| 205 | } |
| 206 | |
| 207 | buf := c.unqueuedBuffers[0] |
| 208 | copy(c.unqueuedBuffers, c.unqueuedBuffers[1:]) |
| 209 | c.unqueuedBuffers = c.unqueuedBuffers[:len(c.unqueuedBuffers)-1] |
| 210 | |
| 211 | c.mux.ReadFloat32s(buf32) |
| 212 | copy(unsafe.Slice((*float32)(unsafe.Pointer(buf.mAudioData)), buf.mAudioDataByteSize/float32SizeInBytes), buf32) |
| 213 | |
| 214 | if osstatus := _AudioQueueEnqueueBuffer(c.audioQueue, buf, 0, nil); osstatus != noErr { |
| 215 | c.err.TryStore(fmt.Errorf("oto: AudioQueueEnqueueBuffer failed: %d", osstatus)) |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | func (c *context) Suspend() error { |
| 220 | c.cond.L.Lock() |