MCPcopy Index your code
hub / github.com/EngoEngine/engo / read

Method read

common/audio.go:176–219  ·  view source on GitHub ↗

Read reads from all the currently playing entities and combines them into a single stream that is passed to the oto player.

(b []byte, players []*Player)

Source from the content-addressed store, hash-verified

174// Read reads from all the currently playing entities and combines them into a
175// single stream that is passed to the oto player.
176func (a *AudioSystem) read(b []byte, players []*Player) (int, error) {
177 l := len(b)
178 l &= mask
179
180 if len(players) == 0 {
181 copy(b, make([]byte, l))
182 return l, nil
183 }
184
185 b16s := [][]int16{}
186 for _, player := range players {
187 buf, err := player.bufferToInt16(l)
188 if err != nil {
189 return 0, err
190 }
191 b16s = append(b16s, buf)
192 }
193 for i := 0; i < l/2; i++ {
194 x := 0
195 for _, b16 := range b16s {
196 x += int(b16[i])
197 }
198 if x > (1<<15)-1 {
199 x = (1 << 15) - 1
200 }
201 if x < -(1 << 15) {
202 x = -(1 << 15)
203 }
204 b[2*i] = byte(x)
205 b[2*i+1] = byte(x >> 8)
206 }
207
208 for _, player := range players {
209 if player.eof() {
210 if player.Repeat {
211 player.Rewind()
212 } else {
213 player.Pause()
214 }
215 }
216 }
217
218 return l, nil
219}
220
221// Close closes the AudioSystem's loop. After this is called the AudioSystem
222// can no longer play audio.

Callers 1

NewMethod · 0.95

Calls 4

bufferToInt16Method · 0.80
eofMethod · 0.80
RewindMethod · 0.80
PauseMethod · 0.45

Tested by

no test coverage detected