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

Method New

common/audio.go:78–131  ·  view source on GitHub ↗

New is called when the AudioSystem is added to the world.

(w *ecs.World)

Source from the content-addressed store, hash-verified

76
77// New is called when the AudioSystem is added to the world.
78func (a *AudioSystem) New(w *ecs.World) {
79 switch engo.CurrentBackEnd {
80 case engo.BackEndMobile:
81 a.bufsize = 12288
82 default:
83 a.bufsize = 8192
84 }
85 if engo.Headless() {
86 otoPlayer = &stepPlayer{
87 stepStart: make(chan []byte),
88 stepDone: make(chan struct{}, 1),
89 }
90 } else {
91 if otoPlayer == nil {
92 c, err := oto.NewContext(SampleRate, channelNum, bytesPerSample, a.bufsize)
93 if err != nil {
94 log.Printf("audio error. Unable to create new OtoContext: %v \n\r", err)
95 }
96
97 otoPlayer = c.NewPlayer()
98 } else {
99 closeCh <- struct{}{}
100 <-loopClosedCh
101 }
102 }
103 // run oto on a separate thread so it doesn't slow down updates
104 closeCh = make(chan struct{}, 1)
105 a.pauseCh = make(chan struct{}, 1)
106 a.restartCh = make(chan struct{}, 1)
107 a.playerCh = make(chan []*Player, 25)
108 loopClosedCh = make(chan struct{})
109 go func() {
110 players := make([]*Player, 0)
111 loop:
112 for {
113 select {
114 case <-closeCh:
115 break loop
116 case <-a.pauseCh:
117 <-a.restartCh
118 case players = <-a.playerCh:
119 default:
120 buf := make([]byte, 2048)
121 a.read(buf, players)
122
123 if _, err := otoPlayer.Write(buf); err != nil {
124 log.Printf("error copying to OtoPlayer: %v \r\n", err)
125 }
126 }
127 }
128 loopClosedCh <- struct{}{}
129 }()
130 masterVolume = 1
131}
132
133// Add adds an entity to the AudioSystem
134func (a *AudioSystem) Add(basic *ecs.BasicEntity, audio *AudioComponent) {

Callers 1

WriteMethod · 0.45

Calls 3

readMethod · 0.95
HeadlessFunction · 0.92
WriteMethod · 0.80

Tested by

no test coverage detected